Skip to content

Commit 9e79a93

Browse files
committed
security patch
1 parent 16c3181 commit 9e79a93

File tree

6 files changed

+111
-10
lines changed

6 files changed

+111
-10
lines changed

.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
language: node_js
3+
node_js:
4+
- "14.16"
5+
6+
jobs:
7+
include:
8+
- stage: npm release
9+
node_js: "14.16"
10+
script: echo "Deploying to npm ..."
11+
deploy:
12+
provider: npm
13+
email: $NPM_EMAIL
14+
api_key: $NPM_API_KEY
15+
on:
16+
tags: true

README.md

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

3-
![License](https://img.shields.io/github/license/appwrite/sdk-for-node.svg?v=1)
4-
![Version](https://img.shields.io/badge/api%20version-0.7.0-blue.svg?v=1)
3+
![License](https://img.shields.io/github/license/appwrite/sdk-for-node.svg?style=flat-square)
4+
![Version](https://img.shields.io/badge/api%20version-0.7.0-blue.svg?style=flat-square)
55

6-
**This SDK is compatible with Appwrite server version 0.7.0. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-node/releases).**
6+
**This SDK is compatible with Appwrite server version 0.7.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-node/releases).**
77

88
> This is the Node.js SDK for integrating with Appwrite from your Node.js server-side code.
99
If you're looking to integrate from the browser, you should check [appwrite/sdk-for-web](https://github.com/appwrite/sdk-for-web)
@@ -22,6 +22,69 @@ To install via [NPM](https://www.npmjs.com/):
2222
npm install node-appwrite --save
2323
```
2424

25+
26+
## Getting Started
27+
28+
### Init your SDK
29+
Initialize your SDK code with your project ID which can be found in your project settings page and your new API secret Key project API keys section.
30+
31+
```js
32+
const sdk = require('node-appwrite');
33+
34+
let client = new sdk.Client();
35+
36+
client
37+
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
38+
.setProject('5df5acd0d48c2') // Your project ID
39+
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
40+
;
41+
```
42+
43+
### Make Your First Request
44+
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 section.
45+
46+
```js
47+
let users = new sdk.Users(client);
48+
49+
let promise = users.create('[email protected]', 'password');
50+
51+
promise.then(function (response) {
52+
console.log(response);
53+
}, function (error) {
54+
console.log(error);
55+
});
56+
```
57+
58+
### Full Example
59+
```js
60+
const sdk = require('node-appwrite');
61+
62+
let client = new sdk.Client();
63+
64+
client
65+
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
66+
.setProject('5df5acd0d48c2') // Your project ID
67+
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
68+
;
69+
70+
let users = new sdk.Users(client);
71+
let promise = users.create('[email protected]', 'password');
72+
73+
promise.then(function (response) {
74+
console.log(response);
75+
}, function (error) {
76+
console.log(error);
77+
});
78+
```
79+
80+
### Learn more
81+
You can use followng resources to learn more and get help
82+
- 🚀 [Getting Started Tutorial](https://appwrite.io/docs/getting-started-for-server)
83+
- 📜 [Appwrite Docs](https://appwrite.io/docs)
84+
- 💬 [Discord Community](https://appwrite.io/discord)
85+
- 🚂 [Appwrite Node Playground](https://github.com/appwrite/playground-for-node)
86+
87+
2588
## Contribution
2689

2790
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.

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const Client = require('./lib/client.js');
2+
const AppwriteException = require('./lib/exception.js');
23
const Avatars = require('./lib/services/avatars.js');
34
const Database = require('./lib/services/database.js');
45
const Functions = require('./lib/services/functions.js');
@@ -10,6 +11,7 @@ const Users = require('./lib/services/users.js');
1011

1112
module.exports = {
1213
Client,
14+
AppwriteException,
1315
Avatars,
1416
Database,
1517
Functions,

lib/client.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
const URL = require('url').URL;
22
const axios = require('axios');
33
const FormData = require('form-data');
4+
const AppwriteException = require('./exception.js');
45

56
class Client {
67

78
constructor() {
89
this.endpoint = 'https://appwrite.io/v1';
910
this.headers = {
1011
'content-type': '',
11-
'x-sdk-version': 'appwrite:nodejs:2.0.0',
12+
'x-sdk-version': 'appwrite:nodejs:2.1.0',
1213
};
1314
this.selfSigned = false;
1415
}
@@ -124,10 +125,20 @@ class Client {
124125
data: (method.toUpperCase() === 'GET' || contentType.startsWith('multipart/form-data')) ? formData : params,
125126
json: (contentType.startsWith('application/json'))
126127
};
127-
128-
let response = await axios(options);
129-
130-
return response.data;
128+
try {
129+
let response = await axios(options);
130+
return response.data;
131+
} catch(error) {
132+
if('response' in error) {
133+
if('data' in error.response) {
134+
throw new AppwriteException(error.response.data.message, error.response.status, error.response.data);
135+
}else{
136+
throw new AppwriteException(error.response.statusText, error.response.status, error.response.data);
137+
}
138+
}else{
139+
throw new AppwriteException(error.message);
140+
}
141+
}
131142
}
132143

133144
flatten(data, prefix = '') {

lib/exception.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class AppwriteException extends Error {
2+
constructor(message, code, response) {
3+
super(message);
4+
this.code = code;
5+
this.response = response;
6+
}
7+
}
8+
9+
module.exports = AppwriteException;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "node-appwrite",
33
"homepage": "https://appwrite.io/support",
44
"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",
5-
"version": "2.0.0",
5+
"version": "2.1.0",
66
"license": "BSD-3-Clause",
77
"main": "index.js",
88
"repository": {
@@ -11,7 +11,7 @@
1111
},
1212
"devDependencies": {},
1313
"dependencies": {
14-
"axios": "^0.20.0",
14+
"axios": "^0.21.1",
1515
"form-data": "^3.0.0"
1616
}
1717
}

0 commit comments

Comments
 (0)