feat: SDK update for version 20.1.0#306
Conversation
Greptile SummaryThis PR bumps the CLI to version 20.1.0 and refactors the Confidence Score: 4/5Safe to merge; only P2 findings — no data loss or auth regressions identified. All findings are P2: a duplicated constant that could drift, a helper function with undocumented side effects, and a subtle ordering change in session deduplication. None affect correctness in the normal login/switch flow. lib/commands/generic.ts (duplicate DEFAULT_ENDPOINT, getCurrentAccount side effects) and lib/config.ts (getSessions deduplication ordering) Important Files Changed
|
| localConfig, | ||
| normalizeCloudConsoleEndpoint, | ||
| } from "../config.js"; | ||
| import { EXECUTABLE_NAME } from "../constants.js"; |
There was a problem hiding this comment.
DEFAULT_ENDPOINT is already exported from lib/constants.ts (which questions.ts and other modules already import). Defining a private duplicate here creates a maintenance risk — if the canonical value ever changes, this copy would silently diverge.
| import { EXECUTABLE_NAME } from "../constants.js"; | |
| import { EXECUTABLE_NAME, DEFAULT_ENDPOINT } from "../constants.js"; |
| } from "@appwrite.io/console"; | ||
| import ClientLegacy from "../client.js"; | ||
|
|
||
| const DEFAULT_ENDPOINT = "https://cloud.appwrite.io/v1"; |
| const getCurrentAccount = async (): Promise<Models.User | null> => { | ||
| if (globalConfig.getEndpoint() === "" || globalConfig.getCookie() === "") { | ||
| return null; | ||
| } | ||
|
|
||
| const endpoint = normalizeCloudConsoleEndpoint(globalConfig.getEndpoint()); | ||
| if (endpoint !== globalConfig.getEndpoint()) { | ||
| globalConfig.setEndpoint(endpoint); | ||
| } | ||
|
|
||
| const client = await sdkForConsole(false); | ||
| const accountClient = new Account(client); | ||
|
|
||
| try { | ||
| const account = await accountClient.get(); | ||
| globalConfig.setEmail(account.email); | ||
| return account; | ||
| } catch (err) { | ||
| if (isGuestUnauthorizedError(err)) { | ||
| removeCurrentSession(); | ||
| } | ||
| return null; | ||
| } | ||
| }; |
There was a problem hiding this comment.
getCurrentAccount carries silent, destructive side effects
Beyond returning the current user, this function: (1) mutates globalConfig by normalizing and persisting the endpoint on every call, and (2) permanently removes the current session from local config when general_unauthorized_scope is returned. A transient network error (connection refused, timeout) causes the catch block to skip removal and return null, which causes loginCommand to bypass the "already logged in" early-return and re-prompt the user — potentially creating a duplicate session for the same account. At minimum, network errors should be distinguished from authorization errors so callers can decide how to handle each case.
This PR contains updates to the SDK for version 20.1.0.
What's Changed
--switchand--newflags onappwrite loginto explicitly manage multiple saved accountsappwrite loginto verify the current session via the API and clean up stale guest/unauthorized sessions instead of trusting local metadatahttps://cloud.appwrite.io/v1and reject regional Cloud endpoints