Skip to content

Commit 276a2f9

Browse files
authored
Merge pull request #327 from appwrite/dev
feat: SDK update for version 22.1.2
2 parents d91c596 + 6fc1d47 commit 276a2f9

10 files changed

Lines changed: 73 additions & 48 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## 22.1.2
4+
5+
* Added: OAuth2 login now requests the `account.admin` scope
6+
* Fixed: `logout` now reports the underlying server error when a session can't be revoked
7+
* Fixed: `logout` and `client --reset` no longer report success when the server session revocation fails
8+
39
## 22.1.1
410

511
* Added: Support for logging into staging Cloud environments (`stage.cloud.appwrite.io`)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using
2929

3030
```sh
3131
$ appwrite -v
32-
22.1.1
32+
22.1.2
3333
```
3434

3535
### Install using prebuilt binaries
@@ -83,7 +83,7 @@ $ scoop install https://raw.githubusercontent.com/appwrite/sdk-for-cli/master/sc
8383
Once the installation completes, you can verify your install using
8484
```
8585
$ appwrite -v
86-
22.1.1
86+
22.1.2
8787
```
8888

8989
## Getting Started

install.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# You can use "View source" of this page to see the full script.
1414

1515
# REPO
16-
$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/22.1.1/appwrite-cli-win-x64.exe"
17-
$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/22.1.1/appwrite-cli-win-arm64.exe"
16+
$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/22.1.2/appwrite-cli-win-x64.exe"
17+
$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/22.1.2/appwrite-cli-win-arm64.exe"
1818

1919
$APPWRITE_BINARY_NAME = "appwrite.exe"
2020

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ verifyMacOSCodeSignature() {
120120
downloadBinary() {
121121
echo "[2/5] Downloading executable for $OS ($ARCH) ..."
122122

123-
GITHUB_LATEST_VERSION="22.1.1"
123+
GITHUB_LATEST_VERSION="22.1.2"
124124
GITHUB_FILE="appwrite-cli-${OS}-${ARCH}"
125125
GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE"
126126

lib/auth/session.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ export const removeCurrentSession = (): void => {
8282
*/
8383
export const deleteServerSession = async (
8484
sessionId: string,
85-
): Promise<boolean> => {
85+
): Promise<{ deleted: boolean; error?: string }> => {
8686
const session = getSession(sessionId);
8787
if (!session?.endpoint) {
88-
return false;
88+
return { deleted: false };
8989
}
9090

9191
try {
@@ -95,7 +95,7 @@ export const deleteServerSession = async (
9595
session.refreshToken,
9696
session.clientId || OAUTH2_CLIENT_ID,
9797
);
98-
return true;
98+
return { deleted: true };
9999
}
100100

101101
if (session.cookie) {
@@ -110,12 +110,15 @@ export const deleteServerSession = async (
110110
await legacyClient.call("DELETE", "/account/sessions/current", {
111111
"content-type": "application/json",
112112
});
113-
return true;
113+
return { deleted: true };
114114
}
115115

116-
return false;
117-
} catch (_e) {
118-
return false;
116+
return { deleted: false };
117+
} catch (e) {
118+
return {
119+
deleted: false,
120+
error: e instanceof Error ? e.message : String(e),
121+
};
119122
}
120123
};
121124

@@ -126,9 +129,10 @@ export const deleteServerSession = async (
126129
*/
127130
export const logoutSessions = async (
128131
sessionIds: string[],
129-
): Promise<{ failed: number; failedIds: string[] }> => {
132+
): Promise<{ failed: number; failedIds: string[]; errors: string[] }> => {
130133
let failed = 0;
131134
const failedIds: string[] = [];
135+
const errors: string[] = [];
132136

133137
for (const sessionId of sessionIds) {
134138
if (isLocalOnlySession(sessionId)) {
@@ -137,16 +141,19 @@ export const logoutSessions = async (
137141
}
138142

139143
globalConfig.setCurrentSession(sessionId);
140-
const serverDeleted = await deleteServerSession(sessionId);
141-
if (serverDeleted) {
144+
const result = await deleteServerSession(sessionId);
145+
if (result.deleted) {
142146
globalConfig.removeSession(sessionId);
143147
} else {
144148
failed++;
145149
failedIds.push(sessionId);
150+
if (result.error) {
151+
errors.push(result.error);
152+
}
146153
}
147154
}
148155

149-
return { failed, failedIds };
156+
return { failed, failedIds, errors };
150157
};
151158

152159
export const removeLegacySessionsExcept = async (
@@ -160,8 +167,8 @@ export const removeLegacySessionsExcept = async (
160167
continue;
161168
}
162169

163-
const serverDeleted = await deleteServerSession(sessionId);
164-
if (serverDeleted) {
170+
const result = await deleteServerSession(sessionId);
171+
if (result.deleted) {
165172
globalConfig.removeSession(sessionId);
166173
removed++;
167174
} else {

lib/commands/generic.ts

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
commandDescriptions,
1111
error,
1212
parse,
13-
hint,
1413
log,
1514
drawTable,
1615
cliConfig,
@@ -27,6 +26,17 @@ import {
2726

2827
export { loginCommand };
2928

29+
const logMessages = {
30+
noActiveSessions: "No active sessions found.",
31+
logoutFailure: (errors: string[] = []): string => {
32+
const uniqueErrors = [...new Set(errors)];
33+
const details = uniqueErrors.length ? `: ${uniqueErrors.join("; ")}` : "";
34+
return `Could not log out because the server session could not be revoked${details}. Kept local session data.`;
35+
},
36+
logoutSuccess: "Logged out successfully",
37+
clientConfigUpdated: "Client configuration updated",
38+
} as const;
39+
3040
export const whoami = new Command("whoami")
3141
.description(commandDescriptions["whoami"])
3242
.action(
@@ -101,38 +111,37 @@ export const logout = new Command("logout")
101111
const originalCurrent = current;
102112

103113
if (current === "" || !sessions.length) {
104-
log("No active sessions found.");
114+
log(logMessages.noActiveSessions);
105115
return;
106116
}
107117
if (sessions.length === 1) {
108-
const { failed, failedIds } = await logoutSessions(
118+
const { failed, failedIds, errors } = await logoutSessions(
109119
planSessionLogout([current]),
110120
);
111121

112122
if (failed > 0) {
113123
restoreCurrentSessionFallback(originalCurrent, failedIds);
114-
hint(
115-
"Could not reach server for all sessions; kept local session data",
116-
);
124+
error(logMessages.logoutFailure(errors));
125+
return;
117126
} else {
118127
globalConfig.setCurrentSession("");
119128
}
120-
success("Logged out successfully");
129+
success(logMessages.logoutSuccess);
121130

122131
return;
123132
}
124133

125134
const answers = await inquirer.prompt(questionsLogout);
135+
let logoutFailed = false;
126136

127137
if (answers.accounts?.length) {
128-
const { failed } = await logoutSessions(
138+
const { failed, errors } = await logoutSessions(
129139
planSessionLogout(answers.accounts as string[]),
130140
);
131141

132142
if (failed > 0) {
133-
hint(
134-
"Could not reach server for all sessions; kept local session data",
135-
);
143+
logoutFailed = true;
144+
error(logMessages.logoutFailure(errors));
136145
}
137146
}
138147

@@ -149,16 +158,20 @@ export const logout = new Command("logout")
149158
remainingSessions[0];
150159
globalConfig.setCurrentSession(nextSession.id);
151160

152-
success(
153-
nextSession.email
154-
? `Switched to ${nextSession.email}`
155-
: `Switched to session at ${nextSession.endpoint}`,
156-
);
161+
if (!logoutFailed) {
162+
success(
163+
nextSession.email
164+
? `Switched to ${nextSession.email}`
165+
: `Switched to session at ${nextSession.endpoint}`,
166+
);
167+
}
157168
} else if (remainingSessions.length === 0) {
158169
globalConfig.setCurrentSession("");
159170
}
160171

161-
success("Logged out successfully");
172+
if (!logoutFailed) {
173+
success(logMessages.logoutSuccess);
174+
}
162175
}),
163176
);
164177

@@ -288,22 +301,21 @@ export const client = new Command("client")
288301

289302
if (reset !== undefined) {
290303
const originalCurrent = globalConfig.getCurrentSession();
291-
const { failed, failedIds } = await logoutSessions(
304+
const { failed, failedIds, errors } = await logoutSessions(
292305
globalConfig.getSessionIds(),
293306
);
294307

295308
if (failed > 0) {
296309
restoreCurrentSessionFallback(originalCurrent, failedIds);
297-
hint(
298-
"Could not reach server for all sessions; kept local session data",
299-
);
310+
error(logMessages.logoutFailure(errors));
311+
return;
300312
} else {
301313
globalConfig.setCurrentSession("");
302314
}
303315
}
304316

305317
if (!debug) {
306-
success("Setting client");
318+
success(logMessages.clientConfigUpdated);
307319
}
308320
},
309321
),

lib/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SDK
22
export const SDK_TITLE = 'Appwrite';
33
export const SDK_TITLE_LOWER = 'appwrite';
4-
export const SDK_VERSION = '22.1.1';
4+
export const SDK_VERSION = '22.1.2';
55
export const SDK_NAME = 'Command Line';
66
export const SDK_PLATFORM = 'console';
77
export const SDK_LANGUAGE = 'cli';
@@ -29,7 +29,7 @@ export const DEFAULT_ENDPOINT = 'https://cloud.appwrite.io/v1';
2929

3030
// OAuth2
3131
export const OAUTH2_CLIENT_ID = "appwrite-cli";
32-
export const OAUTH2_SCOPES = "openid email profile";
32+
export const OAUTH2_SCOPES = "openid email profile account.admin";
3333

3434
// Config resources
3535
export const CONFIG_RESOURCE_KEYS = [

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "module",
44
"homepage": "https://appwrite.io/support",
55
"description": "Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API",
6-
"version": "22.1.1",
6+
"version": "22.1.2",
77
"license": "BSD-3-Clause",
88
"main": "dist/index.cjs",
99
"module": "dist/index.js",

scoop/appwrite.config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/schema.json",
3-
"version": "22.1.1",
3+
"version": "22.1.2",
44
"description": "The Appwrite CLI is a command-line application that allows you to interact with Appwrite and perform server-side tasks using your terminal.",
55
"homepage": "https://github.com/appwrite/sdk-for-cli",
66
"license": "BSD-3-Clause",
77
"architecture": {
88
"64bit": {
9-
"url": "https://github.com/appwrite/sdk-for-cli/releases/download/22.1.1/appwrite-cli-win-x64.exe",
9+
"url": "https://github.com/appwrite/sdk-for-cli/releases/download/22.1.2/appwrite-cli-win-x64.exe",
1010
"bin": [
1111
[
1212
"appwrite-cli-win-x64.exe",
@@ -15,7 +15,7 @@
1515
]
1616
},
1717
"arm64": {
18-
"url": "https://github.com/appwrite/sdk-for-cli/releases/download/22.1.1/appwrite-cli-win-arm64.exe",
18+
"url": "https://github.com/appwrite/sdk-for-cli/releases/download/22.1.2/appwrite-cli-win-arm64.exe",
1919
"bin": [
2020
[
2121
"appwrite-cli-win-arm64.exe",

0 commit comments

Comments
 (0)