Skip to content

feat(core): support organization API keys - #2021

Open
eoinest wants to merge 8 commits into
mainfrom
e/core/support-org-api-key
Open

feat(core): support organization API keys#2021
eoinest wants to merge 8 commits into
mainfrom
e/core/support-org-api-key

Conversation

@eoinest

@eoinest eoinest commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Accept apiKey, devApiKey, and orgApiKey as configuration aliases normalized into one stored API key.
  • Read GT_ORG_API_KEY as an environment fallback while continuing to require a project ID for project operations.

Testing

  • pnpm --filter generaltranslation test — passed (31 files, 504 tests)
  • pnpm --filter generaltranslation typecheck — passed
  • pnpm check:library-defaults — passed (4 tests)
  • pnpm build — passed (20 packages)
  • pnpm exec oxfmt --check packages/core/src/runtime.ts packages/core/src/__tests__/index.test.ts .changeset/tidy-oranges-agree.md — passed

Notes

  • Changeset: added a patch release for generaltranslation.
  • Follow-up: #2022 adds organization-authenticated project creation and is stacked on this branch.

Greptile Summary

This PR consolidates three API key aliases (apiKey, devApiKey, orgApiKey) and the new GT_ORG_API_KEY environment variable into a single this.apiKey field, establishing a clear left-to-right priority (apiKey > devApiKey > orgApiKey, and env fallbacks in the same order). Explicit constructor/setConfig values now always override environment-loaded keys, fixing a previously-noted silent precedence bug.

  • New orgApiKey alias: accepted in both GTConstructorParams and setConfig, normalized into this.apiKey with the lowest priority among the three aliases; GT_ORG_API_KEY is added as an env fallback.
  • devApiKey field removed: the public devApiKey class property on GTRuntime is removed; both dev and org keys are now stored under this.apiKey. This is a breaking API change for any consumer that reads instance.devApiKey directly.
  • Changeset bump: the changeset is classified as patch, but the removal of the public field warrants at least a minor bump.

Confidence Score: 4/5

Safe to merge after confirming the semver classification — the logic changes are correct and well-tested, but the changeset bump needs to be revisited.

The key-resolution logic is sound and the explicit-over-env priority is now correctly enforced. The only real concern is that removing the public devApiKey field from GTRuntime is a breaking API surface change for TypeScript consumers who access that property directly, yet the changeset marks this as a patch release.

Files Needing Attention: packages/core/src/runtime.ts (removal of devApiKey public field) and .changeset/tidy-oranges-agree.md (version classification).

Important Files Changed

Filename Overview
packages/core/src/runtime.ts Merges apiKey/devApiKey/orgApiKey into a single this.apiKey field with
packages/core/src/tests/index.test.ts Adds four new test cases covering orgApiKey construction, env-vs-explicit priority order, missing projectId, and missing apiKey validation; updates the all-options config test to match the new normalized-key behaviour.
.changeset/tidy-oranges-agree.md Changeset is marked patch; removing the public devApiKey field makes this at least a minor bump.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Constructor called with GTConstructorParams] --> B{process defined?}
    B -- Yes --> C["this.apiKey ||= GT_API_KEY || GT_DEV_API_KEY || GT_ORG_API_KEY"]
    B -- No --> D[skip env read]
    C --> E[setConfig called with params]
    D --> E
    E --> F["this.apiKey = apiKey || devApiKey || orgApiKey || this.apiKey"]
    F --> G{Explicit key passed?}
    G -- Yes --> H[Explicit key wins - env key overwritten]
    G -- No --> I[Env key preserved]
    H --> J[_getTranslationConfig returns this.apiKey]
    I --> J
    J --> K{apiKey && projectId?}
    K -- No --> L[_validateAuth throws error]
    K -- Yes --> M[Translation request sent]
Loading

Reviews (8): Last reviewed commit: "refactor(core): expose one API key field" | Re-trigger Greptile

Comment thread packages/core/src/runtime.ts Outdated
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
generaltranslation 18.1 KB (+0.11% 🔺)
generaltranslation/runtime 14.87 KB (+0.05% 🔺)
generaltranslation/id 2.55 KB (0%)
generaltranslation/internal 7.36 KB (0%)
generaltranslation/types 115 B (0%)
generaltranslation/errors 81 B (0%)
@generaltranslation/format 9.5 KB (0%)
@generaltranslation/format/types 89 B (0%)
@generaltranslation/format/internal 880 B (0%)
gt-i18n 11.88 KB (0%)
gt-i18n/types 13 B (0%)
gt-i18n/internal 22.51 KB (+0.25% 🔺)
gt-i18n/internal/types 13 B (0%)
@generaltranslation/react-core/pure 25.55 KB (+0.12% 🔺)
@generaltranslation/react-core/hooks 20.58 KB (-0.04% 🔽)
@generaltranslation/react-core/components 22.73 KB (+0.24% 🔺)
@generaltranslation/react-core/components-rsc 26.17 KB (+0.08% 🔺)
gt-react (client) 32.05 KB (+0.19% 🔺)
gt-react (rsc) 28.71 KB (+0.26% 🔺)
gt-react (server) 31.67 KB (+0.15% 🔺)
gt-react/macros 8.81 KB (0%)
gt-next (client) 43.96 KB (+0.31% 🔺)
gt-next (rsc) 47.88 KB (+0.23% 🔺)
gt-next (server) 44.02 KB (-0.21% 🔽)
gt-next/config 269.89 KB (-0.04% 🔽)
gt-next/server 46.4 KB (+0.01% 🔺)
gt-next/middleware 36.55 KB (+0.08% 🔺)
gt-next/link 42.74 KB (-0.34% 🔽)
gt-next/internal/_dictionary 144 B (0%)
gt-next/internal/_load-translations 144 B (0%)
gt-next/internal/_load-dictionary 144 B (0%)
gt-next/internal/_getLocale 125 B (0%)
gt-next/internal/_getRegion 122 B (0%)
gt-node 23.49 KB (-0.05% 🔽)
gt-node/types 219 B (0%)
gt-node/internal 13.45 KB (0%)
gt-tanstack-start (client) 31.62 KB (+0.02% 🔺)
gt-tanstack-start (server) 32.03 KB (0%)
gt-tanstack-start/server 10.24 KB (0%)
gt-react-native 30.1 KB (+0.09% 🔺)
gt-react-native/plugin 4.6 KB (0%)
gt-react-native/internal 746 B (0%)

@eoinest

eoinest commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai

@eoinest

eoinest commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai

@eoinest eoinest left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

lgtm

@eoinest

eoinest commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai

@eoinest

eoinest commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai

Comment on lines +149 to 153
this.apiKey ||=
process.env?.GT_API_KEY ||
process.env?.GT_DEV_API_KEY ||
process.env?.GT_ORG_API_KEY;
this.projectId ||= process.env?.GT_PROJECT_ID;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 GT_ORG_API_KEY silently ignored when GT_DEV_API_KEY is also set

GT_ORG_API_KEY is placed last in the || chain, so it is never evaluated when GT_DEV_API_KEY is present in the environment. A developer who moves to org-scoped authentication by adding GT_ORG_API_KEY to their environment but still has GT_DEV_API_KEY in their shell profile (common in dev setups) will have the org key silently dropped — API calls will authenticate with the old dev key, which may lack the org-level permissions needed, causing opaque auth failures.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/core/src/runtime.ts
Line: 149-153

Comment:
**`GT_ORG_API_KEY` silently ignored when `GT_DEV_API_KEY` is also set**

`GT_ORG_API_KEY` is placed last in the `||` chain, so it is never evaluated when `GT_DEV_API_KEY` is present in the environment. A developer who moves to org-scoped authentication by adding `GT_ORG_API_KEY` to their environment but still has `GT_DEV_API_KEY` in their shell profile (common in dev setups) will have the org key silently dropped — API calls will authenticate with the old dev key, which may lack the org-level permissions needed, causing opaque auth failures.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

@eoinest

eoinest commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai

@eoinest

eoinest commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai

@eoinest

eoinest commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai

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.

1 participant