Skip to content

Commit f4f0f16

Browse files
authored
Merge pull request #135 from appwrite/dev
Add 1.8.x support
2 parents f7316fd + 9efde82 commit f4f0f16

File tree

108 files changed

+4643
-732
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+4643
-732
lines changed

README.md

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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.7.4-blue.svg?style=flat-square)
4+
![Version](https://img.shields.io/badge/api%20version-1.8.0-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)
88

9-
**This SDK is compatible with Appwrite server version 1.7.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-web/releases).**
9+
**This SDK is compatible with Appwrite server version 1.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-web/releases).**
1010

1111
Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Web SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)
1212

@@ -33,18 +33,20 @@ 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/appwrite@18.2.0"></script>
36+
<script src="https://cdn.jsdelivr.net/npm/appwrite@19.0.0"></script>
3737
```
3838

3939

4040
## Getting Started
4141

4242
### Add your Web Platform
43+
4344
For you to init your SDK and interact with Appwrite services you need to add a web platform to your project. To add a new platform, go to your Appwrite console, choose the project you created in the step before and click the 'Add Platform' button.
4445

4546
From the options, choose to add a **Web** platform and add your client app hostname. By adding your hostname to your project platform you are allowing cross-domain communication between your project and the Appwrite API.
4647

4748
### Init your SDK
49+
4850
Initialize your SDK with your Appwrite server API endpoint and project ID which can be found in your project settings page.
4951

5052
```js
@@ -58,6 +60,7 @@ client
5860
```
5961

6062
### Make Your First Request
63+
6164
Once your SDK object is set, access any of the Appwrite services and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the [API References](https://appwrite.io/docs) section.
6265

6366
```js
@@ -74,6 +77,7 @@ account.create(ID.unique(), "email@example.com", "password", "Walter O'Brien")
7477
```
7578

7679
### Full Example
80+
7781
```js
7882
// Init your Web SDK
7983
const client = new Client();
@@ -94,7 +98,83 @@ account.create(ID.unique(), "email@example.com", "password", "Walter O'Brien")
9498
});
9599
```
96100

101+
### Type Safety with Models
102+
103+
The Appwrite Web SDK provides type safety when working with database documents through generic methods. Methods like `listDocuments`, `getDocument`, and others accept a generic type parameter that allows you to specify your custom model type for full type safety.
104+
105+
**TypeScript:**
106+
```typescript
107+
interface Book {
108+
name: string;
109+
author: string;
110+
releaseYear?: string;
111+
category?: string;
112+
genre?: string[];
113+
isCheckedOut: boolean;
114+
}
115+
116+
const databases = new Databases(client);
117+
118+
try {
119+
const documents = await databases.listDocuments<Book>(
120+
'your-database-id',
121+
'your-collection-id'
122+
);
123+
124+
documents.documents.forEach(book => {
125+
console.log(`Book: ${book.name} by ${book.author}`); // Now you have full type safety
126+
});
127+
} catch (error) {
128+
console.error('Appwrite error:', error);
129+
}
130+
```
131+
132+
**JavaScript (with JSDoc for type hints):**
133+
```javascript
134+
/**
135+
* @typedef {Object} Book
136+
* @property {string} name
137+
* @property {string} author
138+
* @property {string} [releaseYear]
139+
* @property {string} [category]
140+
* @property {string[]} [genre]
141+
* @property {boolean} isCheckedOut
142+
*/
143+
144+
const databases = new Databases(client);
145+
146+
try {
147+
/** @type {Models.DocumentList<Book>} */
148+
const documents = await databases.listDocuments(
149+
'your-database-id',
150+
'your-collection-id'
151+
);
152+
153+
documents.documents.forEach(book => {
154+
console.log(`Book: ${book.name} by ${book.author}`); // Type hints available in IDE
155+
});
156+
} catch (error) {
157+
console.error('Appwrite error:', error);
158+
}
159+
```
160+
161+
**Tip**: You can use the `appwrite types` command to automatically generate TypeScript interfaces based on your Appwrite database schema. Learn more about [type generation](https://appwrite.io/docs/products/databases/type-generation).
162+
163+
### Error Handling
164+
165+
The Appwrite Web SDK raises an `AppwriteException` object with `message`, `code` and `response` properties. You can handle any errors by catching the exception and present the `message` to the user or handle it yourself based on the provided error information. Below is an example.
166+
167+
```javascript
168+
try {
169+
const user = await account.create(ID.unique(), "email@example.com", "password", "Walter O'Brien");
170+
console.log('User created:', user);
171+
} catch (error) {
172+
console.error('Appwrite error:', error.message);
173+
}
174+
```
175+
97176
### Learn more
177+
98178
You can use the following resources to learn more and get help
99179
- 🚀 [Getting Started Tutorial](https://appwrite.io/docs/getting-started-for-web)
100180
- 📜 [Appwrite Docs](https://appwrite.io/docs)

docs/examples/account/create-email-password-session.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const client = new Client()
66

77
const account = new Account(client);
88

9-
const result = await account.createEmailPasswordSession(
10-
'email@example.com', // email
11-
'password' // password
12-
);
9+
const result = await account.createEmailPasswordSession({
10+
email: 'email@example.com',
11+
password: 'password'
12+
});
1313

1414
console.log(result);

docs/examples/account/create-email-token.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ const client = new Client()
66

77
const account = new Account(client);
88

9-
const result = await account.createEmailToken(
10-
'<USER_ID>', // userId
11-
'email@example.com', // email
12-
false // phrase (optional)
13-
);
9+
const result = await account.createEmailToken({
10+
userId: '<USER_ID>',
11+
email: 'email@example.com',
12+
phrase: false // optional
13+
});
1414

1515
console.log(result);
File renamed without changes.

docs/examples/account/create-magic-u-r-l-token.md renamed to docs/examples/account/create-magic-url-token.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const client = new Client()
66

77
const account = new Account(client);
88

9-
const result = await account.createMagicURLToken(
10-
'<USER_ID>', // userId
11-
'email@example.com', // email
12-
'https://example.com', // url (optional)
13-
false // phrase (optional)
14-
);
9+
const result = await account.createMagicURLToken({
10+
userId: '<USER_ID>',
11+
email: 'email@example.com',
12+
url: 'https://example.com', // optional
13+
phrase: false // optional
14+
});
1515

1616
console.log(result);

docs/examples/account/create-mfa-authenticator.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const client = new Client()
66

77
const account = new Account(client);
88

9-
const result = await account.createMfaAuthenticator(
10-
AuthenticatorType.Totp // type
11-
);
9+
const result = await account.createMFAAuthenticator({
10+
type: AuthenticatorType.Totp
11+
});
1212

1313
console.log(result);

docs/examples/account/create-mfa-challenge.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const client = new Client()
66

77
const account = new Account(client);
88

9-
const result = await account.createMfaChallenge(
10-
AuthenticationFactor.Email // factor
11-
);
9+
const result = await account.createMFAChallenge({
10+
factor: AuthenticationFactor.Email
11+
});
1212

1313
console.log(result);

docs/examples/account/create-mfa-recovery-codes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ const client = new Client()
66

77
const account = new Account(client);
88

9-
const result = await account.createMfaRecoveryCodes();
9+
const result = await account.createMFARecoveryCodes();
1010

1111
console.log(result);

docs/examples/account/create-o-auth2token.md renamed to docs/examples/account/create-o-auth-2-session.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ const client = new Client()
66

77
const account = new Account(client);
88

9-
account.createOAuth2Token(
10-
OAuthProvider.Amazon, // provider
11-
'https://example.com', // success (optional)
12-
'https://example.com', // failure (optional)
13-
[] // scopes (optional)
14-
);
9+
account.createOAuth2Session({
10+
provider: OAuthProvider.Amazon,
11+
success: 'https://example.com', // optional
12+
failure: 'https://example.com', // optional
13+
scopes: [] // optional
14+
});
1515

docs/examples/account/create-o-auth2session.md renamed to docs/examples/account/create-o-auth-2-token.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ const client = new Client()
66

77
const account = new Account(client);
88

9-
account.createOAuth2Session(
10-
OAuthProvider.Amazon, // provider
11-
'https://example.com', // success (optional)
12-
'https://example.com', // failure (optional)
13-
[] // scopes (optional)
14-
);
9+
account.createOAuth2Token({
10+
provider: OAuthProvider.Amazon,
11+
success: 'https://example.com', // optional
12+
failure: 'https://example.com', // optional
13+
scopes: [] // optional
14+
});
1515

0 commit comments

Comments
 (0)