Skip to content

Commit cdf0f36

Browse files
authored
Merge pull request #68 from appwrite/dev
Add 1.8.x support
2 parents 9f082cb + 643454b commit cdf0f36

File tree

108 files changed

+4535
-1084
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

+4535
-1084
lines changed

README.md

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Appwrite React Native SDK
22

33
![License](https://img.shields.io/github/license/appwrite/sdk-for-react-native.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-react-native/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-react-native/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 React Native 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

@@ -21,15 +21,16 @@ npx expo install react-native-appwrite react-native-url-polyfill
2121
```
2222

2323

24-
2524
## Getting Started
2625

2726
### Add your Platform
27+
2828
If this is your first time using Appwrite, create an account and create your first project.
2929

3030
Then, under **Add a platform**, add a **Android app** or a **Apple app**. You can skip optional steps.
3131

3232
#### iOS steps
33+
3334
Add your app **name** and **Bundle ID**. You can find your **Bundle Identifier** in the **General** tab for your app's primary target in XCode. For Expo projects you can set or find it on **app.json** file at your project's root directory.
3435

3536
#### Android steps
@@ -47,6 +48,7 @@ import 'react-native-url-polyfill/auto'
4748
> `cd ios && pod install && cd ..`
4849
4950
### Init your SDK
51+
5052
Initialize your SDK with your Appwrite server API endpoint and project ID which can be found in your project settings page.
5153

5254
```js
@@ -62,6 +64,7 @@ client
6264
```
6365

6466
### Make Your First Request
67+
6568
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.
6669

6770
```js
@@ -78,6 +81,7 @@ account.create(ID.unique(), 'me@example.com', 'password', 'Jane Doe')
7881
```
7982

8083
### Full Example
84+
8185
```js
8286
import { Client, Account } from 'react-native-appwrite';
8387
// Init your React Native SDK
@@ -100,13 +104,90 @@ account.create(ID.unique(), 'me@example.com', 'password', 'Jane Doe')
100104
});
101105
```
102106

107+
### Type Safety with Models
108+
109+
The Appwrite React Native 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.
110+
111+
**TypeScript:**
112+
```typescript
113+
interface Book {
114+
name: string;
115+
author: string;
116+
releaseYear?: string;
117+
category?: string;
118+
genre?: string[];
119+
isCheckedOut: boolean;
120+
}
121+
122+
const databases = new Databases(client);
123+
124+
try {
125+
const documents = await databases.listDocuments<Book>(
126+
'your-database-id',
127+
'your-collection-id'
128+
);
129+
130+
documents.documents.forEach(book => {
131+
console.log(`Book: ${book.name} by ${book.author}`); // Now you have full type safety
132+
});
133+
} catch (error) {
134+
console.error('Appwrite error:', error);
135+
}
136+
```
137+
138+
**JavaScript (with JSDoc for type hints):**
139+
```javascript
140+
/**
141+
* @typedef {Object} Book
142+
* @property {string} name
143+
* @property {string} author
144+
* @property {string} [releaseYear]
145+
* @property {string} [category]
146+
* @property {string[]} [genre]
147+
* @property {boolean} isCheckedOut
148+
*/
149+
150+
const databases = new Databases(client);
151+
152+
try {
153+
/** @type {Models.DocumentList<Book>} */
154+
const documents = await databases.listDocuments(
155+
'your-database-id',
156+
'your-collection-id'
157+
);
158+
159+
documents.documents.forEach(book => {
160+
console.log(`Book: ${book.name} by ${book.author}`); // Type hints available in IDE
161+
});
162+
} catch (error) {
163+
console.error('Appwrite error:', error);
164+
}
165+
```
166+
167+
**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).
168+
169+
### Error Handling
170+
171+
The Appwrite React Native 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.
172+
173+
```javascript
174+
try {
175+
const user = await account.create(ID.unique(), "email@example.com", "password", "Walter O'Brien");
176+
console.log('User created:', user);
177+
} catch (error) {
178+
console.error('Appwrite error:', error.message);
179+
}
180+
```
181+
103182
### Learn more
183+
104184
You can use the following resources to learn more and get help
105185
- 🚀 [Getting Started Tutorial](https://appwrite.io/docs/quick-starts/react-native)
106186
- 📜 [Appwrite Docs](https://appwrite.io/docs)
107187
- 💬 [Discord Community](https://appwrite.io/discord)
108188
- 🚂 [Appwrite React Native Playground](https://github.com/appwrite/playground-for-react-native)
109189

190+
110191
## Contribution
111192

112193
This library is auto-generated by Appwrite custom [SDK Generator](https://github.com/appwrite/sdk-generator). To learn more about how you can help us improve this SDK, please check the [contribution guide](https://github.com/appwrite/sdk-generator/blob/master/CONTRIBUTING.md) before sending a pull-request.

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)