node-appwrite 10.0.0 → 10.0.1
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 +1 -1
- package/lib/client.js +2 -2
- package/lib/role.js +74 -3
- package/lib/services/functions.js +12 -7
- package/lib/services/storage.js +13 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Appwrite Node.js 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)
|
package/lib/client.js
CHANGED
|
@@ -12,11 +12,11 @@ class Client {
|
|
|
12
12
|
this.headers = {
|
|
13
13
|
'accept-encoding': '*',
|
|
14
14
|
'content-type': '',
|
|
15
|
-
'user-agent' : `AppwriteNodeJSSDK/10.0.
|
|
15
|
+
'user-agent' : `AppwriteNodeJSSDK/10.0.1 (${os.type()}; ${os.version()}; ${os.arch()})`,
|
|
16
16
|
'x-sdk-name': 'Node.js',
|
|
17
17
|
'x-sdk-platform': 'server',
|
|
18
18
|
'x-sdk-language': 'nodejs',
|
|
19
|
-
'x-sdk-version': '10.0.
|
|
19
|
+
'x-sdk-version': '10.0.1',
|
|
20
20
|
'X-Appwrite-Response-Format' : '1.4.0',
|
|
21
21
|
};
|
|
22
22
|
this.selfSigned = false;
|
package/lib/role.js
CHANGED
|
@@ -1,31 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper class to generate role strings for `Permission`.
|
|
3
|
+
*/
|
|
1
4
|
class Role {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Grants access to anyone.
|
|
8
|
+
*
|
|
9
|
+
* This includes authenticated and unauthenticated users.
|
|
10
|
+
*
|
|
11
|
+
* @returns {string}
|
|
12
|
+
*/
|
|
2
13
|
static any = () => {
|
|
3
14
|
return 'any'
|
|
4
15
|
}
|
|
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
|
+
*/
|
|
5
27
|
static user = (id, status = '') => {
|
|
6
|
-
if(status === '') {
|
|
28
|
+
if (status === '') {
|
|
7
29
|
return `user:${id}`
|
|
8
30
|
}
|
|
9
31
|
return `user:${id}/${status}`
|
|
10
32
|
}
|
|
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
|
+
*/
|
|
11
43
|
static users = (status = '') => {
|
|
12
|
-
if(status === '') {
|
|
44
|
+
if (status === '') {
|
|
13
45
|
return 'users'
|
|
14
46
|
}
|
|
15
47
|
return `users/${status}`
|
|
16
48
|
}
|
|
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
|
+
*/
|
|
17
57
|
static guests = () => {
|
|
18
58
|
return 'guests'
|
|
19
59
|
}
|
|
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
|
+
*/
|
|
20
71
|
static team = (id, role = '') => {
|
|
21
|
-
if(role === '') {
|
|
72
|
+
if (role === '') {
|
|
22
73
|
return 'team:' + id
|
|
23
74
|
}
|
|
24
75
|
return 'team:' + id + '/' + role
|
|
25
76
|
}
|
|
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
|
+
*/
|
|
26
87
|
static member = (id) => {
|
|
27
88
|
return 'member:' + id
|
|
28
89
|
}
|
|
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
|
+
}
|
|
29
100
|
}
|
|
30
101
|
|
|
31
102
|
module.exports = Role;
|
|
@@ -428,7 +428,7 @@ class Functions extends Service {
|
|
|
428
428
|
|
|
429
429
|
const size = code.size;
|
|
430
430
|
|
|
431
|
-
const
|
|
431
|
+
const apiHeaders = {
|
|
432
432
|
'content-type': 'multipart/form-data',
|
|
433
433
|
};
|
|
434
434
|
|
|
@@ -450,20 +450,24 @@ class Functions extends Service {
|
|
|
450
450
|
}
|
|
451
451
|
|
|
452
452
|
const start = currentChunkStart;
|
|
453
|
-
const end =
|
|
453
|
+
const end = currentChunkStart + currentChunkSize - 1;
|
|
454
454
|
|
|
455
455
|
if(!lastUpload || currentChunkStart !== 0) {
|
|
456
|
-
|
|
456
|
+
apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
|
|
457
457
|
}
|
|
458
458
|
|
|
459
459
|
if (id) {
|
|
460
|
-
|
|
460
|
+
apiHeaders['x-appwrite-id'] = id;
|
|
461
461
|
}
|
|
462
462
|
|
|
463
|
-
|
|
464
|
-
|
|
463
|
+
payload['code'] = {
|
|
464
|
+
type: 'file',
|
|
465
|
+
file: currentChunk,
|
|
466
|
+
filename: code.filename,
|
|
467
|
+
size: currentChunkSize
|
|
468
|
+
};
|
|
465
469
|
|
|
466
|
-
response = await selfClient.call('post', apiPath,
|
|
470
|
+
response = await selfClient.call('post', apiPath, apiHeaders, payload);
|
|
467
471
|
|
|
468
472
|
if (!id) {
|
|
469
473
|
id = response['$id'];
|
|
@@ -502,6 +506,7 @@ class Functions extends Service {
|
|
|
502
506
|
if(chunkSize + currentChunkSize == client.CHUNK_SIZE) {
|
|
503
507
|
// Upload chunk
|
|
504
508
|
currentChunk = Buffer.concat([currentChunk, chunk]);
|
|
509
|
+
currentChunkSize = Buffer.byteLength(currentChunk);
|
|
505
510
|
await uploadChunk();
|
|
506
511
|
currentChunk = Buffer.from('');
|
|
507
512
|
currentChunkSize = 0;
|
package/lib/services/storage.js
CHANGED
|
@@ -325,7 +325,7 @@ class Storage extends Service {
|
|
|
325
325
|
|
|
326
326
|
const size = file.size;
|
|
327
327
|
|
|
328
|
-
const
|
|
328
|
+
const apiHeaders = {
|
|
329
329
|
'content-type': 'multipart/form-data',
|
|
330
330
|
};
|
|
331
331
|
|
|
@@ -336,7 +336,7 @@ class Storage extends Service {
|
|
|
336
336
|
|
|
337
337
|
if(fileId != 'unique()') {
|
|
338
338
|
try {
|
|
339
|
-
response = await this.client.call('get', apiPath + '/' + fileId,
|
|
339
|
+
response = await this.client.call('get', apiPath + '/' + fileId, apiHeaders);
|
|
340
340
|
chunksUploaded = response.chunksUploaded;
|
|
341
341
|
} catch(e) {
|
|
342
342
|
}
|
|
@@ -354,20 +354,24 @@ class Storage extends Service {
|
|
|
354
354
|
}
|
|
355
355
|
|
|
356
356
|
const start = currentChunkStart;
|
|
357
|
-
const end =
|
|
357
|
+
const end = currentChunkStart + currentChunkSize - 1;
|
|
358
358
|
|
|
359
359
|
if(!lastUpload || currentChunkStart !== 0) {
|
|
360
|
-
|
|
360
|
+
apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
|
|
361
361
|
}
|
|
362
362
|
|
|
363
363
|
if (id) {
|
|
364
|
-
|
|
364
|
+
apiHeaders['x-appwrite-id'] = id;
|
|
365
365
|
}
|
|
366
366
|
|
|
367
|
-
|
|
368
|
-
|
|
367
|
+
payload['file'] = {
|
|
368
|
+
type: 'file',
|
|
369
|
+
file: currentChunk,
|
|
370
|
+
filename: file.filename,
|
|
371
|
+
size: currentChunkSize
|
|
372
|
+
};
|
|
369
373
|
|
|
370
|
-
response = await selfClient.call('post', apiPath,
|
|
374
|
+
response = await selfClient.call('post', apiPath, apiHeaders, payload);
|
|
371
375
|
|
|
372
376
|
if (!id) {
|
|
373
377
|
id = response['$id'];
|
|
@@ -406,6 +410,7 @@ class Storage extends Service {
|
|
|
406
410
|
if(chunkSize + currentChunkSize == client.CHUNK_SIZE) {
|
|
407
411
|
// Upload chunk
|
|
408
412
|
currentChunk = Buffer.concat([currentChunk, chunk]);
|
|
413
|
+
currentChunkSize = Buffer.byteLength(currentChunk);
|
|
409
414
|
await uploadChunk();
|
|
410
415
|
currentChunk = Buffer.from('');
|
|
411
416
|
currentChunkSize = 0;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "node-appwrite",
|
|
3
3
|
"homepage": "https://appwrite.io/support",
|
|
4
4
|
"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.
|
|
5
|
+
"version": "10.0.1",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
7
7
|
"main": "./index.js",
|
|
8
8
|
"types": "./index.d.ts",
|