Skip to content

Commit 7af9954

Browse files
committed
fix: remove content-type from GET requests
1 parent d6f2f30 commit 7af9954

12 files changed

+28
-50
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Appwrite Web SDK
22

33
![License](https://img.shields.io/github/license/appwrite/sdk-for-web.svg?style=flat-square)
4-
![Version](https://img.shields.io/badge/api%20version-1.6.1-blue.svg?style=flat-square)
4+
![Version](https://img.shields.io/badge/api%20version-1.6.2-blue.svg?style=flat-square)
55
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
66
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
77
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
@@ -33,7 +33,7 @@ import { Client, Account } from "appwrite";
3333
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:
3434

3535
```html
36-
<script src="https://cdn.jsdelivr.net/npm/[email protected].1"></script>
36+
<script src="https://cdn.jsdelivr.net/npm/[email protected].2"></script>
3737
```
3838

3939

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "appwrite",
33
"homepage": "https://appwrite.io/support",
44
"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",
5-
"version": "17.0.1",
5+
"version": "17.0.2",
66
"license": "BSD-3-Clause",
77
"main": "dist/cjs/sdk.js",
88
"exports": {

src/client.ts

+22-8
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ class Client {
315315
'x-sdk-name': 'Web',
316316
'x-sdk-platform': 'client',
317317
'x-sdk-language': 'web',
318-
'x-sdk-version': '17.0.1',
318+
'x-sdk-version': '17.0.2',
319319
'X-Appwrite-Response-Format': '1.6.0',
320320
};
321321

@@ -329,8 +329,12 @@ class Client {
329329
* @returns {this}
330330
*/
331331
setEndpoint(endpoint: string): this {
332+
if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
333+
throw new AppwriteException('Invalid endpoint URL: ' + endpoint);
334+
}
335+
332336
this.config.endpoint = endpoint;
333-
this.config.endpointRealtime = this.config.endpointRealtime || this.config.endpoint.replace('https://', 'wss://').replace('http://', 'ws://');
337+
this.config.endpointRealtime = endpoint.replace('https://', 'wss://').replace('http://', 'ws://');
334338

335339
return this;
336340
}
@@ -343,8 +347,11 @@ class Client {
343347
* @returns {this}
344348
*/
345349
setEndpointRealtime(endpointRealtime: string): this {
346-
this.config.endpointRealtime = endpointRealtime;
350+
if (!endpointRealtime.startsWith('ws://') && !endpointRealtime.startsWith('wss://')) {
351+
throw new AppwriteException('Invalid realtime endpoint URL: ' + endpointRealtime);
352+
}
347353

354+
this.config.endpointRealtime = endpointRealtime;
348355
return this;
349356
}
350357

@@ -656,6 +663,10 @@ class Client {
656663
async chunkedUpload(method: string, url: URL, headers: Headers = {}, originalPayload: Payload = {}, onProgress: (progress: UploadProgress) => void) {
657664
const file = Object.values(originalPayload).find((value) => value instanceof File);
658665

666+
if (!file) {
667+
throw new Error('File not found in payload');
668+
}
669+
659670
if (file.size <= Client.CHUNK_SIZE) {
660671
return await this.call(method, url, headers, originalPayload);
661672
}
@@ -704,7 +715,6 @@ class Client {
704715
const { uri, options } = this.prepareRequest(method, url, headers, params);
705716

706717
let data: any = null;
707-
let text: string = '';
708718

709719
const response = await fetch(uri, options);
710720

@@ -715,18 +725,22 @@ class Client {
715725

716726
if (response.headers.get('content-type')?.includes('application/json')) {
717727
data = await response.json();
718-
text = JSON.stringify(data);
719728
} else if (responseType === 'arrayBuffer') {
720729
data = await response.arrayBuffer();
721730
} else {
722-
text = await response.text();
723731
data = {
724-
message: text
732+
message: await response.text()
725733
};
726734
}
727735

728736
if (400 <= response.status) {
729-
throw new AppwriteException(data?.message, response.status, data?.type, text);
737+
let responseText = '';
738+
if (response.headers.get('content-type')?.includes('application/json') || responseType === 'arrayBuffer') {
739+
responseText = JSON.stringify(data);
740+
} else {
741+
responseText = data?.message;
742+
}
743+
throw new AppwriteException(data?.message, response.status, data?.type, responseText);
730744
}
731745

732746
const cookieFallback = response.headers.get('X-Fallback-Cookies');

src/enums/credit-card.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ export enum CreditCard {
1515
Visa = 'visa',
1616
MIR = 'mir',
1717
Maestro = 'maestro',
18+
Rupay = 'rupay',
1819
}

src/enums/o-auth-provider.ts

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export enum OAuthProvider {
1313
Dropbox = 'dropbox',
1414
Etsy = 'etsy',
1515
Facebook = 'facebook',
16+
Figma = 'figma',
1617
Github = 'github',
1718
Gitlab = 'gitlab',
1819
Google = 'google',

src/services/account.ts

-10
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export class Account {
2424
const uri = new URL(this.client.config.endpoint + apiPath);
2525

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

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

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

141139
return this.client.call(
@@ -209,7 +207,6 @@ This endpoint can also be used to convert an anonymous account to a normal one,
209207
const uri = new URL(this.client.config.endpoint + apiPath);
210208

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

215212
return this.client.call(
@@ -410,7 +407,6 @@ This endpoint can also be used to convert an anonymous account to a normal one,
410407
const uri = new URL(this.client.config.endpoint + apiPath);
411408

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

416412
return this.client.call(
@@ -432,7 +428,6 @@ This endpoint can also be used to convert an anonymous account to a normal one,
432428
const uri = new URL(this.client.config.endpoint + apiPath);
433429

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

438433
return this.client.call(
@@ -596,7 +591,6 @@ This endpoint can also be used to convert an anonymous account to a normal one,
596591
const uri = new URL(this.client.config.endpoint + apiPath);
597592

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

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

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

734727
return this.client.call(
@@ -889,7 +882,6 @@ A user is limited to 10 active sessions at a time by default. [Learn more about
889882
const uri = new URL(this.client.config.endpoint + apiPath);
890883

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

895887
payload['project'] = this.client.config.project;
@@ -993,7 +985,6 @@ A user is limited to 10 active sessions at a time by default. [Learn more about
993985
const uri = new URL(this.client.config.endpoint + apiPath);
994986

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

999990
return this.client.call(
@@ -1297,7 +1288,6 @@ A user is limited to 10 active sessions at a time by default. [Learn more about
12971288
const uri = new URL(this.client.config.endpoint + apiPath);
12981289

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

13031293
payload['project'] = this.client.config.project;

src/services/avatars.ts

-7
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ When one dimension is specified and the other is 0, the image is scaled with pre
4242
const uri = new URL(this.client.config.endpoint + apiPath);
4343

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

4847
payload['project'] = this.client.config.project;
@@ -84,7 +83,6 @@ When one dimension is specified and the other is 0, the image is scaled with pre
8483
const uri = new URL(this.client.config.endpoint + apiPath);
8584

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

9088
payload['project'] = this.client.config.project;
@@ -116,7 +114,6 @@ This endpoint does not follow HTTP redirects.
116114
const uri = new URL(this.client.config.endpoint + apiPath);
117115

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

122119
payload['project'] = this.client.config.project;
@@ -158,7 +155,6 @@ When one dimension is specified and the other is 0, the image is scaled with pre
158155
const uri = new URL(this.client.config.endpoint + apiPath);
159156

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

164160
payload['project'] = this.client.config.project;
@@ -200,7 +196,6 @@ This endpoint does not follow HTTP redirects.
200196
const uri = new URL(this.client.config.endpoint + apiPath);
201197

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

206201
payload['project'] = this.client.config.project;
@@ -244,7 +239,6 @@ When one dimension is specified and the other is 0, the image is scaled with pre
244239
const uri = new URL(this.client.config.endpoint + apiPath);
245240

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

250244
payload['project'] = this.client.config.project;
@@ -287,7 +281,6 @@ When one dimension is specified and the other is 0, the image is scaled with pre
287281
const uri = new URL(this.client.config.endpoint + apiPath);
288282

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

293286
payload['project'] = this.client.config.project;

src/services/databases.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export class Databases {
3333
const uri = new URL(this.client.config.endpoint + apiPath);
3434

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

3938
return this.client.call(
@@ -45,6 +44,7 @@ export class Databases {
4544
}
4645
/**
4746
* Create a new Document. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console.
47+
4848
*
4949
* @param {string} databaseId
5050
* @param {string} collectionId
@@ -119,7 +119,6 @@ export class Databases {
119119
const uri = new URL(this.client.config.endpoint + apiPath);
120120

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

125124
return this.client.call(

src/services/functions.ts

-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export class Functions {
3434
const uri = new URL(this.client.config.endpoint + apiPath);
3535

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

4039
return this.client.call(
@@ -114,7 +113,6 @@ export class Functions {
114113
const uri = new URL(this.client.config.endpoint + apiPath);
115114

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

120118
return this.client.call(

src/services/locale.ts

-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export class Locale {
2323
const uri = new URL(this.client.config.endpoint + apiPath);
2424

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

2928
return this.client.call(
@@ -45,7 +44,6 @@ export class Locale {
4544
const uri = new URL(this.client.config.endpoint + apiPath);
4645

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

5149
return this.client.call(
@@ -67,7 +65,6 @@ export class Locale {
6765
const uri = new URL(this.client.config.endpoint + apiPath);
6866

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

7370
return this.client.call(
@@ -89,7 +86,6 @@ export class Locale {
8986
const uri = new URL(this.client.config.endpoint + apiPath);
9087

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

9591
return this.client.call(
@@ -111,7 +107,6 @@ export class Locale {
111107
const uri = new URL(this.client.config.endpoint + apiPath);
112108

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

117112
return this.client.call(
@@ -133,7 +128,6 @@ export class Locale {
133128
const uri = new URL(this.client.config.endpoint + apiPath);
134129

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

139133
return this.client.call(
@@ -155,7 +149,6 @@ export class Locale {
155149
const uri = new URL(this.client.config.endpoint + apiPath);
156150

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

161154
return this.client.call(
@@ -177,7 +170,6 @@ export class Locale {
177170
const uri = new URL(this.client.config.endpoint + apiPath);
178171

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

183175
return this.client.call(

0 commit comments

Comments
 (0)