Skip to content

Commit 821bc8d

Browse files
authored
Merge pull request #337 from appwrite/dev
feat: SDK update for version 22.6.0
2 parents 048ffff + f232e97 commit 821bc8d

13 files changed

Lines changed: 368 additions & 190 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.6.0
4+
5+
* Added: `push functions` and `pull` now work with API key authentication, enabling CI usage without a console session
6+
* Updated: Console-only steps during push, like default domain rules, are skipped with a warning when using an API key
7+
* Updated: Clearer authentication errors that distinguish API key and console session requirements
8+
39
## 22.5.0
410

511
* Updated: `tablesdb create` now takes `--specification` instead of `--dedicated-database-id`

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.5.0
32+
22.6.0
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.5.0
86+
22.6.0
8787
```
8888

8989
## Getting Started

bun.lock

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

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.5.0/appwrite-cli-win-x64.exe"
17-
$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/22.5.0/appwrite-cli-win-arm64.exe"
16+
$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/22.6.0/appwrite-cli-win-x64.exe"
17+
$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/22.6.0/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.5.0"
123+
GITHUB_LATEST_VERSION="22.6.0"
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/capabilities.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { EXECUTABLE_NAME } from "../constants.js";
2+
import { globalConfig } from "../config.js";
3+
import { AppwriteException } from "@appwrite.io/console";
4+
import { hasAuthSession } from "./session.js";
5+
6+
export type AuthMode = "session" | "apiKey" | "none";
7+
8+
export const hasApiKey = (): boolean => globalConfig.getKey() !== "";
9+
10+
export const getAuthMode = (): AuthMode => {
11+
if (hasAuthSession()) {
12+
return "session";
13+
}
14+
15+
if (hasApiKey()) {
16+
return "apiKey";
17+
}
18+
19+
return "none";
20+
};
21+
22+
export const canUseConsole = (): boolean => hasAuthSession();
23+
24+
export const requireProjectAuth = (): void => {
25+
if (getAuthMode() !== "none") {
26+
return;
27+
}
28+
29+
throw new Error(
30+
`Authentication not found. Run \`${EXECUTABLE_NAME} login\` or \`${EXECUTABLE_NAME} client --key <API_KEY>\`.`,
31+
);
32+
};
33+
34+
export const requireConsoleAuth = (action: string): void => {
35+
if (canUseConsole()) {
36+
return;
37+
}
38+
39+
if (hasApiKey()) {
40+
throw new Error(
41+
`${action} requires a console session. API keys work for project commands (e.g. \`${EXECUTABLE_NAME} push functions\`), not console-only commands. Run \`${EXECUTABLE_NAME} login\`.`,
42+
);
43+
}
44+
45+
throw new Error(
46+
`${action} requires a console session. Run \`${EXECUTABLE_NAME} login\`.`,
47+
);
48+
};
49+
50+
/**
51+
* True only for missing-scope / missing-session failures that optional
52+
* console side-effects (e.g. default domain rules) should soft-fail on.
53+
* Intentionally narrow: do not treat generic "unauthorized" text or all
54+
* HTTP 403s as scope errors, so real authorization failures still surface.
55+
*/
56+
export const isAuthScopeError = (error: unknown): boolean => {
57+
if (!(error instanceof Error)) {
58+
return false;
59+
}
60+
61+
const message = error.message.toLowerCase();
62+
const isScopeMessage =
63+
message.includes("missing scope") ||
64+
message.includes("missing scopes") ||
65+
message.includes("session not found") ||
66+
message.includes("console session required");
67+
68+
if (error instanceof AppwriteException) {
69+
return (
70+
isScopeMessage ||
71+
String(error.type ?? "").toLowerCase() === "general_unauthorized_scope"
72+
);
73+
}
74+
75+
return isScopeMessage;
76+
};

lib/commands/pull.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ import { getFunctionsService, getSitesService } from "../services.js";
2222
import { sdkForProject, sdkForConsole } from "../sdks.js";
2323
import { localConfig } from "../config.js";
2424
import { applyConfigFilters } from "../config-filters.js";
25+
import {
26+
canUseConsole,
27+
requireConsoleAuth,
28+
requireProjectAuth,
29+
} from "../auth/capabilities.js";
2530
import { paginate } from "../paginate.js";
2631
import {
2732
questionsPullFunctions,
@@ -100,14 +105,16 @@ export interface PullSettingsResult {
100105
async function createPullInstance(
101106
options: {
102107
silent?: boolean;
103-
requiresConsoleAuth?: boolean;
104108
resource?: "functions" | "sites";
105109
} = {},
106110
): Promise<Pull> {
107-
const { silent = false, requiresConsoleAuth = false, resource } = options;
111+
const { silent = false, resource } = options;
112+
requireProjectAuth();
108113
const projectClient = await sdkForProject();
114+
// Console credentials are attached when present. Console-required ops
115+
// call requireConsoleAuth() themselves instead of gating the whole pull.
109116
const consoleClient = await sdkForConsole({
110-
requiresAuth: requiresConsoleAuth,
117+
requiresAuth: canUseConsole(),
111118
});
112119

113120
const pullInstance = new Pull(projectClient, consoleClient, silent);
@@ -851,9 +858,8 @@ export const pullResources = async ({
851858
};
852859

853860
const pullSettings = async (): Promise<void> => {
854-
const pullInstance = await createPullInstance({
855-
requiresConsoleAuth: true,
856-
});
861+
requireConsoleAuth("Pulling project settings");
862+
const pullInstance = await createPullInstance();
857863
const project = localConfig.getProject();
858864
const projectId = project.projectId;
859865
const settings = await pullInstance.pullSettings(

0 commit comments

Comments
 (0)