@robosystems/core 0.20.0 → 0.21.0
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/components/repositories/ActiveSubscriptions.d.ts +3 -1
- package/components/repositories/ActiveSubscriptions.js +3 -1
- package/components/repositories/BrowseRepositories.js +29 -5
- package/contexts/service-offerings-context.d.ts +2 -0
- package/contexts/service-offerings-context.js +2 -0
- package/lib/utc-date.d.ts +6 -0
- package/lib/utc-date.js +8 -0
- package/package.json +1 -1
|
@@ -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"] }) })] })] }),
|
|
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
|
-
|
|
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
|
|
@@ -157,10 +173,16 @@ export function BrowseRepositories({ onSubscribed, onViewSubscriptions, showHead
|
|
|
157
173
|
return repoData.enabled && !repoData.comingSoon;
|
|
158
174
|
})
|
|
159
175
|
.map(([repoType, repo]) => {
|
|
176
|
+
var _a;
|
|
160
177
|
const repoData = repo;
|
|
161
178
|
const userSub = getUserSubscription(repoType);
|
|
162
|
-
|
|
163
|
-
|
|
179
|
+
const trialDays = !userSub && !trialSpent.has(repoType)
|
|
180
|
+
? ((_a = repoData.trialDays) !== null && _a !== void 0 ? _a : 0)
|
|
181
|
+
: 0;
|
|
182
|
+
const trialEndsAt = userSub === null || userSub === void 0 ? void 0 : userSub.trial_ends_at;
|
|
183
|
+
const onTrial = !!trialEndsAt && utcDate(trialEndsAt) > new Date();
|
|
184
|
+
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() +
|
|
185
|
+
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. Raw Cypher queries, the AI analyst and your monthly credits open with the first payment. A card is required; your plan starts when the trial ends, and you can cancel any time before then and keep the rest of the trial."] }) })), _jsx("div", { className: `grid gap-6 ${repoData.plans.length === 2
|
|
164
186
|
? 'mx-auto max-w-3xl lg:grid-cols-2'
|
|
165
187
|
: 'lg:grid-cols-3'}`, children: repoData.plans.map((plan, index) => {
|
|
166
188
|
var _a, _b;
|
|
@@ -182,12 +204,14 @@ export function BrowseRepositories({ onSubscribed, onViewSubscriptions, showHead
|
|
|
182
204
|
? 'border-primary-500 bg-primary-50 dark:bg-primary-900/20 shadow-lg'
|
|
183
205
|
: isPopular
|
|
184
206
|
? '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: () => {
|
|
207
|
+
: '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
208
|
var _a;
|
|
187
209
|
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);
|
|
188
210
|
}, 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
211
|
? 'Subscribing...'
|
|
190
|
-
:
|
|
212
|
+
: trialDays > 0
|
|
213
|
+
? `Start ${plan.name} free trial`
|
|
214
|
+
: `Subscribe to ${plan.name}` })) })] }, plan.plan));
|
|
191
215
|
}) })] }) }, repoType));
|
|
192
216
|
}), (!(offerings === null || offerings === void 0 ? void 0 : offerings.repositoryPlans) ||
|
|
193
217
|
Object.keys(offerings.repositoryPlans).filter((key) => offerings.repositoryPlans[key].enabled &&
|
|
@@ -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,
|
package/lib/utc-date.js
ADDED
|
@@ -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