@mastra/connect 1.1.0-alpha.3 → 1.1.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.ts CHANGED
@@ -23,13 +23,33 @@ export interface ConnectClientOptions {
23
23
  baseUrl?: string;
24
24
  /** Fetch implementation, for testing or custom transports. Defaults to globalThis.fetch. */
25
25
  fetch?: typeof globalThis.fetch;
26
+ /**
27
+ * End-user resource key this client acts for. When set, every platform call
28
+ * asserts it via the `x-mastra-resource-id` header and connection listings
29
+ * are scoped to global + that resource's connections. The platform rejects
30
+ * calls against a resource-scoped connection whose key does not match (404),
31
+ * and ignores the header on global connections. No env fallback on purpose:
32
+ * a resource scope is always an explicit, per-identity decision.
33
+ */
34
+ resourceId?: string;
26
35
  }
27
36
  export interface ResolvedClient {
28
37
  baseUrl: string;
29
38
  headers: Record<string, string>;
30
39
  fetch: typeof globalThis.fetch;
31
40
  accessToken: string;
41
+ /** Validated end-user resource key this client asserts, when scoped. */
42
+ resourceId?: string;
32
43
  }
44
+ /** Header asserting the end-user resource key on platform data-path calls. */
45
+ export declare const RESOURCE_ID_HEADER = "x-mastra-resource-id";
46
+ /**
47
+ * Validates an end-user resource key against the platform contract: an opaque
48
+ * string of 1–256 characters after trimming. Returns the trimmed key.
49
+ * Mirrors the platform's `resourceIdSchema` so an invalid key fails here —
50
+ * before any platform call — instead of as an opaque 400.
51
+ */
52
+ export declare function validateResourceId(resourceId: string): string;
33
53
  export declare function resolveClient(options?: ConnectClientOptions): ResolvedClient;
34
54
  /** Builds a locked MCP transport that can only call one Platform connection endpoint. */
35
55
  export declare function platformMcpTransport(client: ResolvedClient, connectionId: string): {
@@ -45,13 +65,40 @@ export declare const connectionSchema: z.ZodObject<{
45
65
  connectedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
46
66
  createdAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
47
67
  accountLabel: z.ZodOptional<z.ZodNullable<z.ZodString>>;
68
+ resourceId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
48
69
  }, z.core.$strip>;
49
70
  export type ProjectConnection = z.infer<typeof connectionSchema>;
71
+ /**
72
+ * One credential-form field from the platform catalog, as the hosted connect
73
+ * surface needs it. Lenient subset of the platform's `VendorAuthField`.
74
+ */
75
+ export declare const catalogAuthFieldSchema: z.ZodObject<{
76
+ name: z.ZodString;
77
+ label: z.ZodOptional<z.ZodNullable<z.ZodString>>;
78
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
79
+ placeholder: z.ZodOptional<z.ZodNullable<z.ZodString>>;
80
+ secret: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
81
+ required: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
82
+ order: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
83
+ }, z.core.$strip>;
84
+ export type CatalogAuthField = z.infer<typeof catalogAuthFieldSchema>;
50
85
  export declare const integrationCatalogEntrySchema: z.ZodObject<{
51
86
  id: z.ZodString;
52
87
  capabilities: z.ZodObject<{
53
88
  mcp: z.ZodOptional<z.ZodBoolean>;
54
89
  }, z.core.$strip>;
90
+ displayName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
91
+ logoUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
92
+ authType: z.ZodOptional<z.ZodNullable<z.ZodString>>;
93
+ authFields: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
94
+ name: z.ZodString;
95
+ label: z.ZodOptional<z.ZodNullable<z.ZodString>>;
96
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
97
+ placeholder: z.ZodOptional<z.ZodNullable<z.ZodString>>;
98
+ secret: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
99
+ required: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
100
+ order: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
101
+ }, z.core.$strip>>>>;
55
102
  }, z.core.$strip>;
56
103
  export type IntegrationCatalogEntry = z.infer<typeof integrationCatalogEntrySchema>;
57
104
  /**
@@ -118,5 +165,21 @@ export interface ProxyResponse {
118
165
  export declare function proxyRequest(client: ResolvedClient, connectionId: string, options: ProxyRequestOptions): Promise<unknown>;
119
166
  /** Preserves HTTP metadata for tools with status-dependent provider contracts. */
120
167
  export declare function proxyRequestWithResponse(client: ResolvedClient, connectionId: string, options: ProxyRequestOptions): Promise<ProxyResponse>;
168
+ export declare const connectSessionSchema: z.ZodObject<{
169
+ connectionId: z.ZodString;
170
+ integrationId: z.ZodString;
171
+ connectUrl: z.ZodString;
172
+ sessionToken: z.ZodString;
173
+ expiresAt: z.ZodString;
174
+ }, z.core.$strip>;
175
+ export type ConnectSession = z.infer<typeof connectSessionSchema>;
176
+ /**
177
+ * Creates a project-scoped connect session. A resource-scoped client passes
178
+ * its resource key in the body, so the resulting connection is owned by that
179
+ * end user; an unscoped client creates a global connection.
180
+ */
181
+ export declare function createProjectConnectSession(client: ResolvedClient, projectId: string, integrationId: string): Promise<ConnectSession>;
182
+ /** Disconnects a connection. The platform tears down the vendor side asynchronously. */
183
+ export declare function disconnectConnection(client: ResolvedClient, connectionId: string): Promise<void>;
121
184
  export {};
122
185
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,0GAA0G;IAC1G,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yGAAyG;IACzG,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4FAA4F;IAC5F,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAED,MAAM,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E,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAOtG"}
@@ -2,8 +2,13 @@ import type { ConnectClientOptions, ConnectionCredential } from './client.js';
2
2
  /**
3
3
  * Fetches the raw credential for a connection, for building custom
4
4
  * interactions (own SDKs, MCP servers). Never log the result.
5
+ *
6
+ * Pass `resourceId` when the connection is scoped to an end user: the call
7
+ * then asserts `x-mastra-resource-id`, which the platform requires for
8
+ * resource-scoped connections (mismatch or omission → not found).
5
9
  */
6
10
  export declare function credential(connectionId: string, options?: {
7
11
  client?: ConnectClientOptions;
12
+ resourceId?: string;
8
13
  }): Promise<ConnectionCredential>;
9
14
  //# sourceMappingURL=credential.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"credential.d.ts","sourceRoot":"","sources":["../src/credential.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAG9E;;;GAGG;AACH,wBAAsB,UAAU,CAC9B,YAAY,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,oBAAoB,CAAA;CAAE,GAC1C,OAAO,CAAC,oBAAoB,CAAC,CAG/B"}
1
+ {"version":3,"file":"credential.d.ts","sourceRoot":"","sources":["../src/credential.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAG9E;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAC9B,YAAY,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GAC/D,OAAO,CAAC,oBAAoB,CAAC,CAK/B"}