react-native-appwrite 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -3
- package/dist/cjs/sdk.js +1854 -1121
- package/dist/cjs/sdk.js.map +1 -1
- package/dist/esm/sdk.js +1854 -1122
- package/dist/esm/sdk.js.map +1 -1
- package/docs/examples/account/create-email-password-session.md +4 -4
- package/docs/examples/account/create-email-token.md +5 -5
- package/docs/examples/account/{create-magic-u-r-l-token.md → create-magic-url-token.md} +6 -6
- package/docs/examples/account/create-mfa-authenticator.md +3 -3
- package/docs/examples/account/create-mfa-challenge.md +3 -3
- package/docs/examples/account/create-mfa-recovery-codes.md +1 -1
- package/docs/examples/account/{create-o-auth2token.md → create-o-auth-2-session.md} +6 -6
- package/docs/examples/account/{create-o-auth2session.md → create-o-auth-2-token.md} +6 -6
- package/docs/examples/account/create-phone-token.md +4 -4
- package/docs/examples/account/create-push-target.md +5 -5
- package/docs/examples/account/create-recovery.md +4 -4
- package/docs/examples/account/create-session.md +4 -4
- package/docs/examples/account/create-verification.md +3 -3
- package/docs/examples/account/create.md +6 -6
- package/docs/examples/account/delete-identity.md +3 -3
- package/docs/examples/account/delete-mfa-authenticator.md +3 -3
- package/docs/examples/account/delete-push-target.md +3 -3
- package/docs/examples/account/delete-session.md +3 -3
- package/docs/examples/account/get-mfa-recovery-codes.md +1 -1
- package/docs/examples/account/get-session.md +3 -3
- package/docs/examples/account/list-identities.md +3 -3
- package/docs/examples/account/list-logs.md +3 -3
- package/docs/examples/account/list-mfa-factors.md +1 -1
- package/docs/examples/account/update-email.md +4 -4
- package/docs/examples/account/{update-magic-u-r-l-session.md → update-magic-url-session.md} +4 -4
- package/docs/examples/account/update-mfa-authenticator.md +4 -4
- package/docs/examples/account/update-mfa-challenge.md +4 -4
- package/docs/examples/account/update-mfa-recovery-codes.md +1 -1
- package/docs/examples/account/{update-m-f-a.md → update-mfa.md} +3 -3
- package/docs/examples/account/update-name.md +3 -3
- package/docs/examples/account/update-password.md +4 -4
- package/docs/examples/account/update-phone-session.md +4 -4
- package/docs/examples/account/update-phone-verification.md +4 -4
- package/docs/examples/account/update-phone.md +4 -4
- package/docs/examples/account/update-prefs.md +7 -3
- package/docs/examples/account/update-push-target.md +4 -4
- package/docs/examples/account/update-recovery.md +5 -5
- package/docs/examples/account/update-session.md +3 -3
- package/docs/examples/account/update-verification.md +4 -4
- package/docs/examples/avatars/get-browser.md +6 -6
- package/docs/examples/avatars/get-credit-card.md +6 -6
- package/docs/examples/avatars/get-favicon.md +3 -3
- package/docs/examples/avatars/get-flag.md +6 -6
- package/docs/examples/avatars/get-image.md +5 -5
- package/docs/examples/avatars/get-initials.md +6 -6
- package/docs/examples/avatars/{get-q-r.md → get-qr.md} +6 -6
- package/docs/examples/databases/create-document.md +13 -7
- package/docs/examples/databases/decrement-document-attribute.md +8 -8
- package/docs/examples/databases/delete-document.md +5 -5
- package/docs/examples/databases/get-document.md +6 -6
- package/docs/examples/databases/increment-document-attribute.md +8 -8
- package/docs/examples/databases/list-documents.md +5 -5
- package/docs/examples/databases/update-document.md +7 -7
- package/docs/examples/databases/upsert-document.md +7 -7
- package/docs/examples/functions/create-execution.md +9 -9
- package/docs/examples/functions/get-execution.md +4 -4
- package/docs/examples/functions/list-executions.md +4 -4
- package/docs/examples/graphql/mutation.md +3 -3
- package/docs/examples/graphql/query.md +3 -3
- package/docs/examples/messaging/create-subscriber.md +5 -5
- package/docs/examples/messaging/delete-subscriber.md +4 -4
- package/docs/examples/storage/create-file.md +6 -6
- package/docs/examples/storage/delete-file.md +4 -4
- package/docs/examples/storage/get-file-download.md +5 -5
- package/docs/examples/storage/get-file-preview.md +16 -16
- package/docs/examples/storage/get-file-view.md +5 -5
- package/docs/examples/storage/get-file.md +4 -4
- package/docs/examples/storage/list-files.md +5 -5
- package/docs/examples/storage/update-file.md +6 -6
- package/docs/examples/tablesdb/create-row.md +23 -0
- package/docs/examples/tablesdb/decrement-row-column.md +18 -0
- package/docs/examples/tablesdb/delete-row.md +15 -0
- package/docs/examples/tablesdb/get-row.md +16 -0
- package/docs/examples/tablesdb/increment-row-column.md +18 -0
- package/docs/examples/tablesdb/list-rows.md +15 -0
- package/docs/examples/tablesdb/update-row.md +17 -0
- package/docs/examples/tablesdb/upsert-row.md +17 -0
- package/docs/examples/teams/create-membership.md +9 -9
- package/docs/examples/teams/create.md +5 -5
- package/docs/examples/teams/delete-membership.md +4 -4
- package/docs/examples/teams/delete.md +3 -3
- package/docs/examples/teams/get-membership.md +4 -4
- package/docs/examples/teams/get-prefs.md +3 -3
- package/docs/examples/teams/get.md +3 -3
- package/docs/examples/teams/list-memberships.md +5 -5
- package/docs/examples/teams/list.md +4 -4
- package/docs/examples/teams/update-membership-status.md +6 -6
- package/docs/examples/teams/update-membership.md +5 -5
- package/docs/examples/teams/update-name.md +4 -4
- package/docs/examples/teams/update-prefs.md +4 -4
- package/package.json +1 -1
- package/src/client.ts +2 -2
- package/src/enums/credit-card.ts +1 -1
- package/src/enums/execution-method.ts +1 -0
- package/src/index.ts +1 -0
- package/src/models.ts +72 -27
- package/src/query.ts +247 -4
- package/src/services/account.ts +1469 -315
- package/src/services/avatars.ts +289 -80
- package/src/services/databases.ts +345 -63
- package/src/services/functions.ts +115 -20
- package/src/services/graphql.ts +52 -4
- package/src/services/locale.ts +8 -19
- package/src/services/messaging.ts +66 -7
- package/src/services/storage.ts +345 -76
- package/src/services/tables-db.ts +621 -0
- package/src/services/teams.ts +454 -93
- package/types/enums/credit-card.d.ts +1 -1
- package/types/enums/execution-method.d.ts +2 -1
- package/types/index.d.ts +1 -0
- package/types/models.d.ts +69 -25
- package/types/query.d.ts +201 -4
- package/types/services/account.d.ts +734 -280
- package/types/services/avatars.d.ts +168 -73
- package/types/services/databases.d.ts +199 -58
- package/types/services/functions.d.ts +62 -17
- package/types/services/graphql.d.ts +24 -2
- package/types/services/locale.d.ts +8 -19
- package/types/services/messaging.d.ts +33 -5
- package/types/services/storage.d.ts +201 -68
- package/types/services/tables-db.d.ts +245 -0
- package/types/services/teams.d.ts +242 -80
- /package/docs/examples/account/{create-j-w-t.md → create-jwt.md} +0 -0
- /package/docs/examples/locale/{list-countries-e-u.md → list-countries-eu.md} +0 -0
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# Appwrite React Native SDK
|
|
2
2
|
|
|
3
3
|

|
|
4
|
-

|
|
5
5
|
[](https://travis-ci.com/appwrite/sdk-generator)
|
|
6
6
|
[](https://twitter.com/appwrite)
|
|
7
7
|
[](https://appwrite.io/discord)
|
|
8
8
|
|
|
9
|
-
**This SDK is compatible with Appwrite server version 1.
|
|
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).**
|
|
10
10
|
|
|
11
11
|
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)
|
|
12
12
|
|
|
@@ -21,15 +21,16 @@ npx expo install react-native-appwrite react-native-url-polyfill
|
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
|
|
25
24
|
## Getting Started
|
|
26
25
|
|
|
27
26
|
### Add your Platform
|
|
27
|
+
|
|
28
28
|
If this is your first time using Appwrite, create an account and create your first project.
|
|
29
29
|
|
|
30
30
|
Then, under **Add a platform**, add a **Android app** or a **Apple app**. You can skip optional steps.
|
|
31
31
|
|
|
32
32
|
#### iOS steps
|
|
33
|
+
|
|
33
34
|
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.
|
|
34
35
|
|
|
35
36
|
#### Android steps
|
|
@@ -47,6 +48,7 @@ import 'react-native-url-polyfill/auto'
|
|
|
47
48
|
> `cd ios && pod install && cd ..`
|
|
48
49
|
|
|
49
50
|
### Init your SDK
|
|
51
|
+
|
|
50
52
|
Initialize your SDK with your Appwrite server API endpoint and project ID which can be found in your project settings page.
|
|
51
53
|
|
|
52
54
|
```js
|
|
@@ -62,6 +64,7 @@ client
|
|
|
62
64
|
```
|
|
63
65
|
|
|
64
66
|
### Make Your First Request
|
|
67
|
+
|
|
65
68
|
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.
|
|
66
69
|
|
|
67
70
|
```js
|
|
@@ -78,6 +81,7 @@ account.create(ID.unique(), 'me@example.com', 'password', 'Jane Doe')
|
|
|
78
81
|
```
|
|
79
82
|
|
|
80
83
|
### Full Example
|
|
84
|
+
|
|
81
85
|
```js
|
|
82
86
|
import { Client, Account } from 'react-native-appwrite';
|
|
83
87
|
// Init your React Native SDK
|
|
@@ -100,13 +104,90 @@ account.create(ID.unique(), 'me@example.com', 'password', 'Jane Doe')
|
|
|
100
104
|
});
|
|
101
105
|
```
|
|
102
106
|
|
|
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
|
+
|
|
103
182
|
### Learn more
|
|
183
|
+
|
|
104
184
|
You can use the following resources to learn more and get help
|
|
105
185
|
- 🚀 [Getting Started Tutorial](https://appwrite.io/docs/quick-starts/react-native)
|
|
106
186
|
- 📜 [Appwrite Docs](https://appwrite.io/docs)
|
|
107
187
|
- 💬 [Discord Community](https://appwrite.io/discord)
|
|
108
188
|
- 🚂 [Appwrite React Native Playground](https://github.com/appwrite/playground-for-react-native)
|
|
109
189
|
|
|
190
|
+
|
|
110
191
|
## Contribution
|
|
111
192
|
|
|
112
193
|
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.
|