@streamoid/settings 0.1.0 → 0.1.1

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
@@ -490,6 +490,20 @@ interface SettingsApiAdapter {
490
490
  fetchReferrals?: () => Promise<unknown[]>;
491
491
  }
492
492
  interface SettingsNavigationAdapter {
493
+ /**
494
+ * Resolve a fully-qualified URL the host wants Stripe checkout to redirect
495
+ * back to after success / cancel. Both flows typically land on the billing
496
+ * tab. The package calls this for `updateSubscription` (upgrade/downgrade)
497
+ * and `buyCredits` (topup) checkout payloads.
498
+ *
499
+ * When omitted, the package falls back to
500
+ * `${window.location.origin}${window.location.pathname}` — i.e. brings the
501
+ * user back to the page they triggered checkout from. Hosts override when
502
+ * they need a different URL shape (e.g. CXO uses
503
+ * `/dashboard/<wsId>/billing`, Photogenix uses
504
+ * `/workspace/<wsId>/settings/billing`).
505
+ */
506
+ getCheckoutReturnUrl?: (kind: "success" | "cancel") => string;
493
507
  /** Imperative navigate to another settings tab. */
494
508
  navigateToTab: (tab: SettingsTab) => void;
495
509
  /** External-link navigate (e.g. for "What's new" or referral promo links). */
package/dist/index.d.ts CHANGED
@@ -490,6 +490,20 @@ interface SettingsApiAdapter {
490
490
  fetchReferrals?: () => Promise<unknown[]>;
491
491
  }
492
492
  interface SettingsNavigationAdapter {
493
+ /**
494
+ * Resolve a fully-qualified URL the host wants Stripe checkout to redirect
495
+ * back to after success / cancel. Both flows typically land on the billing
496
+ * tab. The package calls this for `updateSubscription` (upgrade/downgrade)
497
+ * and `buyCredits` (topup) checkout payloads.
498
+ *
499
+ * When omitted, the package falls back to
500
+ * `${window.location.origin}${window.location.pathname}` — i.e. brings the
501
+ * user back to the page they triggered checkout from. Hosts override when
502
+ * they need a different URL shape (e.g. CXO uses
503
+ * `/dashboard/<wsId>/billing`, Photogenix uses
504
+ * `/workspace/<wsId>/settings/billing`).
505
+ */
506
+ getCheckoutReturnUrl?: (kind: "success" | "cancel") => string;
493
507
  /** Imperative navigate to another settings tab. */
494
508
  navigateToTab: (tab: SettingsTab) => void;
495
509
  /** External-link navigate (e.g. for "What's new" or referral promo links). */
package/dist/index.js CHANGED
@@ -4546,7 +4546,7 @@ function UpdateSubscriptionModal({
4546
4546
  lineHeight: "var(--line-height-line-height-xxl)",
4547
4547
  color: "var(--alias-text---icons-primary)"
4548
4548
  },
4549
- children: currentPlanName === "free" ? "Free" : "Pro"
4549
+ children: currentPlanName || "Free"
4550
4550
  }
4551
4551
  ),
4552
4552
  /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "flex flex-col items-end", children: [
@@ -5360,9 +5360,16 @@ function UsageLogsTable({
5360
5360
  );
5361
5361
  }
5362
5362
  function BillingContent({ embedded = false } = {}) {
5363
- const { auth, workspace, api, toast } = useSettingsAdapters();
5363
+ const { auth, workspace, api, toast, navigation } = useSettingsAdapters();
5364
5364
  const user = auth.user;
5365
5365
  const workspaceId = workspace.current?.id ?? null;
5366
+ const resolveReturnUrl = (kind) => {
5367
+ if (navigation.getCheckoutReturnUrl) {
5368
+ return navigation.getCheckoutReturnUrl(kind);
5369
+ }
5370
+ if (typeof window === "undefined") return "";
5371
+ return `${window.location.origin}${window.location.pathname}`;
5372
+ };
5366
5373
  const [activeTab, setActiveTab] = (0, import_react8.useState)("invoice");
5367
5374
  const [showPlans, setShowPlans] = (0, import_react8.useState)(false);
5368
5375
  const [showExportModal, setShowExportModal] = (0, import_react8.useState)(false);
@@ -5487,8 +5494,8 @@ function BillingContent({ embedded = false } = {}) {
5487
5494
  quantity: 1,
5488
5495
  customerEmail: user.email,
5489
5496
  customMetadata: { ref: "Unified dashboard" },
5490
- successUrl: `${window.location.origin}/dashboard/${workspaceId}/billing`,
5491
- cancelUrl: `${window.location.origin}/dashboard/${workspaceId}/billing`,
5497
+ successUrl: resolveReturnUrl("success"),
5498
+ cancelUrl: resolveReturnUrl("cancel"),
5492
5499
  action: "upgrade"
5493
5500
  };
5494
5501
  try {
@@ -5585,8 +5592,8 @@ function BillingContent({ embedded = false } = {}) {
5585
5592
  if (loadingBilling) return;
5586
5593
  setShowInitialLoader(false);
5587
5594
  }, [showInitialLoader, initialFetchTriggered, loadingBilling]);
5588
- const planName = subscription?.plan?.amount != null && subscription.plan.amount > 0 ? "Pro" : "Free";
5589
- const isFreePlan = subscription?.plan?.amount === 0 && planName.trim().toLowerCase() === "free";
5595
+ const planName = subscription?.plan?.name?.trim() || (subscription?.plan?.amount != null && subscription.plan.amount > 0 ? "Pro" : "Free");
5596
+ const isFreePlan = subscription?.plan?.amount == null || subscription.plan.amount === 0;
5590
5597
  const planAmount = subscription?.plan?.amount != null ? `$${(subscription.plan.amount / 100).toFixed(2)} / month` : "$0";
5591
5598
  const usedCredits = availableCredits != null && totalCredits != null ? Math.max(0, totalCredits - availableCredits) : null;
5592
5599
  const progressPct = usedCredits != null && totalCredits != null && totalCredits > 0 ? Math.min(100, Math.round(usedCredits / totalCredits * 100)) : 0;
@@ -5683,7 +5690,6 @@ function BillingContent({ embedded = false } = {}) {
5683
5690
  additionalInfo: `${credits}:${price}`
5684
5691
  }
5685
5692
  );
5686
- const returnUrl = `${window.location.origin}/dashboard/${workspaceId}/billing`;
5687
5693
  try {
5688
5694
  const res = await api.buyCredits({
5689
5695
  serviceName: DEFAULT_TOPUP_SERVICE,
@@ -5691,8 +5697,8 @@ function BillingContent({ embedded = false } = {}) {
5691
5697
  unitAmount: price,
5692
5698
  itemCount: 1,
5693
5699
  currency: "usd",
5694
- successUrl: returnUrl,
5695
- cancelUrl: returnUrl,
5700
+ successUrl: resolveReturnUrl("success"),
5701
+ cancelUrl: resolveReturnUrl("cancel"),
5696
5702
  metadata: { source: "self-serve" }
5697
5703
  });
5698
5704
  const payloadData = "data" in res && res.data ? res.data : res;
package/dist/index.mjs CHANGED
@@ -4554,7 +4554,7 @@ function UpdateSubscriptionModal({
4554
4554
  lineHeight: "var(--line-height-line-height-xxl)",
4555
4555
  color: "var(--alias-text---icons-primary)"
4556
4556
  },
4557
- children: currentPlanName === "free" ? "Free" : "Pro"
4557
+ children: currentPlanName || "Free"
4558
4558
  }
4559
4559
  ),
4560
4560
  /* @__PURE__ */ jsxs9("div", { className: "flex flex-col items-end", children: [
@@ -5368,9 +5368,16 @@ function UsageLogsTable({
5368
5368
  );
5369
5369
  }
5370
5370
  function BillingContent({ embedded = false } = {}) {
5371
- const { auth, workspace, api, toast } = useSettingsAdapters();
5371
+ const { auth, workspace, api, toast, navigation } = useSettingsAdapters();
5372
5372
  const user = auth.user;
5373
5373
  const workspaceId = workspace.current?.id ?? null;
5374
+ const resolveReturnUrl = (kind) => {
5375
+ if (navigation.getCheckoutReturnUrl) {
5376
+ return navigation.getCheckoutReturnUrl(kind);
5377
+ }
5378
+ if (typeof window === "undefined") return "";
5379
+ return `${window.location.origin}${window.location.pathname}`;
5380
+ };
5374
5381
  const [activeTab, setActiveTab] = useState7("invoice");
5375
5382
  const [showPlans, setShowPlans] = useState7(false);
5376
5383
  const [showExportModal, setShowExportModal] = useState7(false);
@@ -5495,8 +5502,8 @@ function BillingContent({ embedded = false } = {}) {
5495
5502
  quantity: 1,
5496
5503
  customerEmail: user.email,
5497
5504
  customMetadata: { ref: "Unified dashboard" },
5498
- successUrl: `${window.location.origin}/dashboard/${workspaceId}/billing`,
5499
- cancelUrl: `${window.location.origin}/dashboard/${workspaceId}/billing`,
5505
+ successUrl: resolveReturnUrl("success"),
5506
+ cancelUrl: resolveReturnUrl("cancel"),
5500
5507
  action: "upgrade"
5501
5508
  };
5502
5509
  try {
@@ -5593,8 +5600,8 @@ function BillingContent({ embedded = false } = {}) {
5593
5600
  if (loadingBilling) return;
5594
5601
  setShowInitialLoader(false);
5595
5602
  }, [showInitialLoader, initialFetchTriggered, loadingBilling]);
5596
- const planName = subscription?.plan?.amount != null && subscription.plan.amount > 0 ? "Pro" : "Free";
5597
- const isFreePlan = subscription?.plan?.amount === 0 && planName.trim().toLowerCase() === "free";
5603
+ const planName = subscription?.plan?.name?.trim() || (subscription?.plan?.amount != null && subscription.plan.amount > 0 ? "Pro" : "Free");
5604
+ const isFreePlan = subscription?.plan?.amount == null || subscription.plan.amount === 0;
5598
5605
  const planAmount = subscription?.plan?.amount != null ? `$${(subscription.plan.amount / 100).toFixed(2)} / month` : "$0";
5599
5606
  const usedCredits = availableCredits != null && totalCredits != null ? Math.max(0, totalCredits - availableCredits) : null;
5600
5607
  const progressPct = usedCredits != null && totalCredits != null && totalCredits > 0 ? Math.min(100, Math.round(usedCredits / totalCredits * 100)) : 0;
@@ -5691,7 +5698,6 @@ function BillingContent({ embedded = false } = {}) {
5691
5698
  additionalInfo: `${credits}:${price}`
5692
5699
  }
5693
5700
  );
5694
- const returnUrl = `${window.location.origin}/dashboard/${workspaceId}/billing`;
5695
5701
  try {
5696
5702
  const res = await api.buyCredits({
5697
5703
  serviceName: DEFAULT_TOPUP_SERVICE,
@@ -5699,8 +5705,8 @@ function BillingContent({ embedded = false } = {}) {
5699
5705
  unitAmount: price,
5700
5706
  itemCount: 1,
5701
5707
  currency: "usd",
5702
- successUrl: returnUrl,
5703
- cancelUrl: returnUrl,
5708
+ successUrl: resolveReturnUrl("success"),
5709
+ cancelUrl: resolveReturnUrl("cancel"),
5704
5710
  metadata: { source: "self-serve" }
5705
5711
  });
5706
5712
  const payloadData = "data" in res && res.data ? res.data : res;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamoid/settings",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",