Skip to content

fix: remove content-type from GET requests #108

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

Merged
merged 2 commits into from
Apr 17, 2025
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Appwrite Node.js SDK

![License](https://img.shields.io/github/license/appwrite/sdk-for-node.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.6.1-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.6.2-blue.svg?style=flat-square)
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/databases/update-float-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const result = await databases.updateFloatAttribute(
'<COLLECTION_ID>', // collectionId
'', // key
false, // required
null, // min
null, // max
null, // default
null, // min (optional)
null, // max (optional)
'' // newKey (optional)
);
4 changes: 2 additions & 2 deletions docs/examples/databases/update-integer-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const result = await databases.updateIntegerAttribute(
'<COLLECTION_ID>', // collectionId
'', // key
false, // required
null, // min
null, // max
null, // default
null, // min (optional)
null, // max (optional)
'' // newKey (optional)
);
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ const client = new sdk.Client()

const health = new sdk.Health(client);

const result = await health.getQueueUsageDump(
const result = await health.getQueueStatsResources(
null // threshold (optional)
);
10 changes: 0 additions & 10 deletions docs/examples/health/get-queue.md

This file was deleted.

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": "node-appwrite",
"homepage": "https://appwrite.io/support",
"description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API",
"version": "15.0.1",
"version": "16.0.0",
"license": "BSD-3-Clause",
"main": "dist/index.js",
"type": "commonjs",
Expand Down
26 changes: 18 additions & 8 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AppwriteException extends Error {
}

function getUserAgent() {
let ua = 'AppwriteNodeJSSDK/15.0.1';
let ua = 'AppwriteNodeJSSDK/16.0.0';

// `process` is a global in Node.js, but not fully available in all runtimes.
const platform: string[] = [];
Expand Down Expand Up @@ -82,7 +82,7 @@ class Client {
'x-sdk-name': 'Node.js',
'x-sdk-platform': 'server',
'x-sdk-language': 'nodejs',
'x-sdk-version': '15.0.1',
'x-sdk-version': '16.0.0',
'user-agent' : getUserAgent(),
'X-Appwrite-Response-Format': '1.6.0',
};
Expand All @@ -97,8 +97,11 @@ class Client {
* @returns {this}
*/
setEndpoint(endpoint: string): this {
this.config.endpoint = endpoint;
if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
throw new AppwriteException('Invalid endpoint URL: ' + endpoint);
}

this.config.endpoint = endpoint;
return this;
}

Expand Down Expand Up @@ -265,6 +268,10 @@ class Client {
async chunkedUpload(method: string, url: URL, headers: Headers = {}, originalPayload: Payload = {}, onProgress: (progress: UploadProgress) => void) {
const file = Object.values(originalPayload).find((value) => value instanceof File);

if (!file) {
throw new Error('File not found in payload');
}

if (file.size <= Client.CHUNK_SIZE) {
return await this.call(method, url, headers, originalPayload);
}
Expand Down Expand Up @@ -328,7 +335,6 @@ class Client {
const { uri, options } = this.prepareRequest(method, url, headers, params);

let data: any = null;
let text: string = '';

const response = await fetch(uri, options);

Expand All @@ -339,18 +345,22 @@ class Client {

if (response.headers.get('content-type')?.includes('application/json')) {
data = await response.json();
text = JSON.stringify(data);
} else if (responseType === 'arrayBuffer') {
data = await response.arrayBuffer();
} else {
text = await response.text();
data = {
message: text
message: await response.text()
};
}

if (400 <= response.status) {
throw new AppwriteException(data?.message, response.status, data?.type, text);
let responseText = '';
if (response.headers.get('content-type')?.includes('application/json') || responseType === 'arrayBuffer') {
responseText = JSON.stringify(data);
} else {
responseText = data?.message;
}
throw new AppwriteException(data?.message, response.status, data?.type, responseText);
}

return data;
Expand Down
1 change: 1 addition & 0 deletions src/enums/credit-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export enum CreditCard {
Visa = 'visa',
MIR = 'mir',
Maestro = 'maestro',
Rupay = 'rupay',
}
4 changes: 2 additions & 2 deletions src/enums/name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export enum Name {
V1audits = 'v1-audits',
V1mails = 'v1-mails',
V1functions = 'v1-functions',
V1usage = 'v1-usage',
V1usagedump = 'v1-usage-dump',
V1statsresources = 'v1-stats-resources',
V1statsusage = 'v1-stats-usage',
V1webhooks = 'v1-webhooks',
V1certificates = 'v1-certificates',
V1builds = 'v1-builds',
Expand Down
1 change: 1 addition & 0 deletions src/enums/o-auth-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export enum OAuthProvider {
Dropbox = 'dropbox',
Etsy = 'etsy',
Facebook = 'facebook',
Figma = 'figma',
Github = 'github',
Gitlab = 'gitlab',
Google = 'google',
Expand Down
9 changes: 0 additions & 9 deletions src/services/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export class Account {
const uri = new URL(this.client.config.endpoint + apiPath);

const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}

return this.client.call(
Expand Down Expand Up @@ -134,7 +133,6 @@ This endpoint can also be used to convert an anonymous account to a normal one,
const uri = new URL(this.client.config.endpoint + apiPath);

const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}

return this.client.call(
Expand Down Expand Up @@ -208,7 +206,6 @@ This endpoint can also be used to convert an anonymous account to a normal one,
const uri = new URL(this.client.config.endpoint + apiPath);

const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}

return this.client.call(
Expand Down Expand Up @@ -409,7 +406,6 @@ This endpoint can also be used to convert an anonymous account to a normal one,
const uri = new URL(this.client.config.endpoint + apiPath);

const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}

return this.client.call(
Expand All @@ -431,7 +427,6 @@ This endpoint can also be used to convert an anonymous account to a normal one,
const uri = new URL(this.client.config.endpoint + apiPath);

const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}

return this.client.call(
Expand Down Expand Up @@ -595,7 +590,6 @@ This endpoint can also be used to convert an anonymous account to a normal one,
const uri = new URL(this.client.config.endpoint + apiPath);

const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}

return this.client.call(
Expand Down Expand Up @@ -727,7 +721,6 @@ Please note that in order to avoid a [Redirect Attack](https://github.com/OWASP/
const uri = new URL(this.client.config.endpoint + apiPath);

const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}

return this.client.call(
Expand Down Expand Up @@ -943,7 +936,6 @@ A user is limited to 10 active sessions at a time by default. [Learn more about
const uri = new URL(this.client.config.endpoint + apiPath);

const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}

return this.client.call(
Expand Down Expand Up @@ -1148,7 +1140,6 @@ A user is limited to 10 active sessions at a time by default. [Learn more about
const uri = new URL(this.client.config.endpoint + apiPath);

const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}

return this.client.redirect(
Expand Down
7 changes: 0 additions & 7 deletions src/services/avatars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ When one dimension is specified and the other is 0, the image is scaled with pre
const uri = new URL(this.client.config.endpoint + apiPath);

const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}

return this.client.call(
Expand Down Expand Up @@ -83,7 +82,6 @@ When one dimension is specified and the other is 0, the image is scaled with pre
const uri = new URL(this.client.config.endpoint + apiPath);

const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}

return this.client.call(
Expand Down Expand Up @@ -115,7 +113,6 @@ This endpoint does not follow HTTP redirects.
const uri = new URL(this.client.config.endpoint + apiPath);

const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}

return this.client.call(
Expand Down Expand Up @@ -157,7 +154,6 @@ When one dimension is specified and the other is 0, the image is scaled with pre
const uri = new URL(this.client.config.endpoint + apiPath);

const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}

return this.client.call(
Expand Down Expand Up @@ -199,7 +195,6 @@ This endpoint does not follow HTTP redirects.
const uri = new URL(this.client.config.endpoint + apiPath);

const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}

return this.client.call(
Expand Down Expand Up @@ -243,7 +238,6 @@ When one dimension is specified and the other is 0, the image is scaled with pre
const uri = new URL(this.client.config.endpoint + apiPath);

const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}

return this.client.call(
Expand Down Expand Up @@ -286,7 +280,6 @@ When one dimension is specified and the other is 0, the image is scaled with pre
const uri = new URL(this.client.config.endpoint + apiPath);

const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}

return this.client.call(
Expand Down
Loading