Skip to content

[V8] remove direct process.env access, replacing with getEnv helper#1312

Merged
nicknisi merged 2 commits intoversion-8from
nicknisi/v8-remove-direct-process-access
Jul 22, 2025
Merged

[V8] remove direct process.env access, replacing with getEnv helper#1312
nicknisi merged 2 commits intoversion-8from
nicknisi/v8-remove-direct-process-access

Conversation

@nicknisi
Copy link
Copy Markdown
Member

Description

This pull request refactors how environment variables are accessed in the WorkOS class to improve code clarity and maintainability. The changes replace direct access to process.env with a utility function getEnv.

Refactoring environment variable access:

  • src/workos.ts: Introduced the getEnv utility function from ./common/utils/env to centralize and simplify access to environment variables.
  • src/workos.ts: Replaced direct usage of process.env.WORKOS_API_KEY with getEnv('WORKOS_API_KEY') for retrieving the API key. This ensures consistent handling of environment variables across environments.
  • src/workos.ts: Replaced direct usage of process.env.WORKOS_CLIENT_ID with getEnv('WORKOS_CLIENT_ID') for retrieving the client ID. This further standardizes the approach to accessing environment variables.

Documentation

Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.

[ ] Yes

If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.

@nicknisi nicknisi requested a review from a team as a code owner July 17, 2025 16:54
@nicknisi nicknisi requested review from stacurry and removed request for a team July 17, 2025 16:54
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Summary

This PR improves the cross-runtime compatibility of the WorkOS Node.js SDK by replacing direct process.env access with a new getEnv utility function. This change is particularly important as it:

  1. Enables the SDK to work in environments where process.env isn't available (like Deno, Bun, Cloudflare Workers, etc.)
  2. Centralizes environment variable access through a single utility function
  3. Makes the code more maintainable by abstracting environment handling

The changes specifically affect how WORKOS_API_KEY and WORKOS_CLIENT_ID are accessed in the WorkOS class.

Confidence score: 4/5

  1. This PR is safe to merge as it maintains existing functionality while improving runtime compatibility
  2. High confidence due to the straightforward nature of the changes and their clear benefits for cross-runtime support
  3. Files needing attention:
    • src/common/utils/env.ts - Verify the implementation of getEnv utility
    • src/workos.ts - Ensure all process.env accesses are properly replaced

1 file reviewed, 1 comment
Edit PR Review Bot Settings | Greptile

@nicknisi nicknisi merged commit 23da99a into version-8 Jul 22, 2025
7 checks passed
@nicknisi nicknisi deleted the nicknisi/v8-remove-direct-process-access branch July 22, 2025 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants