@zuplo/zudoku-plugin-monetization 0.0.36 → 0.0.38

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.
@@ -486,7 +486,7 @@ const PricingTable = ({ plans, showYearlyPrice = true, units, renderAction, rend
486
486
  const firstPlan = plans[0];
487
487
  const taxLegendSentence = showTaxLegend && firstPlan ? taxBehaviorLegendSentence(collectDefaultTaxBehaviors(firstPlan)) : void 0;
488
488
  return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("div", {
489
- className: cn("w-full grid grid-cols-1 sm:grid-cols-[repeat(auto-fit,minmax(300px,max-content))] justify-center gap-6", className),
489
+ className: cn("w-full grid grid-cols-1 sm:grid-cols-[repeat(auto-fit,minmax(200px,1fr))] justify-center gap-2", className),
490
490
  children: plans.map((plan) => {
491
491
  const popular = isPopular(plan);
492
492
  const defaultCard = /* @__PURE__ */ jsx(PricingCard, {
package/dist/index.d.mts CHANGED
@@ -1,5 +1,3 @@
1
- import * as _$zudoku from "zudoku";
2
-
3
1
  //#region src/MonetizationContext.d.ts
4
2
  interface MonetizationConfig {
5
3
  pricing?: {
@@ -11,6 +9,6 @@ interface MonetizationConfig {
11
9
  }
12
10
  //#endregion
13
11
  //#region src/ZuploMonetizationPlugin.d.ts
14
- declare const zuploMonetizationPlugin: (options?: MonetizationConfig | undefined) => _$zudoku.ZudokuPlugin;
12
+ declare const zuploMonetizationPlugin: (options?: MonetizationConfig | undefined) => import("zudoku").ZudokuPlugin;
15
13
  //#endregion
16
14
  export { zuploMonetizationPlugin };
package/dist/index.mjs CHANGED
@@ -1,17 +1,16 @@
1
- import { _ as formatDuration, a as subscriptionTaxLegendSentence, c as getPriceFromPlan, f as categorizeRateCards, g as formatPrice, h as formatMinorCurrencyAmount, i as planHasDefaultTaxBehavior, l as PlanEntitlements, m as formatStaticEntitlementConfig, p as formatTieredPriceBreakdown, t as PricingTable, v as formatDurationAdjective, y as formatDurationInterval } from "./PricingTable-BW6uq2El.mjs";
2
- import { Suspense, createContext, use, useEffect, useMemo, useState } from "react";
1
+ import { _ as formatDuration, a as subscriptionTaxLegendSentence, c as getPriceFromPlan, f as categorizeRateCards, g as formatPrice, h as formatMinorCurrencyAmount, i as planHasDefaultTaxBehavior, l as PlanEntitlements, m as formatStaticEntitlementConfig, p as formatTieredPriceBreakdown, t as PricingTable, v as formatDurationAdjective, y as formatDurationInterval } from "./PricingTable-Dsbd3E2Q.mjs";
3
2
  import { cn, createPlugin, joinUrl, throwIfProblemJson } from "zudoku";
4
3
  import { AlertTriangleIcon, ArrowDownIcon, ArrowLeftRightIcon, ArrowUpIcon, CalendarIcon, CheckCheckIcon, CheckIcon, CircleSlashIcon, ClockIcon, CreditCardIcon, Grid2x2XIcon, InfoIcon, Loader2Icon, LockIcon, MoreVerticalIcon, RefreshCcw, RefreshCwIcon, Settings, ShieldIcon, StarsIcon, Trash2Icon, XIcon } from "zudoku/icons";
5
4
  import { Button, ClientOnly, Head, Heading, Link, Slot } from "zudoku/components";
6
5
  import { useAuth, useZudoku } from "zudoku/hooks";
7
- import { QueryClient, QueryClientProvider, useMutation, useQuery, useQueryClient, useSuspenseQuery } from "zudoku/react-query";
6
+ import { QueryClient, QueryClientProvider, queryOptions, useMutation, useQuery, useQueryClient, useSuspenseQuery } from "zudoku/react-query";
8
7
  import { Link as Link$1, Outlet, useLocation, useNavigate, useSearchParams } from "zudoku/router";
9
8
  import { Alert, AlertAction, AlertDescription, AlertTitle } from "zudoku/ui/Alert";
10
9
  import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "zudoku/ui/Card";
11
10
  import { Separator } from "zudoku/ui/Separator";
11
+ import { createContext, use, useEffect, useMemo, useState } from "react";
12
12
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
13
13
  import { Button as Button$1 } from "zudoku/ui/Button";
14
- import { Skeleton } from "zudoku/ui/Skeleton";
15
14
  import { DismissibleAlert, DismissibleAlertAction } from "zudoku/ui/DismissibleAlert";
16
15
  import { ActionButton } from "zudoku/ui/ActionButton";
17
16
  import { Item, ItemContent, ItemDescription, ItemMedia, ItemTitle } from "zudoku/ui/Item";
@@ -443,26 +442,34 @@ const ManagePaymentPage = () => {
443
442
  });
444
443
  };
445
444
  //#endregion
445
+ //#region src/queries.ts
446
+ const getDeploymentName = (context) => {
447
+ const deploymentName = context.env.ZUPLO_PUBLIC_DEPLOYMENT_NAME;
448
+ if (!deploymentName) throw new Error("ZUPLO_PUBLIC_DEPLOYMENT_NAME is not set");
449
+ return deploymentName;
450
+ };
451
+ const pricingPageQuery = (context) => queryOptions({
452
+ queryKey: [`/v3/zudoku-metering/${getDeploymentName(context)}/pricing-page`],
453
+ meta: { context: context.getAuthState().isAuthenticated ? context : void 0 }
454
+ });
455
+ const subscriptionsQuery = (context) => queryOptions({
456
+ queryKey: [`/v3/zudoku-metering/${getDeploymentName(context)}/subscriptions`],
457
+ meta: { context }
458
+ });
459
+ //#endregion
446
460
  //#region src/hooks/usePlans.ts
447
461
  const usePlans = () => {
448
- const zudoku = useZudoku();
449
- const auth = useAuth();
450
- return useSuspenseQuery({
451
- queryKey: [`/v3/zudoku-metering/${useDeploymentName()}/pricing-page`],
452
- meta: { context: auth.isAuthenticated ? zudoku : void 0 }
453
- });
462
+ return useSuspenseQuery(pricingPageQuery(useZudoku()));
454
463
  };
455
464
  //#endregion
456
465
  //#region src/pages/PricingPage.tsx
457
466
  const PricingPage = () => {
458
467
  const { pricing } = useMonetizationConfig();
459
468
  const zudoku = useZudoku();
460
- const deploymentName = useDeploymentName();
461
469
  const auth = useAuth();
462
470
  const { data: pricingTable } = usePlans();
463
471
  const { data: subscriptions = { items: [] } } = useQuery({
464
- meta: { context: zudoku },
465
- queryKey: [`/v3/zudoku-metering/${deploymentName}/subscriptions`],
472
+ ...subscriptionsQuery(zudoku),
466
473
  enabled: auth.isAuthenticated
467
474
  });
468
475
  const isSubscribed = subscriptions.items.some((subscription) => ["active", "canceled"].includes(subscription.status));
@@ -510,36 +517,6 @@ const PricingPage = () => {
510
517
  });
511
518
  };
512
519
  //#endregion
513
- //#region src/pages/PricingPageSkeleton.tsx
514
- const PricingPageSkeleton = () => /* @__PURE__ */ jsxs("div", {
515
- className: "w-full px-4 pt-(--padding-content-top) pb-(--padding-content-bottom)",
516
- children: [/* @__PURE__ */ jsxs("div", {
517
- className: "text-center space-y-4 mb-12",
518
- children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-9 w-48 mx-auto" }), /* @__PURE__ */ jsx(Skeleton, { className: "h-5 w-96 mx-auto" })]
519
- }), /* @__PURE__ */ jsx("div", {
520
- className: "w-full grid grid-cols-1 sm:grid-cols-[repeat(auto-fit,minmax(300px,max-content))] justify-center gap-6",
521
- children: [
522
- 1,
523
- 2,
524
- 3
525
- ].map((i) => /* @__PURE__ */ jsxs(Card, {
526
- className: "w-[300px]",
527
- children: [/* @__PURE__ */ jsxs(CardHeader, {
528
- className: "space-y-3",
529
- children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-6 w-24" }), /* @__PURE__ */ jsx(Skeleton, { className: "h-8 w-32" })]
530
- }), /* @__PURE__ */ jsxs(CardContent, {
531
- className: "space-y-3",
532
- children: [
533
- /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-full" }),
534
- /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-full" }),
535
- /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-3/4" }),
536
- /* @__PURE__ */ jsx(Skeleton, { className: "h-10 w-full mt-4" })
537
- ]
538
- })]
539
- }, i))
540
- })]
541
- });
542
- //#endregion
543
520
  //#region src/pages/SubscriptionChangeConfirmPage.tsx
544
521
  const SubscriptionChangeConfirmPage = () => {
545
522
  const [search] = useSearchParams();
@@ -698,11 +675,9 @@ const SubscriptionChangeConfirmPage = () => {
698
675
  };
699
676
  //#endregion
700
677
  //#region src/hooks/useSubscriptions.ts
701
- const useSubscriptions = (environmentName) => {
702
- const zudoku = useZudoku();
678
+ const useSubscriptions = () => {
703
679
  return useSuspenseQuery({
704
- queryKey: [`/v3/zudoku-metering/${environmentName}/subscriptions`],
705
- meta: { context: zudoku },
680
+ ...subscriptionsQuery(useZudoku()),
706
681
  select: (data) => ({
707
682
  ...data,
708
683
  items: [...data.items].sort((a, b) => {
@@ -2319,7 +2294,7 @@ const SubscriptionItem = ({ subscription, isSelected, isExpired }) => {
2319
2294
  //#region src/pages/SubscriptionsPage.tsx
2320
2295
  const SubscriptionsPage = () => {
2321
2296
  const deploymentName = useDeploymentName();
2322
- const { data } = useSubscriptions(deploymentName);
2297
+ const { data } = useSubscriptions();
2323
2298
  const [searchParams] = useSearchParams();
2324
2299
  const subscriptionId = searchParams.get("subscriptionId");
2325
2300
  const subscriptions = data?.items ?? [];
@@ -2360,39 +2335,6 @@ const SubscriptionsPage = () => {
2360
2335
  });
2361
2336
  };
2362
2337
  //#endregion
2363
- //#region src/pages/SubscriptionsPageSkeleton.tsx
2364
- const SubscriptionsPageSkeleton = () => /* @__PURE__ */ jsx("div", {
2365
- className: "w-full pt-(--padding-content-top) pb-(--padding-content-bottom)",
2366
- children: /* @__PURE__ */ jsxs("div", {
2367
- className: "max-w-4xl space-y-8",
2368
- children: [
2369
- /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-8 w-56 mb-2" }), /* @__PURE__ */ jsx(Skeleton, { className: "h-5 w-80" })] }),
2370
- /* @__PURE__ */ jsx("div", {
2371
- className: "grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3",
2372
- children: [1, 2].map((i) => /* @__PURE__ */ jsx(Skeleton, { className: "h-20 rounded-lg" }, i))
2373
- }),
2374
- /* @__PURE__ */ jsxs("div", {
2375
- className: "space-y-4",
2376
- children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-16" }), /* @__PURE__ */ jsxs(Card, { children: [/* @__PURE__ */ jsx(CardHeader, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-5 w-32" }) }), /* @__PURE__ */ jsxs(CardContent, {
2377
- className: "space-y-2",
2378
- children: [
2379
- /* @__PURE__ */ jsxs("div", {
2380
- className: "flex justify-between",
2381
- children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-20" }), /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-24" })]
2382
- }),
2383
- /* @__PURE__ */ jsx(Skeleton, { className: "h-2 w-full" }),
2384
- /* @__PURE__ */ jsx(Skeleton, { className: "h-3 w-48" })
2385
- ]
2386
- })] })]
2387
- }),
2388
- /* @__PURE__ */ jsxs("div", {
2389
- className: "space-y-4",
2390
- children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-20" }), /* @__PURE__ */ jsx(Skeleton, { className: "h-12 rounded-lg" })]
2391
- })
2392
- ]
2393
- })
2394
- });
2395
- //#endregion
2396
2338
  //#region src/ZuploMonetizationPlugin.tsx
2397
2339
  const PRICING_PATH = "/pricing";
2398
2340
  const zuploMonetizationPlugin = createPlugin((options = {}) => ({
@@ -2403,13 +2345,12 @@ const zuploMonetizationPlugin = createPlugin((options = {}) => ({
2403
2345
  to: PRICING_PATH
2404
2346
  }] }
2405
2347
  }),
2348
+ initialize: (context) => {
2349
+ queryClient.prefetchQuery(pricingPageQuery(context));
2350
+ if (context.getAuthState().isAuthenticated) queryClient.prefetchQuery(subscriptionsQuery(context));
2351
+ },
2406
2352
  getIdentities: async (context) => {
2407
- const deploymentName = context.env.ZUPLO_PUBLIC_DEPLOYMENT_NAME;
2408
- if (!deploymentName) throw new Error("ZUPLO_PUBLIC_DEPLOYMENT_NAME is not set");
2409
- return (await queryClient.fetchQuery({
2410
- queryKey: [`/v3/zudoku-metering/${deploymentName}/subscriptions`],
2411
- meta: { context }
2412
- })).items.flatMap((sub) => sub.status !== "active" ? [] : sub.consumer.apiKeys.flatMap((apiKey) => apiKey.expiresOn && new Date(apiKey.expiresOn) < /* @__PURE__ */ new Date() ? [] : {
2353
+ return (await queryClient.fetchQuery(subscriptionsQuery(context))).items.flatMap((sub) => sub.status !== "active" ? [] : sub.consumer.apiKeys.flatMap((apiKey) => apiKey.expiresOn && new Date(apiKey.expiresOn) < /* @__PURE__ */ new Date() ? [] : {
2413
2354
  label: `${sub.name} (****${apiKey.key.slice(-5)})`,
2414
2355
  id: apiKey.id,
2415
2356
  authorizeRequest: async (request) => {
@@ -2455,16 +2396,10 @@ const zuploMonetizationPlugin = createPlugin((options = {}) => ({
2455
2396
  element: /* @__PURE__ */ jsx(ZuploMonetizationWrapper, { options }),
2456
2397
  children: [{
2457
2398
  path: PRICING_PATH,
2458
- element: /* @__PURE__ */ jsx(Suspense, {
2459
- fallback: /* @__PURE__ */ jsx(PricingPageSkeleton, {}),
2460
- children: /* @__PURE__ */ jsx(PricingPage, {})
2461
- })
2399
+ element: /* @__PURE__ */ jsx(PricingPage, {})
2462
2400
  }, {
2463
2401
  path: "/subscriptions",
2464
- element: /* @__PURE__ */ jsx(Suspense, {
2465
- fallback: /* @__PURE__ */ jsx(SubscriptionsPageSkeleton, {}),
2466
- children: /* @__PURE__ */ jsx(SubscriptionsPage, {})
2467
- })
2402
+ element: /* @__PURE__ */ jsx(SubscriptionsPage, {})
2468
2403
  }]
2469
2404
  }];
2470
2405
  },
@@ -1,5 +1,4 @@
1
1
  import { ReactNode } from "react";
2
- import * as _$react_jsx_runtime0 from "react/jsx-runtime";
3
2
 
4
3
  //#region src/types/PlanType.d.ts
5
4
  type EntitlementTemplate = MeteredEntitlementTemplate | StaticEntitlementTemplate | BooleanEntitlementTemplate;
@@ -141,7 +140,7 @@ declare const FeatureItem: ({
141
140
  }: {
142
141
  feature: Feature;
143
142
  className?: string;
144
- }) => _$react_jsx_runtime0.JSX.Element;
143
+ }) => import("react/jsx-runtime").JSX.Element;
145
144
  //#endregion
146
145
  //#region src/pricing-ui/PlanEntitlements.d.ts
147
146
  declare const PlanEntitlements: ({
@@ -156,7 +155,7 @@ declare const PlanEntitlements: ({
156
155
  billingCadence?: string;
157
156
  units?: Record<string, string>;
158
157
  itemClassName?: string;
159
- }) => _$react_jsx_runtime0.JSX.Element;
158
+ }) => import("react/jsx-runtime").JSX.Element;
160
159
  //#endregion
161
160
  //#region src/pricing-ui/PricingCard.d.ts
162
161
  type PricingCardProps = {
@@ -174,7 +173,7 @@ declare const PricingCard: ({
174
173
  units,
175
174
  action,
176
175
  className
177
- }: PricingCardProps) => _$react_jsx_runtime0.JSX.Element | null;
176
+ }: PricingCardProps) => import("react/jsx-runtime").JSX.Element | null;
178
177
  //#endregion
179
178
  //#region src/pricing-ui/PricingTable.d.ts
180
179
  type PricingTableProps = {
@@ -226,7 +225,7 @@ declare const PricingTable: ({
226
225
  showTaxLegend,
227
226
  className,
228
227
  cardClassName
229
- }: PricingTableProps) => _$react_jsx_runtime0.JSX.Element;
228
+ }: PricingTableProps) => import("react/jsx-runtime").JSX.Element;
230
229
  //#endregion
231
230
  //#region src/pricing-ui/QuotaItem.d.ts
232
231
  declare const QuotaItem: ({
@@ -235,7 +234,7 @@ declare const QuotaItem: ({
235
234
  }: {
236
235
  quota: Quota;
237
236
  className?: string;
238
- }) => _$react_jsx_runtime0.JSX.Element;
237
+ }) => import("react/jsx-runtime").JSX.Element;
239
238
  //#endregion
240
239
  //#region src/utils/categorizeRateCards.d.ts
241
240
  declare const categorizeRateCards: (rateCards: RateCard[], options?: {
@@ -1,2 +1,2 @@
1
- import { _ as formatDuration, a as subscriptionTaxLegendSentence, c as getPriceFromPlan, d as FeatureItem, f as categorizeRateCards, g as formatPrice, h as formatMinorCurrencyAmount, i as planHasDefaultTaxBehavior, l as PlanEntitlements, m as formatStaticEntitlementConfig, n as PricingCard, o as taxBehaviorLegendSentence, p as formatTieredPriceBreakdown, r as collectDefaultTaxBehaviors, s as derivePriceFromPlan, t as PricingTable, u as QuotaItem, v as formatDurationAdjective, y as formatDurationInterval } from "./PricingTable-BW6uq2El.mjs";
1
+ import { _ as formatDuration, a as subscriptionTaxLegendSentence, c as getPriceFromPlan, d as FeatureItem, f as categorizeRateCards, g as formatPrice, h as formatMinorCurrencyAmount, i as planHasDefaultTaxBehavior, l as PlanEntitlements, m as formatStaticEntitlementConfig, n as PricingCard, o as taxBehaviorLegendSentence, p as formatTieredPriceBreakdown, r as collectDefaultTaxBehaviors, s as derivePriceFromPlan, t as PricingTable, u as QuotaItem, v as formatDurationAdjective, y as formatDurationInterval } from "./PricingTable-Dsbd3E2Q.mjs";
2
2
  export { FeatureItem, PlanEntitlements, PricingCard, PricingTable, QuotaItem, categorizeRateCards, collectDefaultTaxBehaviors, derivePriceFromPlan, formatDuration, formatDurationAdjective, formatDurationInterval, formatMinorCurrencyAmount, formatPrice, formatStaticEntitlementConfig, formatTieredPriceBreakdown, getPriceFromPlan, planHasDefaultTaxBehavior, subscriptionTaxLegendSentence, taxBehaviorLegendSentence };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuplo/zudoku-plugin-monetization",
3
- "version": "0.0.36",
3
+ "version": "0.0.38",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/zuplo/zudoku",
@@ -24,7 +24,7 @@
24
24
  ],
25
25
  "dependencies": {
26
26
  "clsx": "2.1.1",
27
- "tailwind-merge": "3.5.0",
27
+ "tailwind-merge": "3.6.0",
28
28
  "tinyduration": "3.4.1"
29
29
  },
30
30
  "devDependencies": {
@@ -36,7 +36,7 @@
36
36
  "happy-dom": "20.9.0",
37
37
  "react": "19.2.5",
38
38
  "react-dom": "19.2.5",
39
- "tsdown": "0.21.10",
39
+ "tsdown": "0.22.0",
40
40
  "zudoku": "0.77.0"
41
41
  },
42
42
  "peerDependencies": {