Skip to content

Commit 27e7a62

Browse files
authored
Merge pull request #60 from appwrite/dev
chore: update sdks for appwrite 1.4.x
2 parents aaea14a + c3126b7 commit 27e7a62

File tree

6 files changed

+103
-22
lines changed

6 files changed

+103
-22
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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.4.0-blue.svg?style=flat-square)
4+
![Version](https://img.shields.io/badge/api%20version-1.4.1-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)

lib/client.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ class Client {
1212
this.headers = {
1313
'accept-encoding': '*',
1414
'content-type': '',
15-
'user-agent' : `AppwriteNodeJSSDK/10.0.0 (${os.type()}; ${os.version()}; ${os.arch()})`,
15+
'user-agent' : `AppwriteNodeJSSDK/10.0.1 (${os.type()}; ${os.version()}; ${os.arch()})`,
1616
'x-sdk-name': 'Node.js',
1717
'x-sdk-platform': 'server',
1818
'x-sdk-language': 'nodejs',
19-
'x-sdk-version': '10.0.0',
19+
'x-sdk-version': '10.0.1',
2020
'X-Appwrite-Response-Format' : '1.4.0',
2121
};
2222
this.selfSigned = false;

lib/role.js

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,102 @@
1+
/**
2+
* Helper class to generate role strings for `Permission`.
3+
*/
14
class Role {
5+
6+
/**
7+
* Grants access to anyone.
8+
*
9+
* This includes authenticated and unauthenticated users.
10+
*
11+
* @returns {string}
12+
*/
213
static any = () => {
314
return 'any'
415
}
16+
17+
/**
18+
* Grants access to a specific user by user ID.
19+
*
20+
* You can optionally pass verified or unverified for
21+
* `status` to target specific types of users.
22+
*
23+
* @param {string} id
24+
* @param {string} status
25+
* @returns {string}
26+
*/
527
static user = (id, status = '') => {
6-
if(status === '') {
28+
if (status === '') {
729
return `user:${id}`
830
}
931
return `user:${id}/${status}`
1032
}
33+
34+
/**
35+
* Grants access to any authenticated or anonymous user.
36+
*
37+
* You can optionally pass verified or unverified for
38+
* `status` to target specific types of users.
39+
*
40+
* @param {string} status
41+
* @returns {string}
42+
*/
1143
static users = (status = '') => {
12-
if(status === '') {
44+
if (status === '') {
1345
return 'users'
1446
}
1547
return `users/${status}`
1648
}
49+
50+
/**
51+
* Grants access to any guest user without a session.
52+
*
53+
* Authenticated users don't have access to this role.
54+
*
55+
* @returns {string}
56+
*/
1757
static guests = () => {
1858
return 'guests'
1959
}
60+
61+
/**
62+
* Grants access to a team by team ID.
63+
*
64+
* You can optionally pass a role for `role` to target
65+
* team members with the specified role.
66+
*
67+
* @param {string} id
68+
* @param {string} role
69+
* @returns {string}
70+
*/
2071
static team = (id, role = '') => {
21-
if(role === '') {
72+
if (role === '') {
2273
return 'team:' + id
2374
}
2475
return 'team:' + id + '/' + role
2576
}
77+
78+
/**
79+
* Grants access to a specific member of a team.
80+
*
81+
* When the member is removed from the team, they will
82+
* no longer have access.
83+
*
84+
* @param {string} id
85+
* @returns {string}
86+
*/
2687
static member = (id) => {
2788
return 'member:' + id
2889
}
90+
91+
/**
92+
* Grants access to a user with the specified label.
93+
*
94+
* @param {string} name
95+
* @returns {string}
96+
*/
97+
static label = (name) => {
98+
return 'label:' + name;
99+
}
29100
}
30101

31102
module.exports = Role;

lib/services/functions.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ class Functions extends Service {
428428

429429
const size = code.size;
430430

431-
const headers = {
431+
const apiHeaders = {
432432
'content-type': 'multipart/form-data',
433433
};
434434

@@ -450,20 +450,24 @@ class Functions extends Service {
450450
}
451451

452452
const start = currentChunkStart;
453-
const end = Math.min(((start + client.CHUNK_SIZE) - 1), size);
453+
const end = currentChunkStart + currentChunkSize - 1;
454454

455455
if(!lastUpload || currentChunkStart !== 0) {
456-
headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
456+
apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
457457
}
458458

459459
if (id) {
460-
headers['x-appwrite-id'] = id;
460+
apiHeaders['x-appwrite-id'] = id;
461461
}
462462

463-
const stream = Stream.Readable.from(currentChunk);
464-
payload['code'] = { type: 'file', file: stream, filename: code.filename };
463+
payload['code'] = {
464+
type: 'file',
465+
file: currentChunk,
466+
filename: code.filename,
467+
size: currentChunkSize
468+
};
465469

466-
response = await selfClient.call('post', apiPath, headers, payload);
470+
response = await selfClient.call('post', apiPath, apiHeaders, payload);
467471

468472
if (!id) {
469473
id = response['$id'];
@@ -502,6 +506,7 @@ class Functions extends Service {
502506
if(chunkSize + currentChunkSize == client.CHUNK_SIZE) {
503507
// Upload chunk
504508
currentChunk = Buffer.concat([currentChunk, chunk]);
509+
currentChunkSize = Buffer.byteLength(currentChunk);
505510
await uploadChunk();
506511
currentChunk = Buffer.from('');
507512
currentChunkSize = 0;

lib/services/storage.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ class Storage extends Service {
325325

326326
const size = file.size;
327327

328-
const headers = {
328+
const apiHeaders = {
329329
'content-type': 'multipart/form-data',
330330
};
331331

@@ -336,7 +336,7 @@ class Storage extends Service {
336336

337337
if(fileId != 'unique()') {
338338
try {
339-
response = await this.client.call('get', apiPath + '/' + fileId, headers);
339+
response = await this.client.call('get', apiPath + '/' + fileId, apiHeaders);
340340
chunksUploaded = response.chunksUploaded;
341341
} catch(e) {
342342
}
@@ -354,20 +354,24 @@ class Storage extends Service {
354354
}
355355

356356
const start = currentChunkStart;
357-
const end = Math.min(((start + client.CHUNK_SIZE) - 1), size);
357+
const end = currentChunkStart + currentChunkSize - 1;
358358

359359
if(!lastUpload || currentChunkStart !== 0) {
360-
headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
360+
apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
361361
}
362362

363363
if (id) {
364-
headers['x-appwrite-id'] = id;
364+
apiHeaders['x-appwrite-id'] = id;
365365
}
366366

367-
const stream = Stream.Readable.from(currentChunk);
368-
payload['file'] = { type: 'file', file: stream, filename: file.filename };
367+
payload['file'] = {
368+
type: 'file',
369+
file: currentChunk,
370+
filename: file.filename,
371+
size: currentChunkSize
372+
};
369373

370-
response = await selfClient.call('post', apiPath, headers, payload);
374+
response = await selfClient.call('post', apiPath, apiHeaders, payload);
371375

372376
if (!id) {
373377
id = response['$id'];
@@ -406,6 +410,7 @@ class Storage extends Service {
406410
if(chunkSize + currentChunkSize == client.CHUNK_SIZE) {
407411
// Upload chunk
408412
currentChunk = Buffer.concat([currentChunk, chunk]);
413+
currentChunkSize = Buffer.byteLength(currentChunk);
409414
await uploadChunk();
410415
currentChunk = Buffer.from('');
411416
currentChunkSize = 0;

package.json

Lines changed: 1 addition & 1 deletion
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": "10.0.0",
5+
"version": "10.0.1",
66
"license": "BSD-3-Clause",
77
"main": "./index.js",
88
"types": "./index.d.ts",

0 commit comments

Comments
 (0)