@zuplo/zudoku-plugin-monetization 0.0.6 → 0.0.8
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 +10 -3
- package/dist/index.mjs +45 -42
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as zudoku0 from "zudoku";
|
|
2
|
-
import { ZudokuConfig } from "zudoku";
|
|
3
2
|
import * as zudoku_icons0 from "zudoku/icons";
|
|
4
3
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
5
4
|
import * as react0 from "react";
|
|
@@ -8,9 +7,17 @@ import * as zudoku_plugins0 from "zudoku/plugins";
|
|
|
8
7
|
//#region src/ZuploMonetizationPlugin.d.ts
|
|
9
8
|
type ZudokuMonetizationPluginOptions = {
|
|
10
9
|
environmentName: string;
|
|
10
|
+
pricing?: {
|
|
11
|
+
subtitle?: string;
|
|
12
|
+
title?: string;
|
|
13
|
+
};
|
|
11
14
|
};
|
|
12
|
-
declare const enableMonetization: (config: ZudokuConfig, options: ZudokuMonetizationPluginOptions) => ZudokuConfig;
|
|
13
15
|
declare const zuploMonetizationPlugin: (options: ZudokuMonetizationPluginOptions) => {
|
|
16
|
+
transformConfig: (config: zudoku0.ZudokuConfig) => {
|
|
17
|
+
slots: {
|
|
18
|
+
"head-navigation-start": () => react_jsx_runtime0.JSX.Element;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
14
21
|
getIdentities: (context: zudoku0.ZudokuContext) => Promise<{
|
|
15
22
|
label: string;
|
|
16
23
|
id: string;
|
|
@@ -44,4 +51,4 @@ declare const zuploMonetizationPlugin: (options: ZudokuMonetizationPluginOptions
|
|
|
44
51
|
getProtectedRoutes: () => string[];
|
|
45
52
|
} & zudoku_plugins0.TransformConfigPlugin;
|
|
46
53
|
//#endregion
|
|
47
|
-
export {
|
|
54
|
+
export { zuploMonetizationPlugin };
|
package/dist/index.mjs
CHANGED
|
@@ -403,9 +403,8 @@ const useUrlUtils = () => {
|
|
|
403
403
|
//#endregion
|
|
404
404
|
//#region src/pages/CheckoutPage.tsx
|
|
405
405
|
const CheckoutPage = ({ environmentName }) => {
|
|
406
|
-
const
|
|
406
|
+
const { planId } = useParams();
|
|
407
407
|
const zudoku = useZudoku();
|
|
408
|
-
const planId = search.get("plan");
|
|
409
408
|
const auth = useAuth();
|
|
410
409
|
const { generateUrl } = useUrlUtils();
|
|
411
410
|
const { data: _data } = useQuery({
|
|
@@ -472,7 +471,7 @@ var CheckoutPage_default = CheckoutPage;
|
|
|
472
471
|
|
|
473
472
|
//#endregion
|
|
474
473
|
//#region src/pages/pricing/PricingCard.tsx
|
|
475
|
-
const PricingCard = ({ plan, isPopular = false }) => {
|
|
474
|
+
const PricingCard = ({ plan, isPopular = false, disabled = false }) => {
|
|
476
475
|
const defaultPhase = plan.phases.at(-1);
|
|
477
476
|
if (!defaultPhase) return null;
|
|
478
477
|
const { quotas, features } = categorizeRateCards(defaultPhase.rateCards);
|
|
@@ -526,7 +525,7 @@ const PricingCard = ({ plan, isPopular = false }) => {
|
|
|
526
525
|
]
|
|
527
526
|
}),
|
|
528
527
|
/* @__PURE__ */ jsxs("div", {
|
|
529
|
-
className: "space-y-4 mb-6
|
|
528
|
+
className: "space-y-4 mb-6 grow",
|
|
530
529
|
children: [quotas.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
531
530
|
className: "space-y-2",
|
|
532
531
|
children: quotas.map((quota) => /* @__PURE__ */ jsx(QuotaItem, { quota }, quota.key))
|
|
@@ -535,11 +534,15 @@ const PricingCard = ({ plan, isPopular = false }) => {
|
|
|
535
534
|
children: features.map((feature) => /* @__PURE__ */ jsx(FeatureItem, { feature }, feature.key))
|
|
536
535
|
})]
|
|
537
536
|
}),
|
|
538
|
-
/* @__PURE__ */ jsx(Button, {
|
|
537
|
+
disabled ? /* @__PURE__ */ jsx(Button, {
|
|
538
|
+
disabled: true,
|
|
539
|
+
variant: isPopular ? "default" : "secondary",
|
|
540
|
+
children: "Already subscribed"
|
|
541
|
+
}) : /* @__PURE__ */ jsx(Button, {
|
|
539
542
|
variant: isPopular ? "default" : "secondary",
|
|
540
543
|
asChild: true,
|
|
541
544
|
children: /* @__PURE__ */ jsx(Link, {
|
|
542
|
-
to: `/checkout
|
|
545
|
+
to: `/checkout/${plan.id}`,
|
|
543
546
|
children: "Subscribe"
|
|
544
547
|
})
|
|
545
548
|
})
|
|
@@ -549,17 +552,14 @@ const PricingCard = ({ plan, isPopular = false }) => {
|
|
|
549
552
|
|
|
550
553
|
//#endregion
|
|
551
554
|
//#region src/pages/PricingPage.tsx
|
|
552
|
-
const PricingPage = ({ environmentName }) => {
|
|
553
|
-
const { data:
|
|
554
|
-
const
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
];
|
|
561
|
-
const sortedPlans = [...pricingTableData.items].sort((a, b) => {
|
|
562
|
-
return planOrder.indexOf(a.key) - planOrder.indexOf(b.key);
|
|
555
|
+
const PricingPage = ({ environmentName, subtitle = "See our pricing options and choose the one that best suits your needs.", title = "Pricing" }) => {
|
|
556
|
+
const { data: pricingTable } = useSuspenseQuery({ queryKey: [`/v3/zudoku-metering/${environmentName}/pricing-page`] });
|
|
557
|
+
const zudoku = useZudoku();
|
|
558
|
+
const auth = useAuth();
|
|
559
|
+
const { data: subscriptions = { items: [] } } = useQuery({
|
|
560
|
+
meta: { context: zudoku },
|
|
561
|
+
queryKey: [`/v3/zudoku-metering/${environmentName}/subscriptions`],
|
|
562
|
+
enabled: auth.isAuthenticated
|
|
563
563
|
});
|
|
564
564
|
const getGridCols = (count) => {
|
|
565
565
|
if (count === 1) return "lg:grid-cols-1";
|
|
@@ -574,18 +574,19 @@ const PricingPage = ({ environmentName }) => {
|
|
|
574
574
|
className: "text-center mb-12",
|
|
575
575
|
children: [/* @__PURE__ */ jsx(Heading, {
|
|
576
576
|
level: 1,
|
|
577
|
-
children:
|
|
577
|
+
children: title
|
|
578
578
|
}), /* @__PURE__ */ jsx("p", {
|
|
579
579
|
className: "text-lg text-gray-600 dark:text-gray-400",
|
|
580
|
-
children:
|
|
580
|
+
children: subtitle
|
|
581
581
|
})]
|
|
582
582
|
}), /* @__PURE__ */ jsx("div", {
|
|
583
583
|
className: "flex justify-center",
|
|
584
584
|
children: /* @__PURE__ */ jsx("div", {
|
|
585
|
-
className: cn("w-full md:w-auto grid grid-cols-1 md:grid-cols-2 gap-6 md:max-w-fit", getGridCols(
|
|
586
|
-
children:
|
|
585
|
+
className: cn("w-full md:w-auto grid grid-cols-1 md:grid-cols-2 gap-6 md:max-w-fit", getGridCols(pricingTable?.items?.length ?? 0)),
|
|
586
|
+
children: pricingTable?.items?.map((plan) => /* @__PURE__ */ jsx(PricingCard, {
|
|
587
587
|
plan,
|
|
588
|
-
isPopular: plan.key === "pro"
|
|
588
|
+
isPopular: plan.key === "pro",
|
|
589
|
+
disabled: subscriptions.items.some((subscription) => subscription.plan.id === plan.id)
|
|
589
590
|
}, plan.id))
|
|
590
591
|
})
|
|
591
592
|
})]
|
|
@@ -949,15 +950,17 @@ const Usage = ({ subscriptionId, environmentName, currentItems }) => {
|
|
|
949
950
|
queryKey: [`/v3/zudoku-metering/${environmentName}/subscriptions/${subscriptionId}/usage`],
|
|
950
951
|
meta: { context: zudoku }
|
|
951
952
|
});
|
|
952
|
-
const meteredEntitlements = currentItems?.filter((item) => item.included.entitlement?.type === "metered") ?? [];
|
|
953
953
|
return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(Heading, {
|
|
954
954
|
level: 3,
|
|
955
955
|
className: "mb-4",
|
|
956
956
|
children: "Usage"
|
|
957
|
-
}),
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
957
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
958
|
+
className: "space-y-4",
|
|
959
|
+
children: Object.entries(usage.entitlements).filter((entry) => isMeteredEntitlement(entry[1])).map(([key, metric]) => /* @__PURE__ */ jsx(UsageItem, {
|
|
960
|
+
meter: { ...metric },
|
|
961
|
+
item: currentItems?.find((item) => item.featureKey === key)
|
|
962
|
+
}, key))
|
|
963
|
+
})] });
|
|
961
964
|
};
|
|
962
965
|
|
|
963
966
|
//#endregion
|
|
@@ -971,7 +974,7 @@ const SubscriptionsPage = ({ environmentName }) => {
|
|
|
971
974
|
if (subscriptionId) return subscriptions.find((s) => s.id === subscriptionId) ?? subscriptions[0];
|
|
972
975
|
return subscriptions[0];
|
|
973
976
|
}, [subscriptions, subscriptionId]);
|
|
974
|
-
const activePhase = activeSubscription
|
|
977
|
+
const activePhase = activeSubscription?.phases.find((p) => new Date(p.activeFrom) <= /* @__PURE__ */ new Date() && (!p.activeTo || new Date(p.activeTo) >= /* @__PURE__ */ new Date()));
|
|
975
978
|
return /* @__PURE__ */ jsx("div", {
|
|
976
979
|
className: "w-full py-12",
|
|
977
980
|
children: /* @__PURE__ */ jsxs("div", {
|
|
@@ -1014,19 +1017,15 @@ var SubscriptionsPage_default = SubscriptionsPage;
|
|
|
1014
1017
|
//#endregion
|
|
1015
1018
|
//#region src/ZuploMonetizationPlugin.tsx
|
|
1016
1019
|
const PRICING_PATH = "/pricing";
|
|
1017
|
-
const
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
plugins: [...config.plugins ?? [], zuploMonetizationPlugin(options)],
|
|
1021
|
-
slots: { "head-navigation-start": () => {
|
|
1020
|
+
const zuploMonetizationPlugin = createPlugin((options) => ({
|
|
1021
|
+
transformConfig: (config) => {
|
|
1022
|
+
return { slots: { "head-navigation-start": () => {
|
|
1022
1023
|
return /* @__PURE__ */ jsx(Link, {
|
|
1023
1024
|
to: PRICING_PATH,
|
|
1024
1025
|
children: "Pricing"
|
|
1025
1026
|
});
|
|
1026
|
-
} }
|
|
1027
|
-
}
|
|
1028
|
-
};
|
|
1029
|
-
const zuploMonetizationPlugin = createPlugin((options) => ({
|
|
1027
|
+
} } };
|
|
1028
|
+
},
|
|
1030
1029
|
getIdentities: async (context) => {
|
|
1031
1030
|
return (await queryClient.fetchQuery({
|
|
1032
1031
|
queryKey: [`/v3/zudoku-metering/${options.environmentName}/subscriptions`],
|
|
@@ -1049,7 +1048,7 @@ const zuploMonetizationPlugin = createPlugin((options) => ({
|
|
|
1049
1048
|
Component: ZuploMonetizationWrapper_default,
|
|
1050
1049
|
handle: { layout: "none" },
|
|
1051
1050
|
children: [{
|
|
1052
|
-
path: "/checkout",
|
|
1051
|
+
path: "/checkout/:planId?",
|
|
1053
1052
|
element: /* @__PURE__ */ jsx(CheckoutPage_default, { environmentName: options.environmentName })
|
|
1054
1053
|
}, {
|
|
1055
1054
|
path: "/checkout-confirm",
|
|
@@ -1060,7 +1059,11 @@ const zuploMonetizationPlugin = createPlugin((options) => ({
|
|
|
1060
1059
|
children: [
|
|
1061
1060
|
{
|
|
1062
1061
|
path: "/pricing",
|
|
1063
|
-
element: /* @__PURE__ */ jsx(PricingPage_default, {
|
|
1062
|
+
element: /* @__PURE__ */ jsx(PricingPage_default, {
|
|
1063
|
+
environmentName: options.environmentName,
|
|
1064
|
+
subtitle: options.pricing?.subtitle,
|
|
1065
|
+
title: options.pricing?.title
|
|
1066
|
+
})
|
|
1064
1067
|
},
|
|
1065
1068
|
{
|
|
1066
1069
|
path: "/checkout-failed",
|
|
@@ -1074,12 +1077,12 @@ const zuploMonetizationPlugin = createPlugin((options) => ({
|
|
|
1074
1077
|
}],
|
|
1075
1078
|
getProtectedRoutes: () => {
|
|
1076
1079
|
return [
|
|
1077
|
-
"/checkout",
|
|
1080
|
+
"/checkout/*",
|
|
1078
1081
|
"/checkout-success",
|
|
1079
1082
|
"/checkout-failed"
|
|
1080
1083
|
];
|
|
1081
1084
|
}
|
|
1082
|
-
})
|
|
1085
|
+
}));
|
|
1083
1086
|
|
|
1084
1087
|
//#endregion
|
|
1085
|
-
export {
|
|
1088
|
+
export { zuploMonetizationPlugin };
|