@zuplo/zudoku-plugin-monetization 0.0.19 → 0.0.21

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.
Files changed (2) hide show
  1. package/dist/index.mjs +69 -36
  2. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -391,7 +391,8 @@ const CheckoutConfirmPage = () => {
391
391
  }), /* @__PURE__ */ jsx(Button, {
392
392
  variant: "ghost",
393
393
  className: "w-full",
394
- asChild: true,
394
+ disabled: createSubscriptionMutation.isPending,
395
+ asChild: !createSubscriptionMutation.isPending,
395
396
  children: /* @__PURE__ */ jsx(Link$1, {
396
397
  to: "/pricing",
397
398
  children: "Cancel"
@@ -1189,7 +1190,12 @@ const ChangeIndicator = ({ change }) => {
1189
1190
  if (change === "decrease" || change === "removed" || change === "downgraded") return /* @__PURE__ */ jsx(ArrowDownIcon, { className: "w-4 h-4 text-amber-600 shrink-0" });
1190
1191
  return /* @__PURE__ */ jsx(CheckIcon, { className: "w-4 h-4 text-green-600 shrink-0" });
1191
1192
  };
1192
- const PlanComparisonItem = ({ comparison, subscriptionId, onRequestChange }) => {
1193
+ const modeLabelMap = {
1194
+ upgrade: "Upgrade",
1195
+ downgrade: "Downgrade",
1196
+ private: "Switch"
1197
+ };
1198
+ const PlanComparisonItem = ({ comparison, subscriptionId, mode, onRequestChange }) => {
1193
1199
  const price = getPriceFromPlan(comparison.plan);
1194
1200
  const isCustom = comparison.plan.key === "enterprise";
1195
1201
  const displayPrice = price.monthly;
@@ -1218,14 +1224,14 @@ const PlanComparisonItem = ({ comparison, subscriptionId, onRequestChange }) =>
1218
1224
  size: "sm",
1219
1225
  children: "Contact Sales"
1220
1226
  }) : /* @__PURE__ */ jsx(Button$1, {
1221
- variant: comparison.isUpgrade ? "default" : "outline",
1227
+ variant: mode === "upgrade" ? "default" : "outline",
1222
1228
  onClick: () => onRequestChange({
1223
1229
  subscriptionId,
1224
1230
  plan: comparison.plan,
1225
- mode: comparison.isUpgrade ? "upgrade" : "downgrade"
1231
+ mode
1226
1232
  }),
1227
1233
  size: "sm",
1228
- children: comparison.isUpgrade ? "Upgrade" : "Downgrade"
1234
+ children: modeLabelMap[mode]
1229
1235
  })]
1230
1236
  }), hasChanges && /* @__PURE__ */ jsxs("div", {
1231
1237
  className: "space-y-1.5",
@@ -1337,7 +1343,7 @@ const ConfirmSwitchAlert = ({ switchTo, onRequestClose }) => {
1337
1343
  onSuccess: async (subscription) => {
1338
1344
  await queryClient.invalidateQueries();
1339
1345
  navigate(`/subscriptions/${subscription.id}`, { state: { planSwitched: {
1340
- isUpgrade: switchTo.mode === "upgrade",
1346
+ mode: switchTo.mode,
1341
1347
  newPlanName: switchTo.plan.name
1342
1348
  } } });
1343
1349
  onRequestClose();
@@ -1351,7 +1357,11 @@ const ConfirmSwitchAlert = ({ switchTo, onRequestClose }) => {
1351
1357
  open: true,
1352
1358
  onOpenChange: onRequestClose,
1353
1359
  children: /* @__PURE__ */ jsxs(AlertDialogContent, { children: [/* @__PURE__ */ jsxs(AlertDialogHeader, { children: [
1354
- /* @__PURE__ */ jsxs(AlertDialogTitle, { children: ["Confirm ", switchTo.mode === "upgrade" ? "upgrade" : "downgrade"] }),
1360
+ /* @__PURE__ */ jsxs(AlertDialogTitle, { children: [
1361
+ "Confirm",
1362
+ " ",
1363
+ switchTo.mode === "private" ? "plan change" : switchTo.mode === "upgrade" ? "upgrade" : "downgrade"
1364
+ ] }),
1355
1365
  mutation.isError && /* @__PURE__ */ jsx(Alert, {
1356
1366
  variant: "destructive",
1357
1367
  children: /* @__PURE__ */ jsx(AlertDescription, {
@@ -1359,14 +1369,14 @@ const ConfirmSwitchAlert = ({ switchTo, onRequestClose }) => {
1359
1369
  children: mutation.error.message
1360
1370
  })
1361
1371
  }),
1362
- /* @__PURE__ */ jsx(AlertDialogDescription, { children: switchTo.mode === "upgrade" ? `Are you sure you want to upgrade to ${switchTo.plan.name}? This will take effect immediately.` : `Are you sure you want to downgrade to ${switchTo.plan.name}? This will take effect at the start of your next billing cycle.` })
1372
+ /* @__PURE__ */ jsx(AlertDialogDescription, { children: switchTo.mode === "private" ? `Are you sure you want to switch to ${switchTo.plan.name}? This will take effect immediately.` : switchTo.mode === "upgrade" ? `Are you sure you want to upgrade to ${switchTo.plan.name}? This will take effect immediately.` : `Are you sure you want to downgrade to ${switchTo.plan.name}? This will take effect at the start of your next billing cycle.` })
1363
1373
  ] }), /* @__PURE__ */ jsxs(AlertDialogFooter, { children: [/* @__PURE__ */ jsx(AlertDialogCancel, {
1364
1374
  disabled: mutation.isPending,
1365
1375
  children: "Cancel"
1366
1376
  }), /* @__PURE__ */ jsx(ActionButton, {
1367
1377
  isPending: mutation.isPending,
1368
1378
  onClick: () => mutation.mutate(),
1369
- children: switchTo.mode === "upgrade" ? "Upgrade" : "Downgrade"
1379
+ children: modeLabelMap[switchTo.mode]
1370
1380
  })] })] })
1371
1381
  });
1372
1382
  };
@@ -1375,15 +1385,18 @@ const SwitchPlanModal = ({ subscription, children }) => {
1375
1385
  const { data: plansData } = usePlans();
1376
1386
  const [switchTo, setSwitchTo] = useState(null);
1377
1387
  const currentPlan = plansData?.items.find((p) => p.id === subscription.plan.id);
1378
- const { upgrades, downgrades } = useMemo(() => {
1388
+ const { upgrades, downgrades, privatePlans } = useMemo(() => {
1379
1389
  if (!plansData?.items || !currentPlan) return {
1380
1390
  upgrades: [],
1381
- downgrades: []
1391
+ downgrades: [],
1392
+ privatePlans: []
1382
1393
  };
1394
+ const isPrivatePlan = (plan) => plan.metadata?.zuplo_is_private === "true";
1383
1395
  const allComparisons = plansData.items.filter((p) => p.id !== currentPlan.id).map((plan) => comparePlans(currentPlan, plan));
1384
1396
  return {
1385
- upgrades: allComparisons.filter((c) => c.isUpgrade),
1386
- downgrades: allComparisons.filter((c) => !c.isUpgrade)
1397
+ upgrades: allComparisons.filter((c) => c.isUpgrade && !isPrivatePlan(c.plan)),
1398
+ downgrades: allComparisons.filter((c) => !c.isUpgrade && !isPrivatePlan(c.plan)),
1399
+ privatePlans: allComparisons.filter((c) => isPrivatePlan(c.plan))
1387
1400
  };
1388
1401
  }, [plansData?.items, currentPlan]);
1389
1402
  return /* @__PURE__ */ jsxs(Fragment, { children: [switchTo !== null && /* @__PURE__ */ jsx(ConfirmSwitchAlert, {
@@ -1434,11 +1447,8 @@ const SwitchPlanModal = ({ subscription, children }) => {
1434
1447
  children: upgrades.map((comparison) => /* @__PURE__ */ jsx(PlanComparisonItem, {
1435
1448
  comparison,
1436
1449
  subscriptionId: subscription.id,
1437
- onRequestChange: ({ subscriptionId, plan }) => setSwitchTo({
1438
- subscriptionId,
1439
- plan,
1440
- mode: "upgrade"
1441
- })
1450
+ mode: "upgrade",
1451
+ onRequestChange: setSwitchTo
1442
1452
  }, comparison.plan.id))
1443
1453
  })] }),
1444
1454
  downgrades.length > 0 && /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("div", {
@@ -1458,11 +1468,29 @@ const SwitchPlanModal = ({ subscription, children }) => {
1458
1468
  children: downgrades.map((comparison) => /* @__PURE__ */ jsx(PlanComparisonItem, {
1459
1469
  comparison,
1460
1470
  subscriptionId: subscription.id,
1461
- onRequestChange: ({ subscriptionId, plan }) => setSwitchTo({
1462
- subscriptionId,
1463
- plan,
1464
- mode: "downgrade"
1465
- })
1471
+ mode: "downgrade",
1472
+ onRequestChange: setSwitchTo
1473
+ }, comparison.plan.id))
1474
+ })] }),
1475
+ privatePlans.length > 0 && /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("div", {
1476
+ className: "flex items-center justify-between mb-3",
1477
+ children: [/* @__PURE__ */ jsxs("div", {
1478
+ className: "flex items-center gap-2",
1479
+ children: [/* @__PURE__ */ jsx(ArrowLeftRightIcon, { className: "size-5 text-muted-foreground" }), /* @__PURE__ */ jsx("span", {
1480
+ className: "font-medium text-foreground",
1481
+ children: "Private Plan Option"
1482
+ })]
1483
+ }), /* @__PURE__ */ jsx("span", {
1484
+ className: "text-sm text-muted-foreground",
1485
+ children: "Takes effect immediately"
1486
+ })]
1487
+ }), /* @__PURE__ */ jsx("div", {
1488
+ className: "space-y-3",
1489
+ children: privatePlans.map((comparison) => /* @__PURE__ */ jsx(PlanComparisonItem, {
1490
+ comparison,
1491
+ subscriptionId: subscription.id,
1492
+ mode: "private",
1493
+ onRequestChange: setSwitchTo
1466
1494
  }, comparison.plan.id))
1467
1495
  })] })
1468
1496
  ]
@@ -1719,7 +1747,11 @@ const ActiveSubscription = ({ subscription, deploymentName }) => {
1719
1747
  variant: "info",
1720
1748
  children: [
1721
1749
  /* @__PURE__ */ jsx(CheckCheckIcon, { className: "size-4" }),
1722
- /* @__PURE__ */ jsxs(AlertTitle, { children: ["Plan ", planSwitched.isUpgrade ? "upgraded" : "downgraded"] }),
1750
+ /* @__PURE__ */ jsxs(AlertTitle, { children: [
1751
+ "Plan",
1752
+ " ",
1753
+ planSwitched.mode === "upgrade" ? "upgraded" : planSwitched.mode === "downgrade" ? "downgraded" : "changed"
1754
+ ] }),
1723
1755
  /* @__PURE__ */ jsxs(AlertDescription, { children: [
1724
1756
  "You have successfully switched to ",
1725
1757
  planSwitched.newPlanName,
@@ -1923,20 +1955,21 @@ const zuploMonetizationPlugin = createPlugin((options) => ({
1923
1955
  {
1924
1956
  path: "/manage-payment",
1925
1957
  element: /* @__PURE__ */ jsx(ManagePaymentPage, {})
1958
+ },
1959
+ {
1960
+ path: PRICING_PATH,
1961
+ handle: { layout: "default" },
1962
+ element: /* @__PURE__ */ jsx(PricingPage, {
1963
+ subtitle: options?.pricing?.subtitle,
1964
+ title: options?.pricing?.title
1965
+ })
1966
+ },
1967
+ {
1968
+ handle: { layout: "default" },
1969
+ path: "/subscriptions/:subscriptionId?",
1970
+ element: /* @__PURE__ */ jsx(SubscriptionsPage, {})
1926
1971
  }
1927
1972
  ]
1928
- }, {
1929
- Component: ZuploMonetizationWrapper,
1930
- children: [{
1931
- path: "/pricing",
1932
- element: /* @__PURE__ */ jsx(PricingPage, {
1933
- subtitle: options?.pricing?.subtitle,
1934
- title: options?.pricing?.title
1935
- })
1936
- }, {
1937
- path: "/subscriptions/:subscriptionId?",
1938
- element: /* @__PURE__ */ jsx(SubscriptionsPage, {})
1939
- }]
1940
1973
  }];
1941
1974
  },
1942
1975
  getProtectedRoutes: () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuplo/zudoku-plugin-monetization",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/zuplo/zudoku",
@@ -27,11 +27,11 @@
27
27
  "@testing-library/react": "16.3.2",
28
28
  "@types/react": "19.2.14",
29
29
  "@types/react-dom": "19.2.3",
30
- "happy-dom": "20.6.1",
30
+ "happy-dom": "20.7.0",
31
31
  "react": "19.2.4",
32
32
  "react-dom": "19.2.4",
33
33
  "tsdown": "0.20.3",
34
- "zudoku": "0.69.3"
34
+ "zudoku": "0.70.3"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "react": ">=19.2.0",