feat: add branch support to browser extension plugin#3513
Conversation
Read branch from sessionStorage and pass it via overrideCredentials so the chrome extension can control which branch translations are fetched from. Also include branch in the LibConfig handshake message.
WalkthroughAdds an optional Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/web/src/package/BrowserExtensionPlugin/BrowserExtensionPlugin.ts`:
- Around line 18-22: getCredentials currently always returns { apiKey, apiUrl,
branch } which can overwrite a configured SDK branch with undefined when
__tolgee_branch is missing; update getCredentials so it only includes branch in
the returned object when branch is defined (e.g., conditionally add branch or
filter undefined values) so merging with devCredentials or initial options does
not wipe an existing branch; look for the getCredentials function and the
variables apiKey, apiUrl, branch, and places where devCredentials/initial
options are merged to implement the conditional inclusion.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 959cc751-3a7a-4a5e-a43f-827685c958da
📒 Files selected for processing (3)
packages/core/src/types/plugin.tspackages/web/src/package/BrowserExtensionPlugin/BrowserExtensionPlugin.tspackages/web/src/package/tools/extension.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/web/src/package/__test__/browser.extension.test.ts`:
- Around line 81-91: The test currently only asserts loadInContextLib call count
but must also verify the branch value; update the test so after running tolgee
you assert that loadInContextLib was called with an initializer object whose
credentials.branch equals 'my-branch' (e.g. use
expect(loadInContextLib).toHaveBeenCalledWith(expect.objectContaining({
credentials: expect.objectContaining({ branch: 'my-branch' }) })) so the
BrowserExtensionPlugin/TolgeeCore integration actually consumes
BRANCH_LOCAL_STORAGE.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c0d35c1c-062c-4354-99fd-ab43de72c3ad
📒 Files selected for processing (2)
packages/core/src/__test/options.test.tspackages/web/src/package/__test__/browser.extension.test.ts
924b949 to
0283279
Compare
) ## Summary - Add `branchingEnabled` boolean to `/v2/api-keys/current` response (`ApiKeyWithLanguagesModel`) so clients can conditionally show branch-related UI - Use `ProjectFeatureGuard.isFeatureEnabled(Feature.BRANCHING)` which checks both org-level feature flag and project-level `useBranching` setting - Rename `BRANCHING_NOT_ENABLED_FOR_PROJECT` to generic `FEATURE_NOT_ENABLED_FOR_PROJECT` with feature name as parameter - Switch `ProjectFeatureGuard` from `ValidationException` to `BadRequestException` for consistency with `OrganizationFeatureGuard` - Add frontend error translation for `feature_not_enabled_for_project` ## Related PRs - chrome-plugin: tolgee/chrome-plugin#38 - tolgee-js: tolgee/tolgee-js#3513 ## Test plan - [ ] Verify `/v2/api-keys/current` response includes `branchingEnabled: true` when branching is enabled - [ ] Verify `branchingEnabled: false` when branching feature is disabled at org level - [ ] Verify `branchingEnabled: false` when project has `useBranching = false` - [ ] Verify `FEATURE_NOT_ENABLED_FOR_PROJECT` error includes the feature name - [ ] Verify frontend displays translated error message for `feature_not_enabled_for_project` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * API key info now includes whether branching is enabled for the project (visible in API responses and client schema). * **Improvements** * Error reporting for disabled features renamed and clarified; messages now indicate which feature is unavailable and client error codes/translations were updated accordingly. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary
branchtoDevCredentialstype sooverrideCredentialscan pass branch to the SDK__tolgee_branchfrom sessionStorage inBrowserExtensionPluginand include it in credentialsbranchtoLibConfigtype so the SDK sends its configured branch in theTOLGEE_READYhandshake message__tolgee_branchfrom sessionStorage on credential resetRelated PRs
Test plan
?branch=Xquery parameter is appended to translation API callsTOLGEE_READYhandshake message to the extensionSummary by CodeRabbit