@lukoweb/apitogo-plugin-dev-portal-billing 0.1.48 → 0.1.50

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 +72 -7
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -713,14 +713,25 @@ const CredentialsPage = () => {
713
713
  });
714
714
  };
715
715
 
716
+ //#endregion
717
+ //#region src/utils/pricing-config.ts
718
+ function isPreviewPricingEnabled() {
719
+ return manifestCatalog?.pricingEnabled === true;
720
+ }
721
+
716
722
  //#endregion
717
723
  //#region src/pages/PricingPage.tsx
718
724
  const PricingPage = () => {
719
725
  const { pricing } = useDevPortalBillingConfig();
720
726
  const auth = useAuth();
721
727
  const isPreview = useDevPortalPreviewMode();
728
+ const pricingEnabled = isPreviewPricingEnabled();
722
729
  const { data: catalog, isLoading, isError } = usePlans();
723
730
  const { data: me } = useMySubscriptions();
731
+ if (!pricingEnabled) return /* @__PURE__ */ jsx(Navigate, {
732
+ to: "/",
733
+ replace: true
734
+ });
724
735
  if (auth.isAuthenticated) return /* @__PURE__ */ jsx(Navigate, {
725
736
  to: "/account/plans",
726
737
  replace: true
@@ -782,9 +793,25 @@ const PricingPage = () => {
782
793
  mode: "public",
783
794
  isSubscribed: activeSkus.has(plan.sku)
784
795
  }, plan.sku))
785
- }) : !isLoading && !isError ? /* @__PURE__ */ jsx("div", {
796
+ }) : !isLoading && !isError ? /* @__PURE__ */ jsxs("div", {
786
797
  className: "mx-auto max-w-lg rounded-xl border border-dashed p-8 text-center text-sm text-muted-foreground",
787
- children: "No plans are available yet. Sync plans from your APItoGo manifest or platform gateway."
798
+ children: [
799
+ "No plans are configured yet. Add plans in",
800
+ " ",
801
+ /* @__PURE__ */ jsx("code", {
802
+ className: "rounded bg-muted px-1.5 py-0.5",
803
+ children: "apitogo.json"
804
+ }),
805
+ " ",
806
+ "and set",
807
+ " ",
808
+ /* @__PURE__ */ jsx("code", {
809
+ className: "rounded bg-muted px-1.5 py-0.5",
810
+ children: "pricing.enabled"
811
+ }),
812
+ " ",
813
+ "to true."
814
+ ]
788
815
  }) : null
789
816
  ]
790
817
  });
@@ -912,14 +939,52 @@ const SubscriptionsPage = () => {
912
939
  });
913
940
  };
914
941
 
942
+ //#endregion
943
+ //#region src/utils/navigation-plans.ts
944
+ function withoutPricingNavigation(items) {
945
+ if (!items?.length) return [];
946
+ return items.map((item) => {
947
+ if (typeof item === "string") return item;
948
+ if (item.type === "link" && item.to === PRICING_PATH) return null;
949
+ if (item.items?.length) {
950
+ const filteredItems = withoutPricingNavigation(item.items);
951
+ return {
952
+ ...item,
953
+ items: filteredItems
954
+ };
955
+ }
956
+ return item;
957
+ }).filter((item) => item !== null);
958
+ }
959
+
915
960
  //#endregion
916
961
  //#region src/DevPortalBillingPlugin.tsx
962
+ function isNodeRuntime() {
963
+ return typeof process !== "undefined" && typeof process.versions?.node === "string";
964
+ }
965
+ async function resolvePricingEnabled(config) {
966
+ const rootDir = config.__meta?.rootDir;
967
+ if (rootDir && isNodeRuntime()) {
968
+ const { isPricingEnabled, readEffectiveManifest, resolveManifestEnv } = await import("@lukoweb/apitogo/local-manifest");
969
+ return isPricingEnabled(await readEffectiveManifest(rootDir, resolveManifestEnv(config.__meta?.mode ?? "development")));
970
+ }
971
+ return isPreviewPricingEnabled();
972
+ }
917
973
  const devPortalBillingPlugin = createPlugin((options = {}) => ({
918
- transformConfig: ({ config, merge }) => merge({ header: { navigation: [...config.header?.navigation ?? [], {
919
- label: "Pricing",
920
- to: PRICING_PATH,
921
- display: "anon"
922
- }] } }),
974
+ transformConfig: async ({ config, merge }) => {
975
+ if (!await resolvePricingEnabled(config)) return merge({
976
+ navigation: withoutPricingNavigation(config.navigation),
977
+ header: {
978
+ ...config.header,
979
+ navigation: withoutPricingNavigation(config.header?.navigation)
980
+ }
981
+ });
982
+ return merge({ header: { navigation: [...config.header?.navigation ?? [], {
983
+ label: "Pricing",
984
+ to: PRICING_PATH,
985
+ display: "anon"
986
+ }] } });
987
+ },
923
988
  getProfileMenuItems: () => [{
924
989
  label: "My Subscriptions",
925
990
  path: SUBSCRIPTIONS_PATH,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lukoweb/apitogo-plugin-dev-portal-billing",
3
- "version": "0.1.48",
3
+ "version": "0.1.50",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/zuplo/zudoku",
@@ -46,7 +46,7 @@
46
46
  "react": "19.2.4",
47
47
  "react-dom": "19.2.4",
48
48
  "tsdown": "0.20.3",
49
- "@lukoweb/apitogo": "0.1.48"
49
+ "@lukoweb/apitogo": "0.1.50"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "react": ">=19.2.0",