@vercel/connect 0.4.3 → 0.5.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.
@@ -0,0 +1,32 @@
1
+ import { type ConnectOptions } from './token.js';
2
+ /**
3
+ * Connector metadata as returned by Vercel Connect. This is the stable, useful
4
+ * subset of the connector object the management APIs return.
5
+ */
6
+ export interface ConnectorMetadata {
7
+ /** Opaque Vercel Connect connector id (e.g. `scl_…`). */
8
+ id: string;
9
+ /** Human-readable Vercel Connect connector UID. */
10
+ uid: string;
11
+ name: string;
12
+ /** Connector type identifier (e.g. `snowflake`, `oauth`). */
13
+ type: string;
14
+ /** Service the connector integrates with. */
15
+ service: string;
16
+ /** Fully-qualified URL for the connector's service when derivable. */
17
+ clientUrl?: string;
18
+ createdAt: number;
19
+ updatedAt: number;
20
+ /** Vendor-specific public configuration. */
21
+ vendor: Record<string, unknown>;
22
+ }
23
+ /**
24
+ * Fetch a connector's metadata from Vercel Connect.
25
+ *
26
+ * Authenticates with the deployment's Vercel OIDC token (same as
27
+ * {@link getToken}); the connector must be attached to the requesting
28
+ * deployment's project and enabled for its environment.
29
+ *
30
+ * @param connector - The connector id or UID.
31
+ */
32
+ export declare function getConnectorMetadata(connector: string, options?: ConnectOptions): Promise<ConnectorMetadata>;
@@ -0,0 +1,27 @@
1
+ import { getVercelOidcToken } from '@vercel/oidc';
2
+ import { createConnectErrorFromResponse, } from './token.js';
3
+ /**
4
+ * Fetch a connector's metadata from Vercel Connect.
5
+ *
6
+ * Authenticates with the deployment's Vercel OIDC token (same as
7
+ * {@link getToken}); the connector must be attached to the requesting
8
+ * deployment's project and enabled for its environment.
9
+ *
10
+ * @param connector - The connector id or UID.
11
+ */
12
+ export async function getConnectorMetadata(connector, options) {
13
+ const vercelToken = options?.vercelToken ?? (await getVercelOidcToken());
14
+ const endpoint = `https://api.vercel.com/v1/connect/connectors/${encodeURIComponent(connector)}`;
15
+ const response = await fetch(endpoint, {
16
+ method: 'GET',
17
+ headers: {
18
+ Accept: 'application/json',
19
+ Authorization: `Bearer ${vercelToken}`,
20
+ },
21
+ });
22
+ if (!response.ok) {
23
+ throw await createConnectErrorFromResponse(response, 'Failed to get connector');
24
+ }
25
+ const { data, ...rest } = (await response.json());
26
+ return { ...rest, vendor: data ?? {} };
27
+ }
@@ -10,4 +10,5 @@ export { connect, type EveAuthorizationInput, type EveAuthorizationOptions, type
10
10
  export { CONNECT_OAUTH_ISSUER, connectOAuth, type ConnectOAuthAudienceEnvironment, type ConnectOAuthEnvironment, type ConnectOAuthOptions, } from './connect-oauth.js';
11
11
  export { connectGitHubCredentials, type ConnectGitHubCredentialsParams, } from './github-credentials.js';
12
12
  export { connectLinearCredentials, type ConnectLinearCredentialsParams, } from './linear-credentials.js';
13
+ export { connectPhotonCredentials, type ConnectPhotonCredentialProvider, type PhotonCredentials, type ConnectPhotonCredentialsParams, } from './photon-credentials.js';
13
14
  export { connectSlackCredentials, type ConnectSlackCredentialsParams, } from './slack-credentials.js';
package/dist/eve/index.js CHANGED
@@ -10,4 +10,5 @@ export { connect, } from './connection-authorization.js';
10
10
  export { CONNECT_OAUTH_ISSUER, connectOAuth, } from './connect-oauth.js';
11
11
  export { connectGitHubCredentials, } from './github-credentials.js';
12
12
  export { connectLinearCredentials, } from './linear-credentials.js';
13
+ export { connectPhotonCredentials, } from './photon-credentials.js';
13
14
  export { connectSlackCredentials, } from './slack-credentials.js';
@@ -0,0 +1,34 @@
1
+ import { type ConnectOptions, type ConnectTokenParams } from '../index.js';
2
+ /** Photon project credentials resolved by {@link connectPhotonCredentials}. */
3
+ export interface PhotonCredentials {
4
+ projectId: string;
5
+ projectSecret: string;
6
+ }
7
+ /** Lazy Photon credential provider returned by {@link connectPhotonCredentials}. */
8
+ export type ConnectPhotonCredentialProvider = () => Promise<PhotonCredentials>;
9
+ /**
10
+ * Token parameters accepted by {@link connectPhotonCredentials}.
11
+ *
12
+ * Mirrors {@link ConnectTokenParams} from `@vercel/connect`, minus
13
+ * `subject` — Photon project credentials are app-scoped, so `subject`
14
+ * is pinned to `{ type: "app" }` by this helper and cannot be overridden.
15
+ */
16
+ export type ConnectPhotonCredentialsParams = Omit<ConnectTokenParams, 'subject'>;
17
+ /**
18
+ * Build a lazy Photon credential provider backed by a Vercel Connect
19
+ * connector.
20
+ *
21
+ * Photon connectors issue the project secret as an app-scoped token and the
22
+ * project ID as public token metadata. The returned provider resolves both
23
+ * fields when the Photon client or adapter first needs them.
24
+ *
25
+ * ```ts
26
+ * import { connectPhotonCredentials } from '@vercel/connect/eve';
27
+ * import { createiMessageAdapter } from '@photon-ai/chat-adapter-imessage';
28
+ *
29
+ * const imessage = createiMessageAdapter({
30
+ * credentials: connectPhotonCredentials('photon/my-project'),
31
+ * });
32
+ * ```
33
+ */
34
+ export declare function connectPhotonCredentials(connector: string, params?: ConnectPhotonCredentialsParams, options?: ConnectOptions): ConnectPhotonCredentialProvider;
@@ -0,0 +1,31 @@
1
+ import { getTokenResponse, } from '../index.js';
2
+ /**
3
+ * Build a lazy Photon credential provider backed by a Vercel Connect
4
+ * connector.
5
+ *
6
+ * Photon connectors issue the project secret as an app-scoped token and the
7
+ * project ID as public token metadata. The returned provider resolves both
8
+ * fields when the Photon client or adapter first needs them.
9
+ *
10
+ * ```ts
11
+ * import { connectPhotonCredentials } from '@vercel/connect/eve';
12
+ * import { createiMessageAdapter } from '@photon-ai/chat-adapter-imessage';
13
+ *
14
+ * const imessage = createiMessageAdapter({
15
+ * credentials: connectPhotonCredentials('photon/my-project'),
16
+ * });
17
+ * ```
18
+ */
19
+ export function connectPhotonCredentials(connector, params = {}, options) {
20
+ return async () => {
21
+ const response = await getTokenResponse(connector, { ...params, subject: { type: 'app' } }, options);
22
+ const projectId = response.metadata?.projectId;
23
+ if (typeof projectId !== 'string' || projectId.length === 0) {
24
+ throw new Error('Photon connector returned invalid credentials.');
25
+ }
26
+ return {
27
+ projectId,
28
+ projectSecret: response.token,
29
+ };
30
+ };
31
+ }
package/dist/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export { deleteTokenCacheEntry, getToken, getTokenResponse, revokeToken, Connect
2
2
  export { startAuthorization, type ConnectAuthorizationOptions, type ConnectAuthorizationResponse, } from './authorization.js';
3
3
  export { experimental_startInstallation, type ConnectInstallationOptions, type ConnectInstallationParams, type ConnectInstallationResponse, } from './installation.js';
4
4
  export type { ConnectAuthorizationDetail } from './authorization-details.js';
5
+ export { getConnectorMetadata, type ConnectorMetadata, } from './connector.js';
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { deleteTokenCacheEntry, getToken, getTokenResponse, revokeToken, ConnectError, NoValidTokenError, UserAuthorizationRequiredError, ConnectorInstallationRequiredError, } from './token.js';
2
2
  export { startAuthorization, } from './authorization.js';
3
3
  export { experimental_startInstallation, } from './installation.js';
4
+ export { getConnectorMetadata, } from './connector.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/connect",
3
- "version": "0.4.3",
3
+ "version": "0.5.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "repository": {