@streamoid/settings 0.3.2 → 0.3.3
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 +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +53 -8
- package/dist/index.mjs +53 -8
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -265,6 +265,7 @@ interface SubscriptionPlan {
|
|
|
265
265
|
id: string;
|
|
266
266
|
name: string;
|
|
267
267
|
amount: number;
|
|
268
|
+
type?: string;
|
|
268
269
|
subscriptionEndDate?: string;
|
|
269
270
|
/** Three-letter currency code (lowercase) when known, e.g. "inr" / "usd". */
|
|
270
271
|
currency?: string;
|
|
@@ -276,6 +277,10 @@ interface BillingSubscription {
|
|
|
276
277
|
downgradeScheduled: boolean;
|
|
277
278
|
stripeCustomerId: string;
|
|
278
279
|
plan: SubscriptionPlan;
|
|
280
|
+
scheduledDowngradeEffectiveDate?: number | string;
|
|
281
|
+
preDowngradeStripePriceData?: SubscriptionPlan & {
|
|
282
|
+
credits?: string;
|
|
283
|
+
};
|
|
279
284
|
/** Stripe product id; used to look up the matching product in fetched plans. */
|
|
280
285
|
stripeProductId?: string;
|
|
281
286
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -265,6 +265,7 @@ interface SubscriptionPlan {
|
|
|
265
265
|
id: string;
|
|
266
266
|
name: string;
|
|
267
267
|
amount: number;
|
|
268
|
+
type?: string;
|
|
268
269
|
subscriptionEndDate?: string;
|
|
269
270
|
/** Three-letter currency code (lowercase) when known, e.g. "inr" / "usd". */
|
|
270
271
|
currency?: string;
|
|
@@ -276,6 +277,10 @@ interface BillingSubscription {
|
|
|
276
277
|
downgradeScheduled: boolean;
|
|
277
278
|
stripeCustomerId: string;
|
|
278
279
|
plan: SubscriptionPlan;
|
|
280
|
+
scheduledDowngradeEffectiveDate?: number | string;
|
|
281
|
+
preDowngradeStripePriceData?: SubscriptionPlan & {
|
|
282
|
+
credits?: string;
|
|
283
|
+
};
|
|
279
284
|
/** Stripe product id; used to look up the matching product in fetched plans. */
|
|
280
285
|
stripeProductId?: string;
|
|
281
286
|
}
|
package/dist/index.js
CHANGED
|
@@ -4480,6 +4480,16 @@ function formatNextBillingDateLabel(iso) {
|
|
|
4480
4480
|
year: "numeric"
|
|
4481
4481
|
});
|
|
4482
4482
|
}
|
|
4483
|
+
function formatEffectiveDateLabel(value) {
|
|
4484
|
+
if (value == null) return "";
|
|
4485
|
+
const parsed = typeof value === "number" ? new Date(value < 1e10 ? value * 1e3 : value) : new Date(value);
|
|
4486
|
+
if (Number.isNaN(parsed.getTime())) return "";
|
|
4487
|
+
return parsed.toLocaleDateString("en-US", {
|
|
4488
|
+
month: "short",
|
|
4489
|
+
day: "numeric",
|
|
4490
|
+
year: "numeric"
|
|
4491
|
+
});
|
|
4492
|
+
}
|
|
4483
4493
|
function UpdateSubscriptionModal({
|
|
4484
4494
|
open,
|
|
4485
4495
|
currentPlanName,
|
|
@@ -5533,7 +5543,7 @@ function BillingContent({
|
|
|
5533
5543
|
const [availableCredits, setAvailableCredits] = (0, import_react8.useState)(null);
|
|
5534
5544
|
const [products, setProducts] = (0, import_react8.useState)([]);
|
|
5535
5545
|
const [invoices, setInvoices] = (0, import_react8.useState)([]);
|
|
5536
|
-
const [totalCredits, setTotalCredits] = (0, import_react8.useState)(
|
|
5546
|
+
const [totalCredits, setTotalCredits] = (0, import_react8.useState)(null);
|
|
5537
5547
|
const [usageLogs, setUsageLogs] = (0, import_react8.useState)([]);
|
|
5538
5548
|
const [userMap, setUserMap] = (0, import_react8.useState)({});
|
|
5539
5549
|
const [customPlanCredits, setCustomPlanCredits] = (0, import_react8.useState)(
|
|
@@ -5544,6 +5554,7 @@ function BillingContent({
|
|
|
5544
5554
|
);
|
|
5545
5555
|
const [buyCreditsInFlight, setBuyCreditsInFlight] = (0, import_react8.useState)(false);
|
|
5546
5556
|
const [loadingBilling, setLoadingBilling] = (0, import_react8.useState)(false);
|
|
5557
|
+
const [billingOverviewLoaded, setBillingOverviewLoaded] = (0, import_react8.useState)(false);
|
|
5547
5558
|
const [loadingTable, setLoadingTable] = (0, import_react8.useState)(false);
|
|
5548
5559
|
const [showInitialLoader, setShowInitialLoader] = (0, import_react8.useState)(true);
|
|
5549
5560
|
const [initialFetchTriggered, setInitialFetchTriggered] = (0, import_react8.useState)(false);
|
|
@@ -5568,6 +5579,7 @@ function BillingContent({
|
|
|
5568
5579
|
}, [api]);
|
|
5569
5580
|
const fetchBillingOverview = (0, import_react8.useCallback)(async () => {
|
|
5570
5581
|
setLoadingBilling(true);
|
|
5582
|
+
setBillingOverviewLoaded(false);
|
|
5571
5583
|
try {
|
|
5572
5584
|
console.log("calling Billing apis");
|
|
5573
5585
|
const [subRes, creditsRes, productsRes, customRes] = await Promise.all([
|
|
@@ -5596,6 +5608,7 @@ function BillingContent({
|
|
|
5596
5608
|
} catch {
|
|
5597
5609
|
} finally {
|
|
5598
5610
|
setLoadingBilling(false);
|
|
5611
|
+
setBillingOverviewLoaded(true);
|
|
5599
5612
|
}
|
|
5600
5613
|
}, [api, workspace.current?.country]);
|
|
5601
5614
|
const fetchUserMap = (0, import_react8.useCallback)(async () => {
|
|
@@ -5737,6 +5750,12 @@ function BillingContent({
|
|
|
5737
5750
|
(0, import_react8.useEffect)(() => {
|
|
5738
5751
|
setShowInitialLoader(true);
|
|
5739
5752
|
setInitialFetchTriggered(false);
|
|
5753
|
+
setBillingOverviewLoaded(false);
|
|
5754
|
+
setSubscription(null);
|
|
5755
|
+
setAvailableCredits(null);
|
|
5756
|
+
setProducts([]);
|
|
5757
|
+
setTotalCredits(null);
|
|
5758
|
+
setCustomPlanCredits(null);
|
|
5740
5759
|
}, [workspaceId]);
|
|
5741
5760
|
(0, import_react8.useEffect)(() => {
|
|
5742
5761
|
setInitialFetchTriggered(true);
|
|
@@ -5755,17 +5774,39 @@ function BillingContent({
|
|
|
5755
5774
|
(0, import_react8.useEffect)(() => {
|
|
5756
5775
|
if (!showInitialLoader) return;
|
|
5757
5776
|
if (!initialFetchTriggered) return;
|
|
5758
|
-
if (
|
|
5777
|
+
if (!billingOverviewLoaded) return;
|
|
5759
5778
|
setShowInitialLoader(false);
|
|
5760
|
-
}, [showInitialLoader, initialFetchTriggered,
|
|
5779
|
+
}, [showInitialLoader, initialFetchTriggered, billingOverviewLoaded]);
|
|
5761
5780
|
console.log("subscription", subscription);
|
|
5762
5781
|
const isProPlan = products.some(
|
|
5763
5782
|
(product) => product.id == subscription?.stripeProductId && product.name == "Paid"
|
|
5764
5783
|
);
|
|
5765
5784
|
console.log("isProPlan", isProPlan);
|
|
5766
|
-
const
|
|
5785
|
+
const currentPlanPrice = (() => {
|
|
5786
|
+
if (products.length > 0 && subscription?.plan?.id) {
|
|
5787
|
+
for (const product of products) {
|
|
5788
|
+
const price = product.prices.find((p) => p.id === subscription.plan.id);
|
|
5789
|
+
if (price) return price;
|
|
5790
|
+
}
|
|
5791
|
+
}
|
|
5792
|
+
return null;
|
|
5793
|
+
})();
|
|
5794
|
+
const preDowngradePlan = subscription?.downgradeScheduled && subscription.preDowngradeStripePriceData ? subscription.preDowngradeStripePriceData : null;
|
|
5795
|
+
const resolvedPlanName = (preDowngradePlan?.name?.trim() || currentPlanPrice?.metadata?.name?.trim() || subscription?.plan?.name?.trim() || (subscription?.plan?.amount != null ? subscription.plan.amount > 0 ? "Pro" : "Free" : "")).trim();
|
|
5796
|
+
const planName = isProPlan && resolvedPlanName !== "-" ? "Pro" : resolvedPlanName;
|
|
5767
5797
|
const isFreePlan = subscription?.plan?.amount == null || subscription.plan.amount === 0;
|
|
5768
|
-
const
|
|
5798
|
+
const hasResolvedPlanAmount = (preDowngradePlan?.amount ?? subscription?.plan?.amount) != null && Boolean(preDowngradePlan?.currency ?? subscription?.plan?.currency) && Boolean(preDowngradePlan?.interval ?? subscription?.plan?.interval);
|
|
5799
|
+
const planAmount = hasResolvedPlanAmount ? `${(preDowngradePlan?.currency ?? subscription?.plan?.currency) == "inr" ? "\u20B9" : "$"}${((preDowngradePlan?.amount ?? subscription.plan.amount) / 100).toFixed(2)} / ${preDowngradePlan?.interval ?? subscription?.plan?.interval}` : "";
|
|
5800
|
+
const planCreditsFromPrice = Number(
|
|
5801
|
+
preDowngradePlan?.credits ?? currentPlanPrice?.metadata?.credits
|
|
5802
|
+
);
|
|
5803
|
+
const currentPlanCredits = Number.isFinite(planCreditsFromPrice) ? planCreditsFromPrice : customPlanCredits;
|
|
5804
|
+
const planCreditsText = currentPlanCredits != null ? `${formatCredits(currentPlanCredits)} credits` : "";
|
|
5805
|
+
const scheduledDowngradeDateLabel = formatEffectiveDateLabel(
|
|
5806
|
+
subscription?.scheduledDowngradeEffectiveDate
|
|
5807
|
+
);
|
|
5808
|
+
const scheduledDowngradeText = subscription?.downgradeScheduled && subscription.plan?.name ? `Downgrades to ${subscription.plan.name}${scheduledDowngradeDateLabel ? ` ${scheduledDowngradeDateLabel}` : ""}` : void 0;
|
|
5809
|
+
const isPlanDetailsLoading = !billingOverviewLoaded || loadingBilling || subscription?.plan == null || !planName || planName === "-" || !planAmount || currentPlanCredits == null;
|
|
5769
5810
|
const usedCredits = availableCredits != null && totalCredits != null ? Math.max(0, totalCredits - availableCredits) : null;
|
|
5770
5811
|
const progressPct = usedCredits != null && totalCredits != null && totalCredits > 0 ? Math.min(100, Math.round(usedCredits / totalCredits * 100)) : 0;
|
|
5771
5812
|
const remainingPct = 100 - progressPct;
|
|
@@ -5983,11 +6024,13 @@ function BillingContent({
|
|
|
5983
6024
|
import_ui5.ScPlanDetailsCard,
|
|
5984
6025
|
{
|
|
5985
6026
|
planName,
|
|
5986
|
-
planCredits:
|
|
6027
|
+
planCredits: planCreditsText,
|
|
5987
6028
|
planPrice: planAmount,
|
|
5988
6029
|
badgeText: "Active",
|
|
6030
|
+
badgeSubText: scheduledDowngradeText,
|
|
5989
6031
|
currentPlanLabel: "Current plan",
|
|
5990
|
-
upgradeButtonText: subscription?.downgradeScheduled ? "Cancel downgrade" : "
|
|
6032
|
+
upgradeButtonText: subscription?.downgradeScheduled ? "Cancel downgrade" : "Manage Plan",
|
|
6033
|
+
isLoading: isPlanDetailsLoading,
|
|
5991
6034
|
className: "flex-1 min-w-0",
|
|
5992
6035
|
onUpgrade: () => {
|
|
5993
6036
|
void logBillingEvent("billing_plans_opened", "Plans opened", {
|
|
@@ -6084,7 +6127,9 @@ function BillingContent({
|
|
|
6084
6127
|
BuyCreditsModal,
|
|
6085
6128
|
{
|
|
6086
6129
|
country: workspace.current?.country,
|
|
6087
|
-
currencySymbol: getCurrencySymbolByCountry(
|
|
6130
|
+
currencySymbol: getCurrencySymbolByCountry(
|
|
6131
|
+
workspace.current?.country
|
|
6132
|
+
),
|
|
6088
6133
|
onClose: () => setShowBuyCreditsModal(false),
|
|
6089
6134
|
onBuy: (credits, price) => {
|
|
6090
6135
|
handleBuyCredits(credits, price);
|
package/dist/index.mjs
CHANGED
|
@@ -4499,6 +4499,16 @@ function formatNextBillingDateLabel(iso) {
|
|
|
4499
4499
|
year: "numeric"
|
|
4500
4500
|
});
|
|
4501
4501
|
}
|
|
4502
|
+
function formatEffectiveDateLabel(value) {
|
|
4503
|
+
if (value == null) return "";
|
|
4504
|
+
const parsed = typeof value === "number" ? new Date(value < 1e10 ? value * 1e3 : value) : new Date(value);
|
|
4505
|
+
if (Number.isNaN(parsed.getTime())) return "";
|
|
4506
|
+
return parsed.toLocaleDateString("en-US", {
|
|
4507
|
+
month: "short",
|
|
4508
|
+
day: "numeric",
|
|
4509
|
+
year: "numeric"
|
|
4510
|
+
});
|
|
4511
|
+
}
|
|
4502
4512
|
function UpdateSubscriptionModal({
|
|
4503
4513
|
open,
|
|
4504
4514
|
currentPlanName,
|
|
@@ -5552,7 +5562,7 @@ function BillingContent({
|
|
|
5552
5562
|
const [availableCredits, setAvailableCredits] = useState7(null);
|
|
5553
5563
|
const [products, setProducts] = useState7([]);
|
|
5554
5564
|
const [invoices, setInvoices] = useState7([]);
|
|
5555
|
-
const [totalCredits, setTotalCredits] = useState7(
|
|
5565
|
+
const [totalCredits, setTotalCredits] = useState7(null);
|
|
5556
5566
|
const [usageLogs, setUsageLogs] = useState7([]);
|
|
5557
5567
|
const [userMap, setUserMap] = useState7({});
|
|
5558
5568
|
const [customPlanCredits, setCustomPlanCredits] = useState7(
|
|
@@ -5563,6 +5573,7 @@ function BillingContent({
|
|
|
5563
5573
|
);
|
|
5564
5574
|
const [buyCreditsInFlight, setBuyCreditsInFlight] = useState7(false);
|
|
5565
5575
|
const [loadingBilling, setLoadingBilling] = useState7(false);
|
|
5576
|
+
const [billingOverviewLoaded, setBillingOverviewLoaded] = useState7(false);
|
|
5566
5577
|
const [loadingTable, setLoadingTable] = useState7(false);
|
|
5567
5578
|
const [showInitialLoader, setShowInitialLoader] = useState7(true);
|
|
5568
5579
|
const [initialFetchTriggered, setInitialFetchTriggered] = useState7(false);
|
|
@@ -5587,6 +5598,7 @@ function BillingContent({
|
|
|
5587
5598
|
}, [api]);
|
|
5588
5599
|
const fetchBillingOverview = useCallback3(async () => {
|
|
5589
5600
|
setLoadingBilling(true);
|
|
5601
|
+
setBillingOverviewLoaded(false);
|
|
5590
5602
|
try {
|
|
5591
5603
|
console.log("calling Billing apis");
|
|
5592
5604
|
const [subRes, creditsRes, productsRes, customRes] = await Promise.all([
|
|
@@ -5615,6 +5627,7 @@ function BillingContent({
|
|
|
5615
5627
|
} catch {
|
|
5616
5628
|
} finally {
|
|
5617
5629
|
setLoadingBilling(false);
|
|
5630
|
+
setBillingOverviewLoaded(true);
|
|
5618
5631
|
}
|
|
5619
5632
|
}, [api, workspace.current?.country]);
|
|
5620
5633
|
const fetchUserMap = useCallback3(async () => {
|
|
@@ -5756,6 +5769,12 @@ function BillingContent({
|
|
|
5756
5769
|
useEffect4(() => {
|
|
5757
5770
|
setShowInitialLoader(true);
|
|
5758
5771
|
setInitialFetchTriggered(false);
|
|
5772
|
+
setBillingOverviewLoaded(false);
|
|
5773
|
+
setSubscription(null);
|
|
5774
|
+
setAvailableCredits(null);
|
|
5775
|
+
setProducts([]);
|
|
5776
|
+
setTotalCredits(null);
|
|
5777
|
+
setCustomPlanCredits(null);
|
|
5759
5778
|
}, [workspaceId]);
|
|
5760
5779
|
useEffect4(() => {
|
|
5761
5780
|
setInitialFetchTriggered(true);
|
|
@@ -5774,17 +5793,39 @@ function BillingContent({
|
|
|
5774
5793
|
useEffect4(() => {
|
|
5775
5794
|
if (!showInitialLoader) return;
|
|
5776
5795
|
if (!initialFetchTriggered) return;
|
|
5777
|
-
if (
|
|
5796
|
+
if (!billingOverviewLoaded) return;
|
|
5778
5797
|
setShowInitialLoader(false);
|
|
5779
|
-
}, [showInitialLoader, initialFetchTriggered,
|
|
5798
|
+
}, [showInitialLoader, initialFetchTriggered, billingOverviewLoaded]);
|
|
5780
5799
|
console.log("subscription", subscription);
|
|
5781
5800
|
const isProPlan = products.some(
|
|
5782
5801
|
(product) => product.id == subscription?.stripeProductId && product.name == "Paid"
|
|
5783
5802
|
);
|
|
5784
5803
|
console.log("isProPlan", isProPlan);
|
|
5785
|
-
const
|
|
5804
|
+
const currentPlanPrice = (() => {
|
|
5805
|
+
if (products.length > 0 && subscription?.plan?.id) {
|
|
5806
|
+
for (const product of products) {
|
|
5807
|
+
const price = product.prices.find((p) => p.id === subscription.plan.id);
|
|
5808
|
+
if (price) return price;
|
|
5809
|
+
}
|
|
5810
|
+
}
|
|
5811
|
+
return null;
|
|
5812
|
+
})();
|
|
5813
|
+
const preDowngradePlan = subscription?.downgradeScheduled && subscription.preDowngradeStripePriceData ? subscription.preDowngradeStripePriceData : null;
|
|
5814
|
+
const resolvedPlanName = (preDowngradePlan?.name?.trim() || currentPlanPrice?.metadata?.name?.trim() || subscription?.plan?.name?.trim() || (subscription?.plan?.amount != null ? subscription.plan.amount > 0 ? "Pro" : "Free" : "")).trim();
|
|
5815
|
+
const planName = isProPlan && resolvedPlanName !== "-" ? "Pro" : resolvedPlanName;
|
|
5786
5816
|
const isFreePlan = subscription?.plan?.amount == null || subscription.plan.amount === 0;
|
|
5787
|
-
const
|
|
5817
|
+
const hasResolvedPlanAmount = (preDowngradePlan?.amount ?? subscription?.plan?.amount) != null && Boolean(preDowngradePlan?.currency ?? subscription?.plan?.currency) && Boolean(preDowngradePlan?.interval ?? subscription?.plan?.interval);
|
|
5818
|
+
const planAmount = hasResolvedPlanAmount ? `${(preDowngradePlan?.currency ?? subscription?.plan?.currency) == "inr" ? "\u20B9" : "$"}${((preDowngradePlan?.amount ?? subscription.plan.amount) / 100).toFixed(2)} / ${preDowngradePlan?.interval ?? subscription?.plan?.interval}` : "";
|
|
5819
|
+
const planCreditsFromPrice = Number(
|
|
5820
|
+
preDowngradePlan?.credits ?? currentPlanPrice?.metadata?.credits
|
|
5821
|
+
);
|
|
5822
|
+
const currentPlanCredits = Number.isFinite(planCreditsFromPrice) ? planCreditsFromPrice : customPlanCredits;
|
|
5823
|
+
const planCreditsText = currentPlanCredits != null ? `${formatCredits(currentPlanCredits)} credits` : "";
|
|
5824
|
+
const scheduledDowngradeDateLabel = formatEffectiveDateLabel(
|
|
5825
|
+
subscription?.scheduledDowngradeEffectiveDate
|
|
5826
|
+
);
|
|
5827
|
+
const scheduledDowngradeText = subscription?.downgradeScheduled && subscription.plan?.name ? `Downgrades to ${subscription.plan.name}${scheduledDowngradeDateLabel ? ` ${scheduledDowngradeDateLabel}` : ""}` : void 0;
|
|
5828
|
+
const isPlanDetailsLoading = !billingOverviewLoaded || loadingBilling || subscription?.plan == null || !planName || planName === "-" || !planAmount || currentPlanCredits == null;
|
|
5788
5829
|
const usedCredits = availableCredits != null && totalCredits != null ? Math.max(0, totalCredits - availableCredits) : null;
|
|
5789
5830
|
const progressPct = usedCredits != null && totalCredits != null && totalCredits > 0 ? Math.min(100, Math.round(usedCredits / totalCredits * 100)) : 0;
|
|
5790
5831
|
const remainingPct = 100 - progressPct;
|
|
@@ -6002,11 +6043,13 @@ function BillingContent({
|
|
|
6002
6043
|
ScPlanDetailsCard,
|
|
6003
6044
|
{
|
|
6004
6045
|
planName,
|
|
6005
|
-
planCredits:
|
|
6046
|
+
planCredits: planCreditsText,
|
|
6006
6047
|
planPrice: planAmount,
|
|
6007
6048
|
badgeText: "Active",
|
|
6049
|
+
badgeSubText: scheduledDowngradeText,
|
|
6008
6050
|
currentPlanLabel: "Current plan",
|
|
6009
|
-
upgradeButtonText: subscription?.downgradeScheduled ? "Cancel downgrade" : "
|
|
6051
|
+
upgradeButtonText: subscription?.downgradeScheduled ? "Cancel downgrade" : "Manage Plan",
|
|
6052
|
+
isLoading: isPlanDetailsLoading,
|
|
6010
6053
|
className: "flex-1 min-w-0",
|
|
6011
6054
|
onUpgrade: () => {
|
|
6012
6055
|
void logBillingEvent("billing_plans_opened", "Plans opened", {
|
|
@@ -6103,7 +6146,9 @@ function BillingContent({
|
|
|
6103
6146
|
BuyCreditsModal,
|
|
6104
6147
|
{
|
|
6105
6148
|
country: workspace.current?.country,
|
|
6106
|
-
currencySymbol: getCurrencySymbolByCountry(
|
|
6149
|
+
currencySymbol: getCurrencySymbolByCountry(
|
|
6150
|
+
workspace.current?.country
|
|
6151
|
+
),
|
|
6107
6152
|
onClose: () => setShowBuyCreditsModal(false),
|
|
6108
6153
|
onBuy: (credits, price) => {
|
|
6109
6154
|
handleBuyCredits(credits, price);
|