Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 2.1.0

* Add `setSelfSigned` and `setCookie` methods to `Client` class

## 2.0.0

* Update SDK examples to use object-based parameters instead of positional arguments
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { Client, Account } from "@appwrite.io/console";
To install with a CDN (content delivery network) add the following scripts to the bottom of your <body> tag, but before you use any Appwrite services:

```html
<script src="https://cdn.jsdelivr.net/npm/@appwrite.io/console@2.0.0"></script>
<script src="https://cdn.jsdelivr.net/npm/@appwrite.io/console@2.1.0"></script>
```


Expand Down
2 changes: 1 addition & 1 deletion docs/examples/account/update-payment-method.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const account = new Account(client);
const result = await account.updatePaymentMethod({
paymentMethodId: '<PAYMENT_METHOD_ID>',
expiryMonth: 1,
expiryYear: 2025,
expiryYear: 2026,
state: '<STATE>' // optional
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@appwrite.io/console",
"homepage": "https://appwrite.io/support",
"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",
"version": "2.0.0",
"version": "2.1.0",
"license": "BSD-3-Clause",
"main": "dist/cjs/sdk.js",
"exports": {
Expand Down
33 changes: 31 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,18 @@ class Client {
config: {
endpoint: string;
endpointRealtime: string;
[key: string]: string | undefined;
selfSigned: boolean;
[key: string]: string | boolean | undefined;
} = {
endpoint: 'https://cloud.appwrite.io/v1',
endpointRealtime: '',
selfSigned: false,
Comment on lines +306 to +311
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

rg -n --type=ts -C3 'selfSigned' -g '!CHANGELOG.md'

Repository: appwrite/sdk-for-console

Length of output: 1061


🏁 Script executed:

rg -n --type=ts 'config\.selfSigned|this\.config\.selfSigned' -C2

Repository: appwrite/sdk-for-console

Length of output: 284


🏁 Script executed:

rg -n --type=ts 'prepareRequest|call\(' src/client.ts | head -20

Repository: appwrite/sdk-for-console

Length of output: 651


🏁 Script executed:

sed -n '200,450p' src/client.ts | grep -n -A 30 'prepareRequest'

Repository: appwrite/sdk-for-console

Length of output: 50


🏁 Script executed:

sed -n '688,750p' src/client.ts

Repository: appwrite/sdk-for-console

Length of output: 2434


🏁 Script executed:

sed -n '795,850p' src/client.ts

Repository: appwrite/sdk-for-console

Length of output: 2320


Remove unused selfSigned configuration or implement its functionality.

The selfSigned config property is declared and has a setter method, but it is never actually read or used anywhere in the codebase. The prepareRequest and call methods do not reference it, so calling setSelfSigned() has no effect.

If this is intended for Node.js environments using custom HTTPS agents, the implementation is incomplete. If not needed, remove the property, the setter, and the initialization to eliminate dead code.

project: '',
key: '',
jwt: '',
locale: '',
mode: '',
cookie: '',
platform: '',
};
/**
Expand All @@ -321,7 +324,7 @@ class Client {
'x-sdk-name': 'Console',
'x-sdk-platform': 'console',
'x-sdk-language': 'web',
'x-sdk-version': '2.0.0',
'x-sdk-version': '2.1.0',
'X-Appwrite-Response-Format': '1.8.0',
};

Expand Down Expand Up @@ -369,6 +372,18 @@ class Client {
return this;
}

/**
* Set self-signed
*
* @param {boolean} selfSigned
*
* @returns {this}
*/
setSelfSigned(selfSigned: boolean): this {
this.config.selfSigned = selfSigned;
return this;
}

/**
* Set Project
*
Expand Down Expand Up @@ -435,6 +450,20 @@ class Client {
this.config.mode = value;
return this;
}
/**
* Set Cookie
*
* The user cookie to authenticate with
*
* @param value string
*
* @return {this}
*/
setCookie(value: string): this {
this.headers['Cookie'] = value;
this.config.cookie = value;
return this;
}
Comment on lines +453 to +466
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, let's look at the setCookie method and surrounding context in src/client.ts
cat -n src/client.ts | sed -n '440,480p'

Repository: appwrite/sdk-for-console

Length of output: 1198


🏁 Script executed:

# Check file size to understand if we can read more context
wc -l src/client.ts

Repository: appwrite/sdk-for-console

Length of output: 85


🏁 Script executed:

# Search for environment detection or browser-specific code
rg -n "typeof window|process\.env|NODE_ENV|isBrowser|isNode" src/client.ts | head -20

Repository: appwrite/sdk-for-console

Length of output: 229


🏁 Script executed:

# Search for other cookie-related code or authentication patterns
rg -n -i "cookie|auth|credentials" src/client.ts | head -30

Repository: appwrite/sdk-for-console

Length of output: 1784


🏁 Script executed:

# Look for any documentation or comments about intended environments
rg -n "browser|server|node\.js|environment" src/client.ts | head -20

Repository: appwrite/sdk-for-console

Length of output: 126


🌐 Web query:

Can JavaScript set the Cookie HTTP header in browser fetch API

💡 Result:

Short answer: No — browsers forbid JavaScript from setting a request "Cookie" HTTP header in fetch. The Fetch spec and browser implementations treat "Cookie" (and "Set‑Cookie" on responses) as forbidden; the browser controls sending cookies. [1][2]

What to use instead:

  • To send existing cookies with fetch to the request origin (or cross‑origin when allowed), set fetch(..., { credentials: 'same-origin' | 'include' }). [2]
  • To create/modify cookies from page script for same‑origin (non‑HttpOnly) cookies, use document.cookie. HttpOnly cookies must be set by the server via Set‑Cookie. [1][2]

Sources:

  • MDN: Headers / Set-Cookie / forbidden header behavior. [1]
  • Explanation & examples (including credentials) on Stack Overflow. [2]

🏁 Script executed:

# Search for setCookie usage throughout the codebase
rg -n "setCookie" --type ts --type js

Repository: appwrite/sdk-for-console

Length of output: 122


🏁 Script executed:

# Check how config.cookie is used, especially in request execution
rg -n "config\.cookie|this\.config\.cookie" src/client.ts -A 2 -B 2

Repository: appwrite/sdk-for-console

Length of output: 227


🏁 Script executed:

# Look at the request execution logic to see how headers are processed
cat -n src/client.ts | sed -n '700,750p'

Repository: appwrite/sdk-for-console

Length of output: 2286


🏁 Script executed:

# Search for any comments or documentation about server vs browser usage
rg -n "server|node|browser|environment" src/ -B 2 -A 2 | head -40

Repository: appwrite/sdk-for-console

Length of output: 4317


🏁 Script executed:

# Let's check if config.cookie is actually used anywhere in the request building or execution
rg -n "config\.cookie" src/ -B 2 -A 2

Repository: appwrite/sdk-for-console

Length of output: 297


🏁 Script executed:

# Check the headers object usage in the actual request
cat -n src/client.ts | sed -n '670,710p'

Repository: appwrite/sdk-for-console

Length of output: 1737


🏁 Script executed:

# Look for README or documentation that explains browser vs server usage
find . -maxdepth 2 -type f \( -name "README*" -o -name "*.md" \) | head -10

Repository: appwrite/sdk-for-console

Length of output: 94


🏁 Script executed:

# Check if there's any initialization or documentation in index.ts or main entry point
find . -maxdepth 2 -type f -name "index.ts" -o -name "package.json" | xargs ls -la

Repository: appwrite/sdk-for-console

Length of output: 195


🏁 Script executed:

# Check package.json for project purpose and target environments
cat package.json

Repository: appwrite/sdk-for-console

Length of output: 1203


🏁 Script executed:

# Check README for documentation about usage
head -100 README.md

Repository: appwrite/sdk-for-console

Length of output: 3890


🏁 Script executed:

# Check how headers are passed to fetch, and if Cookie header is actually sent
cat -n src/client.ts | sed -n '755,800p'

Repository: appwrite/sdk-for-console

Length of output: 2007


🏁 Script executed:

# Search for any Node.js specific imports or features
rg -n "require|import.*node|globalThis|Buffer" src/client.ts | head -20

Repository: appwrite/sdk-for-console

Length of output: 345


🏁 Script executed:

# Let's confirm if config.cookie is ever used - search the entire codebase
rg -n "config\.cookie" --type ts --type js

Repository: appwrite/sdk-for-console

Length of output: 121


🏁 Script executed:

# Check the call method to see if headers are actually used in the fetch call
cat -n src/client.ts | sed -n '795,825p'

Repository: appwrite/sdk-for-console

Length of output: 1509


🏁 Script executed:

# Let's verify what gets passed to fetch as headers
cat -n src/client.ts | sed -n '688,708p'

Repository: appwrite/sdk-for-console

Length of output: 924


Document that setCookie is for server-side/Node.js usage only.

The setCookie method sets the Cookie HTTP header, which cannot be set by JavaScript in browser environments—it's a forbidden header name in the Fetch API. The browser handles cookies automatically via the credentials: 'include' option (already implemented at line 706), so this method won't function in browser contexts.

Since this SDK supports both browser and server-side usage, clarify either in documentation or with an environment check that setCookie is for Node.js usage only. Alternatively, consider removing the unused config.cookie property (line 464) if this method is deprecated.

🤖 Prompt for AI Agents
In src/client.ts around lines 453 to 466, document or enforce that setCookie is
for server-side/Node.js only because browsers forbid setting the Cookie header;
either (a) add a runtime environment check (e.g., detect window/fetch
environment) that throws or logs a clear error/warning when called in a browser
and preserve behavior for Node, or (b) mark the method with a JSDoc comment
indicating server-side only and remove the unused config.cookie property if you
choose to deprecate the method; implement one of these fixes and update
tests/docs accordingly.

/**
* Set Platform
*
Expand Down