@robosystems/core 0.20.1 → 0.21.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.
@@ -1,5 +1,7 @@
1
1
  import * as SDK from '@robosystems/client';
2
- type SubscriptionInfo = SDK.GraphSubscriptionResponse;
2
+ type SubscriptionInfo = SDK.GraphSubscriptionResponse & {
3
+ trial_ends_at?: string | null;
4
+ };
3
5
  export interface ActiveSubscriptionsProps {
4
6
  /** Called when user clicks "Open Console" for a repository */
5
7
  onOpenConsole?: (repositoryId: string) => void;
@@ -10,6 +10,7 @@ import { useServiceOfferings } from '../../contexts/service-offerings-context';
10
10
  import { useToast } from '../../hooks/use-toast';
11
11
  import { useUser } from '../../hooks/use-user';
12
12
  import { unwrapSdk } from '../../lib/sdk-errors';
13
+ import { utcDate } from '../../lib/utc-date';
13
14
  import { Badge, Button, Card, Spinner } from '../../ui';
14
15
  export function ActiveSubscriptions({ onOpenConsole, onOpenUsage, onGettingStarted, onBackups, onBilling, onBrowse, onCancel, emptyState, }) {
15
16
  const [userSubscriptions, setUserSubscriptions] = useState([]);
@@ -115,6 +116,7 @@ export function ActiveSubscriptions({ onOpenConsole, onOpenUsage, onGettingStart
115
116
  return (_jsx(Card, { children: _jsxs("div", { className: "space-y-6", children: [_jsxs("div", { className: "flex items-start justify-between", children: [_jsxs("div", { className: "flex items-start gap-4", children: [_jsx("div", { className: "from-primary-500 to-secondary-600 rounded-lg bg-gradient-to-br p-3", children: _jsx(GoRepo, { className: "h-8 w-8 text-white" }) }), _jsxs("div", { children: [_jsx("h2", { className: "font-heading text-2xl font-bold text-zinc-900 dark:text-zinc-100", children: (repoOffering === null || repoOffering === void 0 ? void 0 : repoOffering.name) ||
116
117
  subscription.resource_id.toUpperCase() }), _jsx("p", { className: "mt-1 text-zinc-600 dark:text-zinc-400", children: (repoOffering === null || repoOffering === void 0 ? void 0 : repoOffering.description) ||
117
118
  'Shared repository subscription' }), _jsx("div", { className: "mt-2 flex", children: _jsxs(Badge, { color: "purple", children: [subscription.plan_name.charAt(0).toUpperCase() +
118
- subscription.plan_name.slice(1), ' ', "Plan"] }) })] })] }), _jsx(Badge, { color: "success", icon: HiCheckCircle, children: "Active" })] }), _jsxs("div", { className: "border-t border-zinc-200 pt-6 dark:border-zinc-700", children: [_jsx("h4", { className: "font-heading mb-4 text-sm font-semibold tracking-wide text-zinc-500 uppercase dark:text-zinc-400", children: "Quick Actions" }), _jsxs("div", { className: "grid gap-3 sm:grid-cols-2 lg:grid-cols-3", children: [onGettingStarted && (_jsxs(Button, { color: "gray", onClick: () => onGettingStarted(subscription.resource_id), className: "justify-start", children: [_jsx(HiBookOpen, { className: "mr-2 h-4 w-4" }), "Getting Started"] })), onOpenConsole && (_jsxs(Button, { color: "gray", onClick: () => handleOpenConsole(subscription.resource_id), className: "justify-start", children: [_jsx(HiTerminal, { className: "mr-2 h-4 w-4" }), "Console"] })), onOpenUsage && (_jsxs(Button, { color: "gray", onClick: () => handleOpenUsage(subscription.resource_id), className: "justify-start", children: [_jsx(HiLightningBolt, { className: "mr-2 h-4 w-4" }), "Credits & Usage"] })), onBackups && (_jsxs(Button, { color: "gray", onClick: () => handleOpenBackups(subscription.resource_id), className: "justify-start", children: [_jsx(HiCloudDownload, { className: "mr-2 h-4 w-4" }), "Backups"] })), onBrowse && (_jsxs(Button, { color: "gray", onClick: onBrowse, className: "justify-start", children: [_jsx(HiSwitchHorizontal, { className: "mr-2 h-4 w-4" }), "Change Plan"] })), onBilling && (_jsxs(Button, { color: "gray", onClick: onBilling, className: "justify-start", children: [_jsx(HiCreditCard, { className: "mr-2 h-4 w-4" }), "Billing Details"] })), onCancel && (_jsxs(Button, { color: "failure", outline: true, onClick: () => onCancel(subscription), className: "justify-start", children: [_jsx(HiXCircle, { className: "mr-2 h-4 w-4" }), "Cancel Subscription"] }))] })] }), planFeatures && planFeatures.length > 0 && (_jsxs("div", { className: "border-t border-zinc-200 pt-6 dark:border-zinc-700", children: [_jsx("h4", { className: "font-heading mb-4 text-sm font-semibold tracking-wide text-zinc-500 uppercase dark:text-zinc-400", children: "Plan Features" }), _jsx("div", { className: "grid gap-3 sm:grid-cols-2 lg:grid-cols-3", children: planFeatures.map((feature, idx) => (_jsxs("div", { className: "flex items-start gap-2", children: [_jsx(HiCheckCircle, { className: "mt-0.5 h-4 w-4 shrink-0 text-green-500" }), _jsx("span", { className: "text-sm text-zinc-600 dark:text-zinc-400", children: feature })] }, idx))) })] }))] }) }, subscription.resource_id));
119
+ subscription.plan_name.slice(1), ' ', "Plan"] }) })] })] }), subscription.trial_ends_at &&
120
+ utcDate(subscription.trial_ends_at) > now ? (_jsxs(Badge, { color: "info", icon: HiCheckCircle, children: ["Free trial, ends", ' ', utcDate(subscription.trial_ends_at).toLocaleDateString(undefined, { month: 'short', day: 'numeric' })] })) : (_jsx(Badge, { color: "success", icon: HiCheckCircle, children: "Active" }))] }), _jsxs("div", { className: "border-t border-zinc-200 pt-6 dark:border-zinc-700", children: [_jsx("h4", { className: "font-heading mb-4 text-sm font-semibold tracking-wide text-zinc-500 uppercase dark:text-zinc-400", children: "Quick Actions" }), _jsxs("div", { className: "grid gap-3 sm:grid-cols-2 lg:grid-cols-3", children: [onGettingStarted && (_jsxs(Button, { color: "gray", onClick: () => onGettingStarted(subscription.resource_id), className: "justify-start", children: [_jsx(HiBookOpen, { className: "mr-2 h-4 w-4" }), "Getting Started"] })), onOpenConsole && (_jsxs(Button, { color: "gray", onClick: () => handleOpenConsole(subscription.resource_id), className: "justify-start", children: [_jsx(HiTerminal, { className: "mr-2 h-4 w-4" }), "Console"] })), onOpenUsage && (_jsxs(Button, { color: "gray", onClick: () => handleOpenUsage(subscription.resource_id), className: "justify-start", children: [_jsx(HiLightningBolt, { className: "mr-2 h-4 w-4" }), "Credits & Usage"] })), onBackups && (_jsxs(Button, { color: "gray", onClick: () => handleOpenBackups(subscription.resource_id), className: "justify-start", children: [_jsx(HiCloudDownload, { className: "mr-2 h-4 w-4" }), "Backups"] })), onBrowse && (_jsxs(Button, { color: "gray", onClick: onBrowse, className: "justify-start", children: [_jsx(HiSwitchHorizontal, { className: "mr-2 h-4 w-4" }), "Change Plan"] })), onBilling && (_jsxs(Button, { color: "gray", onClick: onBilling, className: "justify-start", children: [_jsx(HiCreditCard, { className: "mr-2 h-4 w-4" }), "Billing Details"] })), onCancel && (_jsxs(Button, { color: "failure", outline: true, onClick: () => onCancel(subscription), className: "justify-start", children: [_jsx(HiXCircle, { className: "mr-2 h-4 w-4" }), "Cancel Subscription"] }))] })] }), planFeatures && planFeatures.length > 0 && (_jsxs("div", { className: "border-t border-zinc-200 pt-6 dark:border-zinc-700", children: [_jsx("h4", { className: "font-heading mb-4 text-sm font-semibold tracking-wide text-zinc-500 uppercase dark:text-zinc-400", children: "Plan Features" }), _jsx("div", { className: "grid gap-3 sm:grid-cols-2 lg:grid-cols-3", children: planFeatures.map((feature, idx) => (_jsxs("div", { className: "flex items-start gap-2", children: [_jsx(HiCheckCircle, { className: "mt-0.5 h-4 w-4 shrink-0 text-green-500" }), _jsx("span", { className: "text-sm text-zinc-600 dark:text-zinc-400", children: feature })] }, idx))) })] }))] }) }, subscription.resource_id));
119
121
  })] }));
120
122
  }
@@ -10,10 +10,14 @@ import { useServiceOfferings } from '../../contexts/service-offerings-context';
10
10
  import { useToast } from '../../hooks/use-toast';
11
11
  import { useUser } from '../../hooks/use-user';
12
12
  import { unwrapSdk } from '../../lib/sdk-errors';
13
+ import { utcDate } from '../../lib/utc-date';
13
14
  import { useRepositorySubscription } from '../../task-monitoring/operationHooks';
14
15
  import { Alert, Badge, Button, Card, Modal, ModalBody, ModalFooter, ModalHeader, Spinner, } from '../../ui';
15
16
  export function BrowseRepositories({ onSubscribed, onViewSubscriptions, showHeader = true, showInfoCard = true, }) {
16
17
  const [userSubscriptions, setUserSubscriptions] = useState([]);
18
+ // Repositories anyone in the org has already subscribed to: the free trial
19
+ // is one per subscriber and per org, so those open on the paid plan.
20
+ const [trialSpent, setTrialSpent] = useState(new Set());
17
21
  const [loading, setLoading] = useState(true);
18
22
  // A failed subscription read must not render as "no subscriptions": that
19
23
  // offers Subscribe on repositories the org already holds.
@@ -45,9 +49,15 @@ export function BrowseRepositories({ onSubscribed, onViewSubscriptions, showHead
45
49
  const repositorySubscriptions = (subscriptions || []).filter((sub) => sub.resource_type === 'repository' &&
46
50
  (!sub.user_id || sub.user_id === (user === null || user === void 0 ? void 0 : user.id)));
47
51
  setUserSubscriptions(repositorySubscriptions);
52
+ setTrialSpent(new Set((subscriptions || [])
53
+ .filter((sub) => sub.resource_type === 'repository' &&
54
+ sub.resource_id &&
55
+ sub.status !== 'failed')
56
+ .map((sub) => sub.resource_id)));
48
57
  }
49
58
  else {
50
59
  setUserSubscriptions([]);
60
+ setTrialSpent(new Set());
51
61
  }
52
62
  }
53
63
  catch (error) {
@@ -66,6 +76,7 @@ export function BrowseRepositories({ onSubscribed, onViewSubscriptions, showHead
66
76
  loadData();
67
77
  }, [loadData]);
68
78
  const handleSubscribe = async (repositoryType, tier) => {
79
+ var _a, _b, _c;
69
80
  if (!(currentOrg === null || currentOrg === void 0 ? void 0 : currentOrg.id)) {
70
81
  showError('No organization found');
71
82
  return;
@@ -81,7 +92,12 @@ export function BrowseRepositories({ onSubscribed, onViewSubscriptions, showHead
81
92
  if (result && 'requires_checkout' in result) {
82
93
  return;
83
94
  }
84
- showSuccess('Successfully subscribed to repository!');
95
+ const trialDays = trialSpent.has(repositoryType)
96
+ ? 0
97
+ : ((_c = (_b = (_a = offerings === null || offerings === void 0 ? void 0 : offerings.repositoryPlans) === null || _a === void 0 ? void 0 : _a[repositoryType]) === null || _b === void 0 ? void 0 : _b.trialDays) !== null && _c !== void 0 ? _c : 0);
98
+ showSuccess(trialDays > 0
99
+ ? `Your ${trialDays}-day free trial has started. Your card is charged when it ends.`
100
+ : 'Successfully subscribed to repository!');
85
101
  // Reload subscriptions
86
102
  await loadData();
87
103
  // Refresh the graphs list to include the new repository
@@ -108,7 +124,7 @@ export function BrowseRepositories({ onSubscribed, onViewSubscriptions, showHead
108
124
  sub.ends_at &&
109
125
  new Date(sub.ends_at) > new Date())));
110
126
  };
111
- const handleChangePlan = (repoType, repoName, currentPlan, currentPlanName, currentPrice, newPlan, newPlanName, newPrice) => {
127
+ const handleChangePlan = (repoType, repoName, currentPlan, currentPlanName, currentPrice, newPlan, newPlanName, newPrice, trialEndsAt) => {
112
128
  setPlanChangeModal({
113
129
  repoType,
114
130
  repoName,
@@ -119,6 +135,7 @@ export function BrowseRepositories({ onSubscribed, onViewSubscriptions, showHead
119
135
  newPlanName,
120
136
  newPrice,
121
137
  isUpgrade: newPrice > currentPrice,
138
+ trialEndsAt,
122
139
  });
123
140
  };
124
141
  const handleChangePlanConfirm = async () => {
@@ -157,10 +174,16 @@ export function BrowseRepositories({ onSubscribed, onViewSubscriptions, showHead
157
174
  return repoData.enabled && !repoData.comingSoon;
158
175
  })
159
176
  .map(([repoType, repo]) => {
177
+ var _a;
160
178
  const repoData = repo;
161
179
  const userSub = getUserSubscription(repoType);
162
- return (_jsx(Card, { className: "overflow-hidden", children: _jsxs("div", { className: "space-y-6", children: [_jsxs("div", { className: "flex items-start justify-between", children: [_jsxs("div", { className: "flex items-start gap-4", children: [_jsx("div", { className: "from-primary-500 to-secondary-600 rounded-lg bg-gradient-to-br p-3", children: _jsx(GoRepo, { className: "h-8 w-8 text-white" }) }), _jsxs("div", { children: [_jsx("h2", { className: "font-heading text-2xl font-bold text-zinc-900 dark:text-zinc-100", children: repoData.name }), _jsx("p", { className: "mt-1 text-zinc-600 dark:text-zinc-400", children: repoData.description })] })] }), userSub && (_jsxs(Badge, { color: "success", icon: HiCheckCircle, size: "lg", children: ["Active -", ' ', userSub.plan_name.charAt(0).toUpperCase() +
163
- userSub.plan_name.slice(1)] }))] }), _jsx("div", { className: `grid gap-6 ${repoData.plans.length === 2
180
+ const trialDays = !userSub && !trialSpent.has(repoType)
181
+ ? ((_a = repoData.trialDays) !== null && _a !== void 0 ? _a : 0)
182
+ : 0;
183
+ const trialEndsAt = userSub === null || userSub === void 0 ? void 0 : userSub.trial_ends_at;
184
+ const onTrial = !!trialEndsAt && utcDate(trialEndsAt) > new Date();
185
+ return (_jsx(Card, { className: "overflow-hidden", children: _jsxs("div", { className: "space-y-6", children: [_jsxs("div", { className: "flex items-start justify-between", children: [_jsxs("div", { className: "flex items-start gap-4", children: [_jsx("div", { className: "from-primary-500 to-secondary-600 rounded-lg bg-gradient-to-br p-3", children: _jsx(GoRepo, { className: "h-8 w-8 text-white" }) }), _jsxs("div", { children: [_jsx("h2", { className: "font-heading text-2xl font-bold text-zinc-900 dark:text-zinc-100", children: repoData.name }), _jsx("p", { className: "mt-1 text-zinc-600 dark:text-zinc-400", children: repoData.description })] })] }), userSub && (_jsxs(Badge, { color: onTrial ? 'info' : 'success', icon: HiCheckCircle, size: "lg", children: [onTrial ? 'Free trial' : 'Active', " -", ' ', userSub.plan_name.charAt(0).toUpperCase() +
186
+ userSub.plan_name.slice(1)] }))] }), trialDays > 0 && (_jsx(Alert, { color: "info", icon: HiInformationCircle, children: _jsxs("p", { className: "text-sm", children: [_jsxs("span", { className: "font-semibold", children: ["Start with a ", trialDays, "-day free trial on either plan."] }), ' ', "The trial opens the analysis tools over MCP and the API, at lower rate limits than the plan. Raw Cypher queries, the AI analyst and your monthly credits open with the first payment. A card is required and your plan starts when the trial ends; you can start it sooner from your organization's Subscriptions tab, or cancel any time before then and keep the rest of the trial."] }) })), _jsx("div", { className: `grid gap-6 ${repoData.plans.length === 2
164
187
  ? 'mx-auto max-w-3xl lg:grid-cols-2'
165
188
  : 'lg:grid-cols-3'}`, children: repoData.plans.map((plan, index) => {
166
189
  var _a, _b;
@@ -182,20 +205,26 @@ export function BrowseRepositories({ onSubscribed, onViewSubscriptions, showHead
182
205
  ? 'border-primary-500 bg-primary-50 dark:bg-primary-900/20 shadow-lg'
183
206
  : isPopular
184
207
  ? 'border-secondary-500 from-secondary-50 dark:from-secondary-900/20 bg-gradient-to-b to-white shadow-md dark:to-zinc-800'
185
- : 'border-zinc-200 bg-white hover:border-zinc-300 dark:border-zinc-700 dark:bg-zinc-800'}`, children: [isPopular && (_jsx("div", { className: "absolute -top-3 left-1/2 -translate-x-1/2", children: _jsx(Badge, { color: "purple", size: "sm", children: "Most Popular" }) })), _jsxs("div", { className: "flex-1", children: [_jsxs("div", { className: "text-center", children: [_jsx("h3", { className: "font-heading mb-2 text-xl font-bold text-zinc-900 dark:text-zinc-100", children: plan.name }), _jsxs("div", { className: "mb-1", children: [_jsxs("span", { className: "text-3xl font-bold text-zinc-900 dark:text-zinc-100", children: ["$", plan.monthlyPrice] }), _jsx("span", { className: "text-zinc-500 dark:text-zinc-400", children: "/month" })] }), _jsxs("p", { className: "mb-6 text-sm font-medium text-zinc-600 dark:text-zinc-400", children: [plan.monthlyCredits.toLocaleString(), ' ', "credits/month"] })] }), plan.features && (_jsx("ul", { className: "mb-6 space-y-2 text-sm", children: plan.features.map((feature, idx) => (_jsxs("li", { className: "flex items-start gap-2", children: [_jsx(HiCheckCircle, { className: "mt-0.5 h-4 w-4 shrink-0 text-green-500" }), _jsx("span", { className: "text-zinc-600 dark:text-zinc-400", children: feature })] }, idx))) }))] }), _jsx("div", { className: "mt-6", children: isCurrentPlan ? (_jsxs(Button, { color: "gray", disabled: true, className: "w-full", size: "lg", children: [_jsx(HiCheckCircle, { className: "mr-2 h-4 w-4" }), "Current Plan"] })) : userSub ? (_jsx(Button, { onClick: () => {
208
+ : 'border-zinc-200 bg-white hover:border-zinc-300 dark:border-zinc-700 dark:bg-zinc-800'}`, children: [isPopular && (_jsx("div", { className: "absolute -top-3 left-1/2 -translate-x-1/2", children: _jsx(Badge, { color: "purple", size: "sm", children: "Most Popular" }) })), _jsxs("div", { className: "flex-1", children: [_jsxs("div", { className: "text-center", children: [_jsx("h3", { className: "font-heading mb-2 text-xl font-bold text-zinc-900 dark:text-zinc-100", children: plan.name }), _jsxs("div", { className: "mb-1", children: [_jsxs("span", { className: "text-3xl font-bold text-zinc-900 dark:text-zinc-100", children: ["$", plan.monthlyPrice] }), _jsx("span", { className: "text-zinc-500 dark:text-zinc-400", children: "/month" })] }), trialDays > 0 && (_jsxs("p", { className: "text-primary-600 dark:text-primary-400 mb-1 text-sm font-medium", children: ["after a ", trialDays, "-day free trial"] })), _jsxs("p", { className: "mb-6 text-sm font-medium text-zinc-600 dark:text-zinc-400", children: [plan.monthlyCredits.toLocaleString(), ' ', "credits/month"] })] }), plan.features && (_jsx("ul", { className: "mb-6 space-y-2 text-sm", children: plan.features.map((feature, idx) => (_jsxs("li", { className: "flex items-start gap-2", children: [_jsx(HiCheckCircle, { className: "mt-0.5 h-4 w-4 shrink-0 text-green-500" }), _jsx("span", { className: "text-zinc-600 dark:text-zinc-400", children: feature })] }, idx))) }))] }), _jsx("div", { className: "mt-6", children: isCurrentPlan ? (_jsxs(Button, { color: "gray", disabled: true, className: "w-full", size: "lg", children: [_jsx(HiCheckCircle, { className: "mr-2 h-4 w-4" }), "Current Plan"] })) : userSub ? (_jsx(Button, { onClick: () => {
186
209
  var _a;
187
- return handleChangePlan(repoType, repoData.name, userSub.plan_name, userSub.plan_display_name, (_a = currentPlanData === null || currentPlanData === void 0 ? void 0 : currentPlanData.monthlyPrice) !== null && _a !== void 0 ? _a : 0, plan.plan, plan.name, plan.monthlyPrice);
210
+ return handleChangePlan(repoType, repoData.name, userSub.plan_name, userSub.plan_display_name, (_a = currentPlanData === null || currentPlanData === void 0 ? void 0 : currentPlanData.monthlyPrice) !== null && _a !== void 0 ? _a : 0, plan.plan, plan.name, plan.monthlyPrice, onTrial
211
+ ? (trialEndsAt !== null && trialEndsAt !== void 0 ? trialEndsAt : undefined)
212
+ : undefined);
188
213
  }, className: "w-full", size: "lg", color: isUpgrade ? 'purple' : 'blue', children: isUpgrade ? (_jsxs(_Fragment, { children: [_jsx(HiArrowUp, { className: "mr-2 h-4 w-4" }), "Upgrade to ", plan.name] })) : (_jsxs(_Fragment, { children: [_jsx(HiArrowDown, { className: "mr-2 h-4 w-4" }), "Downgrade to ", plan.name] })) })) : (_jsx(Button, { onClick: () => handleSubscribe(repoType, plan.plan), disabled: subscribing === `${repoType}-${plan.plan}`, className: "w-full", size: "lg", color: isPopular ? 'purple' : 'blue', children: subscribing === `${repoType}-${plan.plan}`
189
214
  ? 'Subscribing...'
190
- : `Subscribe to ${plan.name}` })) })] }, plan.plan));
215
+ : trialDays > 0
216
+ ? `Start ${plan.name} free trial`
217
+ : `Subscribe to ${plan.name}` })) })] }, plan.plan));
191
218
  }) })] }) }, repoType));
192
219
  }), (!(offerings === null || offerings === void 0 ? void 0 : offerings.repositoryPlans) ||
193
220
  Object.keys(offerings.repositoryPlans).filter((key) => offerings.repositoryPlans[key].enabled &&
194
221
  !offerings.repositoryPlans[key].comingSoon).length === 0) && (_jsx(Card, { children: _jsxs("div", { className: "py-8 text-center", children: [_jsx(HiDatabase, { className: "mx-auto mb-4 h-12 w-12 text-zinc-400" }), _jsx("p", { className: "text-zinc-600 dark:text-zinc-400", children: "No shared repositories available at this time" })] }) })), _jsxs(Modal, { show: !!planChangeModal, onClose: () => !changingPlan && setPlanChangeModal(null), size: "md", children: [_jsxs(ModalHeader, { children: [(planChangeModal === null || planChangeModal === void 0 ? void 0 : planChangeModal.isUpgrade) ? 'Upgrade' : 'Downgrade', " Plan"] }), _jsx(ModalBody, { children: planChangeModal && (_jsxs("div", { className: "space-y-4", children: [_jsxs("div", { className: "flex items-start gap-3", children: [_jsx("div", { className: `rounded-full p-3 ${planChangeModal.isUpgrade
195
222
  ? 'bg-secondary-100 dark:bg-secondary-900/30'
196
- : 'bg-primary-100 dark:bg-primary-900/30'}`, children: planChangeModal.isUpgrade ? (_jsx(HiArrowUp, { className: "text-secondary-600 dark:text-secondary-400 h-6 w-6" })) : (_jsx(HiArrowDown, { className: "text-primary-600 dark:text-primary-400 h-6 w-6" })) }), _jsxs("div", { className: "flex-1", children: [_jsxs("h3", { className: "font-semibold text-gray-900 dark:text-white", children: [planChangeModal.isUpgrade ? 'Upgrade' : 'Downgrade', ' ', planChangeModal.repoName, "?"] }), _jsx("div", { className: "mt-2 text-sm text-gray-600 dark:text-gray-400", children: _jsxs("p", { children: [planChangeModal.currentPlanName, " ($", planChangeModal.currentPrice, "/mo) \u2192", ' ', planChangeModal.newPlanName, " ($", planChangeModal.newPrice, "/mo)"] }) })] })] }), _jsx(Alert, { color: planChangeModal.isUpgrade ? 'info' : 'warning', icon: HiInformationCircle, children: _jsx("p", { className: "text-sm", children: planChangeModal.isUpgrade
197
- ? 'Your new plan will take effect immediately. You will be charged a prorated amount for the remainder of this billing period.'
198
- : 'Your plan will be downgraded immediately. You will receive a prorated credit for the remainder of this billing period.' }) })] })) }), _jsx(ModalFooter, { children: _jsxs("div", { className: "flex w-full gap-3", children: [_jsx(Button, { onClick: () => setPlanChangeModal(null), disabled: changingPlan, color: "gray", className: "flex-1", children: "Cancel" }), _jsx(Button, { onClick: handleChangePlanConfirm, disabled: changingPlan, color: (planChangeModal === null || planChangeModal === void 0 ? void 0 : planChangeModal.isUpgrade) ? 'purple' : 'blue', className: "flex-1", children: changingPlan
223
+ : 'bg-primary-100 dark:bg-primary-900/30'}`, children: planChangeModal.isUpgrade ? (_jsx(HiArrowUp, { className: "text-secondary-600 dark:text-secondary-400 h-6 w-6" })) : (_jsx(HiArrowDown, { className: "text-primary-600 dark:text-primary-400 h-6 w-6" })) }), _jsxs("div", { className: "flex-1", children: [_jsxs("h3", { className: "font-semibold text-gray-900 dark:text-white", children: [planChangeModal.isUpgrade ? 'Upgrade' : 'Downgrade', ' ', planChangeModal.repoName, "?"] }), _jsx("div", { className: "mt-2 text-sm text-gray-600 dark:text-gray-400", children: _jsxs("p", { children: [planChangeModal.currentPlanName, " ($", planChangeModal.currentPrice, "/mo) \u2192", ' ', planChangeModal.newPlanName, " ($", planChangeModal.newPrice, "/mo)"] }) })] })] }), _jsx(Alert, { color: planChangeModal.isUpgrade ? 'info' : 'warning', icon: HiInformationCircle, children: _jsx("p", { className: "text-sm", children: planChangeModal.trialEndsAt
224
+ ? `Your free trial carries on, now for ${planChangeModal.newPlanName}. Nothing is charged today, and the trial's limits stay as they are. The first charge is $${planChangeModal.newPrice} when the trial ends on ${utcDate(planChangeModal.trialEndsAt).toLocaleDateString(undefined, { month: 'short', day: 'numeric' })}.`
225
+ : planChangeModal.isUpgrade
226
+ ? 'Your new plan will take effect immediately. You will be charged a prorated amount for the remainder of this billing period.'
227
+ : 'Your plan will be downgraded immediately. You will receive a prorated credit for the remainder of this billing period.' }) })] })) }), _jsx(ModalFooter, { children: _jsxs("div", { className: "flex w-full gap-3", children: [_jsx(Button, { onClick: () => setPlanChangeModal(null), disabled: changingPlan, color: "gray", className: "flex-1", children: "Cancel" }), _jsx(Button, { onClick: handleChangePlanConfirm, disabled: changingPlan, color: (planChangeModal === null || planChangeModal === void 0 ? void 0 : planChangeModal.isUpgrade) ? 'purple' : 'blue', className: "flex-1", children: changingPlan
199
228
  ? 'Processing...'
200
229
  : `Confirm ${(planChangeModal === null || planChangeModal === void 0 ? void 0 : planChangeModal.isUpgrade) ? 'Upgrade' : 'Downgrade'}` })] }) })] })] }));
201
230
  }
@@ -20,6 +20,8 @@ export interface ServiceOfferings {
20
20
  description: string;
21
21
  enabled: boolean;
22
22
  comingSoon?: boolean;
23
+ /** Days of free trial a first subscription opens with; 0 for none. */
24
+ trialDays?: number;
23
25
  plans: Array<{
24
26
  plan: string;
25
27
  name: string;
@@ -29,11 +29,13 @@ export function ServiceOfferingsProvider({ children, }) {
29
29
  const repositoryPlans = {};
30
30
  if ((_a = apiData.repository_subscriptions) === null || _a === void 0 ? void 0 : _a.repositories) {
31
31
  apiData.repository_subscriptions.repositories.forEach((repo) => {
32
+ var _a;
32
33
  repositoryPlans[repo.type] = {
33
34
  name: repo.name,
34
35
  description: repo.description,
35
36
  enabled: repo.enabled,
36
37
  comingSoon: repo.coming_soon,
38
+ trialDays: (_a = repo.trial_days) !== null && _a !== void 0 ? _a : 0,
37
39
  plans: repo.plans.map((plan) => ({
38
40
  plan: plan.plan,
39
41
  name: plan.name,
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Parse an API timestamp. The API writes UTC with no zone, which `new Date`
3
+ * reads as local time: hours off, enough to show something that ended a
4
+ * moment ago as still running.
5
+ */
6
+ export declare function utcDate(value: string): Date;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Parse an API timestamp. The API writes UTC with no zone, which `new Date`
3
+ * reads as local time: hours off, enough to show something that ended a
4
+ * moment ago as still running.
5
+ */
6
+ export function utcDate(value) {
7
+ return new Date(/(Z|[+-]\d\d:?\d\d)$/.test(value) ? value : `${value}Z`);
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robosystems/core",
3
- "version": "0.20.1",
3
+ "version": "0.21.1",
4
4
  "description": "Shared RoboSystems frontend core library (auth, contexts, task monitoring, UI components) for the RoboSystems Next.js apps",
5
5
  "license": "MIT",
6
6
  "private": false,