@zuplo/zudoku-plugin-monetization 0.0.37 → 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.
- package/dist/index.d.mts +1 -3
- package/dist/index.mjs +29 -91
- package/dist/pricing-ui.d.mts +5 -6
- package/package.json +2 -2
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) =>
|
|
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
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";
|
|
2
|
-
import { Suspense, createContext, use, useEffect, useMemo, useState } from "react";
|
|
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
|
-
|
|
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
|
-
|
|
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,33 +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(200px,1fr))] justify-center gap-2",
|
|
521
|
-
children: [
|
|
522
|
-
1,
|
|
523
|
-
2,
|
|
524
|
-
3
|
|
525
|
-
].map((i) => /* @__PURE__ */ jsxs(Card, { children: [/* @__PURE__ */ jsxs(CardHeader, {
|
|
526
|
-
className: "space-y-3",
|
|
527
|
-
children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-6 w-24" }), /* @__PURE__ */ jsx(Skeleton, { className: "h-8 w-32" })]
|
|
528
|
-
}), /* @__PURE__ */ jsxs(CardContent, {
|
|
529
|
-
className: "space-y-3",
|
|
530
|
-
children: [
|
|
531
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-full" }),
|
|
532
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-full" }),
|
|
533
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-3/4" }),
|
|
534
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-10 w-full mt-4" })
|
|
535
|
-
]
|
|
536
|
-
})] }, i))
|
|
537
|
-
})]
|
|
538
|
-
});
|
|
539
|
-
//#endregion
|
|
540
520
|
//#region src/pages/SubscriptionChangeConfirmPage.tsx
|
|
541
521
|
const SubscriptionChangeConfirmPage = () => {
|
|
542
522
|
const [search] = useSearchParams();
|
|
@@ -695,11 +675,9 @@ const SubscriptionChangeConfirmPage = () => {
|
|
|
695
675
|
};
|
|
696
676
|
//#endregion
|
|
697
677
|
//#region src/hooks/useSubscriptions.ts
|
|
698
|
-
const useSubscriptions = (
|
|
699
|
-
const zudoku = useZudoku();
|
|
678
|
+
const useSubscriptions = () => {
|
|
700
679
|
return useSuspenseQuery({
|
|
701
|
-
|
|
702
|
-
meta: { context: zudoku },
|
|
680
|
+
...subscriptionsQuery(useZudoku()),
|
|
703
681
|
select: (data) => ({
|
|
704
682
|
...data,
|
|
705
683
|
items: [...data.items].sort((a, b) => {
|
|
@@ -2316,7 +2294,7 @@ const SubscriptionItem = ({ subscription, isSelected, isExpired }) => {
|
|
|
2316
2294
|
//#region src/pages/SubscriptionsPage.tsx
|
|
2317
2295
|
const SubscriptionsPage = () => {
|
|
2318
2296
|
const deploymentName = useDeploymentName();
|
|
2319
|
-
const { data } = useSubscriptions(
|
|
2297
|
+
const { data } = useSubscriptions();
|
|
2320
2298
|
const [searchParams] = useSearchParams();
|
|
2321
2299
|
const subscriptionId = searchParams.get("subscriptionId");
|
|
2322
2300
|
const subscriptions = data?.items ?? [];
|
|
@@ -2357,39 +2335,6 @@ const SubscriptionsPage = () => {
|
|
|
2357
2335
|
});
|
|
2358
2336
|
};
|
|
2359
2337
|
//#endregion
|
|
2360
|
-
//#region src/pages/SubscriptionsPageSkeleton.tsx
|
|
2361
|
-
const SubscriptionsPageSkeleton = () => /* @__PURE__ */ jsx("div", {
|
|
2362
|
-
className: "w-full pt-(--padding-content-top) pb-(--padding-content-bottom)",
|
|
2363
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
2364
|
-
className: "max-w-4xl space-y-8",
|
|
2365
|
-
children: [
|
|
2366
|
-
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-8 w-56 mb-2" }), /* @__PURE__ */ jsx(Skeleton, { className: "h-5 w-80" })] }),
|
|
2367
|
-
/* @__PURE__ */ jsx("div", {
|
|
2368
|
-
className: "grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3",
|
|
2369
|
-
children: [1, 2].map((i) => /* @__PURE__ */ jsx(Skeleton, { className: "h-20 rounded-lg" }, i))
|
|
2370
|
-
}),
|
|
2371
|
-
/* @__PURE__ */ jsxs("div", {
|
|
2372
|
-
className: "space-y-4",
|
|
2373
|
-
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, {
|
|
2374
|
-
className: "space-y-2",
|
|
2375
|
-
children: [
|
|
2376
|
-
/* @__PURE__ */ jsxs("div", {
|
|
2377
|
-
className: "flex justify-between",
|
|
2378
|
-
children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-20" }), /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-24" })]
|
|
2379
|
-
}),
|
|
2380
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-2 w-full" }),
|
|
2381
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-3 w-48" })
|
|
2382
|
-
]
|
|
2383
|
-
})] })]
|
|
2384
|
-
}),
|
|
2385
|
-
/* @__PURE__ */ jsxs("div", {
|
|
2386
|
-
className: "space-y-4",
|
|
2387
|
-
children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-20" }), /* @__PURE__ */ jsx(Skeleton, { className: "h-12 rounded-lg" })]
|
|
2388
|
-
})
|
|
2389
|
-
]
|
|
2390
|
-
})
|
|
2391
|
-
});
|
|
2392
|
-
//#endregion
|
|
2393
2338
|
//#region src/ZuploMonetizationPlugin.tsx
|
|
2394
2339
|
const PRICING_PATH = "/pricing";
|
|
2395
2340
|
const zuploMonetizationPlugin = createPlugin((options = {}) => ({
|
|
@@ -2400,13 +2345,12 @@ const zuploMonetizationPlugin = createPlugin((options = {}) => ({
|
|
|
2400
2345
|
to: PRICING_PATH
|
|
2401
2346
|
}] }
|
|
2402
2347
|
}),
|
|
2348
|
+
initialize: (context) => {
|
|
2349
|
+
queryClient.prefetchQuery(pricingPageQuery(context));
|
|
2350
|
+
if (context.getAuthState().isAuthenticated) queryClient.prefetchQuery(subscriptionsQuery(context));
|
|
2351
|
+
},
|
|
2403
2352
|
getIdentities: async (context) => {
|
|
2404
|
-
|
|
2405
|
-
if (!deploymentName) throw new Error("ZUPLO_PUBLIC_DEPLOYMENT_NAME is not set");
|
|
2406
|
-
return (await queryClient.fetchQuery({
|
|
2407
|
-
queryKey: [`/v3/zudoku-metering/${deploymentName}/subscriptions`],
|
|
2408
|
-
meta: { context }
|
|
2409
|
-
})).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() ? [] : {
|
|
2410
2354
|
label: `${sub.name} (****${apiKey.key.slice(-5)})`,
|
|
2411
2355
|
id: apiKey.id,
|
|
2412
2356
|
authorizeRequest: async (request) => {
|
|
@@ -2452,16 +2396,10 @@ const zuploMonetizationPlugin = createPlugin((options = {}) => ({
|
|
|
2452
2396
|
element: /* @__PURE__ */ jsx(ZuploMonetizationWrapper, { options }),
|
|
2453
2397
|
children: [{
|
|
2454
2398
|
path: PRICING_PATH,
|
|
2455
|
-
element: /* @__PURE__ */ jsx(
|
|
2456
|
-
fallback: /* @__PURE__ */ jsx(PricingPageSkeleton, {}),
|
|
2457
|
-
children: /* @__PURE__ */ jsx(PricingPage, {})
|
|
2458
|
-
})
|
|
2399
|
+
element: /* @__PURE__ */ jsx(PricingPage, {})
|
|
2459
2400
|
}, {
|
|
2460
2401
|
path: "/subscriptions",
|
|
2461
|
-
element: /* @__PURE__ */ jsx(
|
|
2462
|
-
fallback: /* @__PURE__ */ jsx(SubscriptionsPageSkeleton, {}),
|
|
2463
|
-
children: /* @__PURE__ */ jsx(SubscriptionsPage, {})
|
|
2464
|
-
})
|
|
2402
|
+
element: /* @__PURE__ */ jsx(SubscriptionsPage, {})
|
|
2465
2403
|
}]
|
|
2466
2404
|
}];
|
|
2467
2405
|
},
|
package/dist/pricing-ui.d.mts
CHANGED
|
@@ -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
|
-
}) =>
|
|
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
|
-
}) =>
|
|
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) =>
|
|
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) =>
|
|
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
|
-
}) =>
|
|
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?: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zuplo/zudoku-plugin-monetization",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/zuplo/zudoku",
|
|
@@ -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.
|
|
39
|
+
"tsdown": "0.22.0",
|
|
40
40
|
"zudoku": "0.77.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|