Skip to content

Fix: vercelSyncEnvVars teamId #1463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rotten-dolphins-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@trigger.dev/build": minor
---

Add teamId option to vercelSyncEnvVars
8 changes: 4 additions & 4 deletions docs/config/config-file.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,10 @@ The `vercelSyncEnvVars` build extension syncs environment variables from your Ve

<Note>
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.
</Note>

```ts
Expand Down
3 changes: 2 additions & 1 deletion docs/guides/examples/vercel-sync-env-vars.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ To sync environment variables, you just need to add our build extension to your
<Note>
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.
</Note>
Expand Down
8 changes: 4 additions & 4 deletions docs/guides/frameworks/nextjs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ If you want to automatically sync environment variables from your Vercel project

<Note>
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.
</Note>

```ts trigger.config.ts
Expand Down
11 changes: 7 additions & 4 deletions packages/build/src/extensions/core/vercelSyncEnvVars.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
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 ??
ctx.env.VERCEL_PROJECT_ID;
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(
Expand Down Expand Up @@ -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, {
Expand Down