Repository navigation
fix(workspace): a blank field in altimate.json reads as signed out, not as an unreadable link
#1911
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -107,6 +107,22 @@ export namespace AltimateApi { | |||||||||||
| return obj | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** The credentials file is there but a required field is blank: signed out, not unreadable. */ | ||||||||||||
| export class IncompleteCredentials extends Error { | ||||||||||||
| constructor(readonly fields: string[]) { | ||||||||||||
| super(`Altimate sign-in is incomplete (${fields.join(", ")} must not be blank); sign in again`) | ||||||||||||
| this.name = "IncompleteCredentials" | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| const REQUIRED_FIELDS = ["altimateUrl", "altimateInstanceName", "altimateApiKey"] as const | ||||||||||||
|
|
||||||||||||
| function blankRequiredFields(raw: unknown): string[] { | ||||||||||||
| if (!raw || typeof raw !== "object") return [] | ||||||||||||
| const record = raw as Record<string, unknown> | ||||||||||||
| return REQUIRED_FIELDS.filter((field) => typeof record[field] === "string" && record[field].trim() === "") | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [🟠 MEDIUM] In TypeScript, type narrowing on indexed access with dynamic keys (like Extracting the property value to a local variable helps TypeScript correctly narrow the type and is generally cleaner. Suggested change:
Suggested change
|
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| export async function getCredentials(): Promise<AltimateCredentials> { | ||||||||||||
| const scoped = currentCredentials() | ||||||||||||
| if (scoped) return scoped | ||||||||||||
|
|
@@ -115,7 +131,15 @@ export namespace AltimateApi { | |||||||||||
| throw new Error(`Altimate credentials not found at ${p}`) | ||||||||||||
| } | ||||||||||||
| const raw = resolveEnvVars(JSON.parse(await Filesystem.readText(p))) | ||||||||||||
| const creds = AltimateCredentials.parse(raw) | ||||||||||||
| const parsed = AltimateCredentials.safeParse(raw) | ||||||||||||
| if (!parsed.success) { | ||||||||||||
| const blank = blankRequiredFields(raw) | ||||||||||||
| // Only blank required fields: a sign-in that was never finished, not a file that can't be read. | ||||||||||||
| if (blank.length > 0 && parsed.error.issues.every((issue) => blank.includes(String(issue.path[0])))) | ||||||||||||
| throw new IncompleteCredentials(blank) | ||||||||||||
| throw parsed.error | ||||||||||||
| } | ||||||||||||
| const creds = parsed.data | ||||||||||||
| return { | ||||||||||||
| ...creds, | ||||||||||||
| altimateUrl: creds.altimateUrl.replace(/\/+$/, ""), | ||||||||||||
|
|
||||||||||||
Uh oh!
There was an error while loading. Please reload this page.