@zuplo/zudoku-plugin-monetization 0.0.38 → 0.0.39

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 +46 -37
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -1324,6 +1324,7 @@ const comparePlans = (currentPlan, targetPlan, currentIndex, targetIndex, units)
1324
1324
  return {
1325
1325
  plan: targetPlan,
1326
1326
  isUpgrade,
1327
+ isNewerVersion: false,
1327
1328
  quotaChanges,
1328
1329
  featureChanges
1329
1330
  };
@@ -1334,6 +1335,14 @@ const ChangeIndicator = ({ change }) => {
1334
1335
  return /* @__PURE__ */ jsx(CheckIcon, { className: "w-4 h-4 text-green-600 shrink-0" });
1335
1336
  };
1336
1337
  const isPrivatePlan = (plan) => plan.metadata?.zuplo_private_plan === "true";
1338
+ const planVersion = (plan) => plan.version ?? 1;
1339
+ const isNewerPlanVersion = (subscribedPlan, target) => target.key === subscribedPlan.key && planVersion(target) > planVersion(subscribedPlan);
1340
+ /** Baseline for comparisons: catalog entry when present, else subscription plan. */
1341
+ const resolvePlanForComparison = (subscribedPlan, catalogItems) => catalogItems?.find((p) => p.id === subscribedPlan.id) ?? subscribedPlan;
1342
+ const resolveIsUpgrade = ({ target, targetIndex, subscribedPlan, currentIndex }) => {
1343
+ if (target.key === subscribedPlan.key) return planVersion(target) > planVersion(subscribedPlan);
1344
+ return targetIndex > currentIndex;
1345
+ };
1337
1346
  const modeLabelMap = {
1338
1347
  upgrade: "Upgrade",
1339
1348
  downgrade: "Downgrade",
@@ -1354,10 +1363,17 @@ const PlanComparisonItem = ({ comparison, subscriptionId, mode, onRequestChange,
1354
1363
  children: [/* @__PURE__ */ jsxs("div", {
1355
1364
  className: "flex items-center justify-between mb-3",
1356
1365
  children: [/* @__PURE__ */ jsxs("div", {
1357
- className: "flex items-baseline gap-2",
1358
- children: [/* @__PURE__ */ jsx("h4", {
1359
- className: "font-semibold text-foreground",
1360
- children: comparison.plan.name
1366
+ className: "flex items-baseline gap-2 flex-wrap",
1367
+ children: [/* @__PURE__ */ jsxs("div", {
1368
+ className: "flex items-center gap-2",
1369
+ children: [/* @__PURE__ */ jsx("h4", {
1370
+ className: "font-semibold text-foreground",
1371
+ children: comparison.plan.name
1372
+ }), comparison.isNewerVersion && /* @__PURE__ */ jsx(Badge, {
1373
+ variant: "outline",
1374
+ className: "rounded-full border-primary/30 bg-primary/10 text-primary font-medium",
1375
+ children: "New version"
1376
+ })]
1361
1377
  }), isCustom ? /* @__PURE__ */ jsx("span", {
1362
1378
  className: "text-primary font-medium",
1363
1379
  children: "Custom"
@@ -1522,35 +1538,35 @@ const SwitchPlanModal = ({ subscription, children }) => {
1522
1538
  window.location.href = data.url;
1523
1539
  }
1524
1540
  });
1525
- const currentPlan = plansData?.items.find((p) => p.key === subscription.plan.key);
1541
+ const subscribedPlan = subscription.plan;
1526
1542
  const { upgrades, downgrades, privatePlans } = useMemo(() => {
1527
- if (!plansData?.items) return {
1543
+ const catalogItems = plansData?.items;
1544
+ if (!catalogItems?.length) return {
1528
1545
  upgrades: [],
1529
1546
  downgrades: [],
1530
1547
  privatePlans: []
1531
1548
  };
1532
- if (!currentPlan) {
1533
- const currentIndex = -1;
1534
- return {
1535
- upgrades: plansData.items.map((plan, targetIndex) => comparePlans(void 0, plan, currentIndex, targetIndex, pricing?.units)).filter((c) => !isPrivatePlan(c.plan)),
1536
- downgrades: [],
1537
- privatePlans: []
1538
- };
1539
- }
1540
- if (isPrivatePlan(currentPlan)) {
1541
- const currentIndex = plansData.items.findIndex((p) => p.id === currentPlan.id);
1542
- return {
1543
- upgrades: plansData.items.filter((p) => p.id !== currentPlan.id).map((plan) => {
1544
- return comparePlans(currentPlan, plan, currentIndex, plansData.items.indexOf(plan), pricing?.units);
1545
- }).filter((c) => !isPrivatePlan(c.plan)),
1546
- downgrades: [],
1547
- privatePlans: []
1548
- };
1549
- }
1550
- const currentIndex = plansData.items.findIndex((p) => p.id === currentPlan.id);
1551
- const allComparisons = plansData.items.filter((p) => p.id !== currentPlan.id).map((plan) => {
1552
- return comparePlans(currentPlan, plan, currentIndex, plansData.items.indexOf(plan), pricing?.units);
1549
+ const planForComparison = resolvePlanForComparison(subscribedPlan, catalogItems);
1550
+ const currentIndex = catalogItems.some((p) => p.id === subscribedPlan.id) ? catalogItems.findIndex((p) => p.id === subscribedPlan.id) : -1;
1551
+ const subscribedIsPrivate = isPrivatePlan(subscribedPlan);
1552
+ const allComparisons = catalogItems.flatMap((plan, targetIndex) => {
1553
+ if (plan.id === subscribedPlan.id) return [];
1554
+ return [{
1555
+ ...comparePlans(planForComparison, plan, currentIndex, targetIndex, pricing?.units),
1556
+ isUpgrade: resolveIsUpgrade({
1557
+ target: plan,
1558
+ targetIndex,
1559
+ subscribedPlan,
1560
+ currentIndex
1561
+ }),
1562
+ isNewerVersion: isNewerPlanVersion(subscribedPlan, plan)
1563
+ }];
1553
1564
  });
1565
+ if (subscribedIsPrivate) return {
1566
+ upgrades: allComparisons.filter((c) => !isPrivatePlan(c.plan)),
1567
+ downgrades: [],
1568
+ privatePlans: allComparisons.filter((c) => isPrivatePlan(c.plan))
1569
+ };
1554
1570
  return {
1555
1571
  upgrades: allComparisons.filter((c) => c.isUpgrade && !isPrivatePlan(c.plan)),
1556
1572
  downgrades: allComparisons.filter((c) => !c.isUpgrade && !isPrivatePlan(c.plan)),
@@ -1558,7 +1574,7 @@ const SwitchPlanModal = ({ subscription, children }) => {
1558
1574
  };
1559
1575
  }, [
1560
1576
  plansData?.items,
1561
- currentPlan,
1577
+ subscribedPlan,
1562
1578
  pricing?.units
1563
1579
  ]);
1564
1580
  return /* @__PURE__ */ jsxs(Dialog, {
@@ -1589,18 +1605,11 @@ const SwitchPlanModal = ({ subscription, children }) => {
1589
1605
  children: switchPlanMutation.error.message
1590
1606
  })
1591
1607
  }),
1592
- currentPlan && /* @__PURE__ */ jsx(Item, {
1593
- variant: "outline",
1594
- children: /* @__PURE__ */ jsxs(ItemContent, { children: [/* @__PURE__ */ jsx(ItemTitle, { children: "Current Plan" }), /* @__PURE__ */ jsx(ItemDescription, {
1595
- className: "text-lg font-bold",
1596
- children: currentPlan.name
1597
- })] })
1598
- }),
1599
- !currentPlan && /* @__PURE__ */ jsx(Item, {
1608
+ /* @__PURE__ */ jsx(Item, {
1600
1609
  variant: "outline",
1601
1610
  children: /* @__PURE__ */ jsxs(ItemContent, { children: [/* @__PURE__ */ jsx(ItemTitle, { children: "Current Plan" }), /* @__PURE__ */ jsx(ItemDescription, {
1602
1611
  className: "text-lg font-bold",
1603
- children: subscription.plan.name
1612
+ children: subscribedPlan.name
1604
1613
  })] })
1605
1614
  }),
1606
1615
  upgrades.length > 0 && /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("div", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuplo/zudoku-plugin-monetization",
3
- "version": "0.0.38",
3
+ "version": "0.0.39",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/zuplo/zudoku",
@@ -37,7 +37,7 @@
37
37
  "react": "19.2.5",
38
38
  "react-dom": "19.2.5",
39
39
  "tsdown": "0.22.0",
40
- "zudoku": "0.77.0"
40
+ "zudoku": "0.78.1"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "react": ">=19.2.0",