Skip to content

fix(sdk): use nameOrRequestOptions in envvars.update outside a task - #4903

Closed
claxman wants to merge 1 commit into
triggerdotdev:mainfrom
claxman:fix/4264-envvars-update-name
Closed

fix(sdk): use nameOrRequestOptions in envvars.update outside a task#4903
claxman wants to merge 1 commit into
triggerdotdev:mainfrom
claxman:fix/4264-envvars-update-name

Conversation

@claxman

@claxman claxman commented Sep 7, 2026

Copy link
Copy Markdown

Fixes #4264

envvars.update(projectRef, slug, name, params) from a plain Node script throws ReferenceError: name is not defined before any HTTP call. Repro on 0a23814:

cd packages/trigger-sdk
../../node_modules/.bin/tsx --eval 'import { update } from "./src/v3/envvars.ts"; update("proj_x","dev","FOO",{value:"bar"})'

Cause: the implementation parameter is nameOrRequestOptions, but the non-task branch assigned $name from a bare name binding at envvars.ts:341. Typecheck passes because lib.dom declares a global name. Node has none.

Fix: the non-task branch checks typeof nameOrRequestOptions === "string" (same shape as the slug/params checks next to it) and assigns that.

Not touched: the in-task 4-arg branch. With taskContext project proj_ctx / env prod, the same call PUTs http://x/api/v1/projects/dev/envvars/dev/FOO because that branch sets $projectRef = slugOrParams. Separate bug, left for a follow-up.

Test: packages/trigger-sdk/src/v3/envvars.test.ts uses a local HTTP server like auth.test.ts and asserts the PUT path /api/v1/projects/proj_x/envvars/dev/FOO and body {value:"bar"}. Without the assignment change both tests fail with the ReferenceError above. With it, pnpm run test ./src/v3/envvars.test.ts --run reports 2 passed. oxlint and oxfmt --check on the two changed files are clean.

The 4-arg management form assigned $name from a binding that is not a
parameter. TypeScript accepted it via the DOM global. Node throws
ReferenceError before any request.

Repro: tsx --eval update("proj_x","dev","FOO",{value:"bar"}) on 0a23814.

Guard the string, assign nameOrRequestOptions, add envvars.test.ts.
Tests failed with ReferenceError without the assignment, 2 passed after.
@changeset-bot

changeset-bot Bot commented Sep 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d8fcd9b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 27 packages
Name Type
@trigger.dev/sdk Patch
@trigger.dev/python Patch
@internal/dashboard-agent Patch
@trigger.dev/build Patch
trigger.dev Patch
@trigger.dev/core Patch
@trigger.dev/react-hooks Patch
@trigger.dev/redis-worker Patch
@trigger.dev/rsc Patch
@trigger.dev/schema-to-json Patch
@trigger.dev/database Patch
@trigger.dev/otlp-importer Patch
@trigger.dev/rbac Patch
@trigger.dev/sso Patch
@internal/clickhouse Patch
@internal/llm-model-catalog Patch
@internal/metrics-pipeline Patch
@internal/redis Patch
@internal/replication Patch
@internal/run-engine Patch
@internal/run-store Patch
@internal/schedule-engine Patch
@internal/tracing Patch
@internal/webhook-engine Patch
@internal/webhook-sources Patch
@internal/testcontainers Patch
@internal/cache Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Hi @claxman, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details.

@github-actions github-actions Bot closed this Sep 7, 2026
@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 32a90877-4a91-436a-8c04-ccb43c4ab790

📥 Commits

Reviewing files that changed from the base of the PR and between 7fb8310 and d8fcd9b.

📒 Files selected for processing (3)
  • .changeset/fix-envvars-update-name.md
  • packages/trigger-sdk/src/v3/envvars.test.ts
  • packages/trigger-sdk/src/v3/envvars.ts

Walkthrough

The SDK now validates the environment variable name in the non-context envvars.update path and throws "name is required" when it is missing or invalid. New tests verify the PUT request, authorization header, request body, and missing-name behavior outside a task context. A changeset declares a patch release for @trigger.dev/sdk.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: envvars.update() throws "ReferenceError: name is not defined" outside a task context

1 participant