Skip to content

Commit eda96d2

Browse files
authored
Merge pull request #119 from appwrite/dev
Add 1.8.x support
2 parents ad40290 + c760255 commit eda96d2

File tree

347 files changed

+19874
-3213
lines changed

Some content is hidden

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

347 files changed

+19874
-3213
lines changed

README.md

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Appwrite Node.js SDK
22

33
![License](https://img.shields.io/github/license/appwrite/sdk-for-node.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-node/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-node/releases).**
1010

1111
> This is the Node.js SDK for integrating with Appwrite from your Node.js server-side code.
1212
If you're looking to integrate from the browser, you should check [appwrite/sdk-for-web](https://github.com/appwrite/sdk-for-web)
@@ -27,6 +27,7 @@ npm install node-appwrite --save
2727
## Getting Started
2828

2929
### Init your SDK
30+
3031
Initialize your SDK with your Appwrite server API endpoint and project ID which can be found in your project settings page and your new API secret Key project API keys section.
3132

3233
```js
@@ -43,6 +44,7 @@ client
4344
```
4445

4546
### Make Your First Request
47+
4648
Once your SDK object is set, create any of the Appwrite service objects 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.
4749

4850
```js
@@ -80,7 +82,70 @@ promise.then(function (response) {
8082
});
8183
```
8284

85+
### Type Safety with Models
86+
87+
The Appwrite Node 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.
88+
89+
**TypeScript:**
90+
```typescript
91+
interface Book {
92+
name: string;
93+
author: string;
94+
releaseYear?: string;
95+
category?: string;
96+
genre?: string[];
97+
isCheckedOut: boolean;
98+
}
99+
100+
const databases = new Databases(client);
101+
102+
try {
103+
const documents = await databases.listDocuments<Book>(
104+
'your-database-id',
105+
'your-collection-id'
106+
);
107+
108+
documents.documents.forEach(book => {
109+
console.log(`Book: ${book.name} by ${book.author}`); // Now you have full type safety
110+
});
111+
} catch (error) {
112+
console.error('Appwrite error:', error);
113+
}
114+
```
115+
116+
**JavaScript (with JSDoc for type hints):**
117+
```javascript
118+
/**
119+
* @typedef {Object} Book
120+
* @property {string} name
121+
* @property {string} author
122+
* @property {string} [releaseYear]
123+
* @property {string} [category]
124+
* @property {string[]} [genre]
125+
* @property {boolean} isCheckedOut
126+
*/
127+
128+
const databases = new Databases(client);
129+
130+
try {
131+
/** @type {Models.DocumentList<Book>} */
132+
const documents = await databases.listDocuments(
133+
'your-database-id',
134+
'your-collection-id'
135+
);
136+
137+
documents.documents.forEach(book => {
138+
console.log(`Book: ${book.name} by ${book.author}`); // Type hints available in IDE
139+
});
140+
} catch (error) {
141+
console.error('Appwrite error:', error);
142+
}
143+
```
144+
145+
**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).
146+
83147
### Error Handling
148+
84149
The Appwrite Node SDK raises `AppwriteException` object with `message`, `code` and `response` properties. You can handle any errors by catching `AppwriteException` and present the `message` to the user or handle it yourself based on the provided error information. Below is an example.
85150

86151
```js

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

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

77
const account = new sdk.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+
});

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

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

77
const account = new sdk.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+
});
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,9 +6,9 @@ const client = new sdk.Client()
66

77
const account = new sdk.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+
});

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

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

88
const account = new sdk.Account(client);
99

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

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

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

77
const account = new sdk.Account(client);
88

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ const client = new sdk.Client()
77

88
const account = new sdk.Account(client);
99

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

docs/examples/account/create-o-auth2token.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,9 +6,9 @@ const client = new sdk.Client()
66

77
const account = new sdk.Account(client);
88

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

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

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

77
const account = new sdk.Account(client);
88

9-
const result = await account.createPhoneToken(
10-
'<USER_ID>', // userId
11-
'+12065550100' // phone
12-
);
9+
const result = await account.createPhoneToken({
10+
userId: '<USER_ID>',
11+
phone: '+12065550100'
12+
});

0 commit comments

Comments
 (0)