@cosmoops/connect-sdk 0.2.0 → 0.6.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.
Files changed (86) hide show
  1. package/CHANGELOG.md +125 -0
  2. package/README.md +284 -7
  3. package/dist/cjs/cli/doctor.js +209 -0
  4. package/dist/cjs/cli/init.js +20 -8
  5. package/dist/cjs/client/components/access-gate.js +162 -0
  6. package/dist/cjs/client/components/account-sessions.js +21 -19
  7. package/dist/cjs/client/components/app-shell.js +157 -0
  8. package/dist/cjs/client/components/apps-grid.js +2 -1
  9. package/dist/cjs/client/components/integrations-modal.js +95 -0
  10. package/dist/cjs/client/components/motion.js +27 -0
  11. package/dist/cjs/client/components/nav.js +97 -0
  12. package/dist/cjs/client/components/plans.js +39 -37
  13. package/dist/cjs/client/components/readiness.js +3 -1
  14. package/dist/cjs/client/components/side-nav.js +58 -0
  15. package/dist/cjs/client/components/subscription.js +2 -1
  16. package/dist/cjs/client/components/surfaces.js +54 -0
  17. package/dist/cjs/client/components/usage-meter.js +3 -2
  18. package/dist/cjs/client/components/user-menu.js +30 -3
  19. package/dist/cjs/client/index.js +29 -1
  20. package/dist/cjs/client/provider.js +54 -2
  21. package/dist/cjs/client/use-active-path.js +77 -0
  22. package/dist/cjs/errors.js +1 -1
  23. package/dist/cjs/next/index.js +96 -15
  24. package/dist/cjs/server/client.js +10 -2
  25. package/dist/cjs/server/handler.js +89 -6
  26. package/dist/cjs/server/index.js +8 -1
  27. package/dist/cjs/server/resources/analytics.js +66 -0
  28. package/dist/cjs/server/resources/identity.js +1 -1
  29. package/dist/cjs/server/resources/integrations.js +66 -0
  30. package/dist/cjs/server/resources/sessions.js +1 -1
  31. package/dist/cjs/server/webhooks.js +127 -0
  32. package/dist/cjs/this-entry-is-server-only.js +31 -0
  33. package/dist/esm/cli/doctor.js +206 -0
  34. package/dist/esm/cli/init.js +20 -8
  35. package/dist/esm/client/components/access-gate.js +158 -0
  36. package/dist/esm/client/components/account-sessions.js +21 -19
  37. package/dist/esm/client/components/app-shell.js +154 -0
  38. package/dist/esm/client/components/apps-grid.js +2 -1
  39. package/dist/esm/client/components/integrations-modal.js +92 -0
  40. package/dist/esm/client/components/motion.js +21 -0
  41. package/dist/esm/client/components/nav.js +89 -0
  42. package/dist/esm/client/components/plans.js +39 -37
  43. package/dist/esm/client/components/readiness.js +3 -1
  44. package/dist/esm/client/components/side-nav.js +53 -0
  45. package/dist/esm/client/components/subscription.js +2 -1
  46. package/dist/esm/client/components/surfaces.js +51 -0
  47. package/dist/esm/client/components/usage-meter.js +3 -2
  48. package/dist/esm/client/components/user-menu.js +31 -4
  49. package/dist/esm/client/index.js +15 -1
  50. package/dist/esm/client/provider.js +53 -2
  51. package/dist/esm/client/use-active-path.js +74 -0
  52. package/dist/esm/errors.js +1 -1
  53. package/dist/esm/next/index.js +95 -15
  54. package/dist/esm/server/client.js +10 -2
  55. package/dist/esm/server/handler.js +89 -6
  56. package/dist/esm/server/index.js +5 -0
  57. package/dist/esm/server/resources/analytics.js +62 -0
  58. package/dist/esm/server/resources/identity.js +1 -1
  59. package/dist/esm/server/resources/integrations.js +62 -0
  60. package/dist/esm/server/resources/sessions.js +1 -1
  61. package/dist/esm/server/webhooks.js +123 -0
  62. package/dist/esm/this-entry-is-server-only.js +30 -0
  63. package/dist/theme.css +28 -0
  64. package/dist/types/cli/doctor.d.ts +23 -0
  65. package/dist/types/cli/init.d.ts +2 -3
  66. package/dist/types/client/components/access-gate.d.ts +79 -0
  67. package/dist/types/client/components/app-shell.d.ts +115 -0
  68. package/dist/types/client/components/integrations-modal.d.ts +21 -0
  69. package/dist/types/client/components/motion.d.ts +22 -0
  70. package/dist/types/client/components/nav.d.ts +110 -0
  71. package/dist/types/client/components/side-nav.d.ts +31 -0
  72. package/dist/types/client/components/surfaces.d.ts +51 -0
  73. package/dist/types/client/index.d.ts +12 -1
  74. package/dist/types/client/provider.d.ts +38 -3
  75. package/dist/types/client/use-active-path.d.ts +8 -0
  76. package/dist/types/errors.d.ts +1 -1
  77. package/dist/types/next/index.d.ts +40 -0
  78. package/dist/types/server/client.d.ts +8 -2
  79. package/dist/types/server/index.d.ts +17 -2
  80. package/dist/types/server/resources/analytics.d.ts +31 -0
  81. package/dist/types/server/resources/identity.d.ts +12 -2
  82. package/dist/types/server/resources/integrations.d.ts +40 -0
  83. package/dist/types/server/webhooks.d.ts +67 -0
  84. package/dist/types/this-entry-is-server-only.d.ts +1 -0
  85. package/dist/types/types.d.ts +182 -1
  86. package/package.json +22 -4
@@ -0,0 +1,154 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useCallback, useState, useSyncExternalStore } from "react";
4
+ import { Button, Drawer, Tooltip } from "@heroui/react";
5
+ import { Menu, PanelLeftClose, PanelLeftOpen } from "lucide-react";
6
+ import { useConnect } from "../provider.js";
7
+ import { ConnectAccessGate } from "./access-gate.js";
8
+ import { ConnectAppsGrid } from "./apps-grid.js";
9
+ import { ConnectLoginButton, ConnectRegisterButton } from "./auth-buttons.js";
10
+ import { ConnectLogo } from "./logo.js";
11
+ import { ConnectSideNav, defaultRenderLink } from "./side-nav.js";
12
+ import { ConnectUserMenu } from "./user-menu.js";
13
+ import { gateExemptPaths, normalizePath, } from "./nav.js";
14
+ import { useActivePath } from "../use-active-path.js";
15
+ const COLLAPSED_KEY = "connect_sidenav_collapsed";
16
+ const COLLAPSED_EVENT = "connect:sidenav-collapsed";
17
+ /**
18
+ * The stored rail preference, or `null` when there isn't one (or when reading
19
+ * it is not allowed).
20
+ *
21
+ * `localStorage` throws outright in a partitioned iframe or with site data
22
+ * blocked, and an application frame is not worth losing over a preference.
23
+ */
24
+ function collapsedSnapshot() {
25
+ try {
26
+ const stored = window.localStorage.getItem(COLLAPSED_KEY);
27
+ return stored === null ? null : stored === "1";
28
+ }
29
+ catch {
30
+ return null;
31
+ }
32
+ }
33
+ /**
34
+ * No preference on the server, which is the point: `useSyncExternalStore` uses
35
+ * this for the hydrating render and only then swaps in the real reading, so a
36
+ * returning user's collapsed rail can never make the server's HTML and the
37
+ * client's first pass disagree. Reading storage during render instead is a
38
+ * hydration mismatch waiting for its first user.
39
+ */
40
+ function serverCollapsedSnapshot() {
41
+ return null;
42
+ }
43
+ function subscribeCollapsed(onStoreChange) {
44
+ // `storage` covers the app's other tabs; the custom event covers this one,
45
+ // which `storage` deliberately never fires in.
46
+ window.addEventListener("storage", onStoreChange);
47
+ window.addEventListener(COLLAPSED_EVENT, onStoreChange);
48
+ return () => {
49
+ window.removeEventListener("storage", onStoreChange);
50
+ window.removeEventListener(COLLAPSED_EVENT, onStoreChange);
51
+ };
52
+ }
53
+ /**
54
+ * The sidebar's brand row: the lockup when expanded, the badge alone when not.
55
+ */
56
+ function BrandLink({ name, icon, homeHref, collapsed, renderLink, }) {
57
+ return renderLink({
58
+ href: homeHref,
59
+ className: `flex items-center rounded-lg focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus ${collapsed ? "justify-center" : ""}`,
60
+ // `ConnectLogo` names itself, but it does it with `role="img"` on a
61
+ // `<span>`, which the `<a>` wrapping it does not inherit as its own name.
62
+ "aria-label": `${name} home`,
63
+ children: _jsx(ConnectLogo, { name: name, icon: icon, collapsed: collapsed }),
64
+ });
65
+ }
66
+ /**
67
+ * The application frame every CosmoOps service platform runs inside: a
68
+ * collapsible sidebar, a top bar carrying the app launcher and the account
69
+ * menu, and your pages in the middle.
70
+ *
71
+ * This is the piece each partner was otherwise writing by hand, and writing
72
+ * slightly differently - which is how a family of services stops looking like
73
+ * one product. Everything that should be identical across platforms (the
74
+ * lockup, the rail geometry, the active-route treatment, the launcher, the
75
+ * account menu, the access gate) lives here; everything that genuinely
76
+ * differs is a prop:
77
+ *
78
+ * ```tsx
79
+ * "use client";
80
+ * import Link from "next/link";
81
+ * import { usePathname } from "next/navigation";
82
+ * import { ConnectAppShell } from "@cosmoops/connect-sdk/client";
83
+ * import { LayoutDashboard, Truck } from "lucide-react";
84
+ *
85
+ * export function Shell({ children }: { children: React.ReactNode }) {
86
+ * return (
87
+ * <ConnectAppShell
88
+ * name="Dispatch"
89
+ * icon={<Truck />}
90
+ * activePath={usePathname()}
91
+ * renderLink={(props) => <Link {...props} />}
92
+ * nav={[
93
+ * { label: "Overview", href: "/", icon: <LayoutDashboard className="size-5" /> },
94
+ * { label: "Plans", href: "/plans", icon: <Truck className="size-5" />, gateExempt: true },
95
+ * ]}
96
+ * >
97
+ * {children}
98
+ * </ConnectAppShell>
99
+ * );
100
+ * }
101
+ * ```
102
+ *
103
+ * There is no `isSignedIn` branch anywhere in here, and there should be none
104
+ * in yours: the auth buttons render nothing once a session exists, the user
105
+ * menu renders nothing without one, and the launcher renders nothing when
106
+ * signed out. The swap happens inside the components.
107
+ *
108
+ * It renders no provider of its own - mount `ConnectProvider` above it, once,
109
+ * so a page with a shell, a plan table and a usage meter still makes one
110
+ * session read.
111
+ */
112
+ export function ConnectAppShell({ name, icon, homeHref = "/", nav, activePath, renderLink = defaultRenderLink, title, headerActions, sidebarFooter, footer, defaultCollapsed = false, collapsed: controlledCollapsed, onCollapsedChange, collapsible = true, showAppsGrid = true, showAuthButtons = true, theme, onThemeChange, gate = true, gateExemptRoutes, className, contentClassName, children, }) {
113
+ const { session, isLoading } = useConnect();
114
+ const pathname = useActivePath(activePath);
115
+ const [mobileOpen, setMobileOpen] = useState(false);
116
+ // The rail's own state lives in `localStorage`, read as an external store
117
+ // rather than copied into React state: it is shared with this app's other
118
+ // tabs, and the reading is not available during the render that hydrates.
119
+ const stored = useSyncExternalStore(subscribeCollapsed, collapsedSnapshot, serverCollapsedSnapshot);
120
+ const isControlled = controlledCollapsed !== undefined;
121
+ const collapsed = collapsible ? (isControlled ? controlledCollapsed : (stored ?? defaultCollapsed)) : false;
122
+ const toggleCollapsed = useCallback(() => {
123
+ const next = !collapsed;
124
+ onCollapsedChange?.(next);
125
+ if (isControlled)
126
+ return;
127
+ try {
128
+ window.localStorage.setItem(COLLAPSED_KEY, next ? "1" : "0");
129
+ }
130
+ catch {
131
+ // Not persisted - but the event below still moves the rail for this session.
132
+ }
133
+ window.dispatchEvent(new Event(COLLAPSED_EVENT));
134
+ }, [collapsed, isControlled, onCollapsedChange]);
135
+ const closeMobile = useCallback(() => setMobileOpen(false), []);
136
+ const currentPath = normalizePath(pathname);
137
+ const exempt = [...gateExemptPaths(nav), ...(gateExemptRoutes ?? []).map(normalizePath)];
138
+ const isExempt = exempt.some((path) => currentPath === path || currentPath.startsWith(`${path}/`));
139
+ // A signed-out visitor has no readiness to check and nothing to be blocked
140
+ // by; `ConnectAccessGate` passes them straight through, but mounting it at
141
+ // all costs an entitlements read that cannot succeed.
142
+ const signedOut = !isLoading && !session?.user;
143
+ const gated = gate && !isExempt && !signedOut;
144
+ const sideNav = (mobile) => (_jsx(ConnectSideNav, { nav: nav, activePath: pathname, renderLink: renderLink, collapsed: mobile ? false : collapsed, onNavigate: mobile ? closeMobile : undefined }));
145
+ return (_jsxs("div", { className: `flex h-screen bg-background ${className ?? ""}`, children: [_jsxs("aside", { "aria-label": "Sidebar", className: `hidden shrink-0 flex-col border-r border-border bg-surface transition-[width] duration-200 ease-in-out will-change-[width] md:flex ${collapsed ? "w-16" : "w-64"}`, children: [_jsx("div", { className: `flex h-16 shrink-0 items-center border-b border-border ${collapsed ? "justify-center px-2" : "px-4"}`, children: _jsx(BrandLink, { name: name, icon: icon, homeHref: homeHref, collapsed: collapsed, renderLink: renderLink }) }), _jsx("div", { className: `flex-1 overflow-y-auto py-4 ${collapsed ? "px-2" : "px-3"}`, children: sideNav(false) }), _jsxs("div", { className: `shrink-0 border-t border-border ${collapsed ? "flex flex-col items-center gap-2 p-2" : "flex flex-col gap-2 p-3"}`, children: [!collapsed && sidebarFooter, collapsible && (
146
+ // The button goes in as a *direct* child, the way `Modal` and
147
+ // `Dropdown` take theirs. `Tooltip.Trigger` renders a wrapper
148
+ // `<div>` and puts the props it is given on that div - so an
149
+ // `aria-label` passed there names a div nobody can reach and
150
+ // leaves this icon-only button with no accessible name at all.
151
+ // The wrapper is for trigger elements React Aria cannot drive
152
+ // directly; a HeroUI `Button` is not one.
153
+ _jsxs(Tooltip, { delay: 200, children: [_jsx(Button, { isIconOnly: true, variant: "tertiary", size: "sm", "aria-label": collapsed ? "Expand sidebar" : "Collapse sidebar", className: collapsed ? "" : "self-start", onPress: toggleCollapsed, children: collapsed ? _jsx(PanelLeftOpen, { className: "size-4" }) : _jsx(PanelLeftClose, { className: "size-4" }) }), _jsx(Tooltip.Content, { placement: "right", children: collapsed ? "Expand sidebar" : "Collapse sidebar" })] }))] })] }), _jsx(Drawer.Backdrop, { isOpen: mobileOpen, onOpenChange: setMobileOpen, children: _jsx(Drawer.Content, { placement: "left", className: "w-72 max-w-[80vw]", children: _jsxs(Drawer.Dialog, { "aria-label": "Navigation menu", children: [_jsx(Drawer.CloseTrigger, {}), _jsx(Drawer.Header, { children: _jsx(Drawer.Heading, { "aria-label": name, children: _jsx(ConnectLogo, { name: name, icon: icon }) }) }), _jsx(Drawer.Body, { children: sideNav(true) }), sidebarFooter && _jsx(Drawer.Footer, { className: "flex flex-col items-stretch gap-3", children: sidebarFooter })] }) }) }), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col", children: [_jsxs("header", { className: "flex h-16 shrink-0 items-center gap-3 border-b border-border bg-surface px-4 md:px-6", children: [_jsx(Button, { isIconOnly: true, variant: "tertiary", size: "sm", className: "md:hidden", "aria-label": "Open navigation menu", onPress: () => setMobileOpen(true), children: _jsx(Menu, { className: "size-5" }) }), typeof title === "string" ? (_jsx("h1", { className: "truncate text-lg font-semibold text-foreground", children: title })) : (title), _jsxs("div", { className: "ml-auto flex items-center gap-1", children: [headerActions, showAppsGrid && _jsx(ConnectAppsGrid, {}), _jsx(ConnectUserMenu, { compact: true, theme: theme, onThemeChange: onThemeChange }), showAuthButtons && (_jsxs(_Fragment, { children: [_jsx(ConnectLoginButton, { size: "sm" }), _jsx(ConnectRegisterButton, { size: "sm" })] }))] })] }), _jsx("main", { className: "flex-1 overflow-y-auto", children: _jsxs("div", { className: contentClassName ?? "mx-auto w-full max-w-6xl px-4 py-6 md:px-6 md:py-8", children: [gated ? _jsx(ConnectAccessGate, { children: children }) : children, footer] }) })] })] }));
154
+ }
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
3
3
  import { Button, Modal, Skeleton } from "@heroui/react";
4
4
  import { AlertCircle, ExternalLink, LayoutGrid } from "lucide-react";
5
5
  import { useConnectApps, useConnect } from "../provider.js";
6
+ import { ENTER, m, MotionProvider } from "./motion.js";
6
7
  function AppTile({ app }) {
7
8
  const disabled = app.launchUrl === null;
8
9
  const body = (_jsxs(_Fragment, { children: [_jsxs("span", { className: "relative flex size-12 items-center justify-center overflow-hidden rounded-xl bg-surface-secondary", children: [app.iconUrl ? (
@@ -35,7 +36,7 @@ export function ConnectAppsGrid({ className, label = "Switch app" }) {
35
36
  if (sessionLoading || !session?.user)
36
37
  return null;
37
38
  const apps = data?.apps ?? [];
38
- return (_jsxs(Modal, { children: [_jsx(Button, { isIconOnly: true, variant: "primary", "aria-label": label, className: className, children: _jsx(LayoutGrid, { className: "size-5" }) }), _jsx(Modal.Backdrop, { children: _jsx(Modal.Container, { children: _jsxs(Modal.Dialog, { className: "sm:max-w-md", children: [_jsx(Modal.CloseTrigger, {}), _jsx(Modal.Header, { children: _jsx(Modal.Heading, { children: "Your apps" }) }), _jsxs(Modal.Body, { children: [isLoading && (_jsx("div", { className: "grid grid-cols-3 gap-2", children: Array.from({ length: 6 }, (_, index) => (_jsxs("div", { className: "flex flex-col items-center gap-2 p-3", children: [_jsx(Skeleton, { className: "size-12 rounded-xl" }), _jsx(Skeleton, { className: "h-3 w-14" })] }, index))) })), !isLoading && error && (_jsx("p", { className: "py-6 text-center text-sm text-danger", children: "Could not load your apps." })), !isLoading && !error && apps.length === 0 && (_jsx("p", { className: "py-6 text-center text-sm text-muted", children: "No other apps yet. Anything this workspace subscribes to shows up here." })), !isLoading && !error && apps.length > 0 && (_jsx("div", { className: "grid grid-cols-3 gap-2", children: apps.map((app) => (_jsx(AppTile, { app: app }, app.serviceId))) }))] }), _jsx(Modal.Footer, { children: _jsx(ConnectBrowseAllLink, {}) })] }) }) })] }));
39
+ return (_jsx(MotionProvider, { children: _jsxs(Modal, { children: [_jsx(Button, { isIconOnly: true, variant: "primary", "aria-label": label, className: className, children: _jsx(LayoutGrid, { className: "size-5" }) }), _jsx(Modal.Backdrop, { children: _jsx(Modal.Container, { children: _jsxs(Modal.Dialog, { className: "sm:max-w-md", children: [_jsx(Modal.CloseTrigger, {}), _jsx(Modal.Header, { children: _jsx(Modal.Heading, { children: "Your apps" }) }), _jsxs(Modal.Body, { children: [isLoading && (_jsx("div", { className: "grid grid-cols-3 gap-2", children: Array.from({ length: 6 }, (_, index) => (_jsxs("div", { className: "flex flex-col items-center gap-2 p-3", children: [_jsx(Skeleton, { className: "size-12 rounded-xl" }), _jsx(Skeleton, { className: "h-3 w-14" })] }, index))) })), !isLoading && error && (_jsx("p", { className: "py-6 text-center text-sm text-danger", children: "Could not load your apps." })), !isLoading && !error && apps.length === 0 && (_jsx("p", { className: "py-6 text-center text-sm text-muted", children: "No other apps yet. Anything this workspace subscribes to shows up here." })), !isLoading && !error && apps.length > 0 && (_jsx(m.div, { className: "grid grid-cols-3 gap-2", variants: { show: { transition: { staggerChildren: 0.04 } } }, initial: "hidden", animate: "show", children: apps.map((app) => (_jsx(m.div, { variants: { hidden: { opacity: 0, y: 8 }, show: { opacity: 1, y: 0, transition: ENTER } }, children: _jsx(AppTile, { app: app }) }, app.serviceId))) }))] }), _jsx(Modal.Footer, { children: _jsx(ConnectBrowseAllLink, {}) })] }) }) })] }) }));
39
40
  }
40
41
  function ConnectBrowseAllLink() {
41
42
  const { appUrl } = useConnect();
@@ -0,0 +1,92 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useState } from "react";
4
+ import { AlertDialog, Button, Chip, Modal, Skeleton } from "@heroui/react";
5
+ import { AlertCircle, Puzzle } from "lucide-react";
6
+ import { useConnect, useConnectIntegrations } from "../provider.js";
7
+ import { ENTER, m, MotionProvider } from "./motion.js";
8
+ const STATUS_LABEL = {
9
+ not_connected: "Not connected",
10
+ pending: "Connecting…",
11
+ active: "Connected",
12
+ failed: "Failed",
13
+ disconnected: "Disconnected",
14
+ expired: "Expired",
15
+ };
16
+ const STATUS_COLOR = {
17
+ not_connected: "default",
18
+ pending: "warning",
19
+ active: "success",
20
+ failed: "danger",
21
+ disconnected: "default",
22
+ expired: "danger",
23
+ };
24
+ const CAN_CONNECT = new Set([
25
+ "not_connected",
26
+ "failed",
27
+ "disconnected",
28
+ "expired",
29
+ ]);
30
+ /**
31
+ * One toolkit's icon, status, and whatever action its current status allows.
32
+ * Never a dead end the way `AppTile` avoids one for a missing `launchUrl`:
33
+ * every status renders *some* affordance - connect, reconnect, disconnect,
34
+ * or a cancel for a stuck `pending` attempt.
35
+ */
36
+ function ToolkitTile({ toolkit, isPending, onConnect, onDisconnect }) {
37
+ const [confirmingDisconnect, setConfirmingDisconnect] = useState(false);
38
+ return (_jsxs("div", { className: "flex flex-col items-center gap-2 rounded-xl border border-separator p-3", children: [_jsxs("span", { className: "relative flex size-12 items-center justify-center overflow-hidden rounded-xl bg-surface-secondary", children: [toolkit.logoUrl ? (
39
+ // Deliberately a plain `<img>`: this package ships into any React app
40
+ // and cannot assume `next/image` or any other framework loader.
41
+ // eslint-disable-next-line @next/next/no-img-element
42
+ _jsx("img", { src: toolkit.logoUrl, alt: "", className: "size-full object-cover" })) : (_jsx(Puzzle, { className: "size-6 text-muted", "aria-hidden": "true" })), toolkit.status === "failed" && (_jsx("span", { className: "absolute -right-0.5 -top-0.5 flex size-4 items-center justify-center rounded-full bg-danger text-danger-foreground", children: _jsx(AlertCircle, { className: "size-3", "aria-hidden": "true" }) }))] }), _jsx("span", { className: "line-clamp-2 text-center text-xs font-medium text-foreground", children: toolkit.name }), _jsx(Chip, { size: "sm", variant: "soft", color: STATUS_COLOR[toolkit.status], children: STATUS_LABEL[toolkit.status] }), _jsxs("div", { className: "flex w-full flex-col gap-1.5 pt-1", children: [CAN_CONNECT.has(toolkit.status) && (_jsx(Button, { size: "sm", variant: "secondary", className: "w-full text-xs", isPending: isPending, isDisabled: isPending, onPress: onConnect, children: "Connect" })), toolkit.status === "active" && (_jsxs(_Fragment, { children: [_jsx(Button, { size: "sm", variant: "secondary", className: "w-full text-xs", isPending: isPending, isDisabled: isPending, onPress: onConnect, children: "Reconnect" }), _jsxs(AlertDialog, { isOpen: confirmingDisconnect, onOpenChange: setConfirmingDisconnect, children: [_jsx(Button, { size: "sm", variant: "tertiary", className: "w-full text-xs text-danger", isDisabled: isPending, children: "Disconnect" }), _jsx(AlertDialog.Backdrop, { children: _jsx(AlertDialog.Container, { children: _jsxs(AlertDialog.Dialog, { className: "sm:max-w-100", children: [_jsx(AlertDialog.CloseTrigger, {}), _jsxs(AlertDialog.Header, { children: [_jsx(AlertDialog.Icon, { status: "danger" }), _jsxs(AlertDialog.Heading, { children: ["Disconnect ", toolkit.name, "?"] })] }), _jsx(AlertDialog.Body, { children: _jsx("p", { className: "text-sm text-muted", children: "Every member loses this connection immediately - it can be reconnected later." }) }), _jsxs(AlertDialog.Footer, { children: [_jsx(Button, { slot: "close", variant: "secondary", className: "text-xs", children: "Cancel" }), _jsx(Button, { slot: "close", variant: "danger", className: "text-xs", onPress: onDisconnect, children: "Disconnect" })] })] }) }) })] })] })), toolkit.status === "pending" && (_jsx(Button, { size: "sm", variant: "tertiary", className: "w-full text-xs text-danger", isDisabled: isPending, onPress: onDisconnect, children: "Cancel" }))] })] }));
43
+ }
44
+ /**
45
+ * A grid of every Composio-hosted toolkit this organization can connect -
46
+ * Google Calendar, Slack, Twitter/X, whatever a platform admin enabled in
47
+ * Connect's own Console. Each tile carries its own connect/reconnect/
48
+ * disconnect action and its own pending state, independent of every other
49
+ * tile - see the doc comment on `pendingSlug` below for why that matters.
50
+ *
51
+ * Not optimistic: a tile stays whatever it already was after "Connect" is
52
+ * pressed, because the connection isn't settled until Composio's webhook
53
+ * confirms it - `mutateResource` here only ever gets as far as `pending`
54
+ * before the browser navigates away to complete the provider's OAuth screen.
55
+ *
56
+ * Renders nothing when signed out, same as `ConnectAppsGrid`.
57
+ */
58
+ export function ConnectIntegrationsModal({ className, label = "Integrations" }) {
59
+ const { session, isLoading: sessionLoading, mutateResource, invalidateResource } = useConnect();
60
+ const { data, isLoading, error, refetch } = useConnectIntegrations();
61
+ // Per-toolkit, not one shared flag - a grid of independent connections is
62
+ // exactly the "list of rows" case a single `isPending` disables wholesale
63
+ // (see CLAUDE.md's mutation-conventions note on this).
64
+ const [pendingSlug, setPendingSlug] = useState(null);
65
+ if (sessionLoading || !session?.user)
66
+ return null;
67
+ const toolkits = data?.toolkits ?? [];
68
+ const connect = (slug) => {
69
+ setPendingSlug(slug);
70
+ void mutateResource("/integrations/connect", {
71
+ toolkitSlug: slug,
72
+ returnUrl: window.location.href,
73
+ })
74
+ .then(({ redirectUrl }) => {
75
+ window.location.href = redirectUrl;
76
+ })
77
+ .catch(() => setPendingSlug(null));
78
+ // No `finally(() => setPendingSlug(null))` on the success path: the
79
+ // browser is about to navigate away, and clearing the flag first would
80
+ // let a slow navigation show the button as re-enabled for a beat.
81
+ };
82
+ const disconnect = (slug) => {
83
+ setPendingSlug(slug);
84
+ void mutateResource("/integrations/disconnect", { toolkitSlug: slug })
85
+ .then(() => {
86
+ invalidateResource("/integrations");
87
+ refetch();
88
+ })
89
+ .finally(() => setPendingSlug(null));
90
+ };
91
+ return (_jsx(MotionProvider, { children: _jsxs(Modal, { children: [_jsxs(Button, { variant: "secondary", className: className, children: [_jsx(Puzzle, { className: "size-4" }), label] }), _jsx(Modal.Backdrop, { children: _jsx(Modal.Container, { children: _jsxs(Modal.Dialog, { className: "sm:max-w-lg", children: [_jsx(Modal.CloseTrigger, {}), _jsx(Modal.Header, { children: _jsx(Modal.Heading, { children: "Integrations" }) }), _jsxs(Modal.Body, { children: [isLoading && (_jsx("div", { className: "grid grid-cols-2 gap-3 sm:grid-cols-3", children: Array.from({ length: 6 }, (_, index) => (_jsxs("div", { className: "flex flex-col items-center gap-2 rounded-xl border border-separator p-3", children: [_jsx(Skeleton, { className: "size-12 rounded-xl" }), _jsx(Skeleton, { className: "h-3 w-16" }), _jsx(Skeleton, { className: "h-7 w-full rounded-lg" })] }, index))) })), !isLoading && error && (_jsx("p", { className: "py-6 text-center text-sm text-danger", children: "Could not load integrations." })), !isLoading && !error && toolkits.length === 0 && (_jsx("p", { className: "py-6 text-center text-sm text-muted", children: "No integrations are enabled on this platform yet." })), !isLoading && !error && toolkits.length > 0 && (_jsx(m.div, { className: "grid grid-cols-2 gap-3 sm:grid-cols-3", variants: { show: { transition: { staggerChildren: 0.04 } } }, initial: "hidden", animate: "show", children: toolkits.map((toolkit) => (_jsx(m.div, { variants: { hidden: { opacity: 0, y: 8 }, show: { opacity: 1, y: 0, transition: ENTER } }, children: _jsx(ToolkitTile, { toolkit: toolkit, isPending: pendingSlug === toolkit.slug, onConnect: () => connect(toolkit.slug), onDisconnect: () => disconnect(toolkit.slug) }) }, toolkit.slug))) }))] })] }) }) })] }) }));
92
+ }
@@ -0,0 +1,21 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { LazyMotion, MotionConfig, domAnimation } from "motion/react";
4
+ export { m, AnimatePresence } from "motion/react";
5
+ /** HeroUI's --ease-out-quart, transcribed for motion transitions. */
6
+ export const EASE_OUT_QUART = [0.165, 0.84, 0.44, 1];
7
+ export const ENTER = { duration: 0.3, ease: EASE_OUT_QUART };
8
+ export const METER_SPRING = {
9
+ type: "spring",
10
+ stiffness: 170,
11
+ damping: 26,
12
+ };
13
+ /**
14
+ * Per-component motion root. domAnimation keeps the feature bundle small,
15
+ * `strict` restricts rendering to `m.*` components, and reducedMotion="user"
16
+ * drops transform animation (keeping opacity) under prefers-reduced-motion -
17
+ * the same contract HeroUI's own `motion-reduce` styles follow.
18
+ */
19
+ export function MotionProvider({ children }) {
20
+ return (_jsx(MotionConfig, { reducedMotion: "user", children: _jsx(LazyMotion, { features: domAnimation, strict: true, children: children }) }));
21
+ }
@@ -0,0 +1,89 @@
1
+ function isSection(entry) {
2
+ return !("href" in entry) && Array.isArray(entry.items);
3
+ }
4
+ /** Folds a mixed `ConnectNav` into sections, gathering consecutive bare items into one untitled group. */
5
+ export function normalizeNav(nav) {
6
+ const sections = [];
7
+ let loose = null;
8
+ for (const entry of nav) {
9
+ if (isSection(entry)) {
10
+ loose = null;
11
+ sections.push(entry);
12
+ continue;
13
+ }
14
+ if (!loose) {
15
+ loose = [];
16
+ sections.push({ items: loose });
17
+ }
18
+ loose.push(entry);
19
+ }
20
+ return sections;
21
+ }
22
+ /** Every item in the tree, parents and children alike, in render order. */
23
+ export function flattenNav(nav) {
24
+ const out = [];
25
+ for (const section of normalizeNav(nav)) {
26
+ for (const item of section.items) {
27
+ out.push(item);
28
+ if (item.items)
29
+ out.push(...item.items);
30
+ }
31
+ }
32
+ return out;
33
+ }
34
+ /**
35
+ * `https://x.test/billing/?tab=1#top` -> `/billing`.
36
+ *
37
+ * Trailing slashes go too, so `/billing/` and `/billing` are the same route -
38
+ * they are, to every router, and treating them as different is how a nav item
39
+ * ends up unhighlighted on exactly one of the two URLs a user can arrive at.
40
+ */
41
+ export function normalizePath(path) {
42
+ const withoutOrigin = path.replace(/^[a-z][a-z0-9+.-]*:\/\/[^/]*/i, "");
43
+ const withoutQuery = withoutOrigin.split(/[?#]/)[0] ?? "";
44
+ const trimmed = withoutQuery.replace(/\/+$/, "");
45
+ return trimmed === "" ? "/" : trimmed;
46
+ }
47
+ /**
48
+ * The href of the nav item the current path belongs to, or `null`.
49
+ *
50
+ * Longest prefix wins, so `/settings/billing` lights up Billing and not also
51
+ * its parent Settings - a plain `startsWith` over an unordered list lights up
52
+ * both, and the sidebar grows two highlights.
53
+ *
54
+ * External items never match: they leave the app, so no path inside it is
55
+ * ever "on" them.
56
+ */
57
+ export function resolveActivePath(pathname, nav) {
58
+ const current = normalizePath(pathname);
59
+ let best = null;
60
+ for (const item of flattenNav(nav)) {
61
+ if (item.external)
62
+ continue;
63
+ const href = normalizePath(item.href);
64
+ const exact = item.exact || href === "/";
65
+ const matches = current === href || (!exact && current.startsWith(`${href}/`));
66
+ if (matches && (best === null || href.length > best.length))
67
+ best = href;
68
+ }
69
+ return best;
70
+ }
71
+ /**
72
+ * Whether `item` is the destination `resolveActivePath` picked.
73
+ *
74
+ * Not just `normalizePath(item.href) === activeHref`, which is the trap this
75
+ * exists to close: `normalizePath` strips the origin off an absolute URL, so
76
+ * an external item pointed at `https://docs.example.com` normalizes to `/` and
77
+ * lights up on every app's home route. External items are never active.
78
+ */
79
+ export function isNavItemActive(item, activeHref) {
80
+ if (activeHref === null || item.external)
81
+ return false;
82
+ return normalizePath(item.href) === activeHref;
83
+ }
84
+ /** Hrefs declared `gateExempt` - the routes `ConnectAppShell` renders outside its `ConnectAccessGate`. */
85
+ export function gateExemptPaths(nav) {
86
+ return flattenNav(nav)
87
+ .filter((item) => item.gateExempt)
88
+ .map((item) => normalizePath(item.href));
89
+ }
@@ -5,6 +5,7 @@ import { Check, CheckCircle2, ExternalLink, Loader2, Sparkles, Tag } from "lucid
5
5
  import { useMemo, useState } from "react";
6
6
  import { useConnect, useConnectEntitlements, useConnectPlans } from "../provider.js";
7
7
  import { buildCancelUrl, buildCheckoutUrl, useConnectCheckout, } from "../use-checkout.js";
8
+ import { AnimatePresence, ENTER, m, MotionProvider } from "./motion.js";
8
9
  import { ConnectSubscribeDialog } from "./subscribe-dialog.js";
9
10
  import { ACTION_LABEL, discountLabel, formatPrice, groupPlansByTier, resolveAction, } from "./plan-pricing.js";
10
11
  /**
@@ -104,41 +105,41 @@ export function ConnectPlans({ planIds, hideCoupon = false, className }) {
104
105
  if (error) {
105
106
  return _jsx("p", { className: "text-sm text-danger", children: "Could not load plans." });
106
107
  }
107
- return (_jsxs("div", { className: `flex flex-col gap-6 ${className ?? ""}`, children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-4", children: [hasAnnual && hasMonthly && (_jsxs("div", { className: "flex items-center gap-3", children: [_jsx("span", { className: showAnnual ? "text-sm text-muted" : "text-sm font-medium text-foreground", children: "Monthly" }), _jsx(Switch, { "aria-label": "Bill annually", isSelected: showAnnual, onChange: setAnnual, children: _jsx(Switch.Content, { children: _jsx(Switch.Control, { children: _jsx(Switch.Thumb, {}) }) }) }), _jsx("span", { className: showAnnual ? "text-sm font-medium text-foreground" : "text-sm text-muted", children: "Annual" }), bestSaving !== null && (_jsxs(Chip, { className: "bg-accent-soft text-accent", children: ["Save up to ", bestSaving, "%"] }))] })), !hideCoupon && (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Tag, { className: "size-4 text-muted", "aria-hidden": "true" }), _jsx(Input, { "aria-label": "Coupon code", placeholder: "Coupon code", value: coupon, onChange: (event) => setCoupon(event.target.value.toUpperCase()), className: "w-40" })] }))] }), subscription?.subscription?.appliedDiscount && (_jsxs("div", { className: "flex items-center gap-2 rounded-lg bg-accent-soft px-3 py-2 text-sm text-accent", children: [_jsx(Sparkles, { className: "size-4 shrink-0", "aria-hidden": "true" }), _jsxs("span", { children: [discountLabel(subscription.subscription.appliedDiscount), subscription.subscription.appliedDiscount.code
108
- ? ` - code ${subscription.subscription.appliedDiscount.code}`
109
- : ""] })] })), _jsx(ConnectCheckoutStatusRow, { checkout: checkout }), _jsx("div", { className: "grid gap-4 sm:grid-cols-2 lg:grid-cols-3", children: tiers.map((tier) => {
110
- // The price point this card is showing. A tier missing the toggled
111
- // cadence falls back to the one it does sell rather than dropping
112
- // out of the grid, and says so under the price.
113
- const plan = pickTierPlan(tier, showAnnual);
114
- if (!plan)
115
- return null;
116
- const action = resolveAction(plan, subscription);
117
- // "Current" belongs to the tier, not just the exact price point: an
118
- // org on Growth annual looking at monthly pricing is still on the
119
- // Growth tier, and marking only the row it literally subscribes to
120
- // would leave its own card unmarked half the time.
121
- const isCurrentTier = subscription?.plan != null &&
122
- (tier.monthly?.id === subscription.plan.id || tier.annual?.id === subscription.plan.id);
123
- const isCurrent = action === "current";
124
- const cadenceUnavailable = showAnnual ? tier.annual === null : tier.monthly === null;
125
- return (_jsxs(Card, { className: isCurrentTier ? "border-accent" : undefined, children: [_jsxs(Card.Header, { children: [_jsxs("div", { className: "flex items-start justify-between gap-2", children: [_jsx(Card.Title, { children: tier.name }), _jsxs("div", { className: "flex shrink-0 items-center gap-1.5", children: [tier.annualSavingPercent !== null && showAnnual && (_jsxs(Chip, { className: "bg-accent-soft text-accent", children: ["Save ", tier.annualSavingPercent, "%"] })), isCurrentTier && _jsx(Chip, { className: "bg-accent-soft text-accent", children: "Current" })] })] }), tier.description && _jsx(Card.Description, { children: tier.description })] }), _jsxs(Card.Content, { className: "flex flex-col gap-4", children: [_jsxs("div", { children: [_jsx("span", { className: "text-2xl font-semibold text-foreground", children: formatPrice(plan.price) }), _jsxs("span", { className: "text-sm text-muted", children: ["/", plan.billingInterval === "annual" ? "year" : "month"] }), _jsxs("p", { className: "mt-1 text-xs text-muted", children: ["+", plan.gstRate, "% GST"] }), cadenceUnavailable && (_jsxs("p", { className: "mt-1 text-xs text-muted", children: ["Only sold ", plan.billingInterval === "annual" ? "annually" : "monthly", "."] }))] }), plan.trialDays ? (_jsxs("p", { className: "text-xs font-medium text-accent", children: [plan.trialDays, "-day free trial"] })) : null, plan.features.length > 0 && (_jsx("ul", { className: "flex flex-col gap-1.5", children: plan.features.map((feature) => (
126
- // `name`, not `key` - the key is an identifier
127
- // ("campaign-module"), and printing it here is what this
128
- // card used to do. The description rides along as a
129
- // title so a feature that needs explaining can have one
130
- // without a second line in every card.
131
- _jsxs("li", { className: "flex items-start gap-2 text-sm text-foreground", title: feature.description || undefined, children: [_jsx(Check, { className: "mt-0.5 size-4 shrink-0 text-accent", "aria-hidden": "true" }), _jsx("span", { children: feature.name })] }, feature.key))) })), plan.addons.length > 0 && (_jsxs("div", { className: "flex flex-col gap-1.5 border-t border-separator pt-3", children: [_jsx("p", { className: "text-xs font-medium uppercase tracking-wide text-muted", children: "Add-ons" }), plan.addons.map((addon) => (_jsxs("div", { className: "flex items-baseline justify-between gap-2 text-sm", children: [_jsxs("span", { className: "text-foreground", children: [addon.name, addon.consumable && (_jsxs("span", { className: "text-muted", children: [" ", "- ", addon.consumable.includedPerCycle.toLocaleString("en-IN"), " ", addon.consumable.unit, "/cycle"] }))] }), _jsx("span", { className: "shrink-0 text-muted", children: formatPrice(addon.price) })] }, addon.id)))] })), _jsxs("p", { className: "text-xs text-muted", children: [plan.seats.model === "unlimited" && "Unlimited seats", plan.seats.model === "fixed" && `${plan.seats.included} seats included`, plan.seats.model === "per-seat" &&
132
- `${plan.seats.included ?? 0} seats included, then ${formatPrice(plan.seats.pricePerExtraSeat ?? 0)} each`] })] }), _jsx(Card.Footer, { children: _jsxs(Button, { className: "w-full", variant: action === "upgrade" || action === "subscribe" || action === "switch-to-annual"
133
- ? "primary"
134
- : "secondary",
135
- // Disabled while a hand-off is in flight, not just on the
136
- // card that started it: the org has one subscription per
137
- // service, so a second checkout opened against a different
138
- // plan would race the first and one of them would be
139
- // rejected on arrival.
140
- isDisabled: isCurrent || checkout.status === "waiting", onPress: () => setPending({ plan, action }), children: [ACTION_LABEL[action], !isCurrent && _jsx(ExternalLink, { className: "size-3.5" })] }) })] }, tier.planGroup));
141
- }) }), subscription?.subscription && (_jsx(ConnectUnsubscribeRow, { subscription: subscription.subscription, appUrl: appUrl, checkout: checkout })), _jsx(ConnectSubscribeDialog, { plan: pending?.plan ?? null, action: pending?.action ?? "subscribe", current: subscription, coupon: hideCoupon ? undefined : coupon, onClose: () => setPending(null), onConfirm: () => pending && startCheckout(pending.plan) })] }));
108
+ return (_jsx(MotionProvider, { children: _jsxs("div", { className: `flex flex-col gap-6 ${className ?? ""}`, children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-4", children: [hasAnnual && hasMonthly && (_jsxs("div", { className: "flex items-center gap-3", children: [_jsx("span", { className: showAnnual ? "text-sm text-muted" : "text-sm font-medium text-foreground", children: "Monthly" }), _jsx(Switch, { "aria-label": "Bill annually", isSelected: showAnnual, onChange: setAnnual, children: _jsx(Switch.Content, { children: _jsx(Switch.Control, { children: _jsx(Switch.Thumb, {}) }) }) }), _jsx("span", { className: showAnnual ? "text-sm font-medium text-foreground" : "text-sm text-muted", children: "Annual" }), bestSaving !== null && (_jsxs(Chip, { className: "bg-accent-soft text-accent", children: ["Save up to ", bestSaving, "%"] }))] })), !hideCoupon && (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Tag, { className: "size-4 text-muted", "aria-hidden": "true" }), _jsx(Input, { "aria-label": "Coupon code", placeholder: "Coupon code", value: coupon, onChange: (event) => setCoupon(event.target.value.toUpperCase()), className: "w-40" })] }))] }), subscription?.subscription?.appliedDiscount && (_jsxs("div", { className: "flex items-center gap-2 rounded-lg bg-accent-soft px-3 py-2 text-sm text-accent", children: [_jsx(Sparkles, { className: "size-4 shrink-0", "aria-hidden": "true" }), _jsxs("span", { children: [discountLabel(subscription.subscription.appliedDiscount), subscription.subscription.appliedDiscount.code
109
+ ? ` - code ${subscription.subscription.appliedDiscount.code}`
110
+ : ""] })] })), _jsx(ConnectCheckoutStatusRow, { checkout: checkout }), _jsx(m.div, { className: "grid gap-4 sm:grid-cols-2 lg:grid-cols-3", variants: { show: { transition: { staggerChildren: 0.06 } } }, initial: "hidden", animate: "show", children: tiers.map((tier) => {
111
+ // The price point this card is showing. A tier missing the toggled
112
+ // cadence falls back to the one it does sell rather than dropping
113
+ // out of the grid, and says so under the price.
114
+ const plan = pickTierPlan(tier, showAnnual);
115
+ if (!plan)
116
+ return null;
117
+ const action = resolveAction(plan, subscription);
118
+ // "Current" belongs to the tier, not just the exact price point: an
119
+ // org on Growth annual looking at monthly pricing is still on the
120
+ // Growth tier, and marking only the row it literally subscribes to
121
+ // would leave its own card unmarked half the time.
122
+ const isCurrentTier = subscription?.plan != null &&
123
+ (tier.monthly?.id === subscription.plan.id || tier.annual?.id === subscription.plan.id);
124
+ const isCurrent = action === "current";
125
+ const cadenceUnavailable = showAnnual ? tier.annual === null : tier.monthly === null;
126
+ return (_jsx(m.div, { variants: { hidden: { opacity: 0, y: 12 }, show: { opacity: 1, y: 0, transition: ENTER } }, children: _jsxs(Card, { className: isCurrentTier ? "h-full border-accent" : "h-full", children: [_jsxs(Card.Header, { children: [_jsxs("div", { className: "flex items-start justify-between gap-2", children: [_jsx(Card.Title, { children: tier.name }), _jsxs("div", { className: "flex shrink-0 items-center gap-1.5", children: [tier.annualSavingPercent !== null && showAnnual && (_jsxs(Chip, { className: "bg-accent-soft text-accent", children: ["Save ", tier.annualSavingPercent, "%"] })), isCurrentTier && _jsx(Chip, { className: "bg-accent-soft text-accent", children: "Current" })] })] }), tier.description && _jsx(Card.Description, { children: tier.description })] }), _jsxs(Card.Content, { className: "flex flex-col gap-4", children: [_jsxs("div", { children: [_jsx(AnimatePresence, { mode: "popLayout", initial: false, children: _jsxs(m.div, { initial: { opacity: 0, y: 6 }, animate: { opacity: 1, y: 0 }, exit: { opacity: 0, y: -6 }, transition: { duration: 0.15 }, children: [_jsx("span", { className: "text-2xl font-semibold text-foreground", children: formatPrice(plan.price) }), _jsxs("span", { className: "text-sm text-muted", children: ["/", plan.billingInterval === "annual" ? "year" : "month"] })] }, plan.billingInterval) }), _jsxs("p", { className: "mt-1 text-xs text-muted", children: ["+", plan.gstRate, "% GST"] }), cadenceUnavailable && (_jsxs("p", { className: "mt-1 text-xs text-muted", children: ["Only sold ", plan.billingInterval === "annual" ? "annually" : "monthly", "."] }))] }), plan.trialDays ? (_jsxs("p", { className: "text-xs font-medium text-accent", children: [plan.trialDays, "-day free trial"] })) : null, plan.features.length > 0 && (_jsx("ul", { className: "flex flex-col gap-1.5", children: plan.features.map((feature) => (
127
+ // `name`, not `key` - the key is an identifier
128
+ // ("campaign-module"), and printing it here is what this
129
+ // card used to do. The description rides along as a
130
+ // title so a feature that needs explaining can have one
131
+ // without a second line in every card.
132
+ _jsxs("li", { className: "flex items-start gap-2 text-sm text-foreground", title: feature.description || undefined, children: [_jsx(Check, { className: "mt-0.5 size-4 shrink-0 text-accent", "aria-hidden": "true" }), _jsx("span", { children: feature.name })] }, feature.key))) })), plan.addons.length > 0 && (_jsxs("div", { className: "flex flex-col gap-1.5 border-t border-separator pt-3", children: [_jsx("p", { className: "text-xs font-medium uppercase tracking-wide text-muted", children: "Add-ons" }), plan.addons.map((addon) => (_jsxs("div", { className: "flex items-baseline justify-between gap-2 text-sm", children: [_jsxs("span", { className: "text-foreground", children: [addon.name, addon.consumable && (_jsxs("span", { className: "text-muted", children: [" ", "- ", addon.consumable.includedPerCycle.toLocaleString("en-IN"), " ", addon.consumable.unit, "/cycle"] }))] }), _jsx("span", { className: "shrink-0 text-muted", children: formatPrice(addon.price) })] }, addon.id)))] })), _jsxs("p", { className: "text-xs text-muted", children: [plan.seats.model === "unlimited" && "Unlimited seats", plan.seats.model === "fixed" && `${plan.seats.included} seats included`, plan.seats.model === "per-seat" &&
133
+ `${plan.seats.included ?? 0} seats included, then ${formatPrice(plan.seats.pricePerExtraSeat ?? 0)} each`] })] }), _jsx(Card.Footer, { children: _jsxs(Button, { className: "w-full", variant: action === "upgrade" || action === "subscribe" || action === "switch-to-annual"
134
+ ? "primary"
135
+ : "secondary",
136
+ // Disabled while a hand-off is in flight, not just on the
137
+ // card that started it: the org has one subscription per
138
+ // service, so a second checkout opened against a different
139
+ // plan would race the first and one of them would be
140
+ // rejected on arrival.
141
+ isDisabled: isCurrent || checkout.status === "waiting", onPress: () => setPending({ plan, action }), children: [ACTION_LABEL[action], !isCurrent && _jsx(ExternalLink, { className: "size-3.5" })] }) })] }) }, tier.planGroup));
142
+ }) }), subscription?.subscription && (_jsx(ConnectUnsubscribeRow, { subscription: subscription.subscription, appUrl: appUrl, checkout: checkout })), _jsx(ConnectSubscribeDialog, { plan: pending?.plan ?? null, action: pending?.action ?? "subscribe", current: subscription, coupon: hideCoupon ? undefined : coupon, onClose: () => setPending(null), onConfirm: () => pending && startCheckout(pending.plan) })] }) }));
142
143
  }
143
144
  /**
144
145
  * What the page says while the customer is off in Connect, and after.
@@ -150,8 +151,9 @@ export function ConnectPlans({ planIds, hideCoupon = false, className }) {
150
151
  * read as one.
151
152
  */
152
153
  function ConnectCheckoutStatusRow({ checkout, }) {
153
- if (checkout.status === "idle")
154
- return null;
154
+ return (_jsx(AnimatePresence, { mode: "wait", initial: false, children: checkout.status !== "idle" && (_jsx(m.div, { initial: { opacity: 0, y: 4 }, animate: { opacity: 1, y: 0 }, exit: { opacity: 0, y: -4 }, transition: { duration: 0.18 }, children: _jsx(CheckoutStatusRowContent, { checkout: checkout }) }, checkout.status)) }));
155
+ }
156
+ function CheckoutStatusRowContent({ checkout, }) {
155
157
  if (checkout.status === "waiting") {
156
158
  return (_jsxs("div", { className: "flex items-center gap-2 rounded-lg border border-separator px-3 py-2 text-sm text-muted", children: [_jsx(Loader2, { className: "size-4 shrink-0 animate-spin", "aria-hidden": "true" }), _jsx("span", { children: "Finish up in the Connect window. This page updates on its own." })] }));
157
159
  }
@@ -4,6 +4,7 @@ import { Button, Card } from "@heroui/react";
4
4
  import { AlertTriangle, ExternalLink, Info, Loader2 } from "lucide-react";
5
5
  import { blockingBlockers } from "../../helpers.js";
6
6
  import { useConnect, useConnectEntitlements } from "../provider.js";
7
+ import { ENTER, m, MotionProvider } from "./motion.js";
7
8
  /**
8
9
  * Codes that mean "somebody at Connect is looking at it" - there is no action
9
10
  * for the customer to take, so these get an informational treatment and no
@@ -22,6 +23,7 @@ const ACTION_LABELS = {
22
23
  verification_rejected: "Review verification",
23
24
  verification_expired: "Renew verification",
24
25
  seat_limit_reached: "Manage seats",
26
+ payment_retry_pending: "Resolve payment",
25
27
  };
26
28
  function actionLabel(blocker) {
27
29
  return ACTION_LABELS[blocker.code] ?? "Resolve on Connect";
@@ -62,7 +64,7 @@ export function ConnectReadinessBanner({ includeAdvisory = false, hideWhenReady
62
64
  const blockers = includeAdvisory ? data.readiness.readiness.blockers : blockingBlockers(data.readiness);
63
65
  if (blockers.length === 0)
64
66
  return hideWhenReady ? null : _jsx(ReadyRow, { className: className });
65
- return (_jsx("div", { className: `flex flex-col gap-2 ${className ?? ""}`, role: "status", children: blockers.map((blocker) => (_jsx(BlockerRow, { blocker: blocker }, `${blocker.code}-${blocker.message}`))) }));
67
+ return (_jsx(MotionProvider, { children: _jsx(m.div, { className: `flex flex-col gap-2 ${className ?? ""}`, role: "status", initial: { opacity: 0, y: -6 }, animate: { opacity: 1, y: 0 }, transition: ENTER, children: blockers.map((blocker) => (_jsx(BlockerRow, { blocker: blocker }, `${blocker.code}-${blocker.message}`))) }) }));
66
68
  }
67
69
  function BlockerRow({ blocker }) {
68
70
  const inProgress = IN_PROGRESS_CODES.has(blocker.code);
@@ -0,0 +1,53 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Tooltip } from "@heroui/react";
4
+ import { ArrowUpRight } from "lucide-react";
5
+ import { useActivePath } from "../use-active-path.js";
6
+ import { isNavItemActive, normalizeNav, resolveActivePath, } from "./nav.js";
7
+ /** A plain anchor - correct anywhere, and a full page load. See `ConnectLinkRenderer`. */
8
+ export const defaultRenderLink = ({ children, ...props }) => _jsx("a", { ...props, children: children });
9
+ const ROW = "group relative flex items-center rounded-lg text-sm transition-colors focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus";
10
+ function rowClass(isActive, collapsed, depth) {
11
+ const shape = collapsed ? "size-10 justify-center" : `min-h-9 justify-start gap-3 px-3 py-2 ${depth > 0 ? "ml-4" : ""}`;
12
+ const tone = isActive
13
+ ? "bg-accent-soft font-medium text-accent"
14
+ : "text-foreground hover:bg-surface-secondary";
15
+ return `${ROW} ${shape} ${tone}`;
16
+ }
17
+ function NavRow({ item, isActive, hasActiveChild, collapsed, depth, renderLink, onNavigate, }) {
18
+ const linkProps = {
19
+ href: item.href,
20
+ className: rowClass(isActive, collapsed, depth),
21
+ "aria-label": item.label,
22
+ "aria-current": isActive ? "page" : undefined,
23
+ onClick: onNavigate,
24
+ ...(item.external ? { target: "_blank", rel: "noopener noreferrer" } : {}),
25
+ children: (_jsxs(_Fragment, { children: [item.icon && _jsx("span", { className: "relative flex size-5 shrink-0 items-center justify-center", children: item.icon }), !collapsed && _jsx("span", { className: "relative flex-1 truncate", children: item.label }), !collapsed && item.badge, !collapsed && item.external && (_jsx(ArrowUpRight, { className: "size-3.5 shrink-0 text-muted", "aria-hidden": "true" })), collapsed && hasActiveChild && !isActive && (_jsx("span", { "aria-hidden": "true", className: "absolute bottom-1 size-1 rounded-full bg-accent" }))] })),
26
+ };
27
+ // The tooltip stays mounted across expand/collapse and only toggles
28
+ // `isDisabled`. Branching into two trees instead re-creates every item's
29
+ // overlay and focus machinery on each toggle, which is what makes the width
30
+ // animation stutter.
31
+ return (_jsxs(Tooltip, { delay: 200, isDisabled: !collapsed, children: [_jsx(Tooltip.Trigger, { "aria-label": item.label, children: renderLink(linkProps) }), _jsx(Tooltip.Content, { placement: "right", children: item.label })] }));
32
+ }
33
+ /**
34
+ * The sidebar's nav column on its own - sections, items, one level of
35
+ * children, and the active highlight.
36
+ *
37
+ * `ConnectAppShell` renders this inside its rail and its mobile drawer, and it
38
+ * is exported for a host that wants the shell's navigation without its
39
+ * chrome: the same items, the same active resolution, dropped into a layout
40
+ * you already have.
41
+ */
42
+ export function ConnectSideNav({ nav, activePath, renderLink = defaultRenderLink, collapsed = false, onNavigate, className, }) {
43
+ const pathname = useActivePath(activePath);
44
+ const active = resolveActivePath(pathname, nav);
45
+ const sections = normalizeNav(nav);
46
+ return (_jsx("div", { className: `flex flex-col gap-4 ${className ?? ""}`, children: sections.map((section, index) => (_jsxs("nav", { "aria-label": section.title ?? "Main", className: `flex flex-col gap-1 ${collapsed ? "items-center" : ""}`, children: [section.title && !collapsed && (_jsx("h2", { className: "px-3 pb-1 text-xs font-semibold uppercase tracking-wider text-muted", children: section.title })), section.title && collapsed && index > 0 && _jsx("span", { className: "my-1 h-px w-6 bg-separator", "aria-hidden": "true" }), section.items.map((item) => {
47
+ const isActive = isNavItemActive(item, active);
48
+ const activeChild = (item.items ?? []).some((child) => isNavItemActive(child, active));
49
+ return (_jsxs("div", { className: `flex flex-col gap-1 ${collapsed ? "" : "w-full"}`, children: [_jsx(NavRow, { item: item, isActive: isActive, hasActiveChild: activeChild, collapsed: collapsed, depth: 0, renderLink: renderLink, onNavigate: onNavigate }), !collapsed &&
50
+ (isActive || activeChild) &&
51
+ item.items?.map((child) => (_jsx(NavRow, { item: child, isActive: isNavItemActive(child, active), hasActiveChild: false, collapsed: false, depth: 1, renderLink: renderLink, onNavigate: onNavigate }, child.href)))] }, item.href));
52
+ })] }, section.title ?? index))) }));
53
+ }
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
3
3
  import { Button, Card, Chip, Skeleton } from "@heroui/react";
4
4
  import { AlertTriangle, ArrowRight, Clock, CreditCard, ExternalLink, Users } from "lucide-react";
5
5
  import { useConnect, useConnectEntitlements } from "../provider.js";
6
+ import { m, MotionProvider } from "./motion.js";
6
7
  import { formatPrice } from "./plan-pricing.js";
7
8
  import { ConnectLinkButton } from "./link-button.js";
8
9
  /** Where the plan catalogue lives in the host app. Overridable, because not every app mounts it at `/plans`. */
@@ -76,7 +77,7 @@ export function ConnectSubscriptionCard({ plansHref, className }) {
76
77
  return _jsx(Skeleton, { className: `h-48 rounded-xl ${className ?? ""}` });
77
78
  if (!detail || !plan)
78
79
  return _jsx(ConnectNoSubscriptionCard, { plansHref: plansHref, className: className });
79
- return (_jsxs(Card, { className: className, children: [_jsxs(Card.Header, { children: [_jsxs("div", { className: "flex items-start justify-between gap-2", children: [_jsx(Card.Title, { children: plan.name }), _jsx(SubscriptionChip, { state: state })] }), _jsxs(Card.Description, { children: [formatPrice(plan.price), " + ", plan.gstRate, "% GST per", " ", plan.billingInterval === "annual" ? "year" : "month"] })] }), _jsxs(Card.Content, { className: "flex flex-col gap-2 text-sm", children: [_jsx(NextEvent, { detail: detail, state: state }), _jsx(ConnectSeatUsage, { plan: plan, detail: detail })] }), _jsxs(Card.Footer, { className: "flex flex-wrap gap-2", children: [_jsxs(Button, { variant: "secondary", onPress: () => window.open(`${appUrl}/billing/subscriptions/${detail.id}`, "_blank", "noopener,noreferrer"), children: ["Manage on Connect", _jsx(ExternalLink, { className: "size-3.5" })] }), _jsx(ConnectLinkButton, { href: plansHref ?? DEFAULT_PLANS_HREF, variant: "tertiary", children: "Change plan" })] })] }));
80
+ return (_jsx(MotionProvider, { children: _jsx(m.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, transition: { duration: 0.2 }, children: _jsxs(Card, { className: className, children: [_jsxs(Card.Header, { children: [_jsxs("div", { className: "flex items-start justify-between gap-2", children: [_jsx(Card.Title, { children: plan.name }), _jsx(SubscriptionChip, { state: state })] }), _jsxs(Card.Description, { children: [formatPrice(plan.price), " + ", plan.gstRate, "% GST per", " ", plan.billingInterval === "annual" ? "year" : "month"] })] }), _jsxs(Card.Content, { className: "flex flex-col gap-2 text-sm", children: [_jsx(NextEvent, { detail: detail, state: state }), _jsx(ConnectSeatUsage, { plan: plan, detail: detail })] }), _jsxs(Card.Footer, { className: "flex flex-wrap gap-2", children: [_jsxs(Button, { variant: "secondary", onPress: () => window.open(`${appUrl}/billing/subscriptions/${detail.id}`, "_blank", "noopener,noreferrer"), children: ["Manage on Connect", _jsx(ExternalLink, { className: "size-3.5" })] }), _jsx(ConnectLinkButton, { href: plansHref ?? DEFAULT_PLANS_HREF, variant: "tertiary", children: "Change plan" })] })] }) }) }));
80
81
  }
81
82
  function SubscriptionChip({ state }) {
82
83
  switch (state) {