@cosmoops/connect-sdk 0.9.0 → 0.16.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 (155) hide show
  1. package/CHANGELOG.md +566 -0
  2. package/README.md +113 -42
  3. package/dist/cjs/cli/doctor.js +3 -3
  4. package/dist/cjs/cli/init.js +3 -3
  5. package/dist/cjs/client/components/access-gate.js +20 -1
  6. package/dist/cjs/client/components/ai-screens.js +73 -0
  7. package/dist/cjs/client/components/ai-widgets.js +37 -0
  8. package/dist/cjs/client/components/app-shell.js +75 -41
  9. package/dist/cjs/client/components/apps-grid.js +3 -2
  10. package/dist/cjs/client/components/ask-ai.js +50 -5
  11. package/dist/cjs/client/components/confirm-dialog.js +40 -0
  12. package/dist/cjs/client/components/cursor-pagination.js +22 -0
  13. package/dist/cjs/client/components/filter-tabs.js +24 -0
  14. package/dist/cjs/client/components/grievance-notice.js +30 -0
  15. package/dist/cjs/client/components/link-button.js +17 -10
  16. package/dist/cjs/client/components/logo.js +4 -3
  17. package/dist/cjs/client/components/nav.js +41 -0
  18. package/dist/cjs/client/components/plan-pricing.js +27 -0
  19. package/dist/cjs/client/components/plans.js +1 -1
  20. package/dist/cjs/client/components/platform-gate.js +48 -0
  21. package/dist/cjs/client/components/shell-context.js +149 -0
  22. package/dist/cjs/client/components/side-nav.js +49 -23
  23. package/dist/cjs/client/components/sidebar.js +127 -0
  24. package/dist/cjs/client/components/subscribe-dialog.js +2 -2
  25. package/dist/cjs/client/components/subscription.js +1 -1
  26. package/dist/cjs/client/components/user-menu.js +96 -37
  27. package/dist/cjs/client/components/workspace-switcher.js +100 -0
  28. package/dist/cjs/client/index.js +72 -2
  29. package/dist/cjs/client/provider.js +57 -2
  30. package/dist/cjs/client/use-checkout.js +9 -5
  31. package/dist/cjs/errors.js +1 -1
  32. package/dist/cjs/index.js +16 -1
  33. package/dist/cjs/mcp/index.js +90 -0
  34. package/dist/cjs/mcp/tools.js +369 -0
  35. package/dist/cjs/next/index.js +2 -2
  36. package/dist/cjs/server/client.js +25 -2
  37. package/dist/cjs/server/handler.js +203 -18
  38. package/dist/cjs/server/http.js +6 -2
  39. package/dist/cjs/server/resources/acting-as.js +16 -0
  40. package/dist/cjs/server/resources/ai.js +22 -2
  41. package/dist/cjs/server/resources/data.js +374 -0
  42. package/dist/cjs/server/resources/identity.js +7 -3
  43. package/dist/cjs/server/resources/kv.js +84 -0
  44. package/dist/cjs/server/resources/platform.js +43 -0
  45. package/dist/cjs/server/resources/sessions.js +1 -1
  46. package/dist/cjs/server/resources/workspaces.js +74 -0
  47. package/dist/cjs/store-schema.js +66 -0
  48. package/dist/cjs/store.js +152 -0
  49. package/dist/cjs/ui/empty-state.js +28 -0
  50. package/dist/cjs/ui/index.js +44 -0
  51. package/dist/cjs/ui/page-header.js +27 -0
  52. package/dist/cjs/ui/page-shell.js +44 -0
  53. package/dist/cjs/ui/section.js +20 -0
  54. package/dist/cjs/ui/setting-row.js +14 -0
  55. package/dist/cjs/ui/status-chip.js +17 -0
  56. package/dist/esm/cli/doctor.js +3 -3
  57. package/dist/esm/cli/init.js +3 -3
  58. package/dist/esm/client/components/access-gate.js +20 -1
  59. package/dist/esm/client/components/ai-screens.js +69 -0
  60. package/dist/esm/client/components/ai-widgets.js +37 -1
  61. package/dist/esm/client/components/app-shell.js +81 -47
  62. package/dist/esm/client/components/apps-grid.js +3 -2
  63. package/dist/esm/client/components/ask-ai.js +51 -6
  64. package/dist/esm/client/components/confirm-dialog.js +37 -0
  65. package/dist/esm/client/components/cursor-pagination.js +19 -0
  66. package/dist/esm/client/components/filter-tabs.js +21 -0
  67. package/dist/esm/client/components/grievance-notice.js +27 -0
  68. package/dist/esm/client/components/link-button.js +17 -10
  69. package/dist/esm/client/components/logo.js +4 -3
  70. package/dist/esm/client/components/nav.js +40 -0
  71. package/dist/esm/client/components/plan-pricing.js +25 -0
  72. package/dist/esm/client/components/plans.js +2 -2
  73. package/dist/esm/client/components/platform-gate.js +45 -0
  74. package/dist/esm/client/components/shell-context.js +141 -0
  75. package/dist/esm/client/components/side-nav.js +48 -21
  76. package/dist/esm/client/components/sidebar.js +120 -0
  77. package/dist/esm/client/components/subscribe-dialog.js +3 -3
  78. package/dist/esm/client/components/subscription.js +2 -2
  79. package/dist/esm/client/components/user-menu.js +95 -38
  80. package/dist/esm/client/components/workspace-switcher.js +97 -0
  81. package/dist/esm/client/index.js +47 -4
  82. package/dist/esm/client/provider.js +53 -2
  83. package/dist/esm/client/use-checkout.js +9 -5
  84. package/dist/esm/errors.js +1 -1
  85. package/dist/esm/index.js +4 -0
  86. package/dist/esm/mcp/index.js +85 -0
  87. package/dist/esm/mcp/tools.js +366 -0
  88. package/dist/esm/next/index.js +2 -2
  89. package/dist/esm/server/client.js +25 -2
  90. package/dist/esm/server/handler.js +203 -18
  91. package/dist/esm/server/http.js +6 -2
  92. package/dist/esm/server/resources/acting-as.js +13 -0
  93. package/dist/esm/server/resources/ai.js +22 -2
  94. package/dist/esm/server/resources/data.js +369 -0
  95. package/dist/esm/server/resources/identity.js +7 -3
  96. package/dist/esm/server/resources/kv.js +80 -0
  97. package/dist/esm/server/resources/platform.js +39 -0
  98. package/dist/esm/server/resources/sessions.js +1 -1
  99. package/dist/esm/server/resources/workspaces.js +70 -0
  100. package/dist/esm/store-schema.js +62 -0
  101. package/dist/esm/store.js +141 -0
  102. package/dist/esm/ui/empty-state.js +25 -0
  103. package/dist/esm/ui/index.js +34 -0
  104. package/dist/esm/ui/page-header.js +24 -0
  105. package/dist/esm/ui/page-shell.js +41 -0
  106. package/dist/esm/ui/section.js +17 -0
  107. package/dist/esm/ui/setting-row.js +11 -0
  108. package/dist/esm/ui/status-chip.js +14 -0
  109. package/dist/types/client/components/ai-screens.d.ts +25 -0
  110. package/dist/types/client/components/ai-widgets.d.ts +34 -1
  111. package/dist/types/client/components/app-shell.d.ts +65 -27
  112. package/dist/types/client/components/apps-grid.d.ts +11 -2
  113. package/dist/types/client/components/ask-ai.d.ts +47 -1
  114. package/dist/types/client/components/confirm-dialog.d.ts +34 -0
  115. package/dist/types/client/components/cursor-pagination.d.ts +27 -0
  116. package/dist/types/client/components/filter-tabs.d.ts +26 -0
  117. package/dist/types/client/components/grievance-notice.d.ts +31 -0
  118. package/dist/types/client/components/link-button.d.ts +32 -9
  119. package/dist/types/client/components/logo.d.ts +18 -2
  120. package/dist/types/client/components/nav.d.ts +24 -0
  121. package/dist/types/client/components/plan-pricing.d.ts +10 -0
  122. package/dist/types/client/components/platform-gate.d.ts +53 -0
  123. package/dist/types/client/components/shell-context.d.ts +116 -0
  124. package/dist/types/client/components/side-nav.d.ts +27 -13
  125. package/dist/types/client/components/sidebar.d.ts +95 -0
  126. package/dist/types/client/components/user-menu.d.ts +68 -22
  127. package/dist/types/client/components/workspace-switcher.d.ts +49 -0
  128. package/dist/types/client/index.d.ts +29 -5
  129. package/dist/types/client/provider.d.ts +109 -6
  130. package/dist/types/client/use-checkout.d.ts +8 -4
  131. package/dist/types/errors.d.ts +1 -1
  132. package/dist/types/index.d.ts +6 -0
  133. package/dist/types/mcp/index.d.ts +74 -0
  134. package/dist/types/mcp/tools.d.ts +107 -0
  135. package/dist/types/next/index.d.ts +1 -1
  136. package/dist/types/server/client.d.ts +25 -2
  137. package/dist/types/server/http.d.ts +8 -2
  138. package/dist/types/server/index.d.ts +4 -0
  139. package/dist/types/server/resources/acting-as.d.ts +11 -0
  140. package/dist/types/server/resources/ai.d.ts +20 -2
  141. package/dist/types/server/resources/data.d.ts +258 -0
  142. package/dist/types/server/resources/kv.d.ts +63 -0
  143. package/dist/types/server/resources/platform.d.ts +32 -0
  144. package/dist/types/server/resources/workspaces.d.ts +55 -0
  145. package/dist/types/store-schema.d.ts +52 -0
  146. package/dist/types/store.d.ts +96 -0
  147. package/dist/types/types.d.ts +369 -16
  148. package/dist/types/ui/empty-state.d.ts +34 -0
  149. package/dist/types/ui/index.d.ts +40 -0
  150. package/dist/types/ui/page-header.d.ts +34 -0
  151. package/dist/types/ui/page-shell.d.ts +39 -0
  152. package/dist/types/ui/section.d.ts +26 -0
  153. package/dist/types/ui/setting-row.d.ts +18 -0
  154. package/dist/types/ui/status-chip.d.ts +36 -0
  155. package/package.json +15 -2
@@ -14,35 +14,81 @@ export interface ConnectUserMenuProps {
14
14
  theme?: ThemeMode;
15
15
  onThemeChange?: (theme: ThemeMode) => void;
16
16
  }
17
+ export interface ConnectProfileModalProps {
18
+ /** Controlled open state. */
19
+ isOpen: boolean;
20
+ onOpenChange: (isOpen: boolean) => void;
21
+ /** Called after sign-out completes, e.g. to route home. */
22
+ onSignOut?: () => void;
23
+ /** See `ConnectUserButtonProps.theme`. */
24
+ theme?: ThemeMode;
25
+ onThemeChange?: (theme: ThemeMode) => void;
26
+ }
17
27
  /**
18
- * Avatar and name in the trigger; an identity card, the three Connect
19
- * destinations (Profile, Billing, Connect), an optional appearance control,
20
- * this account's active sessions, and sign-out in the modal it opens.
28
+ * The account modal with **no trigger of its own**, driven by the host.
29
+ *
30
+ * For an application that already has an account control it wants to keep -
31
+ * an avatar in its own chrome, a "Manage account" row in its own settings
32
+ * page - and wants Connect's modal behind it rather than rebuilding identity,
33
+ * sessions and sign-out. `ConnectUserButton` is the same modal with the
34
+ * trigger supplied; reach for this one only when that trigger is in the way.
21
35
  *
22
- * Profile/Billing/Connect open in a **new tab**, each marked with an
23
- * external-link icon. They are a different application at a different
24
- * origin, and navigating the host app away to reach them would lose
25
- * whatever the user was doing here. Sign out is the only action that acts
26
- * in place, which is why it sits alone in the footer rather than as a fourth
27
- * item in the same list as three navigations.
36
+ * Renders nothing when signed out, open or not - there is no account to show.
37
+ */
38
+ export declare function ConnectProfileModal({ isOpen, onOpenChange, onSignOut, theme, onThemeChange, }: ConnectProfileModalProps): import("react").JSX.Element | null;
39
+ export interface ConnectUserButtonProps {
40
+ /**
41
+ * How the trigger is drawn.
42
+ *
43
+ * - `"row"` - a full-width sidebar row: avatar, name over email, and a
44
+ * trailing glyph. The default, because the account control now lives in
45
+ * the rail's footer rather than in a top bar.
46
+ * - `"compact"` - the avatar alone, for a dense strip.
47
+ * - `"inline"` - avatar and name side by side, for a bar with room.
48
+ */
49
+ variant?: "row" | "compact" | "inline";
50
+ /** Called after sign-out completes, e.g. to route home. */
51
+ onSignOut?: () => void;
52
+ className?: string;
53
+ /**
54
+ * Current theme, and where to send a change - the SDK has no theme provider
55
+ * of its own (no `next-themes` dependency), so this is entirely
56
+ * host-controlled. The Appearance section only renders when both are
57
+ * supplied; omit either to leave theme control out of the modal.
58
+ */
59
+ theme?: ThemeMode;
60
+ onThemeChange?: (theme: ThemeMode) => void;
61
+ }
62
+ /**
63
+ * The signed-in account, as a control that opens the account modal.
28
64
  *
29
- * The session list is account-wide, not scoped to this application - see
30
- * `ConnectUserSession`'s doc comment in `types.ts`. Appearance only renders
31
- * when both `theme` and `onThemeChange` are supplied.
65
+ * In `"row"` form this is the last thing in the sidebar, which is where an
66
+ * account control belongs: it is the one item in the rail that is about *you*
67
+ * rather than about the product, and the foot of a column is where every
68
+ * application a customer already uses puts that. It collapses with the rail -
69
+ * the avatar holds its position and the name fades - because the avatar alone
70
+ * is still a complete account control, which is exactly what an icon rail
71
+ * needs.
32
72
  *
33
- * Renders nothing when signed out - pair it with `<ConnectLoginButton>`, which
34
- * renders nothing when signed *in*, and the two swap cleanly with no branch in
35
- * your own layout.
73
+ * Renders nothing when signed out. Pair it with `<ConnectLoginButton>`, which
74
+ * renders nothing when signed *in*, and the two swap with no branch in your
75
+ * own layout.
36
76
  *
37
77
  * On the HeroUI shape: the trigger is a plain `<Button>` as a **direct child**
38
- * of `<Modal>`, not wrapped in `<Modal.Trigger>`. `Dropdown.Trigger` (and by
39
- * the same construction, `Modal.Trigger`) is itself a React Aria `Button`, so
40
- * wrapping one produces a button inside a button - invalid markup, and press
41
- * handling stops working. Kept uncontrolled (no `isOpen`/`onOpenChange`),
42
- * matching `<ConnectAppsGrid>`'s own `<Modal>` - nothing here needs to close
43
- * the modal programmatically; sign-out uses `slot="close"` instead.
78
+ * of `<Modal>`, not wrapped in `<Modal.Trigger>`. `Dropdown.Trigger` - and by
79
+ * the same construction `Modal.Trigger` - is itself a React Aria `Button`, so
80
+ * wrapping one produces a button inside a button: invalid markup, and press
81
+ * handling stops working.
82
+ */
83
+ export declare function ConnectUserButton({ variant, onSignOut, className, theme, onThemeChange, }: ConnectUserButtonProps): import("react").JSX.Element | null;
84
+ /**
85
+ * @deprecated Renamed to `ConnectUserButton` in 0.12 - it is one button that
86
+ * opens a modal, and calling it a "menu" had people looking for a dropdown
87
+ * that never existed. `compact` maps to `variant="compact"`, and the old
88
+ * default (avatar plus name) to `variant="inline"`. This alias will be removed
89
+ * in a later minor.
44
90
  */
45
- export declare function ConnectUserMenu({ compact, onSignOut, className, theme, onThemeChange, }: ConnectUserMenuProps): import("react").JSX.Element | null;
91
+ export declare function ConnectUserMenu({ compact, ...rest }: ConnectUserMenuProps): import("react").JSX.Element;
46
92
  /**
47
93
  * The "Manage subscription" action on its own, for layouts that want it
48
94
  * visible rather than buried in the account menu - a billing banner, an empty
@@ -0,0 +1,49 @@
1
+ import type { UserWorkspace } from "../../types.js";
2
+ export interface ConnectWorkspaceSwitcherProps {
3
+ /**
4
+ * Called after a successful switch. Defaults to a full reload, which is
5
+ * almost always right: every server-rendered page in the host application
6
+ * was built for the *previous* workspace, and a client-side refresh would
7
+ * leave stale data on screen next to the new workspace's name.
8
+ */
9
+ onSwitched?: (workspace: UserWorkspace) => void;
10
+ /**
11
+ * Draw the trigger as a sidebar row rather than a plain button. On by
12
+ * default inside `AppShell`, where this sits directly under the
13
+ * brand; pass `false` for a standalone placement in your own chrome.
14
+ */
15
+ row?: boolean;
16
+ className?: string;
17
+ }
18
+ /**
19
+ * Switches which workspace this application is looking at.
20
+ *
21
+ * **Rendered in the `AppShell` sidebar header by default**, directly
22
+ * under the brand - which workspace you are in scopes everything below it, so
23
+ * it reads as a heading for the nav rather than as one more destination.
24
+ *
25
+ * It decides for itself whether to appear: an account with one workspace is
26
+ * shown nothing, because a switcher offering one option teaches the user
27
+ * nothing and costs a row of chrome on every screen. That is the opposite of
28
+ * Connect's own switcher, which always renders - Connect is where a workspace
29
+ * is *created*, so hiding it at one workspace would guarantee nobody ever
30
+ * reached two. A partner application creates nothing, so it has no such duty.
31
+ *
32
+ * **Authorization is the data, not a prop.** The list comes from the caller's
33
+ * own session (`GET /workspaces` takes no user id), so a workspace the user
34
+ * may not reach is simply not in it. There is deliberately no `roles` prop to
35
+ * pass or forget - the only way to render a row is for Connect to have
36
+ * returned it.
37
+ *
38
+ * Rows the user *belongs to* but cannot use here - a workspace outside the
39
+ * application's audience, or one with no subscription - are shown **disabled
40
+ * with the reason** rather than hidden. Hiding them reads as data loss to the
41
+ * person who owns the workspace; `switch` refuses the same two cases, so the
42
+ * label and the outcome always agree.
43
+ *
44
+ * A switch rotates the session token. The bridge persists the new one in the
45
+ * host application's own session store and the token never reaches this
46
+ * component - so the only thing to do afterwards is reload, which is what
47
+ * `onSwitched` defaults to.
48
+ */
49
+ export declare function ConnectWorkspaceSwitcher({ onSwitched, row, className, }: Readonly<ConnectWorkspaceSwitcherProps>): import("react").JSX.Element | null;
@@ -10,28 +10,39 @@
10
10
  * whatever theme the host application platform already configured, and one theme
11
11
  * change lands identically in all of them.
12
12
  */
13
- export { ConnectProvider, useConnect, useConnectUser, useConnectWorkspaceType, useConnectAudience, useConnectEntitlements, useConnectPlans, useConnectApps, useConnectAddonUsage, useConnectSessions, useConnectIntegrations, useConnectResource, CONNECT_APP_URL, } from "./provider.js";
13
+ export { ConnectProvider, useConnect, useConnectUser, useConnectWorkspaceType, useConnectAudience, useConnectPlatformAccess, useConnectEntitlements, useConnectPlans, useConnectApps, useConnectCompanyProfile, useConnectAddonUsage, useConnectSessions, useConnectIntegrations, useConnectResource, CONNECT_APP_URL, } from "./provider.js";
14
14
  export type { ConnectProviderProps, ConnectContextValue, ConnectSession } from "./provider.js";
15
15
  export { blockingBlockers, normalizePlanFeatures } from "../helpers.js";
16
16
  export type { WirePlanFeature } from "../helpers.js";
17
17
  export { ConnectError, isConnectError } from "../errors.js";
18
18
  export type * from "../types.js";
19
+ export { ConnectGrievanceNotice } from "./components/grievance-notice.js";
20
+ export type { ConnectGrievanceNoticeProps } from "./components/grievance-notice.js";
19
21
  export { ConnectMark } from "./mark.js";
20
22
  export { ConnectLogo } from "./components/logo.js";
21
23
  export type { ConnectLogoProps } from "./components/logo.js";
22
24
  export { ConnectLoginButton, ConnectRegisterButton } from "./components/auth-buttons.js";
23
25
  export type { ConnectAuthButtonProps } from "./components/auth-buttons.js";
24
- export { ConnectUserMenu, ConnectManageSubscriptionButton, ConnectInvoicesButton, ConnectProfileButton, ConnectHomeButton, ConnectSignOutButton, } from "./components/user-menu.js";
26
+ export { ConnectUserButton, ConnectProfileModal,
27
+ /** @deprecated Renamed to `ConnectUserButton`. */
28
+ ConnectUserMenu, ConnectManageSubscriptionButton, ConnectInvoicesButton, ConnectProfileButton, ConnectHomeButton, ConnectSignOutButton, } from "./components/user-menu.js";
29
+ export type { ConnectUserButtonProps, ConnectProfileModalProps } from "./components/user-menu.js";
25
30
  export { ConnectAccountSessions } from "./components/account-sessions.js";
26
31
  export type { ConnectAccountSessionsProps } from "./components/account-sessions.js";
27
32
  export type { ConnectUserMenuProps } from "./components/user-menu.js";
28
33
  export { AppShell } from "./components/app-shell.js";
29
34
  export type { AppShellProps } from "./components/app-shell.js";
30
- export { ConnectSideNav } from "./components/side-nav.js";
31
- export type { ConnectSideNavProps } from "./components/side-nav.js";
35
+ export { ConnectSidebar, ConnectSidebarHeader, ConnectSidebarBody, ConnectSidebarFooter, ConnectSidebarRow, } from "./components/sidebar.js";
36
+ export type { ConnectSidebarProps, ConnectSidebarHeaderProps, ConnectSidebarRowProps, } from "./components/sidebar.js";
37
+ export { ConnectShellProvider, useConnectShell, sidebarRowClass, RAIL_COLLAPSED, RAIL_EXPANDED, } from "./components/shell-context.js";
38
+ export type { ConnectShellContextValue } from "./components/shell-context.js";
39
+ export { ConnectSidebarNav, ConnectSideNav } from "./components/side-nav.js";
40
+ export type { ConnectSidebarNavProps, ConnectSideNavProps } from "./components/side-nav.js";
32
41
  export { useActivePath } from "./use-active-path.js";
33
- export { normalizeNav, flattenNav, normalizePath, resolveActivePath, isNavItemActive, gateExemptPaths, } from "./components/nav.js";
42
+ export { normalizeNav, flattenNav, normalizePath, resolveActivePath, isNavItemActive, gateExemptPaths, filterNavForAudience, } from "./components/nav.js";
34
43
  export type { ConnectNav, ConnectNavItem, ConnectNavSection, ConnectNavLinkProps, ConnectLinkRenderer, } from "./components/nav.js";
44
+ export type { ConnectScreen } from "../types.js";
45
+ export { matchConnectScreen, isLinkableConnectScreen, } from "./components/ai-screens.js";
35
46
  export { ConnectAppsGrid } from "./components/apps-grid.js";
36
47
  export type { ConnectAppsGridProps } from "./components/apps-grid.js";
37
48
  export { ConnectAskAi } from "./components/ask-ai.js";
@@ -55,11 +66,24 @@ export { ConnectFeatureGate, useConnectFeature } from "./components/feature-gate
55
66
  export type { ConnectFeatureGateProps } from "./components/feature-gate.js";
56
67
  export { ConnectWorkspaceTypeGate } from "./components/workspace-type-gate.js";
57
68
  export type { ConnectWorkspaceTypeGateProps } from "./components/workspace-type-gate.js";
69
+ export { ConnectPlatformGate } from "./components/platform-gate.js";
70
+ export type { ConnectPlatformGateProps } from "./components/platform-gate.js";
58
71
  export { ConnectUsageMeter } from "./components/usage-meter.js";
59
72
  export type { ConnectUsageMeterProps } from "./components/usage-meter.js";
60
73
  export { ConnectPlansPage } from "./components/plans-page.js";
61
74
  export type { ConnectPlansPageProps } from "./components/plans-page.js";
75
+ export { ConnectLinkButton } from "./components/link-button.js";
76
+ export type { ConnectLinkButtonProps } from "./components/link-button.js";
77
+ export { ConnectConfirmDialog } from "./components/confirm-dialog.js";
78
+ export type { ConnectConfirmDialogProps } from "./components/confirm-dialog.js";
79
+ export { ConnectCursorPagination } from "./components/cursor-pagination.js";
80
+ export type { ConnectCursorPaginationProps } from "./components/cursor-pagination.js";
81
+ export { ConnectFilterTabs } from "./components/filter-tabs.js";
82
+ export type { ConnectFilterTabsProps, ConnectFilterTabsOption } from "./components/filter-tabs.js";
62
83
  export { useConnectCheckout, buildCheckoutUrl } from "./use-checkout.js";
63
84
  export type { ConnectCheckoutStatus, ConnectCheckoutState, ConnectEntitlements, StartCheckoutOptions, CheckoutUrlOptions, } from "./use-checkout.js";
64
85
  export { formatPrice, monthlyOf, resolveAction, annualSaving, discountLabel, ACTION_LABEL, groupPlansByTier, resolvePlanGroup, } from "./components/plan-pricing.js";
65
86
  export type { PlanAction, PlanTier, ComparablePlan } from "./components/plan-pricing.js";
87
+ export { ConnectWorkspaceSwitcher } from "./components/workspace-switcher.js";
88
+ export type { ConnectWorkspaceSwitcherProps } from "./components/workspace-switcher.js";
89
+ export { useConnectWorkspaces, useConnectWorkspaceMembers } from "./provider.js";
@@ -1,14 +1,23 @@
1
1
  import type { ReactNode } from "react";
2
- import type { AddonUsageResponse, ConnectUser, IntegrationsListResponse, WorkspaceApp, PlansResponse, ReadinessResponse, ApplicationRole, SessionsListResponse, SessionSubscription, SessionAudience, SubscriptionResponse, WorkspaceType } from "../types.js";
2
+ import type { AddonUsageResponse, CompanyProfileResponse, ConnectUser, IntegrationsListResponse, WorkspaceApp, UserWorkspace, ConnectWorkspaceMember, PlansResponse, ReadinessResponse, SessionsListResponse, SessionSubscription, SessionAudience, SubscriptionResponse, WorkspaceType } from "../types.js";
3
3
  export declare const CONNECT_APP_URL = "https://connect.cosmoops.com";
4
4
  export interface ConnectSession {
5
5
  user: ConnectUser | null;
6
6
  subscription: SessionSubscription | null;
7
- applicationRole: ApplicationRole | null;
8
7
  /**
9
- * `null` when signed out, for the same reason the three above are: there is
10
- * no workspace to compare an audience against yet. Never `null` on a
11
- * signed-in session.
8
+ * The signed-in account's role on this application, or `null` - see
9
+ * `SessionAccess.role`. `null` when signed out too, which is why `user`
10
+ * rather than this is the signed-in test.
11
+ */
12
+ role: string | null;
13
+ /** What to gate on - see `SessionAccess.permissions`. `[]` when signed out. */
14
+ permissions: string[];
15
+ /** Whether this is one of Connect's own operators - see `SessionAccess.staff`. `false` when signed out. */
16
+ staff: boolean;
17
+ /**
18
+ * `null` when signed out, for the same reason `user` and `subscription`
19
+ * are: there is no workspace to compare an audience against yet. Never
20
+ * `null` on a signed-in session.
12
21
  */
13
22
  audience: SessionAudience | null;
14
23
  }
@@ -83,7 +92,7 @@ export interface ConnectContextValue {
83
92
  }
84
93
  export interface ConnectProviderProps {
85
94
  /**
86
- * This application's public `client_id`, from its Integration tab in Connect.
95
+ * This application's public `client_id`, from its Connect client section in Connect.
87
96
  *
88
97
  * Not needed for the default sign-in flow: `signIn()` with no `redirectUri`
89
98
  * bounces the browser to your own `/signin` route, which already knows
@@ -171,6 +180,35 @@ export declare function useConnectWorkspaceType(): WorkspaceType | null;
171
180
  * sign-up CTA you would rather not show to an account that cannot complete it.
172
181
  */
173
182
  export declare function useConnectAudience(): SessionAudience | null;
183
+ /**
184
+ * Whether this session is one of Connect's own operators - see
185
+ * `SessionAccess.staff`.
186
+ *
187
+ * `isStaff` is the branch you want; `roles` narrows further when your operator
188
+ * console has tiers of its own (a `developer` seeing a read-only view of what
189
+ * a `platform_admin` can edit, say).
190
+ *
191
+ * **A rendering decision, not an access decision.** The browser can call this
192
+ * whatever it likes. Everything an operator console exposes must be re-checked
193
+ * server-side against `staff` from
194
+ * `client.identity.getUser(sessionToken)` - see `<ConnectPlatformGate>`, which
195
+ * says the same thing at more length.
196
+ */
197
+ export declare function useConnectPlatformAccess(): {
198
+ isStaff: boolean;
199
+ /**
200
+ * The staff role, as a one-element array.
201
+ *
202
+ * Still an array because `<ConnectPlatformGate accept={[...]}>` matches
203
+ * against a set, and because a session reports one role since
204
+ * `role`/`permissions`/`staff` replaced the old `platformAccess.roles`
205
+ * list - Connect's platform roles nest, so the highest one is the whole
206
+ * answer. Empty for a member session.
207
+ */
208
+ roles: string[];
209
+ /** `true` while the session read is in flight - neither staff nor not-staff yet. */
210
+ isLoading: boolean;
211
+ };
174
212
  /** Readiness gates and the live subscription, fetched on first use. */
175
213
  export declare function useConnectEntitlements(): {
176
214
  data: {
@@ -222,6 +260,29 @@ export declare function useConnectPlans(): {
222
260
  */
223
261
  refetch(): void;
224
262
  };
263
+ /**
264
+ * The platform's legal identity and DPDP grievance channel.
265
+ *
266
+ * The one read here that does not depend on a session, so it resolves the
267
+ * same for a signed-out visitor - which is deliberate, because the moment a
268
+ * grievance channel most needs to be readable is on a public privacy page.
269
+ *
270
+ * Read it rather than copying it into your own configuration; see
271
+ * `CompanyProfile`. `<ConnectGrievanceNotice>` renders it for you.
272
+ */
273
+ export declare function useConnectCompanyProfile(): {
274
+ data: CompanyProfileResponse | null;
275
+ isLoading: boolean;
276
+ error: string | null;
277
+ /**
278
+ * Forces a fresh read - the provider's cache clears the mutated path's
279
+ * entry on a successful `mutateResource` call, but nothing re-triggers
280
+ * this hook's own effect on its own (none of its dependencies change from
281
+ * a cache write nobody here observes). Call this right after a
282
+ * `mutateResource` you made against the same `path` completes.
283
+ */
284
+ refetch(): void;
285
+ };
225
286
  /** The apps this workspace can open. */
226
287
  export declare function useConnectApps(): {
227
288
  data: {
@@ -238,6 +299,48 @@ export declare function useConnectApps(): {
238
299
  */
239
300
  refetch(): void;
240
301
  };
302
+ /**
303
+ * The workspaces this user belongs to - what `<ConnectWorkspaceSwitcher>`
304
+ * renders.
305
+ *
306
+ * Empty or single-entry results are normal, not errors: most accounts have one
307
+ * workspace, and the switcher decides for itself whether that is worth
308
+ * drawing.
309
+ */
310
+ export declare function useConnectWorkspaces(): {
311
+ data: {
312
+ workspaces: UserWorkspace[];
313
+ } | null;
314
+ isLoading: boolean;
315
+ error: string | null;
316
+ /**
317
+ * Forces a fresh read - the provider's cache clears the mutated path's
318
+ * entry on a successful `mutateResource` call, but nothing re-triggers
319
+ * this hook's own effect on its own (none of its dependencies change from
320
+ * a cache write nobody here observes). Call this right after a
321
+ * `mutateResource` you made against the same `path` completes.
322
+ */
323
+ refetch(): void;
324
+ };
325
+ /**
326
+ * The team of the workspace this session is on, with each member's permissions
327
+ * already resolved for this application.
328
+ */
329
+ export declare function useConnectWorkspaceMembers(): {
330
+ data: {
331
+ members: ConnectWorkspaceMember[];
332
+ } | null;
333
+ isLoading: boolean;
334
+ error: string | null;
335
+ /**
336
+ * Forces a fresh read - the provider's cache clears the mutated path's
337
+ * entry on a successful `mutateResource` call, but nothing re-triggers
338
+ * this hook's own effect on its own (none of its dependencies change from
339
+ * a cache write nobody here observes). Call this right after a
340
+ * `mutateResource` you made against the same `path` completes.
341
+ */
342
+ refetch(): void;
343
+ };
241
344
  /** Enabled Composio-hosted toolkits and this workspace's connection status for each. */
242
345
  export declare function useConnectIntegrations(): {
243
346
  data: IntegrationsListResponse | null;
@@ -85,9 +85,13 @@ export declare function buildCancelUrl({ appUrl, subscriptionId }: {
85
85
  * The Connect URL that completes a subscribe or a plan change.
86
86
  *
87
87
  * Both land on a modal Connect renders over the relevant page (an intercepted
88
- * parallel route - `app/@modal/(.)applications/...` and
89
- * `app/@modal/(.)billing/...`), so the customer arrives already looking at the
90
- * confirmation for the plan they picked here, not at a catalogue they have to
91
- * find it in again.
88
+ * parallel route - `app/@modal/(.)apps/...` and `app/@modal/(.)billing/...`),
89
+ * so the customer arrives already looking at the confirmation for the plan
90
+ * they picked here, not at a catalogue they have to find it in again.
91
+ *
92
+ * The subscribe path is `/apps/...`, not `/applications/...`: the portal
93
+ * route customers see is `/apps`, and `/applications` is a Console-only
94
+ * prefix that has never served this page. Building the other one is what
95
+ * sent every first-time subscriber from a partner's pricing page to a 404.
92
96
  */
93
97
  export declare function buildCheckoutUrl({ appUrl, applicationId, planId, subscriptionId, coupon, }: CheckoutUrlOptions): string;
@@ -52,7 +52,7 @@ export declare class ConnectError extends Error {
52
52
  * guessing keys. These two are the exception: reaching them required
53
53
  * presenting a key whose hash matched, so you already hold it, and what you
54
54
  * need to know is that no retry and no scope change will fix this - the key
55
- * has to be reissued from the application's Integration tab.
55
+ * has to be reissued from the application's Connect client section.
56
56
  *
57
57
  * Worth alerting on. It is the one failure that will not resolve itself and
58
58
  * takes down every call your integration makes.
@@ -10,8 +10,14 @@
10
10
  * Holds the API key. Never import this from browser code.
11
11
  * - `@cosmoops/connect-sdk/client` - React components and hooks. Talks to your
12
12
  * own origin only.
13
+ * - `@cosmoops/connect-sdk/mcp` - your store's declaration, derived into MCP
14
+ * tools. Holds the API key; never import this from browser code.
13
15
  */
14
16
  export { ConnectError, isConnectError } from "./errors.js";
15
17
  export { blockingBlockers, normalizePlanFeatures } from "./helpers.js";
18
+ export { arrayRemove, arrayUnion, deleteField, documentExists, increment, serverTimestamp, storeIndexFor, storeIndexSignature, unchangedSince, } from "./store.js";
19
+ export type { StoreIndexDirection, StoreIndexField } from "./store.js";
20
+ export { describeQueryRejection, storeIndexCovers } from "./store-schema.js";
21
+ export type { StoreCollectionDeclaration } from "./store-schema.js";
16
22
  export type { WirePlanFeature } from "./helpers.js";
17
23
  export type * from "./types.js";
@@ -0,0 +1,74 @@
1
+ /**
2
+ * `@cosmoops/connect-sdk/mcp` - your application's store, as an MCP server.
3
+ *
4
+ * Server-only: every call goes out through `ConnectClient`, which holds the API
5
+ * key. The `browser` export condition resolves this entry to a stub, so an
6
+ * import from client code fails the build rather than shipping the key.
7
+ *
8
+ * ## Zero dependencies, on purpose
9
+ *
10
+ * This entry does not import `@modelcontextprotocol/sdk`, and the package takes
11
+ * no dependency on it. `listTools()` and `callTool()` answer in the shapes the
12
+ * MCP protocol defines, so wiring them to the official server is four lines and
13
+ * a transport you choose:
14
+ *
15
+ * ```ts
16
+ * const toolset = createStoreToolset({
17
+ * collections: STORE_SCHEMA,
18
+ * data: connect.data,
19
+ * workspaceId: session.workspaceId,
20
+ * asUser: session.sessionToken,
21
+ * })
22
+ *
23
+ * server.setRequestHandler(ListToolsRequestSchema, () => toolset.listTools())
24
+ * server.setRequestHandler(CallToolRequestSchema, (request) =>
25
+ * toolset.callTool(request.params.name, request.params.arguments ?? {}),
26
+ * )
27
+ * ```
28
+ *
29
+ * The alternative - depending on the MCP SDK so this file could return an
30
+ * `McpServer` - would put a version of it in every install of this package,
31
+ * including the ones that never touch MCP, and pin partners to whichever
32
+ * version shipped here. The protocol shapes are stable and small; the coupling
33
+ * would not be.
34
+ *
35
+ * ## One toolset per session
36
+ *
37
+ * `asUser` is an end user's Connect session token, and Connect checks each
38
+ * collection's declared permission against that member's live roles. A toolset
39
+ * is therefore scoped to one signed-in user - build it per request from
40
+ * `getConnectSession()`, or pass a function for `asUser` if the surrounding
41
+ * server outlives a session.
42
+ */
43
+ export { deriveStoreTools } from "./tools.js";
44
+ export type { JsonSchema, StoreDataPort, StoreTool, StoreToolWrites, StoreToolsetOptions, } from "./tools.js";
45
+ import { type StoreTool, type StoreToolsetOptions } from "./tools.js";
46
+ /** One entry of an MCP `tools/list` response. */
47
+ export interface McpToolDescriptor {
48
+ name: string;
49
+ title: string;
50
+ description: string;
51
+ inputSchema: Record<string, unknown>;
52
+ annotations: {
53
+ readOnlyHint: boolean;
54
+ destructiveHint: boolean;
55
+ idempotentHint: boolean;
56
+ };
57
+ }
58
+ /** An MCP `tools/call` result. */
59
+ export interface McpToolResult {
60
+ content: {
61
+ type: "text";
62
+ text: string;
63
+ }[];
64
+ isError?: boolean;
65
+ }
66
+ export interface StoreToolset {
67
+ /** The derived tools, if you would rather register them yourself. */
68
+ readonly tools: readonly StoreTool[];
69
+ listTools(): {
70
+ tools: McpToolDescriptor[];
71
+ };
72
+ callTool(name: string, args: Record<string, unknown>): Promise<McpToolResult>;
73
+ }
74
+ export declare function createStoreToolset(options: StoreToolsetOptions): StoreToolset;
@@ -0,0 +1,107 @@
1
+ import type { StoreAggregation, StoreDocument, StoreOrderBy, StoreQueryFilter } from "../types.js";
2
+ import { type StoreCollectionDeclaration } from "../store-schema.js";
3
+ /** A JSON Schema object, as the MCP `tools/list` response carries it. */
4
+ export type JsonSchema = Record<string, unknown>;
5
+ /**
6
+ * One derived tool: the wire definition, and the call behind it.
7
+ *
8
+ * Shaped so `listTools`/`callTool` can be answered without this module knowing
9
+ * what transport is in front of it - see the note on `createStoreToolset`.
10
+ */
11
+ export interface StoreTool {
12
+ name: string;
13
+ title: string;
14
+ description: string;
15
+ inputSchema: JsonSchema;
16
+ annotations: {
17
+ readOnlyHint: boolean;
18
+ destructiveHint: boolean;
19
+ idempotentHint: boolean;
20
+ };
21
+ execute(args: Record<string, unknown>): Promise<unknown>;
22
+ }
23
+ /**
24
+ * The subset of `ConnectClient["data"]` a toolset uses.
25
+ *
26
+ * Structural rather than the concrete class so this module pulls in neither the
27
+ * transport nor the key-holding client, and so a test can pass a recording
28
+ * double without a network seam of its own.
29
+ */
30
+ export interface StoreDataPort {
31
+ get(input: {
32
+ workspaceId?: string;
33
+ collection: string;
34
+ id: string;
35
+ asUser?: string;
36
+ }): Promise<StoreDocument>;
37
+ query(input: {
38
+ workspaceId?: string;
39
+ collection: string;
40
+ filters?: StoreQueryFilter[];
41
+ orderBy?: StoreOrderBy;
42
+ limit?: number;
43
+ cursor?: string | null;
44
+ asUser?: string;
45
+ }): Promise<{
46
+ items: StoreDocument[];
47
+ nextCursor: string | null;
48
+ }>;
49
+ aggregate(input: {
50
+ workspaceId?: string;
51
+ collection: string;
52
+ aggregations: StoreAggregation[];
53
+ filters?: StoreQueryFilter[];
54
+ asUser?: string;
55
+ }): Promise<{
56
+ values: Record<string, number | null>;
57
+ }>;
58
+ create(input: {
59
+ workspaceId?: string;
60
+ collection: string;
61
+ data: Record<string, unknown>;
62
+ id?: string;
63
+ asUser?: string;
64
+ }): Promise<StoreDocument>;
65
+ update(input: {
66
+ workspaceId?: string;
67
+ collection: string;
68
+ id: string;
69
+ data: Record<string, unknown>;
70
+ asUser?: string;
71
+ }): Promise<StoreDocument>;
72
+ delete(input: {
73
+ workspaceId?: string;
74
+ collection: string;
75
+ id: string;
76
+ asUser?: string;
77
+ }): Promise<void>;
78
+ }
79
+ /**
80
+ * How much of the write surface to derive.
81
+ *
82
+ * Defaults to `"none"`. A toolset is usually handed to a model driving somebody
83
+ * else's conversation, and the blast radius of a derived `delete` on every
84
+ * collection is not something to acquire by default - opting in is one word,
85
+ * and discovering it by accident is not recoverable.
86
+ */
87
+ export type StoreToolWrites = "none" | "create" | "all";
88
+ export interface StoreToolsetOptions {
89
+ /** The application's own declaration - the same array seeded to `Application.storeSchema`. */
90
+ collections: readonly StoreCollectionDeclaration[];
91
+ data: StoreDataPort;
92
+ /**
93
+ * The end user's Connect session token. Every call is made on their behalf.
94
+ *
95
+ * A function is resolved per call, for a toolset outliving one session.
96
+ */
97
+ asUser: string | (() => string | Promise<string>);
98
+ /** Omit for an application-scoped collection; required for a workspace-scoped one. */
99
+ workspaceId?: string;
100
+ writes?: StoreToolWrites;
101
+ /** Prepended to every tool name, for a server mounting more than one source. */
102
+ prefix?: string;
103
+ /** Collections to derive from. Defaults to every declared `data` collection. */
104
+ include?: readonly string[];
105
+ }
106
+ /** Every tool one declaration yields, in a stable order. */
107
+ export declare function deriveStoreTools(options: StoreToolsetOptions): StoreTool[];
@@ -125,7 +125,7 @@ export declare function getConnectSession(request?: Request, options?: {
125
125
  * A thin wrapper, not a framework of its own - reach for `getConnectSession`
126
126
  * plus your own check when "not signed in" isn't "redirect to sign-in"
127
127
  * (an API route returning 401, say). Role and entitlement checks stay
128
- * outside this function on purpose: `session.applicationRole.granted` and
128
+ * outside this function on purpose: `session.permissions` and
129
129
  * `connect.entitlements.*` are one line each on top of the session this
130
130
  * already gives you, and where that line redirects (a plans page, a
131
131
  * "forbidden" screen) is a decision only your app can make - see