@vercel/connect 0.5.0 → 0.6.1

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,28 @@
1
+ import type { DiscordChannelCredentials } from 'eve/channels/discord';
2
+ import { type ConnectOptions, type ConnectTokenParams } from '../index.js';
3
+ /**
4
+ * Token parameters accepted by {@link connectDiscordCredentials}.
5
+ *
6
+ * Mirrors {@link ConnectTokenParams} from `@vercel/connect`, minus
7
+ * `subject` — Discord bot tokens are app-scoped, so this helper pins the
8
+ * subject to `{ type: "app" }`.
9
+ */
10
+ export type ConnectDiscordCredentialsParams = Omit<ConnectTokenParams, 'subject'>;
11
+ /**
12
+ * Build {@link DiscordChannelCredentials} backed by a Vercel Connect Discord
13
+ * Bot connector.
14
+ *
15
+ * The bot token and application id are resolved from the same Connect token
16
+ * response. The webhook verifier accepts interactions forwarded by Connect
17
+ * using Vercel OIDC, so the eve deployment does not need Discord's public key.
18
+ *
19
+ * ```ts
20
+ * import { discordChannel } from "eve/channels/discord";
21
+ * import { connectDiscordCredentials } from "@vercel/connect/eve";
22
+ *
23
+ * export default discordChannel({
24
+ * credentials: connectDiscordCredentials("discord/my-bot"),
25
+ * });
26
+ * ```
27
+ */
28
+ export declare function connectDiscordCredentials(connector: string, params?: ConnectDiscordCredentialsParams, options?: ConnectOptions): DiscordChannelCredentials;
@@ -0,0 +1,43 @@
1
+ import { vercelOidc } from 'eve/channels/auth';
2
+ import { getTokenResponse, } from '../index.js';
3
+ /**
4
+ * Build {@link DiscordChannelCredentials} backed by a Vercel Connect Discord
5
+ * Bot connector.
6
+ *
7
+ * The bot token and application id are resolved from the same Connect token
8
+ * response. The webhook verifier accepts interactions forwarded by Connect
9
+ * using Vercel OIDC, so the eve deployment does not need Discord's public key.
10
+ *
11
+ * ```ts
12
+ * import { discordChannel } from "eve/channels/discord";
13
+ * import { connectDiscordCredentials } from "@vercel/connect/eve";
14
+ *
15
+ * export default discordChannel({
16
+ * credentials: connectDiscordCredentials("discord/my-bot"),
17
+ * });
18
+ * ```
19
+ */
20
+ export function connectDiscordCredentials(connector, params = {}, options) {
21
+ let pending;
22
+ function resolveCredentials() {
23
+ if (!pending) {
24
+ pending = getTokenResponse(connector, { ...params, subject: { type: 'app' } }, options)
25
+ .then(response => {
26
+ const applicationId = response.metadata?.applicationId;
27
+ if (typeof applicationId !== 'string' || applicationId.length === 0) {
28
+ throw new Error(`Vercel Connect connector ${connector} did not return a Discord application id.`);
29
+ }
30
+ return { applicationId, botToken: response.token };
31
+ })
32
+ .finally(() => {
33
+ pending = undefined;
34
+ });
35
+ }
36
+ return pending;
37
+ }
38
+ return {
39
+ applicationId: async () => (await resolveCredentials()).applicationId,
40
+ botToken: async () => (await resolveCredentials()).botToken,
41
+ webhookVerifier: vercelOidc(),
42
+ };
43
+ }
@@ -8,6 +8,7 @@
8
8
  */
9
9
  export { connect, type EveAuthorizationInput, type EveAuthorizationOptions, type EveConnectAuthorizationDefinition, type EveConnectionAuthorizationContext, type ConnectAuthorizationPhase, type VercelConnectMetadata, } from './connection-authorization.js';
10
10
  export { CONNECT_OAUTH_ISSUER, connectOAuth, type ConnectOAuthAudienceEnvironment, type ConnectOAuthEnvironment, type ConnectOAuthOptions, } from './connect-oauth.js';
11
+ export { connectDiscordCredentials, type ConnectDiscordCredentialsParams, } from './discord-credentials.js';
11
12
  export { connectGitHubCredentials, type ConnectGitHubCredentialsParams, } from './github-credentials.js';
12
13
  export { connectLinearCredentials, type ConnectLinearCredentialsParams, } from './linear-credentials.js';
13
14
  export { connectPhotonCredentials, type ConnectPhotonCredentialProvider, type PhotonCredentials, type ConnectPhotonCredentialsParams, } from './photon-credentials.js';
package/dist/eve/index.js CHANGED
@@ -8,6 +8,7 @@
8
8
  */
9
9
  export { connect, } from './connection-authorization.js';
10
10
  export { CONNECT_OAUTH_ISSUER, connectOAuth, } from './connect-oauth.js';
11
+ export { connectDiscordCredentials, } from './discord-credentials.js';
11
12
  export { connectGitHubCredentials, } from './github-credentials.js';
12
13
  export { connectLinearCredentials, } from './linear-credentials.js';
13
14
  export { connectPhotonCredentials, } from './photon-credentials.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/connect",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "repository": {
@@ -42,7 +42,7 @@
42
42
  "dist"
43
43
  ],
44
44
  "dependencies": {
45
- "@vercel/oidc": "3.8.1"
45
+ "@vercel/oidc": "3.8.2"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "@ai-sdk/mcp": "^1 || ^2",