@zuplo/zudoku-plugin-monetization 0.0.7 → 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 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 { enableMonetization, zuploMonetizationPlugin };
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 [search] = useSearchParams();
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 flex-grow",
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?plan=${plan.id}`,
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: pricingTableData } = useSuspenseQuery({ queryKey: [`/v3/zudoku-metering/${environmentName}/pricing-page`] });
554
- const planOrder = [
555
- "developer",
556
- "startup",
557
- "pro",
558
- "business",
559
- "enterprise"
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: "Pricing"
577
+ children: title
578
578
  }), /* @__PURE__ */ jsx("p", {
579
579
  className: "text-lg text-gray-600 dark:text-gray-400",
580
- children: "Global live music data, flexible plans for every scale"
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(sortedPlans.length)),
586
- children: sortedPlans.map((plan) => /* @__PURE__ */ jsx(PricingCard, {
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,7 +950,6 @@ const Usage = ({ subscriptionId, environmentName, currentItems }) => {
949
950
  queryKey: [`/v3/zudoku-metering/${environmentName}/subscriptions/${subscriptionId}/usage`],
950
951
  meta: { context: zudoku }
951
952
  });
952
- console.log("currentItems", currentItems);
953
953
  return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(Heading, {
954
954
  level: 3,
955
955
  className: "mb-4",
@@ -975,7 +975,6 @@ const SubscriptionsPage = ({ environmentName }) => {
975
975
  return subscriptions[0];
976
976
  }, [subscriptions, subscriptionId]);
977
977
  const activePhase = activeSubscription?.phases.find((p) => new Date(p.activeFrom) <= /* @__PURE__ */ new Date() && (!p.activeTo || new Date(p.activeTo) >= /* @__PURE__ */ new Date()));
978
- console.log("activePhase", activePhase);
979
978
  return /* @__PURE__ */ jsx("div", {
980
979
  className: "w-full py-12",
981
980
  children: /* @__PURE__ */ jsxs("div", {
@@ -1018,19 +1017,15 @@ var SubscriptionsPage_default = SubscriptionsPage;
1018
1017
  //#endregion
1019
1018
  //#region src/ZuploMonetizationPlugin.tsx
1020
1019
  const PRICING_PATH = "/pricing";
1021
- const enableMonetization = (config, options) => {
1022
- return {
1023
- ...config,
1024
- plugins: [...config.plugins ?? [], zuploMonetizationPlugin(options)],
1025
- slots: { "head-navigation-start": () => {
1020
+ const zuploMonetizationPlugin = createPlugin((options) => ({
1021
+ transformConfig: (config) => {
1022
+ return { slots: { "head-navigation-start": () => {
1026
1023
  return /* @__PURE__ */ jsx(Link, {
1027
1024
  to: PRICING_PATH,
1028
1025
  children: "Pricing"
1029
1026
  });
1030
- } }
1031
- };
1032
- };
1033
- const zuploMonetizationPlugin = createPlugin((options) => ({
1027
+ } } };
1028
+ },
1034
1029
  getIdentities: async (context) => {
1035
1030
  return (await queryClient.fetchQuery({
1036
1031
  queryKey: [`/v3/zudoku-metering/${options.environmentName}/subscriptions`],
@@ -1053,7 +1048,7 @@ const zuploMonetizationPlugin = createPlugin((options) => ({
1053
1048
  Component: ZuploMonetizationWrapper_default,
1054
1049
  handle: { layout: "none" },
1055
1050
  children: [{
1056
- path: "/checkout",
1051
+ path: "/checkout/:planId?",
1057
1052
  element: /* @__PURE__ */ jsx(CheckoutPage_default, { environmentName: options.environmentName })
1058
1053
  }, {
1059
1054
  path: "/checkout-confirm",
@@ -1064,7 +1059,11 @@ const zuploMonetizationPlugin = createPlugin((options) => ({
1064
1059
  children: [
1065
1060
  {
1066
1061
  path: "/pricing",
1067
- element: /* @__PURE__ */ jsx(PricingPage_default, { environmentName: options.environmentName })
1062
+ element: /* @__PURE__ */ jsx(PricingPage_default, {
1063
+ environmentName: options.environmentName,
1064
+ subtitle: options.pricing?.subtitle,
1065
+ title: options.pricing?.title
1066
+ })
1068
1067
  },
1069
1068
  {
1070
1069
  path: "/checkout-failed",
@@ -1078,12 +1077,12 @@ const zuploMonetizationPlugin = createPlugin((options) => ({
1078
1077
  }],
1079
1078
  getProtectedRoutes: () => {
1080
1079
  return [
1081
- "/checkout",
1080
+ "/checkout/*",
1082
1081
  "/checkout-success",
1083
1082
  "/checkout-failed"
1084
1083
  ];
1085
1084
  }
1086
- }), import.meta.url);
1085
+ }));
1087
1086
 
1088
1087
  //#endregion
1089
- export { enableMonetization, zuploMonetizationPlugin };
1088
+ export { zuploMonetizationPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuplo/zudoku-plugin-monetization",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "main": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.mts",