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: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Appwrite Web SDK

![License](https://img.shields.io/github/license/appwrite/sdk-for-web.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 Expand Up @@ -33,7 +33,7 @@ import { Client, Account } from "appwrite";
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/[email protected].1"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].2"></script>
```


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",
"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": "17.0.1",
"version": "17.0.2",
"license": "BSD-3-Clause",
"main": "dist/cjs/sdk.js",
"exports": {
Expand Down
30 changes: 22 additions & 8 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ class Client {
'x-sdk-name': 'Web',
'x-sdk-platform': 'client',
'x-sdk-language': 'web',
'x-sdk-version': '17.0.1',
'x-sdk-version': '17.0.2',
'X-Appwrite-Response-Format': '1.6.0',
};

Expand All @@ -329,8 +329,12 @@ class Client {
* @returns {this}
*/
setEndpoint(endpoint: string): this {
if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
throw new AppwriteException('Invalid endpoint URL: ' + endpoint);
}

this.config.endpoint = endpoint;
this.config.endpointRealtime = this.config.endpointRealtime || this.config.endpoint.replace('https://', 'wss://').replace('http://', 'ws://');
this.config.endpointRealtime = endpoint.replace('https://', 'wss://').replace('http://', 'ws://');

return this;
}
Expand All @@ -343,8 +347,11 @@ class Client {
* @returns {this}
*/
setEndpointRealtime(endpointRealtime: string): this {
this.config.endpointRealtime = endpointRealtime;
if (!endpointRealtime.startsWith('ws://') && !endpointRealtime.startsWith('wss://')) {
throw new AppwriteException('Invalid realtime endpoint URL: ' + endpointRealtime);
}

this.config.endpointRealtime = endpointRealtime;
return this;
}

Expand Down Expand Up @@ -656,6 +663,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 @@ -704,7 +715,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 @@ -715,18 +725,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);
}

const cookieFallback = response.headers.get('X-Fallback-Cookies');
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',
}
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
10 changes: 0 additions & 10 deletions src/services/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,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 @@ -135,7 +134,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 @@ -209,7 +207,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 @@ -410,7 +407,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 @@ -432,7 +428,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 @@ -596,7 +591,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 @@ -728,7 +722,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 @@ -889,7 +882,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',
}

payload['project'] = this.client.config.project;
Expand Down Expand Up @@ -993,7 +985,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 @@ -1297,7 +1288,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',
}

payload['project'] = this.client.config.project;
Expand Down
7 changes: 0 additions & 7 deletions src/services/avatars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,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',
}

payload['project'] = this.client.config.project;
Expand Down Expand Up @@ -84,7 +83,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',
}

payload['project'] = this.client.config.project;
Expand Down Expand Up @@ -116,7 +114,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',
}

payload['project'] = this.client.config.project;
Expand Down Expand Up @@ -158,7 +155,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',
}

payload['project'] = this.client.config.project;
Expand Down Expand Up @@ -200,7 +196,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',
}

payload['project'] = this.client.config.project;
Expand Down Expand Up @@ -244,7 +239,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',
}

payload['project'] = this.client.config.project;
Expand Down Expand Up @@ -287,7 +281,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',
}

payload['project'] = this.client.config.project;
Expand Down
3 changes: 1 addition & 2 deletions src/services/databases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export class Databases {
const uri = new URL(this.client.config.endpoint + apiPath);

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

return this.client.call(
Expand All @@ -45,6 +44,7 @@ export class Databases {
}
/**
* 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.
*
* @param {string} databaseId
* @param {string} collectionId
Expand Down Expand Up @@ -119,7 +119,6 @@ export class Databases {
const uri = new URL(this.client.config.endpoint + apiPath);

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

return this.client.call(
Expand Down
2 changes: 0 additions & 2 deletions src/services/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export class Functions {
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 @@ -114,7 +113,6 @@ export class Functions {
const uri = new URL(this.client.config.endpoint + apiPath);

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

return this.client.call(
Expand Down
8 changes: 0 additions & 8 deletions src/services/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export class Locale {
const uri = new URL(this.client.config.endpoint + apiPath);

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

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

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

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

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

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

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

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

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

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

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

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

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

return this.client.call(
Expand All @@ -177,7 +170,6 @@ export class Locale {
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