@cosmoops/connect-sdk 0.9.0 → 0.15.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 (139) hide show
  1. package/CHANGELOG.md +497 -0
  2. package/README.md +111 -41
  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/app-shell.js +75 -41
  7. package/dist/cjs/client/components/apps-grid.js +3 -2
  8. package/dist/cjs/client/components/ask-ai.js +20 -1
  9. package/dist/cjs/client/components/confirm-dialog.js +40 -0
  10. package/dist/cjs/client/components/cursor-pagination.js +22 -0
  11. package/dist/cjs/client/components/filter-tabs.js +24 -0
  12. package/dist/cjs/client/components/grievance-notice.js +30 -0
  13. package/dist/cjs/client/components/link-button.js +17 -10
  14. package/dist/cjs/client/components/logo.js +4 -3
  15. package/dist/cjs/client/components/nav.js +41 -0
  16. package/dist/cjs/client/components/plan-pricing.js +27 -0
  17. package/dist/cjs/client/components/plans.js +1 -1
  18. package/dist/cjs/client/components/platform-gate.js +48 -0
  19. package/dist/cjs/client/components/shell-context.js +149 -0
  20. package/dist/cjs/client/components/side-nav.js +49 -23
  21. package/dist/cjs/client/components/sidebar.js +127 -0
  22. package/dist/cjs/client/components/subscribe-dialog.js +2 -2
  23. package/dist/cjs/client/components/subscription.js +1 -1
  24. package/dist/cjs/client/components/user-menu.js +96 -37
  25. package/dist/cjs/client/components/workspace-switcher.js +100 -0
  26. package/dist/cjs/client/index.js +69 -2
  27. package/dist/cjs/client/provider.js +57 -2
  28. package/dist/cjs/client/use-checkout.js +9 -5
  29. package/dist/cjs/errors.js +1 -1
  30. package/dist/cjs/index.js +11 -1
  31. package/dist/cjs/next/index.js +2 -2
  32. package/dist/cjs/server/client.js +25 -2
  33. package/dist/cjs/server/handler.js +196 -18
  34. package/dist/cjs/server/http.js +6 -2
  35. package/dist/cjs/server/resources/acting-as.js +16 -0
  36. package/dist/cjs/server/resources/ai.js +15 -2
  37. package/dist/cjs/server/resources/data.js +374 -0
  38. package/dist/cjs/server/resources/identity.js +7 -3
  39. package/dist/cjs/server/resources/kv.js +84 -0
  40. package/dist/cjs/server/resources/platform.js +43 -0
  41. package/dist/cjs/server/resources/sessions.js +1 -1
  42. package/dist/cjs/server/resources/workspaces.js +74 -0
  43. package/dist/cjs/store.js +152 -0
  44. package/dist/cjs/ui/empty-state.js +28 -0
  45. package/dist/cjs/ui/index.js +44 -0
  46. package/dist/cjs/ui/page-header.js +27 -0
  47. package/dist/cjs/ui/page-shell.js +44 -0
  48. package/dist/cjs/ui/section.js +20 -0
  49. package/dist/cjs/ui/setting-row.js +14 -0
  50. package/dist/cjs/ui/status-chip.js +17 -0
  51. package/dist/esm/cli/doctor.js +3 -3
  52. package/dist/esm/cli/init.js +3 -3
  53. package/dist/esm/client/components/access-gate.js +20 -1
  54. package/dist/esm/client/components/app-shell.js +81 -47
  55. package/dist/esm/client/components/apps-grid.js +3 -2
  56. package/dist/esm/client/components/ask-ai.js +20 -1
  57. package/dist/esm/client/components/confirm-dialog.js +37 -0
  58. package/dist/esm/client/components/cursor-pagination.js +19 -0
  59. package/dist/esm/client/components/filter-tabs.js +21 -0
  60. package/dist/esm/client/components/grievance-notice.js +27 -0
  61. package/dist/esm/client/components/link-button.js +17 -10
  62. package/dist/esm/client/components/logo.js +4 -3
  63. package/dist/esm/client/components/nav.js +40 -0
  64. package/dist/esm/client/components/plan-pricing.js +25 -0
  65. package/dist/esm/client/components/plans.js +2 -2
  66. package/dist/esm/client/components/platform-gate.js +45 -0
  67. package/dist/esm/client/components/shell-context.js +141 -0
  68. package/dist/esm/client/components/side-nav.js +48 -21
  69. package/dist/esm/client/components/sidebar.js +120 -0
  70. package/dist/esm/client/components/subscribe-dialog.js +3 -3
  71. package/dist/esm/client/components/subscription.js +2 -2
  72. package/dist/esm/client/components/user-menu.js +95 -38
  73. package/dist/esm/client/components/workspace-switcher.js +97 -0
  74. package/dist/esm/client/index.js +46 -4
  75. package/dist/esm/client/provider.js +53 -2
  76. package/dist/esm/client/use-checkout.js +9 -5
  77. package/dist/esm/errors.js +1 -1
  78. package/dist/esm/index.js +1 -0
  79. package/dist/esm/next/index.js +2 -2
  80. package/dist/esm/server/client.js +25 -2
  81. package/dist/esm/server/handler.js +196 -18
  82. package/dist/esm/server/http.js +6 -2
  83. package/dist/esm/server/resources/acting-as.js +13 -0
  84. package/dist/esm/server/resources/ai.js +15 -2
  85. package/dist/esm/server/resources/data.js +369 -0
  86. package/dist/esm/server/resources/identity.js +7 -3
  87. package/dist/esm/server/resources/kv.js +80 -0
  88. package/dist/esm/server/resources/platform.js +39 -0
  89. package/dist/esm/server/resources/sessions.js +1 -1
  90. package/dist/esm/server/resources/workspaces.js +70 -0
  91. package/dist/esm/store.js +141 -0
  92. package/dist/esm/ui/empty-state.js +25 -0
  93. package/dist/esm/ui/index.js +34 -0
  94. package/dist/esm/ui/page-header.js +24 -0
  95. package/dist/esm/ui/page-shell.js +41 -0
  96. package/dist/esm/ui/section.js +17 -0
  97. package/dist/esm/ui/setting-row.js +11 -0
  98. package/dist/esm/ui/status-chip.js +14 -0
  99. package/dist/types/client/components/app-shell.d.ts +65 -27
  100. package/dist/types/client/components/apps-grid.d.ts +11 -2
  101. package/dist/types/client/components/confirm-dialog.d.ts +34 -0
  102. package/dist/types/client/components/cursor-pagination.d.ts +27 -0
  103. package/dist/types/client/components/filter-tabs.d.ts +26 -0
  104. package/dist/types/client/components/grievance-notice.d.ts +31 -0
  105. package/dist/types/client/components/link-button.d.ts +32 -9
  106. package/dist/types/client/components/logo.d.ts +18 -2
  107. package/dist/types/client/components/nav.d.ts +24 -0
  108. package/dist/types/client/components/plan-pricing.d.ts +10 -0
  109. package/dist/types/client/components/platform-gate.d.ts +53 -0
  110. package/dist/types/client/components/shell-context.d.ts +116 -0
  111. package/dist/types/client/components/side-nav.d.ts +27 -13
  112. package/dist/types/client/components/sidebar.d.ts +95 -0
  113. package/dist/types/client/components/user-menu.d.ts +68 -22
  114. package/dist/types/client/components/workspace-switcher.d.ts +49 -0
  115. package/dist/types/client/index.d.ts +27 -5
  116. package/dist/types/client/provider.d.ts +109 -6
  117. package/dist/types/client/use-checkout.d.ts +8 -4
  118. package/dist/types/errors.d.ts +1 -1
  119. package/dist/types/index.d.ts +2 -0
  120. package/dist/types/next/index.d.ts +1 -1
  121. package/dist/types/server/client.d.ts +25 -2
  122. package/dist/types/server/http.d.ts +8 -2
  123. package/dist/types/server/index.d.ts +4 -0
  124. package/dist/types/server/resources/acting-as.d.ts +11 -0
  125. package/dist/types/server/resources/ai.d.ts +9 -1
  126. package/dist/types/server/resources/data.d.ts +258 -0
  127. package/dist/types/server/resources/kv.d.ts +63 -0
  128. package/dist/types/server/resources/platform.d.ts +32 -0
  129. package/dist/types/server/resources/workspaces.d.ts +55 -0
  130. package/dist/types/store.d.ts +96 -0
  131. package/dist/types/types.d.ts +319 -15
  132. package/dist/types/ui/empty-state.d.ts +34 -0
  133. package/dist/types/ui/index.d.ts +40 -0
  134. package/dist/types/ui/page-header.d.ts +34 -0
  135. package/dist/types/ui/page-shell.d.ts +39 -0
  136. package/dist/types/ui/section.d.ts +26 -0
  137. package/dist/types/ui/setting-row.d.ts +18 -0
  138. package/dist/types/ui/status-chip.d.ts +36 -0
  139. package/package.json +6 -2
@@ -10,27 +10,36 @@
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";
35
44
  export { ConnectAppsGrid } from "./components/apps-grid.js";
36
45
  export type { ConnectAppsGridProps } from "./components/apps-grid.js";
@@ -55,11 +64,24 @@ export { ConnectFeatureGate, useConnectFeature } from "./components/feature-gate
55
64
  export type { ConnectFeatureGateProps } from "./components/feature-gate.js";
56
65
  export { ConnectWorkspaceTypeGate } from "./components/workspace-type-gate.js";
57
66
  export type { ConnectWorkspaceTypeGateProps } from "./components/workspace-type-gate.js";
67
+ export { ConnectPlatformGate } from "./components/platform-gate.js";
68
+ export type { ConnectPlatformGateProps } from "./components/platform-gate.js";
58
69
  export { ConnectUsageMeter } from "./components/usage-meter.js";
59
70
  export type { ConnectUsageMeterProps } from "./components/usage-meter.js";
60
71
  export { ConnectPlansPage } from "./components/plans-page.js";
61
72
  export type { ConnectPlansPageProps } from "./components/plans-page.js";
73
+ export { ConnectLinkButton } from "./components/link-button.js";
74
+ export type { ConnectLinkButtonProps } from "./components/link-button.js";
75
+ export { ConnectConfirmDialog } from "./components/confirm-dialog.js";
76
+ export type { ConnectConfirmDialogProps } from "./components/confirm-dialog.js";
77
+ export { ConnectCursorPagination } from "./components/cursor-pagination.js";
78
+ export type { ConnectCursorPaginationProps } from "./components/cursor-pagination.js";
79
+ export { ConnectFilterTabs } from "./components/filter-tabs.js";
80
+ export type { ConnectFilterTabsProps, ConnectFilterTabsOption } from "./components/filter-tabs.js";
62
81
  export { useConnectCheckout, buildCheckoutUrl } from "./use-checkout.js";
63
82
  export type { ConnectCheckoutStatus, ConnectCheckoutState, ConnectEntitlements, StartCheckoutOptions, CheckoutUrlOptions, } from "./use-checkout.js";
64
83
  export { formatPrice, monthlyOf, resolveAction, annualSaving, discountLabel, ACTION_LABEL, groupPlansByTier, resolvePlanGroup, } from "./components/plan-pricing.js";
65
84
  export type { PlanAction, PlanTier, ComparablePlan } from "./components/plan-pricing.js";
85
+ export { ConnectWorkspaceSwitcher } from "./components/workspace-switcher.js";
86
+ export type { ConnectWorkspaceSwitcherProps } from "./components/workspace-switcher.js";
87
+ 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.
@@ -13,5 +13,7 @@
13
13
  */
14
14
  export { ConnectError, isConnectError } from "./errors.js";
15
15
  export { blockingBlockers, normalizePlanFeatures } from "./helpers.js";
16
+ export { arrayRemove, arrayUnion, deleteField, documentExists, increment, serverTimestamp, storeIndexFor, storeIndexSignature, unchangedSince, } from "./store.js";
17
+ export type { StoreIndexDirection, StoreIndexField } from "./store.js";
16
18
  export type { WirePlanFeature } from "./helpers.js";
17
19
  export type * from "./types.js";
@@ -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
@@ -2,6 +2,9 @@ import type { FetchLike } from "./http.js";
2
2
  import { AccessResource } from "./resources/access.js";
3
3
  import { AppsResource } from "./resources/apps.js";
4
4
  import { AiResource } from "./resources/ai.js";
5
+ import { DataResource } from "./resources/data.js";
6
+ import { WorkspacesResource } from "./resources/workspaces.js";
7
+ import { KvResource } from "./resources/kv.js";
5
8
  import { BillingResource } from "./resources/billing.js";
6
9
  import { DriveResource } from "./resources/drive.js";
7
10
  import { EntitlementsResource } from "./resources/entitlements.js";
@@ -11,10 +14,11 @@ import { LogsResource } from "./resources/logs.js";
11
14
  import { AnalyticsResource } from "./resources/analytics.js";
12
15
  import { OtpResource } from "./resources/otp.js";
13
16
  import { SessionsResource } from "./resources/sessions.js";
17
+ import { PlatformResource } from "./resources/platform.js";
14
18
  export declare const DEFAULT_BASE_URL = "https://connect.cosmoops.com";
15
19
  export interface ConnectClientOptions {
16
20
  /**
17
- * The API key plaintext from this application's Integration tab, shown once at
21
+ * The API key plaintext from this application's Connect client section, shown once at
18
22
  * creation.
19
23
  *
20
24
  * One credential does three jobs: it is the `Authorization: Bearer` value
@@ -73,6 +77,10 @@ export declare class ConnectClient {
73
77
  readonly drive: DriveResource;
74
78
  /** RAG chat and structured extraction. */
75
79
  readonly ai: AiResource;
80
+ /** Your application's own document store - see `DataResource`. */
81
+ readonly data: DataResource;
82
+ /** Your application's key/value store - see `KvResource`. */
83
+ readonly kv: KvResource;
76
84
  /** WhatsApp/SMS phone verification. */
77
85
  readonly otp: OtpResource;
78
86
  /** Feature events into the Console's audit log, filterable to your application. */
@@ -83,7 +91,22 @@ export declare class ConnectClient {
83
91
  readonly sessions: SessionsResource;
84
92
  /** Composio-hosted third-party connections (Google Calendar, Slack, ...) a workspace has connected. */
85
93
  readonly integrations: IntegrationsResource;
94
+ /** Which workspaces the signed-in user belongs to, switching between them, and the team - see `WorkspacesResource`. */
95
+ readonly workspaces: WorkspacesResource;
96
+ /** The platform's own legal identity and DPDP grievance channel - see `PlatformResource`. */
97
+ readonly platform: PlatformResource;
98
+ /**
99
+ * Relays one `/data/*` or `/kv/*` request verbatim - `createConnectHandler`'s
100
+ * store route and nothing else. See `storePassthrough`.
101
+ * @internal
102
+ */
103
+ readonly storeRelay: (spec: {
104
+ method: "GET" | "POST" | "PUT" | "DELETE";
105
+ path: string;
106
+ json?: unknown;
107
+ headers?: Record<string, string>;
108
+ }) => Promise<Response>;
86
109
  constructor(options: ConnectClientOptions);
87
110
  }
88
111
  /** Kept in step with `package.json` by `sdk.test.ts`. */
89
- export declare const SDK_VERSION = "0.9.0";
112
+ export declare const SDK_VERSION = "0.14.0";
@@ -1,6 +1,11 @@
1
1
  export type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
2
2
  export interface RequestSpec {
3
- method: "GET" | "POST";
3
+ /**
4
+ * `PUT` and `DELETE` were added for the store resources. Both are idempotent
5
+ * by HTTP's own definition, so both are retried like `GET` - see the retry
6
+ * note on `request`.
7
+ */
8
+ method: "GET" | "POST" | "PUT" | "DELETE";
4
9
  /** Relative to the API base, e.g. `/plans`. */
5
10
  path: string;
6
11
  query?: Record<string, string | number | undefined>;
@@ -49,7 +54,8 @@ export declare function pathSegment(value: string, name: string): string;
49
54
  * `ConnectError`.
50
55
  *
51
56
  * **On retries.** Only idempotent requests are retried without a caller
52
- * opt-in: every `GET`, plus any `POST` carrying an `Idempotency-Key` (the
57
+ * opt-in: every `GET`, `PUT` and `DELETE`, plus any `POST` carrying an
58
+ * `Idempotency-Key` (the
53
59
  * resources that mutate - `billing.consumeAddon`, `otp.send` - always set
54
60
  * one). A bare `POST` is attempted exactly once, because a 429 or a 504 says
55
61
  * nothing about whether the server already did the work.
@@ -18,11 +18,15 @@ export type { AppsResource } from "./resources/apps.js";
18
18
  export type { EntitlementsResource } from "./resources/entitlements.js";
19
19
  export type { BillingResource } from "./resources/billing.js";
20
20
  export type { AiResource } from "./resources/ai.js";
21
+ export type { DataResource } from "./resources/data.js";
22
+ export type { KvResource } from "./resources/kv.js";
23
+ export type { WorkspacesResource } from "./resources/workspaces.js";
21
24
  export type { OtpResource } from "./resources/otp.js";
22
25
  export type { LogsResource } from "./resources/logs.js";
23
26
  export type { AnalyticsResource } from "./resources/analytics.js";
24
27
  export type { SessionsResource } from "./resources/sessions.js";
25
28
  export type { ExecuteIntegrationActionInput, IntegrationsResource } from "./resources/integrations.js";
29
+ export type { PlatformResource } from "./resources/platform.js";
26
30
  /**
27
31
  * Webhook verification and a ready-made POST route. Server-only for the
28
32
  * obvious reason: the signing secret must never reach a browser bundle.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The header that turns a server-to-server store call into one made *on behalf
3
+ * of* a signed-in user.
4
+ *
5
+ * Connect resolves the token to a user and a workspace itself and checks the
6
+ * collection's declared permission against that member's live roles - so a
7
+ * caller supplying this is asking for a *narrower* check than an application
8
+ * call, never a wider one. An unresolvable token is refused rather than
9
+ * quietly downgraded, precisely because the downgrade would be an escalation.
10
+ */
11
+ export declare function actingAs(sessionToken: string | undefined): Record<string, string>;
@@ -1,6 +1,13 @@
1
1
  import { type TransportOptions } from "../http.js";
2
2
  import type { ChatMessage } from "../../types.js";
3
- /** RAG chat and structured extraction against a workspace's data. */
3
+ /**
4
+ * RAG chat and structured extraction against a workspace's data.
5
+ *
6
+ * `asUser` on `chat` behaves as it does on the store resources: pass a
7
+ * signed-in user's `sessionToken` and Connect resolves the workspace from it,
8
+ * ignoring `workspaceId`. Without it you are the application, naming the
9
+ * workspace yourself.
10
+ */
4
11
  export declare class AiResource {
5
12
  private readonly transport;
6
13
  constructor(transport: TransportOptions);
@@ -13,6 +20,7 @@ export declare class AiResource {
13
20
  chat(input: {
14
21
  workspaceId: string;
15
22
  messages: ChatMessage[];
23
+ asUser?: string;
16
24
  }, options?: {
17
25
  signal?: AbortSignal;
18
26
  }): Promise<Response>;
@@ -0,0 +1,258 @@
1
+ import { type TransportOptions } from "../http.js";
2
+ import type { StoreAggregatePage, StoreAggregation, StoreCommitOperation, StoreCommitResult, StoreDocument, StoreQueryFilter, StoreQueryPage, StoreOrderBy, StoreScanPage } from "../../types.js";
3
+ /**
4
+ * Your application's own document store - a dedicated Firestore database that
5
+ * only Connect can reach.
6
+ *
7
+ * You hold no Firebase credential and write no security rules. Collections are
8
+ * declared in the Console; an undeclared name is refused rather than created,
9
+ * and `workspaceId` is a path segment rather than a filter, so a query cannot
10
+ * cross tenants.
11
+ *
12
+ * **A query needs an index for its shape, and there are two ways to have one.**
13
+ * Firestore maintains a single-field index automatically, which covers one
14
+ * filter, or an `orderBy` on that same field. Anything wider - two filters, or
15
+ * a filter ordered by a different field - needs a composite index **declared
16
+ * on your application's Store tab**, which Connect then builds in your
17
+ * database. A query with no matching index is refused up front, naming the
18
+ * index to declare, rather than failing later with a Firestore index error
19
+ * pointing at a console you cannot open.
20
+ *
21
+ * **Dates are ISO-8601 strings.** The store writes what you send it, and JSON
22
+ * has no date type, so a `Date` must be sent as `toISOString()`. That is not a
23
+ * compromise: UTC ISO strings sort lexicographically in chronological order,
24
+ * so ordering and range filters on them behave exactly as they would on a
25
+ * timestamp - and Connect's own `_createdAt`/`_updatedAt` come back in the
26
+ * same form.
27
+ *
28
+ * **`workspaceId` is omitted for master data.** A collection declared
29
+ * application-scoped in the Console belongs to no workspace - one copy, owned
30
+ * by you, read by every tenant. Those are written with your API key only,
31
+ * never on behalf of a user: a write permission is something a *workspace*
32
+ * grants, so honouring one on shared data would give one tenant's admin reach
33
+ * over every other tenant's reference data.
34
+ *
35
+ * **`asUser` is how you act on behalf of a signed-in user.** Pass the opaque
36
+ * `sessionToken` you were given at sign-in and Connect resolves the user and
37
+ * their workspace from it - checking the collection's declared permission
38
+ * against what that member actually holds, and **ignoring `workspaceId`
39
+ * entirely**. Without it you are the application itself: your API key's scopes
40
+ * are the only gate, and the per-user permissions do not apply. The bridge
41
+ * (`createConnectHandler`) always passes it, which is what makes the browser
42
+ * path safe.
43
+ */
44
+ export declare class DataResource {
45
+ private readonly transport;
46
+ constructor(transport: TransportOptions);
47
+ /** Reads one document. Throws `ConnectError` with status 404 when it does not exist. */
48
+ get(input: {
49
+ workspaceId?: string;
50
+ collection: string;
51
+ id: string;
52
+ asUser?: string;
53
+ }): Promise<StoreDocument>;
54
+ /**
55
+ * Lists a collection, one page at a time.
56
+ *
57
+ * `filters` are ANDed. More than one, or one combined with an `orderBy` on a
58
+ * different field, needs a composite index declared on the Store tab - see
59
+ * the class note above.
60
+ *
61
+ * `limit` defaults to 50 and caps at 200. Page by passing the previous
62
+ * page's `nextCursor`; a `null` `nextCursor` is the end of the collection.
63
+ */
64
+ query(input: {
65
+ workspaceId?: string;
66
+ collection: string;
67
+ filters?: StoreQueryFilter[];
68
+ orderBy?: StoreOrderBy;
69
+ limit?: number;
70
+ cursor?: string | null;
71
+ asUser?: string;
72
+ }): Promise<StoreQueryPage>;
73
+ /**
74
+ * Counts, sums and averages a filtered collection - **in Firestore**, not by
75
+ * reading the rows back and adding them up.
76
+ *
77
+ * That distinction is the whole point. An aggregation is billed by the index
78
+ * entries it scans rather than by the documents it would have returned, so a
79
+ * dashboard tile over ten thousand rows costs a handful of reads and stays
80
+ * flat as the collection grows. Paging the rows into your own process to sum
81
+ * them is an unbounded read, and it is what every integration does when
82
+ * there is no aggregate call to reach for.
83
+ *
84
+ * ```ts
85
+ * const { values } = await connect.data.aggregate({
86
+ * workspaceId,
87
+ * collection: "deals",
88
+ * filters: [{ field: "outcome", op: "==", value: "won" }],
89
+ * aggregations: [
90
+ * { op: "count", alias: "count" },
91
+ * { op: "sum", field: "value", alias: "total" },
92
+ * ],
93
+ * });
94
+ * ```
95
+ *
96
+ * A `sum` or `avg` over nothing answers `null` rather than `0`, because
97
+ * "nothing matched" and "the total is zero" are different facts.
98
+ *
99
+ * The index it needs is the one its **filters** need plus the aggregated
100
+ * field - Firestore reads a sum out of the index rather than out of the
101
+ * documents.
102
+ *
103
+ * There is no `orderBy`, `limit` or `cursor`: the aggregate of an ordered
104
+ * page is the aggregate of the whole filtered set.
105
+ */
106
+ aggregate(input: {
107
+ workspaceId?: string;
108
+ collection: string;
109
+ aggregations: StoreAggregation[];
110
+ filters?: StoreQueryFilter[];
111
+ asUser?: string;
112
+ }): Promise<StoreAggregatePage>;
113
+ /**
114
+ * Reads one collection across **every workspace at once** - your own
115
+ * back-office view of your whole customer base. Each row carries the
116
+ * `workspaceId` it came from.
117
+ *
118
+ * Needs the `data:read:all` scope, and the collection must be marked
119
+ * cross-workspace in the Console. There is deliberately **no `asUser`**: a
120
+ * scan is never available on behalf of a signed-in user, because a workspace
121
+ * admin is an admin of their own workspace and not of your other customers.
122
+ *
123
+ * Filtering and ordering follow the same index rules as `query`, and
124
+ * additionally need collection-group scope. Connect creates those from the
125
+ * declaration - the single-field ones when you mark a field queryable, and a
126
+ * group-scoped copy of every composite index the collection declares. A scan
127
+ * issued in the minutes after that declaration may fail while the index
128
+ * builds.
129
+ */
130
+ scan(input: {
131
+ collection: string;
132
+ filters?: StoreQueryFilter[];
133
+ orderBy?: StoreOrderBy;
134
+ limit?: number;
135
+ cursor?: string | null;
136
+ }): Promise<StoreScanPage>;
137
+ /**
138
+ * Creates a document. Pass `id` to choose it, or omit it and one is
139
+ * allocated. An `id` that already exists throws with status 409 - use
140
+ * `replace` to overwrite deliberately.
141
+ */
142
+ create(input: {
143
+ workspaceId?: string;
144
+ collection: string;
145
+ data: Record<string, unknown>;
146
+ id?: string;
147
+ asUser?: string;
148
+ }): Promise<StoreDocument>;
149
+ /** Replaces every field, creating the document if it does not exist. `_createdAt`/`_createdBy` survive. */
150
+ replace(input: {
151
+ workspaceId?: string;
152
+ collection: string;
153
+ id: string;
154
+ data: Record<string, unknown>;
155
+ asUser?: string;
156
+ }): Promise<StoreDocument>;
157
+ /** Merges top-level fields into an existing document. Throws with status 404 if it does not exist. */
158
+ update(input: {
159
+ workspaceId?: string;
160
+ collection: string;
161
+ id: string;
162
+ data: Record<string, unknown>;
163
+ asUser?: string;
164
+ }): Promise<StoreDocument>;
165
+ /** Idempotent - deleting a document that is not there succeeds. */
166
+ delete(input: {
167
+ workspaceId?: string;
168
+ collection: string;
169
+ id: string;
170
+ asUser?: string;
171
+ }): Promise<void>;
172
+ /**
173
+ * Applies a set of writes atomically, across as many of your collections as
174
+ * they name. All of them land, or none.
175
+ *
176
+ * This is the store's answer to a database transaction, and the shape is
177
+ * deliberate: **you never hold one**. A transaction handle passed across an
178
+ * HTTP boundary is a server-side lock whose duration your network controls,
179
+ * with Firestore's sixty-second ceiling and lock contention as the failure
180
+ * mode. Instead you read, decide, and commit *conditional on nothing having
181
+ * moved* - Connect runs the whole set as one short transaction on its side.
182
+ *
183
+ * ```ts
184
+ * await connect.data.commit({
185
+ * workspaceId,
186
+ * operations: [
187
+ * { op: "create", collection: "ledger", id, data: entry },
188
+ * {
189
+ * op: "merge",
190
+ * collection: "funds",
191
+ * id: entry.fundId,
192
+ * data: { balancePaise: increment(entry.amountPaise) },
193
+ * },
194
+ * ],
195
+ * });
196
+ * ```
197
+ *
198
+ * A precondition that no longer holds throws `ConnectError` with status 409
199
+ * and **writes nothing** - see `transaction`, which re-reads and retries for
200
+ * you. Note that the example above needs no precondition at all: an
201
+ * `increment` is commutative, so concurrent commits both land correctly.
202
+ *
203
+ * Returns the id each operation wrote, in order - which is how you learn the
204
+ * id a `create` without one was given.
205
+ */
206
+ commit(input: {
207
+ workspaceId?: string;
208
+ operations: StoreCommitOperation[];
209
+ asUser?: string;
210
+ }): Promise<StoreCommitResult>;
211
+ /**
212
+ * Read, decide, commit - retried when the world moved underneath you.
213
+ *
214
+ * The optimistic-concurrency loop, written once. `build` reads whatever it
215
+ * needs and returns the operations to apply; if any precondition among them
216
+ * has gone stale by the time Connect looks, the commit is rejected whole and
217
+ * `build` runs again against fresh reads.
218
+ *
219
+ * ```ts
220
+ * await connect.data.transaction(async () => {
221
+ * const fund = await connect.data.get({ workspaceId, collection: "funds", id });
222
+ * if (!fund.data.active) throw new Error("That fund is closed.");
223
+ * return [
224
+ * {
225
+ * op: "merge",
226
+ * collection: "funds",
227
+ * id,
228
+ * data: { balancePaise: increment(amount) },
229
+ * precondition: unchangedSince(fund),
230
+ * },
231
+ * ];
232
+ * });
233
+ * ```
234
+ *
235
+ * **Only a 409 is retried.** A 403 or a validation error means the operation
236
+ * was wrong rather than late, and retrying it would turn one clear failure
237
+ * into `attempts` identical ones. An error thrown by `build` itself - the
238
+ * closed-fund check above - is not retried either: it is a decision, not a
239
+ * collision.
240
+ *
241
+ * `build` must be free of side effects outside the returned operations,
242
+ * because it can run more than once. That is the price of not holding a
243
+ * lock, and it is the same contract Firestore's own `runTransaction` states
244
+ * for the same reason.
245
+ */
246
+ transaction(build: () => Promise<StoreCommitOperation[]>, options?: {
247
+ workspaceId?: string;
248
+ asUser?: string;
249
+ attempts?: number;
250
+ }): Promise<StoreCommitResult>;
251
+ private write;
252
+ }
253
+ export declare function storePassthrough(transport: TransportOptions, spec: {
254
+ method: "GET" | "POST" | "PUT" | "DELETE";
255
+ path: string;
256
+ json?: unknown;
257
+ headers?: Record<string, string>;
258
+ }): Promise<Response>;