diff --git a/.changeset/rotten-dolphins-punch.md b/.changeset/rotten-dolphins-punch.md new file mode 100644 index 0000000000..6cd2cf2b42 --- /dev/null +++ b/.changeset/rotten-dolphins-punch.md @@ -0,0 +1,5 @@ +--- +"@trigger.dev/build": minor +--- + +Add teamId option to vercelSyncEnvVars diff --git a/docs/config/config-file.mdx b/docs/config/config-file.mdx index dfc95fcb1c..b225834380 100644 --- a/docs/config/config-file.mdx +++ b/docs/config/config-file.mdx @@ -511,10 +511,10 @@ The `vercelSyncEnvVars` build extension syncs environment variables from your Ve You need to set the `VERCEL_ACCESS_TOKEN` and `VERCEL_PROJECT_ID` environment variables, or pass - in the token and project ID as arguments to the `vercelSyncEnvVars` build extension. You can find - / generate the `VERCEL_ACCESS_TOKEN` in your Vercel - [dashboard](https://vercel.com/account/settings/tokens). Make sure the scope of the token covers - the project you want to sync. + in the token and project ID as arguments to the `vercelSyncEnvVars` build extension. If you're + working with a team project, you'll also need to set `VERCEL_TEAM_ID`. You can find / generate + the `VERCEL_ACCESS_TOKEN` in your Vercel [dashboard](https://vercel.com/account/settings/tokens). + Make sure the scope of the token covers the project you want to sync. ```ts diff --git a/docs/guides/examples/vercel-sync-env-vars.mdx b/docs/guides/examples/vercel-sync-env-vars.mdx index 9cd8cccef6..55aedd7c5c 100644 --- a/docs/guides/examples/vercel-sync-env-vars.mdx +++ b/docs/guides/examples/vercel-sync-env-vars.mdx @@ -13,7 +13,8 @@ To sync environment variables, you just need to add our build extension to your You need to set the `VERCEL_ACCESS_TOKEN` and `VERCEL_PROJECT_ID` environment variables in the Trigger.dev dashboard, or pass in the token and project ID as arguments to the `vercelSyncEnvVars` - build extension. You can find / generate the `VERCEL_ACCESS_TOKEN` in your Vercel + build extension. If you're working with a team project, you'll also need to set `VERCEL_TEAM_ID`. + You can find / generate the `VERCEL_ACCESS_TOKEN` in your Vercel [dashboard](https://vercel.com/account/settings/tokens). Make sure the scope of the token covers the project with the environment variables you want to sync. diff --git a/docs/guides/frameworks/nextjs.mdx b/docs/guides/frameworks/nextjs.mdx index 8cd8ac1583..f6ec3c3ff9 100644 --- a/docs/guides/frameworks/nextjs.mdx +++ b/docs/guides/frameworks/nextjs.mdx @@ -251,10 +251,10 @@ If you want to automatically sync environment variables from your Vercel project You need to set the `VERCEL_ACCESS_TOKEN` and `VERCEL_PROJECT_ID` environment variables, or pass - in the token and project ID as arguments to the `vercelSyncEnvVars` build extension. You can find - / generate the `VERCEL_ACCESS_TOKEN` in your Vercel - [dashboard](https://vercel.com/account/settings/tokens). Make sure the scope of the token covers - the project you want to sync. + in the token and project ID as arguments to the `vercelSyncEnvVars` build extension. If you're + working with a team project, you'll also need to set `VERCEL_TEAM_ID`. You can find / generate + the `VERCEL_ACCESS_TOKEN` in your Vercel [dashboard](https://vercel.com/account/settings/tokens). + Make sure the scope of the token covers the project you want to sync. ```ts trigger.config.ts diff --git a/packages/build/src/extensions/core/vercelSyncEnvVars.ts b/packages/build/src/extensions/core/vercelSyncEnvVars.ts index c6c6f3b11b..16aeba4c47 100644 --- a/packages/build/src/extensions/core/vercelSyncEnvVars.ts +++ b/packages/build/src/extensions/core/vercelSyncEnvVars.ts @@ -1,8 +1,8 @@ import { BuildExtension } from "@trigger.dev/core/v3/build"; import { syncEnvVars } from "../core.js"; -export function syncVercelEnvVars( - options?: { projectId?: string; vercelAccessToken?: string }, +export function vercelSyncEnvVars( + options?: { projectId?: string; vercelAccessToken?: string; vercelTeamId?: string }, ): BuildExtension { const sync = syncEnvVars(async (ctx) => { const projectId = options?.projectId ?? process.env.VERCEL_PROJECT_ID ?? @@ -10,6 +10,8 @@ export function syncVercelEnvVars( const vercelAccessToken = options?.vercelAccessToken ?? process.env.VERCEL_ACCESS_TOKEN ?? ctx.env.VERCEL_ACCESS_TOKEN; + const vercelTeamId = options?.vercelTeamId ?? process.env.VERCEL_TEAM_ID ?? + ctx.env.VERCEL_TEAM_ID; if (!projectId) { throw new Error( @@ -37,8 +39,9 @@ export function syncVercelEnvVars( `Invalid environment '${ctx.environment}'. Expected 'prod', 'staging', or 'dev'.`, ); } - const vercelApiUrl = - `https://api.vercel.com/v8/projects/${projectId}/env?decrypt=true`; + const params = new URLSearchParams({ decrypt: "true" }); + if (vercelTeamId) params.set("teamId", vercelTeamId); + const vercelApiUrl = `https://api.vercel.com/v8/projects/${projectId}/env?${params}`; try { const response = await fetch(vercelApiUrl, {