diff --git a/README.md b/README.md index e136170..b22048b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Appwrite Node.js SDK ![License](https://img.shields.io/github/license/appwrite/sdk-for-node.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.4.0-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.4.1-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) diff --git a/lib/client.js b/lib/client.js index 9dd06f9..2706a59 100644 --- a/lib/client.js +++ b/lib/client.js @@ -12,11 +12,11 @@ class Client { this.headers = { 'accept-encoding': '*', 'content-type': '', - 'user-agent' : `AppwriteNodeJSSDK/10.0.0 (${os.type()}; ${os.version()}; ${os.arch()})`, + 'user-agent' : `AppwriteNodeJSSDK/10.0.1 (${os.type()}; ${os.version()}; ${os.arch()})`, 'x-sdk-name': 'Node.js', 'x-sdk-platform': 'server', 'x-sdk-language': 'nodejs', - 'x-sdk-version': '10.0.0', + 'x-sdk-version': '10.0.1', 'X-Appwrite-Response-Format' : '1.4.0', }; this.selfSigned = false; diff --git a/lib/role.js b/lib/role.js index 5c168c2..41b3cb5 100644 --- a/lib/role.js +++ b/lib/role.js @@ -1,31 +1,102 @@ +/** + * Helper class to generate role strings for `Permission`. + */ class Role { + + /** + * Grants access to anyone. + * + * This includes authenticated and unauthenticated users. + * + * @returns {string} + */ static any = () => { return 'any' } + + /** + * Grants access to a specific user by user ID. + * + * You can optionally pass verified or unverified for + * `status` to target specific types of users. + * + * @param {string} id + * @param {string} status + * @returns {string} + */ static user = (id, status = '') => { - if(status === '') { + if (status === '') { return `user:${id}` } return `user:${id}/${status}` } + + /** + * Grants access to any authenticated or anonymous user. + * + * You can optionally pass verified or unverified for + * `status` to target specific types of users. + * + * @param {string} status + * @returns {string} + */ static users = (status = '') => { - if(status === '') { + if (status === '') { return 'users' } return `users/${status}` } + + /** + * Grants access to any guest user without a session. + * + * Authenticated users don't have access to this role. + * + * @returns {string} + */ static guests = () => { return 'guests' } + + /** + * Grants access to a team by team ID. + * + * You can optionally pass a role for `role` to target + * team members with the specified role. + * + * @param {string} id + * @param {string} role + * @returns {string} + */ static team = (id, role = '') => { - if(role === '') { + if (role === '') { return 'team:' + id } return 'team:' + id + '/' + role } + + /** + * Grants access to a specific member of a team. + * + * When the member is removed from the team, they will + * no longer have access. + * + * @param {string} id + * @returns {string} + */ static member = (id) => { return 'member:' + id } + + /** + * Grants access to a user with the specified label. + * + * @param {string} name + * @returns {string} + */ + static label = (name) => { + return 'label:' + name; + } } module.exports = Role; \ No newline at end of file diff --git a/lib/services/functions.js b/lib/services/functions.js index 424e280..538b4de 100644 --- a/lib/services/functions.js +++ b/lib/services/functions.js @@ -428,7 +428,7 @@ class Functions extends Service { const size = code.size; - const headers = { + const apiHeaders = { 'content-type': 'multipart/form-data', }; @@ -450,20 +450,24 @@ class Functions extends Service { } const start = currentChunkStart; - const end = Math.min(((start + client.CHUNK_SIZE) - 1), size); + const end = currentChunkStart + currentChunkSize - 1; if(!lastUpload || currentChunkStart !== 0) { - headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size; + apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size; } if (id) { - headers['x-appwrite-id'] = id; + apiHeaders['x-appwrite-id'] = id; } - const stream = Stream.Readable.from(currentChunk); - payload['code'] = { type: 'file', file: stream, filename: code.filename }; + payload['code'] = { + type: 'file', + file: currentChunk, + filename: code.filename, + size: currentChunkSize + }; - response = await selfClient.call('post', apiPath, headers, payload); + response = await selfClient.call('post', apiPath, apiHeaders, payload); if (!id) { id = response['$id']; @@ -502,6 +506,7 @@ class Functions extends Service { if(chunkSize + currentChunkSize == client.CHUNK_SIZE) { // Upload chunk currentChunk = Buffer.concat([currentChunk, chunk]); + currentChunkSize = Buffer.byteLength(currentChunk); await uploadChunk(); currentChunk = Buffer.from(''); currentChunkSize = 0; diff --git a/lib/services/storage.js b/lib/services/storage.js index aeb3185..86e037c 100644 --- a/lib/services/storage.js +++ b/lib/services/storage.js @@ -325,7 +325,7 @@ class Storage extends Service { const size = file.size; - const headers = { + const apiHeaders = { 'content-type': 'multipart/form-data', }; @@ -336,7 +336,7 @@ class Storage extends Service { if(fileId != 'unique()') { try { - response = await this.client.call('get', apiPath + '/' + fileId, headers); + response = await this.client.call('get', apiPath + '/' + fileId, apiHeaders); chunksUploaded = response.chunksUploaded; } catch(e) { } @@ -354,20 +354,24 @@ class Storage extends Service { } const start = currentChunkStart; - const end = Math.min(((start + client.CHUNK_SIZE) - 1), size); + const end = currentChunkStart + currentChunkSize - 1; if(!lastUpload || currentChunkStart !== 0) { - headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size; + apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size; } if (id) { - headers['x-appwrite-id'] = id; + apiHeaders['x-appwrite-id'] = id; } - const stream = Stream.Readable.from(currentChunk); - payload['file'] = { type: 'file', file: stream, filename: file.filename }; + payload['file'] = { + type: 'file', + file: currentChunk, + filename: file.filename, + size: currentChunkSize + }; - response = await selfClient.call('post', apiPath, headers, payload); + response = await selfClient.call('post', apiPath, apiHeaders, payload); if (!id) { id = response['$id']; @@ -406,6 +410,7 @@ class Storage extends Service { if(chunkSize + currentChunkSize == client.CHUNK_SIZE) { // Upload chunk currentChunk = Buffer.concat([currentChunk, chunk]); + currentChunkSize = Buffer.byteLength(currentChunk); await uploadChunk(); currentChunk = Buffer.from(''); currentChunkSize = 0; diff --git a/package.json b/package.json index ece91fe..606755c 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "node-appwrite", "homepage": "https://appwrite.io/support", "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", - "version": "10.0.0", + "version": "10.0.1", "license": "BSD-3-Clause", "main": "./index.js", "types": "./index.d.ts",