@lukoweb/apitogo-plugin-dev-portal-billing 0.2.87 → 0.2.89

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.
@@ -1,9 +1,9 @@
1
1
  import { r as useDevPortalBillingConfig } from "./DevPortalBillingContext-BUQPLoyk.mjs";
2
- import { l as isActiveSubscription, m as parseManifestPlans, n as useDevPortalPreviewMode, r as useIsDemoSession, t as useDevPortalApiBaseUrl, x as withPlanFeatures } from "./useDevPortalApiBaseUrl-DwObxX8r.mjs";
3
- import { t as PricingCard } from "./PricingCard-CRH9rxT3.mjs";
2
+ import { S as withPlanFeatures, l as isActiveSubscription, m as parseManifestPlans, n as useDevPortalPreviewMode, r as useIsDemoSession, t as useDevPortalApiBaseUrl } from "./useDevPortalApiBaseUrl-yoRfy0c_.mjs";
3
+ import { t as PricingCard } from "./PricingCard-1t_3YoIl.mjs";
4
4
  import { n as readProblemDetail } from "./problem-details-n20-dy3w.mjs";
5
- import { t as useMySubscriptions } from "./useMySubscriptions-CfZPpul6.mjs";
6
- import { t as usePlans } from "./usePlans-CRFHBOqz.mjs";
5
+ import { t as useMySubscriptions } from "./useMySubscriptions-B0gv3zwT.mjs";
6
+ import { t as usePlans } from "./usePlans-BpZhGMU-.mjs";
7
7
  import { n as readPendingCheckout, t as clearPendingCheckout } from "./pending-checkout-DpVaNnTu.mjs";
8
8
  import { Head } from "@lukoweb/apitogo/components";
9
9
  import { CreditCardIcon } from "@lukoweb/apitogo/icons";
@@ -1,8 +1,8 @@
1
1
  import { n as ALREADY_SUBSCRIBED_PARAM, s as PRICING_PATH, t as ACCOUNT_PLANS_PATH } from "./paths-DBr3Dj_q.mjs";
2
- import { n as useDevPortalPreviewMode, r as useIsDemoSession, t as useDevPortalApiBaseUrl } from "./useDevPortalApiBaseUrl-DwObxX8r.mjs";
2
+ import { n as useDevPortalPreviewMode, r as useIsDemoSession, t as useDevPortalApiBaseUrl } from "./useDevPortalApiBaseUrl-yoRfy0c_.mjs";
3
3
  import { n as readProblemDetail, t as isAlreadySubscribedMessage } from "./problem-details-n20-dy3w.mjs";
4
4
  import { r as rememberPendingCheckout } from "./pending-checkout-DpVaNnTu.mjs";
5
- import { t as FREE_CHECKOUT_MARKER } from "./billing-state-Dal_UzOQ.mjs";
5
+ import { t as FREE_CHECKOUT_MARKER } from "./billing-state-Dxiqz95K.mjs";
6
6
  import { ShieldIcon } from "@lukoweb/apitogo/icons";
7
7
  import { Link, useNavigate, useSearchParams } from "@lukoweb/apitogo/router";
8
8
  import { useEffect } from "react";
@@ -1,8 +1,8 @@
1
1
  import "./DevPortalBillingContext-BUQPLoyk.mjs";
2
2
  import { s as PRICING_PATH } from "./paths-DBr3Dj_q.mjs";
3
- import { d as isPlanCustomPriced, n as useDevPortalPreviewMode, r as useIsDemoSession, t as useDevPortalApiBaseUrl } from "./useDevPortalApiBaseUrl-DwObxX8r.mjs";
3
+ import { d as isPlanCustomPriced, n as useDevPortalPreviewMode, r as useIsDemoSession, t as useDevPortalApiBaseUrl } from "./useDevPortalApiBaseUrl-yoRfy0c_.mjs";
4
4
  import { n as readProblemDetail } from "./problem-details-n20-dy3w.mjs";
5
- import { t as usePlans } from "./usePlans-CRFHBOqz.mjs";
5
+ import { t as usePlans } from "./usePlans-BpZhGMU-.mjs";
6
6
  import { Link, useSearchParams } from "@lukoweb/apitogo/router";
7
7
  import { useState } from "react";
8
8
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -1,9 +1,9 @@
1
1
  import { r as useDevPortalBillingConfig } from "./DevPortalBillingContext-BUQPLoyk.mjs";
2
2
  import { t as ACCOUNT_PLANS_PATH } from "./paths-DBr3Dj_q.mjs";
3
- import { n as useDevPortalPreviewMode, r as useIsDemoSession, t as useDevPortalApiBaseUrl } from "./useDevPortalApiBaseUrl-DwObxX8r.mjs";
3
+ import { n as useDevPortalPreviewMode, r as useIsDemoSession, t as useDevPortalApiBaseUrl } from "./useDevPortalApiBaseUrl-yoRfy0c_.mjs";
4
4
  import { r as createDemoCredentials, t as DEMO_GATEWAY_KEY_HEADER } from "./demo-session-yK9qEqV-.mjs";
5
- import { n as useApiKeys } from "./useApiKeys-CS2SmfJc.mjs";
6
- import { n as apiReferencePath, r as ApiKeysPanel } from "./account-links-QGu5q_vP.mjs";
5
+ import { n as useApiKeys } from "./useApiKeys-BbGhwIcK.mjs";
6
+ import { n as apiReferencePath, r as ApiKeysPanel } from "./account-links-CabbpN7u.mjs";
7
7
  import { i as ChoosePlanNotice, r as keyPlanNote, t as apiKeysPageState } from "./page-state-Cmo0FPLl.mjs";
8
8
  import { Head } from "@lukoweb/apitogo/components";
9
9
  import { KeyRoundIcon } from "@lukoweb/apitogo/icons";
@@ -1,6 +1,6 @@
1
1
  import { r as useDevPortalBillingConfig } from "./DevPortalBillingContext-BUQPLoyk.mjs";
2
2
  import { i as CONTACT_SALES_PATH, r as CHECKOUT_PATH } from "./paths-DBr3Dj_q.mjs";
3
- import { a as formatMoney, c as formatPlanPriceUnit, d as isPlanCustomPriced, f as isPlanFree, i as formatBillingPeriod, l as isActiveSubscription, o as formatPlanDisplayPrice, p as listPlanFeatureLines } from "./useDevPortalApiBaseUrl-DwObxX8r.mjs";
3
+ import { a as formatMoney, c as formatPlanPriceUnit, d as isPlanCustomPriced, f as isPlanFree, i as formatBillingPeriod, l as isActiveSubscription, o as formatPlanDisplayPrice, p as listPlanFeatureLines } from "./useDevPortalApiBaseUrl-yoRfy0c_.mjs";
4
4
  import { Button } from "@lukoweb/apitogo/components";
5
5
  import { Link as Link$1 } from "@lukoweb/apitogo/router";
6
6
  import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "@lukoweb/apitogo/ui/AlertDialog.js";
@@ -1,10 +1,10 @@
1
1
  import { r as useDevPortalBillingConfig } from "./DevPortalBillingContext-BUQPLoyk.mjs";
2
- import { _ as pickFeaturedPlanSku, a as formatMoney, f as isPlanFree, i as formatBillingPeriod, m as parseManifestPlans, n as useDevPortalPreviewMode, x as withPlanFeatures } from "./useDevPortalApiBaseUrl-DwObxX8r.mjs";
3
- import { t as PricingCard } from "./PricingCard-CRH9rxT3.mjs";
4
- import { t as usePlans } from "./usePlans-CRFHBOqz.mjs";
2
+ import { S as withPlanFeatures, _ as pickFeaturedPlanSku, a as formatMoney, f as isPlanFree, i as formatBillingPeriod, m as parseManifestPlans, n as useDevPortalPreviewMode } from "./useDevPortalApiBaseUrl-yoRfy0c_.mjs";
3
+ import { t as PricingCard } from "./PricingCard-1t_3YoIl.mjs";
4
+ import { t as usePlans } from "./usePlans-BpZhGMU-.mjs";
5
5
  import { t as isPreviewPricingEnabled } from "./pricing-config-Bc6eWFUO.mjs";
6
- import { a as isPricingLoading, n as buildCompareRows } from "./billing-state-Dal_UzOQ.mjs";
7
- import { a as featuredSkuForPeriod, i as discountFor, n as addOnPriceFor, o as plansForPeriod, r as availablePeriods, s as savingsLabel, t as PERIOD_LABELS } from "./billing-period-C2PIOhfT.mjs";
6
+ import { a as isPricingLoading, n as buildCompareRows } from "./billing-state-Dxiqz95K.mjs";
7
+ import { a as featuredSkuForPeriod, i as discountFor, n as addOnPriceFor, o as plansForPeriod, r as availablePeriods, s as savingsLabel, t as PERIOD_LABELS } from "./billing-period-d5mtqePH.mjs";
8
8
  import { Head, Heading } from "@lukoweb/apitogo/components";
9
9
  import { Navigate } from "@lukoweb/apitogo/router";
10
10
  import { useState } from "react";
@@ -1,15 +1,15 @@
1
1
  import { r as useDevPortalBillingConfig } from "./DevPortalBillingContext-BUQPLoyk.mjs";
2
2
  import { a as CREDENTIALS_PATH, n as ALREADY_SUBSCRIBED_PARAM, t as ACCOUNT_PLANS_PATH } from "./paths-DBr3Dj_q.mjs";
3
- import { a as formatMoney, f as isPlanFree, h as parseMonthlyQuotaCalls, i as formatBillingPeriod, l as isActiveSubscription, n as useDevPortalPreviewMode, r as useIsDemoSession, s as formatPlanPrice, t as useDevPortalApiBaseUrl } from "./useDevPortalApiBaseUrl-DwObxX8r.mjs";
3
+ import { a as formatMoney, f as isPlanFree, h as parseMonthlyQuotaCalls, i as formatBillingPeriod, l as isActiveSubscription, n as useDevPortalPreviewMode, r as useIsDemoSession, s as formatPlanPrice, t as useDevPortalApiBaseUrl } from "./useDevPortalApiBaseUrl-yoRfy0c_.mjs";
4
4
  import { n as readProblemDetail } from "./problem-details-n20-dy3w.mjs";
5
- import { t as useMySubscriptions } from "./useMySubscriptions-CfZPpul6.mjs";
6
- import { t as usePlans } from "./usePlans-CRFHBOqz.mjs";
5
+ import { t as useMySubscriptions } from "./useMySubscriptions-B0gv3zwT.mjs";
6
+ import { t as usePlans } from "./usePlans-BpZhGMU-.mjs";
7
7
  import { n as readPendingCheckout, t as clearPendingCheckout } from "./pending-checkout-DpVaNnTu.mjs";
8
- import { n as useApiKeys } from "./useApiKeys-CS2SmfJc.mjs";
9
- import { t as useUsage } from "./useUsage-DqizlLwt.mjs";
10
- import { i as hasPaymentProvider, r as checkoutConfirmingText } from "./billing-state-Dal_UzOQ.mjs";
8
+ import { n as useApiKeys } from "./useApiKeys-BbGhwIcK.mjs";
9
+ import { t as useUsage } from "./useUsage-lRPa-4sI.mjs";
10
+ import { i as hasPaymentProvider, r as checkoutConfirmingText } from "./billing-state-Dxiqz95K.mjs";
11
11
  import { i as ChoosePlanNotice, n as billingPageState, r as keyPlanNote } from "./page-state-Cmo0FPLl.mjs";
12
- import { n as addOnPriceFor } from "./billing-period-C2PIOhfT.mjs";
12
+ import { n as addOnPriceFor } from "./billing-period-d5mtqePH.mjs";
13
13
  import { Head, Spinner } from "@lukoweb/apitogo/components";
14
14
  import { Link as Link$1, useSearchParams } from "@lukoweb/apitogo/router";
15
15
  import { useEffect } from "react";
@@ -1,8 +1,8 @@
1
1
  import "./DevPortalBillingContext-BUQPLoyk.mjs";
2
- import { g as parseQuotaPeriodDays, h as parseMonthlyQuotaCalls, l as isActiveSubscription } from "./useDevPortalApiBaseUrl-DwObxX8r.mjs";
3
- import { t as useMySubscriptions } from "./useMySubscriptions-CfZPpul6.mjs";
4
- import { t as usePlans } from "./usePlans-CRFHBOqz.mjs";
5
- import { n as useUsageRecent, t as useUsage } from "./useUsage-DqizlLwt.mjs";
2
+ import { g as parseQuotaPeriodDays, h as parseMonthlyQuotaCalls, l as isActiveSubscription } from "./useDevPortalApiBaseUrl-yoRfy0c_.mjs";
3
+ import { t as useMySubscriptions } from "./useMySubscriptions-B0gv3zwT.mjs";
4
+ import { t as usePlans } from "./usePlans-BpZhGMU-.mjs";
5
+ import { n as useUsageRecent, t as useUsage } from "./useUsage-lRPa-4sI.mjs";
6
6
  import { Head } from "@lukoweb/apitogo/components";
7
7
  import { Link as Link$1 } from "@lukoweb/apitogo/router";
8
8
  import { useState } from "react";
@@ -48,6 +48,13 @@ function endpointLabel(label) {
48
48
  function blockedCount(byStatus) {
49
49
  return byStatus.filter((item) => item.label === "429").reduce((sum, item) => sum + item.count, 0);
50
50
  }
51
+ /**
52
+ * Calls that count toward the plan's quota: every call except those the gateway refused with 429. The gateway's quota
53
+ * leaves 429s out (a customer who keeps calling past the rate limit does not use it up), so the quota card must too.
54
+ */
55
+ function quotaCountedCalls(usage) {
56
+ return Math.max(0, usage.requestCount - blockedCount(usage.byStatus));
57
+ }
51
58
  /** The middle latency of the given calls, or null without any. A slow outlier moves it less than an average. */
52
59
  function medianLatency(latencies) {
53
60
  const values = latencies.filter((value) => typeof value === "number").sort((a, b) => a - b);
@@ -96,7 +103,7 @@ const UsagePage = () => {
96
103
  const plan = subscription ? catalog?.plans.find((item) => item.sku === subscription.planSku) : void 0;
97
104
  const quota = plan ? parseMonthlyQuotaCalls(plan.limitsJson) : null;
98
105
  const periodDays = plan ? parseQuotaPeriodDays(plan.limitsJson) : null;
99
- const summary = quota != null && periodDays != null ? quotaSummary(quotaUsage?.requestCount ?? 0, quota, periodDays, subscription?.currentPeriodEnd) : null;
106
+ const summary = quota != null && periodDays != null ? quotaSummary(quotaUsage ? quotaCountedCalls(quotaUsage) : 0, quota, periodDays, subscription?.currentPeriodEnd) : null;
100
107
  const maxBar = Math.max(1, ...data?.series.map((point) => point.requestCount) ?? [1]);
101
108
  const endpointTotal = data?.byEndpoint.reduce((sum, item) => sum + item.count, 0) ?? 0;
102
109
  if (!auth.isAuthenticated) return /* @__PURE__ */ jsxs("div", {
@@ -1,4 +1,4 @@
1
- import { i as useRevokeApiKey, r as useCreateApiKey, t as API_KEY_CAP_REACHED } from "./useApiKeys-CS2SmfJc.mjs";
1
+ import { i as useRevokeApiKey, r as useCreateApiKey, t as API_KEY_CAP_REACHED } from "./useApiKeys-BbGhwIcK.mjs";
2
2
  import { Spinner } from "@lukoweb/apitogo/components";
3
3
  import { KeyRoundIcon, TrashIcon } from "@lukoweb/apitogo/icons";
4
4
  import { useEffect, useState } from "react";
@@ -1,4 +1,4 @@
1
- import { d as isPlanCustomPriced, f as isPlanFree } from "./useDevPortalApiBaseUrl-DwObxX8r.mjs";
1
+ import { d as isPlanCustomPriced, f as isPlanFree } from "./useDevPortalApiBaseUrl-yoRfy0c_.mjs";
2
2
 
3
3
  //#region src/utils/billing-period.ts
4
4
  const PRICING_PERIODS = [
@@ -1,4 +1,4 @@
1
- import { v as quotaCell, y as rateLimitCell } from "./useDevPortalApiBaseUrl-DwObxX8r.mjs";
1
+ import { v as quotaCell, x as tokenLimitCell, y as rateLimitCell } from "./useDevPortalApiBaseUrl-yoRfy0c_.mjs";
2
2
 
3
3
  //#region src/utils/billing-state.ts
4
4
  /** Whether the pricing page has no plans to show yet because the answer is still on its way. */
@@ -31,13 +31,20 @@ const FREE_CHECKOUT_MARKER = "paid=0";
31
31
  function buildCompareRows(input) {
32
32
  if (input.configuredRows && input.configuredRows.length > 0) return input.configuredRows;
33
33
  if (input.plans.length === 0) return input.isPreview ? input.sampleRows : [];
34
- return [{
35
- label: "Request quota",
36
- values: input.plans.map((plan) => quotaCell(plan.limitsJson) ?? "—")
37
- }, {
38
- label: "Rate limit",
39
- values: input.plans.map((plan) => rateLimitCell(plan.limitsJson) ?? "—")
40
- }].filter((row) => row.values.some((value) => value !== "—"));
34
+ return [
35
+ {
36
+ label: "Request quota",
37
+ values: input.plans.map((plan) => quotaCell(plan.limitsJson) ?? "—")
38
+ },
39
+ {
40
+ label: "Rate limit",
41
+ values: input.plans.map((plan) => rateLimitCell(plan.limitsJson) ?? "—")
42
+ },
43
+ {
44
+ label: "AI token limit",
45
+ values: input.plans.map((plan) => tokenLimitCell(plan.limitsJson) ?? "—")
46
+ }
47
+ ].filter((row) => row.values.some((value) => value !== "—"));
41
48
  }
42
49
 
43
50
  //#endregion
package/dist/index.mjs CHANGED
@@ -1,15 +1,15 @@
1
- import { t as AccountPlansPage } from "./AccountPlansPage-B4gb0WvB.mjs";
1
+ import { t as AccountPlansPage } from "./AccountPlansPage-DOKNdfsT.mjs";
2
2
  import { n as registerDevPortalBillingOptions, r as useDevPortalBillingConfig, t as DevPortalBillingProvider } from "./DevPortalBillingContext-BUQPLoyk.mjs";
3
3
  import { a as CREDENTIALS_PATH, c as SUBSCRIPTIONS_PATH, i as CONTACT_SALES_PATH, l as USAGE_PATH, o as LOGIN_NAV_PATH, r as CHECKOUT_PATH, s as PRICING_PATH, t as ACCOUNT_PLANS_PATH } from "./paths-DBr3Dj_q.mjs";
4
- import { _ as pickFeaturedPlanSku, b as resolveDevPortalApiBaseUrl, c as formatPlanPriceUnit, l as isActiveSubscription, m as parseManifestPlans, o as formatPlanDisplayPrice, p as listPlanFeatureLines } from "./useDevPortalApiBaseUrl-DwObxX8r.mjs";
5
- import "./PricingCard-CRH9rxT3.mjs";
4
+ import { _ as pickFeaturedPlanSku, b as resolveDevPortalApiBaseUrl, c as formatPlanPriceUnit, l as isActiveSubscription, m as parseManifestPlans, o as formatPlanDisplayPrice, p as listPlanFeatureLines } from "./useDevPortalApiBaseUrl-yoRfy0c_.mjs";
5
+ import "./PricingCard-1t_3YoIl.mjs";
6
6
  import { t as DEMO_GATEWAY_KEY_HEADER } from "./demo-session-yK9qEqV-.mjs";
7
- import { t as useMySubscriptions } from "./useMySubscriptions-CfZPpul6.mjs";
8
- import { n as startPlansPrefetch, t as usePlans } from "./usePlans-CRFHBOqz.mjs";
7
+ import { t as useMySubscriptions } from "./useMySubscriptions-B0gv3zwT.mjs";
8
+ import { n as startPlansPrefetch, t as usePlans } from "./usePlans-BpZhGMU-.mjs";
9
9
  import "./pending-checkout-DpVaNnTu.mjs";
10
- import { a as playgroundKeyIdentities, i as useRevokeApiKey, n as useApiKeys, r as useCreateApiKey, t as API_KEY_CAP_REACHED } from "./useApiKeys-CS2SmfJc.mjs";
11
- import { n as useUsageRecent, t as useUsage } from "./useUsage-DqizlLwt.mjs";
12
- import { r as ApiKeysPanel, t as accountLayoutProps } from "./account-links-QGu5q_vP.mjs";
10
+ import { a as playgroundKeyIdentities, i as useRevokeApiKey, n as useApiKeys, r as useCreateApiKey, t as API_KEY_CAP_REACHED } from "./useApiKeys-BbGhwIcK.mjs";
11
+ import { n as useUsageRecent, t as useUsage } from "./useUsage-lRPa-4sI.mjs";
12
+ import { r as ApiKeysPanel, t as accountLayoutProps } from "./account-links-CabbpN7u.mjs";
13
13
  import { t as isPreviewPricingEnabled } from "./pricing-config-Bc6eWFUO.mjs";
14
14
  import { Head, Link } from "@lukoweb/apitogo/components";
15
15
  import { ArrowRightIcon, KeyRoundIcon, StarsIcon } from "@lukoweb/apitogo/icons";
@@ -367,13 +367,13 @@ async function getSignedInIdentities(apiBaseUrl, fetchImpl = fetch) {
367
367
 
368
368
  //#endregion
369
369
  //#region src/DevPortalBillingPlugin.tsx
370
- const AccountPlansPage$1 = lazy(() => import("./AccountPlansPage-B4gb0WvB.mjs").then((n) => n.n));
371
- const CheckoutPage = lazy(() => import("./CheckoutPage-Bom6gjGC.mjs"));
372
- const ContactSalesPage = lazy(() => import("./ContactSalesPage-DvqVqsuC.mjs"));
373
- const CredentialsPage = lazy(() => import("./CredentialsPage-BH8xLVnt.mjs"));
374
- const PricingPage = lazy(() => import("./PricingPage-DJwl2XAp.mjs"));
375
- const SubscriptionsPage = lazy(() => import("./SubscriptionsPage-d5gWSBMr.mjs"));
376
- const UsagePage = lazy(() => import("./UsagePage-lPOEWUOG.mjs"));
370
+ const AccountPlansPage$1 = lazy(() => import("./AccountPlansPage-DOKNdfsT.mjs").then((n) => n.n));
371
+ const CheckoutPage = lazy(() => import("./CheckoutPage-DlbQUHUl.mjs"));
372
+ const ContactSalesPage = lazy(() => import("./ContactSalesPage-cdJA7B-J.mjs"));
373
+ const CredentialsPage = lazy(() => import("./CredentialsPage-CZRT8Wx8.mjs"));
374
+ const PricingPage = lazy(() => import("./PricingPage-ffIoVEQf.mjs"));
375
+ const SubscriptionsPage = lazy(() => import("./SubscriptionsPage-BFGL0Ruo.mjs"));
376
+ const UsagePage = lazy(() => import("./UsagePage-BtB0OSOP.mjs"));
377
377
  function resolvePricingEnabled(config) {
378
378
  if (config.__meta?.pricingEnabled !== void 0) return config.__meta.pricingEnabled;
379
379
  return isPreviewPricingEnabled();
@@ -1,5 +1,5 @@
1
1
  import { r as useDevPortalBillingConfig } from "./DevPortalBillingContext-BUQPLoyk.mjs";
2
- import { n as useDevPortalPreviewMode, r as useIsDemoSession, t as useDevPortalApiBaseUrl } from "./useDevPortalApiBaseUrl-DwObxX8r.mjs";
2
+ import { n as useDevPortalPreviewMode, r as useIsDemoSession, t as useDevPortalApiBaseUrl } from "./useDevPortalApiBaseUrl-yoRfy0c_.mjs";
3
3
  import { n as readProblemDetail } from "./problem-details-n20-dy3w.mjs";
4
4
  import { n as createDemoApiKeys, t as DEMO_GATEWAY_KEY_HEADER } from "./demo-session-yK9qEqV-.mjs";
5
5
  import { useMutation, useQuery, useQueryClient } from "@lukoweb/apitogo/react-query";
@@ -2,6 +2,55 @@ import manifestCatalog from "virtual:apitogo-local-manifest";
2
2
  import zudokuConfig from "virtual:zudoku-config";
3
3
  import { useAuth } from "@lukoweb/apitogo/hooks";
4
4
 
5
+ //#region src/utils/token-limits.ts
6
+ const PERIOD_WORD = {
7
+ hour: "hour",
8
+ day: "day",
9
+ week: "week",
10
+ month: "month",
11
+ year: "year"
12
+ };
13
+ function endpoint(actionKey) {
14
+ const separator = actionKey.indexOf(":");
15
+ return separator <= 0 ? actionKey : `${actionKey.slice(0, separator).toUpperCase()} ${actionKey.slice(separator + 1)}`;
16
+ }
17
+ function operationsOf(limits) {
18
+ const tokenLimit = limits?.tokenLimit;
19
+ if (!tokenLimit || typeof tokenLimit !== "object") return [];
20
+ const operations = tokenLimit.operations;
21
+ if (!operations || typeof operations !== "object") return [];
22
+ return Object.entries(operations).filter((entry) => !!entry[1] && typeof entry[1] === "object").sort(([a], [b]) => a.localeCompare(b));
23
+ }
24
+ function parts(limit, style) {
25
+ const out = [];
26
+ if (typeof limit.tokensPerMinute === "number" && limit.tokensPerMinute > 0) {
27
+ const n = limit.tokensPerMinute.toLocaleString("en-US");
28
+ out.push(style === "line" ? `${n} tokens per minute` : `${n} / min`);
29
+ }
30
+ if (typeof limit.tokenQuota === "number" && limit.tokenQuota > 0) {
31
+ const n = limit.tokenQuota.toLocaleString("en-US");
32
+ const period = PERIOD_WORD[(limit.tokenQuotaPeriod ?? "").toLowerCase()];
33
+ const per = period ? ` / ${period}` : "";
34
+ out.push(style === "line" ? `${n} tokens${per}` : `${n}${per}`);
35
+ }
36
+ return out;
37
+ }
38
+ /** One card line per limited endpoint: "20,000 tokens per minute and 2,000,000 tokens / month on POST /chat". */
39
+ function tokenLimitLines(limits) {
40
+ return operationsOf(limits).flatMap(([actionKey, limit]) => {
41
+ const text = parts(limit, "line");
42
+ return text.length === 0 ? [] : [`${text.join(" and ")} on ${endpoint(actionKey)}`];
43
+ });
44
+ }
45
+ /** The token limits as a short table cell ("20,000 / min, 2,000,000 / month"), naming the endpoint when there are several. */
46
+ function tokenLimitCellOf(limits) {
47
+ const cells = operationsOf(limits).map(([actionKey, limit]) => [actionKey, parts(limit, "cell")]).filter(([, text]) => text.length > 0);
48
+ if (cells.length === 0) return null;
49
+ if (cells.length === 1) return cells[0][1].join(", ");
50
+ return cells.map(([actionKey, text]) => `${endpoint(actionKey)}: ${text.join(", ")}`).join("; ");
51
+ }
52
+
53
+ //#endregion
5
54
  //#region src/utils/dev-portal-api.ts
6
55
  const DEV_PORTAL_PLACEHOLDER_API_URL = "https://dp-example.azurecontainerapps.io";
7
56
  function resolveDevPortalApiBaseUrl(configuredUrl) {
@@ -158,9 +207,11 @@ function formatQuota(quota) {
158
207
  const limit = quota;
159
208
  const calls = limit.calls;
160
209
  const renewalPeriodDays = limit.renewalPeriodDays ?? limit.periodDays;
210
+ const renewalPeriodHours = limit.renewalPeriodHours ?? limit.periodHours;
161
211
  if (calls == null) return null;
162
212
  if (calls < 0) return "Unlimited requests";
163
213
  const formatted = calls.toLocaleString();
214
+ if (renewalPeriodHours != null && renewalPeriodHours > 0) return renewalPeriodHours === 1 ? `${formatted} requests / hour` : `${formatted} requests / ${renewalPeriodHours} hours`;
164
215
  if (renewalPeriodDays === 30 || renewalPeriodDays === 31) return `${formatted} requests / month`;
165
216
  if (renewalPeriodDays === 1) return `${formatted} requests / day`;
166
217
  if (renewalPeriodDays != null) return `${formatted} requests / ${renewalPeriodDays} days`;
@@ -191,6 +242,10 @@ function rateLimitCell(limitsJson) {
191
242
  if (renewalPeriodSeconds === 3600) return `${formatted} / hour`;
192
243
  return `${formatted} / ${renewalPeriodSeconds} sec`;
193
244
  }
245
+ /** The LLM token limits of a plan as a short table cell, or null when the plan has none. */
246
+ function tokenLimitCell(limitsJson) {
247
+ return tokenLimitCellOf(parseLimits(limitsJson));
248
+ }
194
249
  function parseLimits(limitsJson) {
195
250
  if (!limitsJson?.trim()) return null;
196
251
  try {
@@ -228,6 +283,7 @@ function listPlanFeatureLines(plan, options = {}) {
228
283
  if (quotaLine) lines.push(quotaLine);
229
284
  const rateLine = formatRateLimit(limits.rateLimit);
230
285
  if (rateLine) lines.push(rateLine);
286
+ lines.push(...tokenLimitLines(limits));
231
287
  } catch {}
232
288
  for (const feature of plan.features ?? []) if (!lines.includes(feature)) lines.push(feature);
233
289
  const extras = plan.features?.length ? void 0 : SAMPLE_PLAN_FEATURE_EXTRAS[plan.sku.toLowerCase()];
@@ -287,4 +343,4 @@ function useDevPortalPreviewMode() {
287
343
  }
288
344
 
289
345
  //#endregion
290
- export { pickFeaturedPlanSku as _, formatMoney as a, resolveDevPortalApiBaseUrl as b, formatPlanPriceUnit as c, isPlanCustomPriced as d, isPlanFree as f, parseQuotaPeriodDays as g, parseMonthlyQuotaCalls as h, formatBillingPeriod as i, isActiveSubscription as l, parseManifestPlans as m, useDevPortalPreviewMode as n, formatPlanDisplayPrice as o, listPlanFeatureLines as p, useIsDemoSession as r, formatPlanPrice as s, useDevPortalApiBaseUrl as t, isPlaceholderDevPortalApiUrl as u, quotaCell as v, withPlanFeatures as x, rateLimitCell as y };
346
+ export { withPlanFeatures as S, pickFeaturedPlanSku as _, formatMoney as a, resolveDevPortalApiBaseUrl as b, formatPlanPriceUnit as c, isPlanCustomPriced as d, isPlanFree as f, parseQuotaPeriodDays as g, parseMonthlyQuotaCalls as h, formatBillingPeriod as i, isActiveSubscription as l, parseManifestPlans as m, useDevPortalPreviewMode as n, formatPlanDisplayPrice as o, listPlanFeatureLines as p, useIsDemoSession as r, formatPlanPrice as s, useDevPortalApiBaseUrl as t, isPlaceholderDevPortalApiUrl as u, quotaCell as v, tokenLimitCell as x, rateLimitCell as y };
@@ -1,5 +1,5 @@
1
1
  import { r as useDevPortalBillingConfig } from "./DevPortalBillingContext-BUQPLoyk.mjs";
2
- import { n as useDevPortalPreviewMode, r as useIsDemoSession, t as useDevPortalApiBaseUrl } from "./useDevPortalApiBaseUrl-DwObxX8r.mjs";
2
+ import { n as useDevPortalPreviewMode, r as useIsDemoSession, t as useDevPortalApiBaseUrl } from "./useDevPortalApiBaseUrl-yoRfy0c_.mjs";
3
3
  import { i as createDemoMeResponse } from "./demo-session-yK9qEqV-.mjs";
4
4
  import { useQuery } from "@lukoweb/apitogo/react-query";
5
5
  import { useAuth } from "@lukoweb/apitogo/hooks";
@@ -1,5 +1,5 @@
1
1
  import { r as useDevPortalBillingConfig } from "./DevPortalBillingContext-BUQPLoyk.mjs";
2
- import { m as parseManifestPlans, n as useDevPortalPreviewMode, r as useIsDemoSession, t as useDevPortalApiBaseUrl, u as isPlaceholderDevPortalApiUrl, x as withPlanFeatures } from "./useDevPortalApiBaseUrl-DwObxX8r.mjs";
2
+ import { S as withPlanFeatures, m as parseManifestPlans, n as useDevPortalPreviewMode, r as useIsDemoSession, t as useDevPortalApiBaseUrl, u as isPlaceholderDevPortalApiUrl } from "./useDevPortalApiBaseUrl-yoRfy0c_.mjs";
3
3
  import { useQuery } from "@lukoweb/apitogo/react-query";
4
4
 
5
5
  //#region src/utils/plans-prefetch.ts
@@ -1,4 +1,4 @@
1
- import { n as useDevPortalPreviewMode, r as useIsDemoSession, t as useDevPortalApiBaseUrl } from "./useDevPortalApiBaseUrl-DwObxX8r.mjs";
1
+ import { n as useDevPortalPreviewMode, r as useIsDemoSession, t as useDevPortalApiBaseUrl } from "./useDevPortalApiBaseUrl-yoRfy0c_.mjs";
2
2
  import { useQuery } from "@lukoweb/apitogo/react-query";
3
3
  import { useAuth } from "@lukoweb/apitogo/hooks";
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lukoweb/apitogo-plugin-dev-portal-billing",
3
- "version": "0.2.87",
3
+ "version": "0.2.89",
4
4
  "homepage": "https://docs.apitogo.com",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",
@@ -42,8 +42,8 @@
42
42
  "react": "19.2.4",
43
43
  "react-dom": "19.2.4",
44
44
  "tsdown": "0.20.3",
45
- "@lukoweb/apitogo": "0.2.87",
46
- "@lukoweb/apitogo-module-user-panel": "0.2.87"
45
+ "@lukoweb/apitogo": "0.2.89",
46
+ "@lukoweb/apitogo-module-user-panel": "0.2.89"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "react": ">=19.2.0",