-
Notifications
You must be signed in to change notification settings - Fork 2
feat: read MUX_BASE_URL from env-file and persist to config #66
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
Changes from 6 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2422a40
feat: read MUX_BASE_URL from env-file and persist to config
jrmann100 6f9250a
feat: show API endpoint in whoami when nonstandard
jrmann100 e894c3c
test: add tests for MUX_BASE_URL parsing and priority
jrmann100 6a21c55
fix: pass baseUrl to Mux SDK client
jrmann100 f274010
fix: always validate login credentials against explicit base URL
jrmann100 404770f
fix: respect MUX_BASE_URL env var during login and avoid redundant co…
jrmann100 6c6b16f
refactor: extract resolveBaseUrl to eliminate duplicated logic
jrmann100 9975948
refactor: reuse resolveBaseUrl in login
jrmann100 831a184
refactor: remove redundant validationUrl alias in login
jrmann100 76abe68
refactor: use resolveBaseUrl in webhooks/listen to avoid redundant co…
jrmann100 e635ada
style: format resolveBaseUrl and login imports
jrmann100 ee6b73d
refactor: add getAuthContext to avoid redundant config reads
jrmann100 3977964
refactor: rename resolveBaseUrl to getMuxUrl and remove getMuxBaseUrl…
jrmann100 0017213
refactor: rename getMuxUrl back to getMuxBaseUrl
jrmann100 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { afterEach, beforeEach, describe, expect, it } from 'bun:test'; | ||
| import { mkdtemp, rm } from 'node:fs/promises'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { join } from 'node:path'; | ||
| import { setEnvironment } from './config.ts'; | ||
| import { DEFAULT_BASE_URL, getMuxBaseUrl } from './mux.ts'; | ||
|
|
||
| describe('getMuxBaseUrl', () => { | ||
| let testConfigDir: string; | ||
| let originalXdgConfigHome: string | undefined; | ||
| let originalMuxBaseUrl: string | undefined; | ||
|
|
||
| beforeEach(async () => { | ||
| testConfigDir = await mkdtemp(join(tmpdir(), 'mux-cli-test-')); | ||
| originalXdgConfigHome = process.env.XDG_CONFIG_HOME; | ||
| originalMuxBaseUrl = process.env.MUX_BASE_URL; | ||
| process.env.XDG_CONFIG_HOME = testConfigDir; | ||
| delete process.env.MUX_BASE_URL; | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| if (originalXdgConfigHome === undefined) { | ||
| delete process.env.XDG_CONFIG_HOME; | ||
| } else { | ||
| process.env.XDG_CONFIG_HOME = originalXdgConfigHome; | ||
| } | ||
| if (originalMuxBaseUrl === undefined) { | ||
| delete process.env.MUX_BASE_URL; | ||
| } else { | ||
| process.env.MUX_BASE_URL = originalMuxBaseUrl; | ||
| } | ||
| await rm(testConfigDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| it('should return default when no env var or config', async () => { | ||
| expect(await getMuxBaseUrl()).toBe(DEFAULT_BASE_URL); | ||
| }); | ||
|
|
||
| it('should prefer MUX_BASE_URL env var over everything', async () => { | ||
| process.env.MUX_BASE_URL = 'https://env-var.example.com'; | ||
| await setEnvironment('default', { | ||
| tokenId: 'id', | ||
| tokenSecret: 'secret', | ||
| baseUrl: 'https://config.example.com', | ||
| }); | ||
|
|
||
| expect(await getMuxBaseUrl()).toBe('https://env-var.example.com'); | ||
| }); | ||
|
|
||
| it('should use config baseUrl when no env var is set', async () => { | ||
| await setEnvironment('default', { | ||
| tokenId: 'id', | ||
| tokenSecret: 'secret', | ||
| baseUrl: 'https://api.staging.mux.com', | ||
| }); | ||
|
|
||
| expect(await getMuxBaseUrl()).toBe('https://api.staging.mux.com'); | ||
| }); | ||
|
|
||
| it('should fall back to default when config has no baseUrl', async () => { | ||
| await setEnvironment('default', { | ||
| tokenId: 'id', | ||
| tokenSecret: 'secret', | ||
| }); | ||
|
|
||
| expect(await getMuxBaseUrl()).toBe(DEFAULT_BASE_URL); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.