@cosmoops/connect-sdk 0.3.0 → 0.7.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 (137) hide show
  1. package/CHANGELOG.md +125 -0
  2. package/README.md +215 -6
  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 +162 -0
  6. package/dist/cjs/client/components/account-sessions.js +24 -22
  7. package/dist/cjs/client/components/app-shell.js +157 -0
  8. package/dist/cjs/client/components/apps-grid.js +4 -3
  9. package/dist/cjs/client/components/feature-gate.js +2 -2
  10. package/dist/cjs/client/components/integrations-modal.js +95 -0
  11. package/dist/cjs/client/components/logo.js +3 -3
  12. package/dist/cjs/client/components/motion.js +27 -0
  13. package/dist/cjs/client/components/nav.js +97 -0
  14. package/dist/cjs/client/components/plan-pricing.js +1 -1
  15. package/dist/cjs/client/components/plans.js +42 -40
  16. package/dist/cjs/client/components/readiness.js +6 -4
  17. package/dist/cjs/client/components/side-nav.js +58 -0
  18. package/dist/cjs/client/components/subscribe-dialog.js +2 -2
  19. package/dist/cjs/client/components/subscription.js +3 -2
  20. package/dist/cjs/client/components/surfaces.js +54 -0
  21. package/dist/cjs/client/components/usage-meter.js +4 -3
  22. package/dist/cjs/client/components/user-menu.js +33 -6
  23. package/dist/cjs/client/index.js +30 -2
  24. package/dist/cjs/client/mark.js +1 -1
  25. package/dist/cjs/client/provider.js +60 -8
  26. package/dist/cjs/client/use-active-path.js +77 -0
  27. package/dist/cjs/client/use-checkout.js +3 -3
  28. package/dist/cjs/errors.js +4 -4
  29. package/dist/cjs/helpers.js +1 -1
  30. package/dist/cjs/index.js +1 -1
  31. package/dist/cjs/next/index.js +96 -15
  32. package/dist/cjs/server/client.js +22 -14
  33. package/dist/cjs/server/handler.js +99 -16
  34. package/dist/cjs/server/http.js +1 -1
  35. package/dist/cjs/server/index.js +8 -1
  36. package/dist/cjs/server/resources/access.js +3 -3
  37. package/dist/cjs/server/resources/ai.js +1 -1
  38. package/dist/cjs/server/resources/analytics.js +66 -0
  39. package/dist/cjs/server/resources/apps.js +4 -4
  40. package/dist/cjs/server/resources/billing.js +5 -5
  41. package/dist/cjs/server/resources/drive.js +4 -4
  42. package/dist/cjs/server/resources/entitlements.js +7 -7
  43. package/dist/cjs/server/resources/identity.js +4 -4
  44. package/dist/cjs/server/resources/integrations.js +66 -0
  45. package/dist/cjs/server/resources/logs.js +3 -3
  46. package/dist/cjs/server/resources/sessions.js +6 -6
  47. package/dist/cjs/server/webhooks.js +127 -0
  48. package/dist/cjs/types.js +1 -1
  49. package/dist/esm/cli/doctor.js +3 -3
  50. package/dist/esm/cli/init.js +3 -3
  51. package/dist/esm/client/components/access-gate.js +158 -0
  52. package/dist/esm/client/components/account-sessions.js +24 -22
  53. package/dist/esm/client/components/app-shell.js +154 -0
  54. package/dist/esm/client/components/apps-grid.js +4 -3
  55. package/dist/esm/client/components/feature-gate.js +2 -2
  56. package/dist/esm/client/components/integrations-modal.js +92 -0
  57. package/dist/esm/client/components/logo.js +3 -3
  58. package/dist/esm/client/components/motion.js +21 -0
  59. package/dist/esm/client/components/nav.js +89 -0
  60. package/dist/esm/client/components/plan-pricing.js +1 -1
  61. package/dist/esm/client/components/plans.js +42 -40
  62. package/dist/esm/client/components/readiness.js +6 -4
  63. package/dist/esm/client/components/side-nav.js +53 -0
  64. package/dist/esm/client/components/subscribe-dialog.js +2 -2
  65. package/dist/esm/client/components/subscription.js +3 -2
  66. package/dist/esm/client/components/surfaces.js +51 -0
  67. package/dist/esm/client/components/usage-meter.js +4 -3
  68. package/dist/esm/client/components/user-menu.js +34 -7
  69. package/dist/esm/client/index.js +16 -2
  70. package/dist/esm/client/mark.js +1 -1
  71. package/dist/esm/client/provider.js +59 -8
  72. package/dist/esm/client/use-active-path.js +74 -0
  73. package/dist/esm/client/use-checkout.js +3 -3
  74. package/dist/esm/errors.js +4 -4
  75. package/dist/esm/helpers.js +1 -1
  76. package/dist/esm/index.js +1 -1
  77. package/dist/esm/next/index.js +95 -15
  78. package/dist/esm/server/client.js +22 -14
  79. package/dist/esm/server/handler.js +99 -16
  80. package/dist/esm/server/http.js +1 -1
  81. package/dist/esm/server/index.js +5 -0
  82. package/dist/esm/server/resources/access.js +3 -3
  83. package/dist/esm/server/resources/ai.js +1 -1
  84. package/dist/esm/server/resources/analytics.js +62 -0
  85. package/dist/esm/server/resources/apps.js +4 -4
  86. package/dist/esm/server/resources/billing.js +5 -5
  87. package/dist/esm/server/resources/drive.js +4 -4
  88. package/dist/esm/server/resources/entitlements.js +7 -7
  89. package/dist/esm/server/resources/identity.js +4 -4
  90. package/dist/esm/server/resources/integrations.js +62 -0
  91. package/dist/esm/server/resources/logs.js +3 -3
  92. package/dist/esm/server/resources/sessions.js +6 -6
  93. package/dist/esm/server/webhooks.js +123 -0
  94. package/dist/esm/types.js +1 -1
  95. package/dist/theme.css +28 -0
  96. package/dist/types/client/components/access-gate.d.ts +79 -0
  97. package/dist/types/client/components/account-sessions.d.ts +1 -1
  98. package/dist/types/client/components/app-shell.d.ts +115 -0
  99. package/dist/types/client/components/apps-grid.d.ts +1 -1
  100. package/dist/types/client/components/feature-gate.d.ts +1 -1
  101. package/dist/types/client/components/integrations-modal.d.ts +21 -0
  102. package/dist/types/client/components/logo.d.ts +5 -5
  103. package/dist/types/client/components/motion.d.ts +22 -0
  104. package/dist/types/client/components/nav.d.ts +110 -0
  105. package/dist/types/client/components/plan-pricing.d.ts +2 -2
  106. package/dist/types/client/components/readiness.d.ts +2 -2
  107. package/dist/types/client/components/side-nav.d.ts +31 -0
  108. package/dist/types/client/components/subscribe-dialog.d.ts +3 -3
  109. package/dist/types/client/components/surfaces.d.ts +51 -0
  110. package/dist/types/client/components/usage-meter.d.ts +1 -1
  111. package/dist/types/client/components/user-menu.d.ts +2 -2
  112. package/dist/types/client/index.d.ts +13 -2
  113. package/dist/types/client/mark.d.ts +1 -1
  114. package/dist/types/client/provider.d.ts +44 -9
  115. package/dist/types/client/use-active-path.d.ts +8 -0
  116. package/dist/types/client/use-checkout.d.ts +3 -3
  117. package/dist/types/errors.d.ts +4 -4
  118. package/dist/types/helpers.d.ts +1 -1
  119. package/dist/types/index.d.ts +1 -1
  120. package/dist/types/next/index.d.ts +40 -0
  121. package/dist/types/server/client.d.ts +17 -11
  122. package/dist/types/server/handler.d.ts +2 -2
  123. package/dist/types/server/index.d.ts +7 -0
  124. package/dist/types/server/resources/access.d.ts +3 -3
  125. package/dist/types/server/resources/ai.d.ts +2 -2
  126. package/dist/types/server/resources/analytics.d.ts +31 -0
  127. package/dist/types/server/resources/apps.d.ts +4 -4
  128. package/dist/types/server/resources/billing.d.ts +4 -4
  129. package/dist/types/server/resources/drive.d.ts +4 -4
  130. package/dist/types/server/resources/entitlements.d.ts +4 -4
  131. package/dist/types/server/resources/identity.d.ts +14 -4
  132. package/dist/types/server/resources/integrations.d.ts +40 -0
  133. package/dist/types/server/resources/logs.d.ts +3 -3
  134. package/dist/types/server/resources/sessions.d.ts +5 -5
  135. package/dist/types/server/webhooks.d.ts +67 -0
  136. package/dist/types/types.d.ts +220 -39
  137. package/package.json +10 -4
@@ -6,13 +6,15 @@ import { BillingResource } from "./resources/billing.js";
6
6
  import { DriveResource } from "./resources/drive.js";
7
7
  import { EntitlementsResource } from "./resources/entitlements.js";
8
8
  import { IdentityResource } from "./resources/identity.js";
9
+ import { IntegrationsResource } from "./resources/integrations.js";
9
10
  import { LogsResource } from "./resources/logs.js";
11
+ import { AnalyticsResource } from "./resources/analytics.js";
10
12
  import { OtpResource } from "./resources/otp.js";
11
13
  import { SessionsResource } from "./resources/sessions.js";
12
14
  export declare const DEFAULT_BASE_URL = "https://connect.cosmoops.com";
13
15
  export interface ConnectClientOptions {
14
16
  /**
15
- * The API key plaintext from this service's Setup tab, shown once at
17
+ * The API key plaintext from this application's Integration tab, shown once at
16
18
  * creation.
17
19
  *
18
20
  * One credential does three jobs: it is the `Authorization: Bearer` value
@@ -37,9 +39,9 @@ export interface ConnectClientOptions {
37
39
  fetch?: FetchLike;
38
40
  }
39
41
  /**
40
- * The CosmoOps Connect service-partner API.
42
+ * The CosmoOps Connect application-partner API.
41
43
  *
42
- * Covers `/api/v1/service/*` and nothing else - the surface a service platform
44
+ * Covers `/api/v1/application/*` and nothing else - the surface an application platform
43
45
  * integrates against. Connect's internal API is not part of this package and
44
46
  * never will be.
45
47
  *
@@ -50,7 +52,7 @@ export interface ConnectClientOptions {
50
52
  * });
51
53
  *
52
54
  * const session = await connect.identity.exchangeCode({ code, redirectUri });
53
- * const { ready } = await connect.entitlements.getReadiness(session.user.organizationId);
55
+ * const { ready } = await connect.entitlements.getReadiness(session.user.workspaceId);
54
56
  * ```
55
57
  *
56
58
  * Every failure throws a `ConnectError` carrying a stable `code`. Nothing here
@@ -59,25 +61,29 @@ export interface ConnectClientOptions {
59
61
  export declare class ConnectClient {
60
62
  /** "Login with Connect" - the OAuth2 handshake and the session after it. */
61
63
  readonly identity: IdentityResource;
62
- /** What a signed-in member may do on your service. */
64
+ /** What a signed-in member may do on your application. */
63
65
  readonly access: AccessResource;
64
- /** The services an organization can open - for a launcher grid. */
66
+ /** The applications a workspace can open - for a launcher grid. */
65
67
  readonly apps: AppsResource;
66
- /** Whether a workspace may use your service, and on what plan. */
68
+ /** Whether a workspace may use your application, and on what plan. */
67
69
  readonly entitlements: EntitlementsResource;
68
70
  /** Your plan catalog, and metering usage against add-on balances. */
69
71
  readonly billing: BillingResource;
70
- /** Files in an organization's Drive. */
72
+ /** Files in a workspace's Drive. */
71
73
  readonly drive: DriveResource;
72
74
  /** RAG chat and structured extraction. */
73
75
  readonly ai: AiResource;
74
76
  /** WhatsApp/SMS phone verification. */
75
77
  readonly otp: OtpResource;
76
- /** Feature events into the Console's audit log, filterable to your service. */
78
+ /** Feature events into the Console's audit log, filterable to your application. */
77
79
  readonly logs: LogsResource;
78
- /** This Connect account's own login sessions - account-wide, not scoped to this service. Requires the `sessions:manage` scope. */
80
+ /** Emit product events and read back this application's aggregated numbers. */
81
+ readonly analytics: AnalyticsResource;
82
+ /** This Connect account's own login sessions - account-wide, not scoped to this application. Requires the `sessions:manage` scope. */
79
83
  readonly sessions: SessionsResource;
84
+ /** Composio-hosted third-party connections (Google Calendar, Slack, ...) a workspace has connected. */
85
+ readonly integrations: IntegrationsResource;
80
86
  constructor(options: ConnectClientOptions);
81
87
  }
82
88
  /** Kept in step with `package.json` by `sdk.test.ts`. */
83
- export declare const SDK_VERSION = "0.3.0";
89
+ export declare const SDK_VERSION = "0.7.0";
@@ -59,9 +59,9 @@ export interface ConnectHandlerOptions {
59
59
  * export { handler as GET, handler as POST };
60
60
  * ```
61
61
  *
62
- * Every route resolves the organization from the caller's *own* session, never
62
+ * Every route resolves the workspace from the caller's *own* session, never
63
63
  * from a query parameter. A browser must not be able to ask about an
64
- * organization it is not signed into, and a client-supplied `organizationId`
64
+ * workspace it is not signed into, and a client-supplied `workspaceId`
65
65
  * is exactly that hole.
66
66
  */
67
67
  export declare function createConnectHandler(options: ConnectHandlerOptions): (request: Request) => Promise<Response>;
@@ -20,4 +20,11 @@ export type { BillingResource } from "./resources/billing.js";
20
20
  export type { AiResource } from "./resources/ai.js";
21
21
  export type { OtpResource } from "./resources/otp.js";
22
22
  export type { LogsResource } from "./resources/logs.js";
23
+ export type { AnalyticsResource } from "./resources/analytics.js";
23
24
  export type { SessionsResource } from "./resources/sessions.js";
25
+ export type { ExecuteIntegrationActionInput, IntegrationsResource } from "./resources/integrations.js";
26
+ /**
27
+ * Webhook verification and a ready-made POST route. Server-only for the
28
+ * obvious reason: the signing secret must never reach a browser bundle.
29
+ */
30
+ export { createConnectWebhookHandler, verifyConnectWebhook, type ConnectWebhookHandlers, type ConnectWebhookHandlerOptions, } from "./webhooks.js";
@@ -1,6 +1,6 @@
1
1
  import { type TransportOptions } from "../http.js";
2
2
  import type { RolesResponse, UserRolesResponse } from "../../types.js";
3
- /** What a signed-in member may do on your service, and the role catalog behind it. */
3
+ /** What a signed-in member may do on your application, and the role catalog behind it. */
4
4
  export declare class AccessResource {
5
5
  private readonly transport;
6
6
  constructor(transport: TransportOptions);
@@ -10,8 +10,8 @@ export declare class AccessResource {
10
10
  * and already know who the user is.
11
11
  */
12
12
  getUserRoles(userId: string, input: {
13
- organizationId: string;
13
+ workspaceId: string;
14
14
  }): Promise<UserRolesResponse>;
15
- /** Your service's own permission catalog and role definitions - the definitions `getUserRoles` resolves against. */
15
+ /** Your application's own permission catalog and role definitions - the definitions `getUserRoles` resolves against. */
16
16
  listRoles(): Promise<RolesResponse>;
17
17
  }
@@ -1,6 +1,6 @@
1
1
  import { type TransportOptions } from "../http.js";
2
2
  import type { ChatMessage } from "../../types.js";
3
- /** RAG chat and structured extraction against an organization's data. */
3
+ /** RAG chat and structured extraction against a workspace's data. */
4
4
  export declare class AiResource {
5
5
  private readonly transport;
6
6
  constructor(transport: TransportOptions);
@@ -11,7 +11,7 @@ export declare class AiResource {
11
11
  * `response.body` onward, or hand it to the AI SDK's own reader.
12
12
  */
13
13
  chat(input: {
14
- organizationId: string;
14
+ workspaceId: string;
15
15
  messages: ChatMessage[];
16
16
  }, options?: {
17
17
  signal?: AbortSignal;
@@ -0,0 +1,31 @@
1
+ import { type TransportOptions } from "../http.js";
2
+ import type { AnalyticsQuery, AnalyticsResponse, EmitEventInput, EmitEventsResponse } from "../../types.js";
3
+ /**
4
+ * Your application's own analytics: emit product events, and read back the daily
5
+ * numbers Connect aggregates from them.
6
+ *
7
+ * There is no way to name an application in either call. The scope is always the one
8
+ * your API key belongs to - that is the endpoint's security model, not an
9
+ * omission.
10
+ */
11
+ export declare class AnalyticsResource {
12
+ private readonly transport;
13
+ constructor(transport: TransportOptions);
14
+ /**
15
+ * Daily series for the requested metrics, up to 90 days.
16
+ *
17
+ * **Throws on failure**, unlike `emit` below. A read whose result you are
18
+ * about to render has to be able to say "I could not load"; silently
19
+ * returning an empty series would draw a chart of zeroes.
20
+ */
21
+ series(query: AnalyticsQuery): Promise<AnalyticsResponse>;
22
+ /**
23
+ * Never throws - the same judgement `LogsResource.write` makes, for the same
24
+ * reason: telemetry that takes down the code path it was observing is worse
25
+ * than a lost event. A failure is reported through `delivered`.
26
+ *
27
+ * Up to 50 events per call. Pass `sessionToken` on an event to attribute it
28
+ * to the signed-in user; without one it still lands, just unattributed.
29
+ */
30
+ emit(events: EmitEventInput[]): Promise<EmitEventsResponse>;
31
+ }
@@ -1,12 +1,12 @@
1
1
  import { type TransportOptions } from "../http.js";
2
- import type { OrganizationApp } from "../../types.js";
3
- /** The services an organization can open - the data behind a launcher grid. */
2
+ import type { WorkspaceApp } from "../../types.js";
3
+ /** The applications a workspace can open - the data behind a launcher grid. */
4
4
  export declare class AppsResource {
5
5
  private readonly transport;
6
6
  constructor(transport: TransportOptions);
7
7
  /**
8
8
  * Launchable apps only, so a grid tile is never a dead end. The calling
9
- * service is included and flagged `isCurrent` rather than filtered out.
9
+ * application is included and flagged `isCurrent` rather than filtered out.
10
10
  */
11
- list(organizationId: string): Promise<OrganizationApp[]>;
11
+ list(workspaceId: string): Promise<WorkspaceApp[]>;
12
12
  }
@@ -5,7 +5,7 @@ export declare class BillingResource {
5
5
  private readonly transport;
6
6
  constructor(transport: TransportOptions);
7
7
  /**
8
- * Your service's active plans - render live pricing instead of hardcoding it.
8
+ * Your application's active plans - render live pricing instead of hardcoding it.
9
9
  *
10
10
  * `features` is normalised on the way out: Connect used to send bare keys
11
11
  * and now sends `{ key, name, description }`, and this SDK is versioned
@@ -15,7 +15,7 @@ export declare class BillingResource {
15
15
  */
16
16
  listPlans(): Promise<PlansResponse>;
17
17
  /**
18
- * What is left of every consumable add-on on an organization's
18
+ * What is left of every consumable add-on on a workspace's
19
19
  * subscription - the read half of `consumeAddon`.
20
20
  *
21
21
  * Needs a key scoped to `addons:read`, which is separate from
@@ -25,10 +25,10 @@ export declare class BillingResource {
25
25
  * Returns an empty `addons` array rather than throwing when there is
26
26
  * nothing to meter, so a caller can render it unconditionally.
27
27
  */
28
- getAddonUsage(organizationId: string): Promise<AddonUsageResponse>;
28
+ getAddonUsage(workspaceId: string): Promise<AddonUsageResponse>;
29
29
  /**
30
30
  * Debit a consumable add-on's per-cycle balance on behalf of an
31
- * organization's users. Call it at whatever cadence your usage happens.
31
+ * workspace's users. Call it at whatever cadence your usage happens.
32
32
  *
33
33
  * An `Idempotency-Key` is always sent, generated per call when you do not
34
34
  * supply one: a balance cannot be un-spent, so a retried consume without a
@@ -1,7 +1,7 @@
1
1
  import { type TransportOptions } from "../http.js";
2
2
  import type { ThumbnailSize, UploadedFile } from "../../types.js";
3
3
  export interface UploadInput {
4
- organizationId: string;
4
+ workspaceId: string;
5
5
  /** Any `Blob`/`File`. In Node, `new Blob([buffer])` or `fs.openAsBlob(path)`. */
6
6
  file: Blob;
7
7
  /** Defaults to the `Blob`'s own name when it has one. */
@@ -9,18 +9,18 @@ export interface UploadInput {
9
9
  /** Target folder. Omit for the Drive root. */
10
10
  parentId?: string;
11
11
  }
12
- /** Files in an organization's Drive - upload, and signed URLs to read back. */
12
+ /** Files in a workspace's Drive - upload, and signed URLs to read back. */
13
13
  export declare class DriveResource {
14
14
  private readonly transport;
15
15
  constructor(transport: TransportOptions);
16
16
  upload(input: UploadInput): Promise<UploadedFile>;
17
17
  /** A signed URL for the original bytes. Short-lived - fetch it when you need it, do not store it. */
18
18
  getFileUrl(fileId: string, input: {
19
- organizationId: string;
19
+ workspaceId: string;
20
20
  }): Promise<string>;
21
21
  /** A signed URL for the thumbnail. Same lifetime caveat as `getFileUrl`. */
22
22
  getPreviewUrl(fileId: string, input: {
23
- organizationId: string;
23
+ workspaceId: string;
24
24
  size?: ThumbnailSize;
25
25
  }): Promise<string>;
26
26
  }
@@ -8,7 +8,7 @@ export declare class EntitlementsResource {
8
8
  private readonly transport;
9
9
  constructor(transport: TransportOptions);
10
10
  /**
11
- * Every gate Connect owns between an organization and your service -
11
+ * Every gate Connect owns between a workspace and your application -
12
12
  * subscription, KYC/KYB, a chargeable payment method, seat headroom -
13
13
  * resolved in one call.
14
14
  *
@@ -16,9 +16,9 @@ export declare class EntitlementsResource {
16
16
  * Connect screen that fixes it, so you can route them somewhere useful
17
17
  * instead of refusing them with nowhere to go.
18
18
  */
19
- getReadiness(organizationId: string): Promise<ReadinessResponse>;
19
+ getReadiness(workspaceId: string): Promise<ReadinessResponse>;
20
20
  /** The live plan and subscription, including `plan.features`. */
21
- getSubscription(organizationId: string): Promise<SubscriptionResponse>;
21
+ getSubscription(workspaceId: string): Promise<SubscriptionResponse>;
22
22
  /**
23
23
  * Whether an active subscription unlocks a plan feature - the check that
24
24
  * gates a plan-restricted module.
@@ -27,5 +27,5 @@ export declare class EntitlementsResource {
27
27
  * all: "not entitled" is the same answer either way, and a feature gate
28
28
  * should not need a try/catch around it.
29
29
  */
30
- hasFeature(organizationId: string, feature: string): Promise<boolean>;
30
+ hasFeature(workspaceId: string, feature: string): Promise<boolean>;
31
31
  }
@@ -4,9 +4,19 @@ export interface AuthorizeUrlInput {
4
4
  redirectUri: string;
5
5
  /** Fresh and random per request; check it matches on the way back. `createState()` makes one. */
6
6
  state: string;
7
- /** `"create"` opens registration instead of sign-in, so one entry point serves both buttons. */
8
- prompt?: "create";
9
- /** Required only if this service enforces PKCE. */
7
+ /**
8
+ * `"create"` opens registration instead of sign-in, so one entry point
9
+ * serves both buttons.
10
+ *
11
+ * `"none"` is OIDC silent authentication: Connect answers from the
12
+ * visitor's existing session without showing them anything, returning a
13
+ * code if they are signed in and have already authorised this client, and
14
+ * `error=login_required`/`consent_required`/`interaction_required` if not.
15
+ * Use it to sign in a returning visitor with no click - never to *start* a
16
+ * sign-in, since by definition it will never show them a login screen.
17
+ */
18
+ prompt?: "create" | "none";
19
+ /** Required only if this application enforces PKCE. */
10
20
  codeChallenge?: string;
11
21
  }
12
22
  export interface ExchangeCodeInput {
@@ -59,7 +69,7 @@ export declare class IdentityResource {
59
69
  * rest of its ~15-day life. Discard your own copy of `sessionToken` too;
60
70
  * this does not do that for you.
61
71
  *
62
- * `scope` defaults to `"device"`: this sign-in, every other service signed
72
+ * `scope` defaults to `"device"`: this sign-in, every other application signed
63
73
  * into from the same browser, and Connect's own session on that one device.
64
74
  * `"all"` ends every session on every device - an explicit "sign out
65
75
  * everywhere" action only.
@@ -0,0 +1,40 @@
1
+ import { type TransportOptions } from "../http.js";
2
+ import type { DisconnectIntegrationResponse, ExecuteIntegrationActionResponse, InitiateIntegrationConnectionResponse, IntegrationsListResponse } from "../../types.js";
3
+ export interface ExecuteIntegrationActionInput {
4
+ toolkitSlug: string;
5
+ actionSlug: string;
6
+ /** Passed through to Composio verbatim - its shape is defined by the toolkit's own action schema, which Connect does not model. */
7
+ params?: Record<string, unknown>;
8
+ }
9
+ /**
10
+ * Composio-hosted third-party connections (Google Calendar, Slack,
11
+ * Twitter/X, ...) a workspace has connected. Connect proxies every call
12
+ * here - your application never sees or holds the underlying OAuth token, which
13
+ * stays with Composio.
14
+ */
15
+ export declare class IntegrationsResource {
16
+ private readonly transport;
17
+ constructor(transport: TransportOptions);
18
+ /** Enabled toolkits and this workspace's connection status for each. */
19
+ list(workspaceId: string): Promise<IntegrationsListResponse["toolkits"]>;
20
+ /**
21
+ * Starts a Composio-hosted connection for one toolkit. The returned
22
+ * `redirectUrl` is where the browser completes the provider's OAuth
23
+ * screen, then Composio bounces it back to `returnUrl`.
24
+ *
25
+ * **The connection is not active when this returns.** Treat the toolkit
26
+ * as `pending` until a later `list()` call reports `active` - only
27
+ * Connect's own webhook from Composio confirms that, never the redirect
28
+ * itself. Reconnecting a disconnected/failed toolkit calls this same
29
+ * method - there is no separate reconnect.
30
+ *
31
+ * Meant to be called on behalf of a signed-in workspace admin (this is what the
32
+ * bridge's fixed `POST /integrations/connect` route does), not as a bare
33
+ * background action with no admin present to complete the OAuth screen.
34
+ */
35
+ initiateConnect(workspaceId: string, toolkitSlug: string, returnUrl: string): Promise<InitiateIntegrationConnectionResponse>;
36
+ /** Idempotent - disconnecting a toolkit that was never connected, or is already disconnected, is a success. */
37
+ disconnect(workspaceId: string, toolkitSlug: string): Promise<DisconnectIntegrationResponse>;
38
+ /** Calls a Composio action against this workspace's connected account for the named toolkit. */
39
+ execute(workspaceId: string, input: ExecuteIntegrationActionInput): Promise<ExecuteIntegrationActionResponse>;
40
+ }
@@ -1,6 +1,6 @@
1
1
  import { type TransportOptions } from "../http.js";
2
2
  import type { WriteLogInput, WriteLogResponse } from "../../types.js";
3
- /** Push feature events into the Console's audit log, filterable to your service. */
3
+ /** Push feature events into the Console's audit log, filterable to your application. */
4
4
  export declare class LogsResource {
5
5
  private readonly transport;
6
6
  constructor(transport: TransportOptions);
@@ -10,9 +10,9 @@ export declare class LogsResource {
10
10
  * reported through the return value.
11
11
  *
12
12
  * Pass `sessionToken` to attribute the event to the end user it belongs to.
13
- * Both scopes on the stored entry come from something verified - the service
13
+ * Both scopes on the stored entry come from something verified - the application
14
14
  * from your API key, the user from that token, which Connect checks was
15
- * minted for your service before attributing anything. `attributed` in the
15
+ * minted for your application before attributing anything. `attributed` in the
16
16
  * result says whether it resolved; a `false` there still means the line was
17
17
  * stored, just without a user on it.
18
18
  */
@@ -5,11 +5,11 @@ import type { ConnectUserSession, RevokeOtherSessionsResponse } from "../../type
5
5
  * timestamps - the same list Connect's own account settings page shows the
6
6
  * user themselves.
7
7
  *
8
- * **Account-wide, not scoped to this service.** A Connect session is one
9
- * browser's login to Connect, and it fans out to every partner service's own
10
- * `sessionToken` - Connect has no per-service session concept to filter by.
8
+ * **Account-wide, not scoped to this application.** A Connect session is one
9
+ * browser's login to Connect, and it fans out to every partner application's own
10
+ * `sessionToken` - Connect has no per-application session concept to filter by.
11
11
  * `list()` returns every session on the account, including ones that
12
- * originated from a completely different, unrelated service. Requires the
12
+ * originated from a completely different, unrelated application. Requires the
13
13
  * `sessions:manage` scope on your API key - unlike `identity`'s base `sso`
14
14
  * capability, this is never granted to a zero-scope legacy key by default.
15
15
  *
@@ -25,7 +25,7 @@ export declare class SessionsResource {
25
25
  list(sessionToken: string): Promise<ConnectUserSession[]>;
26
26
  /**
27
27
  * Ends one specific session by id - not necessarily the one `sessionToken`
28
- * itself was minted from. Cascades to every partner-service sign-in that
28
+ * itself was minted from. Cascades to every partner-application sign-in that
29
29
  * originated from that same browser, same as Connect's own "sign out this
30
30
  * device".
31
31
  */
@@ -0,0 +1,67 @@
1
+ import type { ConnectWebhookEnvelope, ConnectWebhookEventMap, ConnectWebhookEventType } from "../types.js";
2
+ /**
3
+ * Verifies a `Connect-Signature` header against the raw request body.
4
+ *
5
+ * Exported on its own for anyone wiring this into a framework
6
+ * `createConnectWebhookHandler` does not cover. The **raw** body matters:
7
+ * verify before parsing, and never re-serialise - `JSON.stringify(await
8
+ * req.json())` produces a different string whenever key order or number
9
+ * formatting differs, and the signature will not match.
10
+ *
11
+ * Returns a boolean and never explains which check failed. Reporting "bad
12
+ * timestamp" separately from "bad signature" tells whoever is probing which
13
+ * half of a forgery to keep working on.
14
+ */
15
+ export declare function verifyConnectWebhook(rawBody: string, signatureHeader: string | null | undefined, secret: string, now?: Date): boolean;
16
+ /** One handler per event type. Every one is optional; unhandled types are acknowledged and ignored. */
17
+ export type ConnectWebhookHandlers = {
18
+ [K in ConnectWebhookEventType]?: (data: ConnectWebhookEventMap[K], envelope: ConnectWebhookEnvelope<K>) => void | Promise<void>;
19
+ };
20
+ export interface ConnectWebhookHandlerOptions {
21
+ /** The endpoint's signing secret, from Console. Keep it in an environment variable. */
22
+ secret: string;
23
+ on: ConnectWebhookHandlers;
24
+ /**
25
+ * Called when a handler throws. Return nothing to have the delivery
26
+ * retried (Connect responds to a 5xx by retrying for about 33 hours);
27
+ * the default logs and rethrows, which produces exactly that.
28
+ */
29
+ onError?: (error: unknown, envelope: ConnectWebhookEnvelope) => void | Promise<void>;
30
+ }
31
+ /**
32
+ * A ready-made `POST` route for Connect's webhooks.
33
+ *
34
+ * ```ts
35
+ * export const POST = createConnectWebhookHandler({
36
+ * secret: process.env.CONNECT_WEBHOOK_SECRET!,
37
+ * on: {
38
+ * "workspace.deletion_scheduled": ({ workspaceId, purgeAfter }) =>
39
+ * freeze(workspaceId, purgeAfter),
40
+ * "workspace.deletion_cancelled": ({ workspaceId }) => unfreeze(workspaceId),
41
+ * "workspace.deleted": ({ workspaceId }) => purge(workspaceId),
42
+ * },
43
+ * })
44
+ * ```
45
+ *
46
+ * Three behaviours worth knowing, because each of them is a decision rather
47
+ * than an accident:
48
+ *
49
+ * **An unverified request gets a 401 and nothing else happens.** No parsing,
50
+ * no logging of the body, no handler. The endpoint is a public URL, so
51
+ * anything reachable before the signature check is reachable by anyone.
52
+ *
53
+ * **An unhandled event type is a 200.** Connect adds event types over time,
54
+ * and answering 4xx to one you have not written code for would dead-letter
55
+ * it immediately and, after enough of them, disable your endpoint. Silence
56
+ * is the correct answer to "we do not care about this one".
57
+ *
58
+ * **A throwing handler produces a 500, on purpose.** That is what makes
59
+ * Connect retry. Swallowing the error would acknowledge an event you failed
60
+ * to process, and the retry ladder is the only thing standing between a
61
+ * transient failure and a permanently missed deletion.
62
+ *
63
+ * Delivery is at-least-once and unordered. Dedupe on `envelope.id`, and
64
+ * reconcile against the readiness endpoint rather than trusting arrival
65
+ * order - the pull channel is authoritative, this one is fast.
66
+ */
67
+ export declare function createConnectWebhookHandler(options: ConnectWebhookHandlerOptions): (request: Request) => Promise<Response>;