node-appwrite 10.0.0 → 11.0.0
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/docs/examples/functions/create.md +1 -1
- package/docs/examples/functions/update.md +1 -1
- package/docs/examples/teams/create-membership.md +1 -1
- package/index.d.ts +3 -3
- package/lib/client.js +2 -2
- package/lib/role.js +74 -3
- package/lib/services/functions.js +12 -11
- package/lib/services/storage.js +13 -8
- package/lib/services/teams.js +2 -6
- 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)
|
|
@@ -11,7 +11,7 @@ client
|
|
|
11
11
|
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
|
|
12
12
|
;
|
|
13
13
|
|
|
14
|
-
const promise = functions.create('[FUNCTION_ID]', '[NAME]', 'node-
|
|
14
|
+
const promise = functions.create('[FUNCTION_ID]', '[NAME]', 'node-18.0');
|
|
15
15
|
|
|
16
16
|
promise.then(function (response) {
|
|
17
17
|
console.log(response);
|
|
@@ -11,7 +11,7 @@ client
|
|
|
11
11
|
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
|
|
12
12
|
;
|
|
13
13
|
|
|
14
|
-
const promise = functions.update('[FUNCTION_ID]', '[NAME]'
|
|
14
|
+
const promise = functions.update('[FUNCTION_ID]', '[NAME]');
|
|
15
15
|
|
|
16
16
|
promise.then(function (response) {
|
|
17
17
|
console.log(response);
|
|
@@ -11,7 +11,7 @@ client
|
|
|
11
11
|
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
|
|
12
12
|
;
|
|
13
13
|
|
|
14
|
-
const promise = teams.createMembership('[TEAM_ID]', []
|
|
14
|
+
const promise = teams.createMembership('[TEAM_ID]', []);
|
|
15
15
|
|
|
16
16
|
promise.then(function (response) {
|
|
17
17
|
console.log(response);
|
package/index.d.ts
CHANGED
|
@@ -3279,7 +3279,7 @@ declare module "node-appwrite" {
|
|
|
3279
3279
|
* @throws {AppwriteException}
|
|
3280
3280
|
* @returns {Promise}
|
|
3281
3281
|
*/
|
|
3282
|
-
update(functionId: string, name: string, runtime
|
|
3282
|
+
update(functionId: string, name: string, runtime?: string, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string): Promise<Models.Function>;
|
|
3283
3283
|
/**
|
|
3284
3284
|
* Delete Function
|
|
3285
3285
|
*
|
|
@@ -4028,15 +4028,15 @@ declare module "node-appwrite" {
|
|
|
4028
4028
|
*
|
|
4029
4029
|
* @param {string} teamId
|
|
4030
4030
|
* @param {string[]} roles
|
|
4031
|
-
* @param {string} url
|
|
4032
4031
|
* @param {string} email
|
|
4033
4032
|
* @param {string} userId
|
|
4034
4033
|
* @param {string} phone
|
|
4034
|
+
* @param {string} url
|
|
4035
4035
|
* @param {string} name
|
|
4036
4036
|
* @throws {AppwriteException}
|
|
4037
4037
|
* @returns {Promise}
|
|
4038
4038
|
*/
|
|
4039
|
-
createMembership(teamId: string, roles: string[],
|
|
4039
|
+
createMembership(teamId: string, roles: string[], email?: string, userId?: string, phone?: string, url?: string, name?: string): Promise<Models.Membership>;
|
|
4040
4040
|
/**
|
|
4041
4041
|
* Get Team Membership
|
|
4042
4042
|
*
|
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/
|
|
15
|
+
'user-agent' : `AppwriteNodeJSSDK/11.0.0 (${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': '
|
|
19
|
+
'x-sdk-version': '11.0.0',
|
|
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;
|
|
@@ -247,10 +247,6 @@ class Functions extends Service {
|
|
|
247
247
|
throw new AppwriteException('Missing required parameter: "name"');
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
-
if (typeof runtime === 'undefined') {
|
|
251
|
-
throw new AppwriteException('Missing required parameter: "runtime"');
|
|
252
|
-
}
|
|
253
|
-
|
|
254
250
|
|
|
255
251
|
if (typeof name !== 'undefined') {
|
|
256
252
|
payload['name'] = name;
|
|
@@ -428,7 +424,7 @@ class Functions extends Service {
|
|
|
428
424
|
|
|
429
425
|
const size = code.size;
|
|
430
426
|
|
|
431
|
-
const
|
|
427
|
+
const apiHeaders = {
|
|
432
428
|
'content-type': 'multipart/form-data',
|
|
433
429
|
};
|
|
434
430
|
|
|
@@ -450,20 +446,24 @@ class Functions extends Service {
|
|
|
450
446
|
}
|
|
451
447
|
|
|
452
448
|
const start = currentChunkStart;
|
|
453
|
-
const end =
|
|
449
|
+
const end = currentChunkStart + currentChunkSize - 1;
|
|
454
450
|
|
|
455
451
|
if(!lastUpload || currentChunkStart !== 0) {
|
|
456
|
-
|
|
452
|
+
apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
|
|
457
453
|
}
|
|
458
454
|
|
|
459
455
|
if (id) {
|
|
460
|
-
|
|
456
|
+
apiHeaders['x-appwrite-id'] = id;
|
|
461
457
|
}
|
|
462
458
|
|
|
463
|
-
|
|
464
|
-
|
|
459
|
+
payload['code'] = {
|
|
460
|
+
type: 'file',
|
|
461
|
+
file: currentChunk,
|
|
462
|
+
filename: code.filename,
|
|
463
|
+
size: currentChunkSize
|
|
464
|
+
};
|
|
465
465
|
|
|
466
|
-
response = await selfClient.call('post', apiPath,
|
|
466
|
+
response = await selfClient.call('post', apiPath, apiHeaders, payload);
|
|
467
467
|
|
|
468
468
|
if (!id) {
|
|
469
469
|
id = response['$id'];
|
|
@@ -502,6 +502,7 @@ class Functions extends Service {
|
|
|
502
502
|
if(chunkSize + currentChunkSize == client.CHUNK_SIZE) {
|
|
503
503
|
// Upload chunk
|
|
504
504
|
currentChunk = Buffer.concat([currentChunk, chunk]);
|
|
505
|
+
currentChunkSize = Buffer.byteLength(currentChunk);
|
|
505
506
|
await uploadChunk();
|
|
506
507
|
currentChunk = Buffer.from('');
|
|
507
508
|
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/lib/services/teams.js
CHANGED
|
@@ -220,15 +220,15 @@ class Teams extends Service {
|
|
|
220
220
|
*
|
|
221
221
|
* @param {string} teamId
|
|
222
222
|
* @param {string[]} roles
|
|
223
|
-
* @param {string} url
|
|
224
223
|
* @param {string} email
|
|
225
224
|
* @param {string} userId
|
|
226
225
|
* @param {string} phone
|
|
226
|
+
* @param {string} url
|
|
227
227
|
* @param {string} name
|
|
228
228
|
* @throws {AppwriteException}
|
|
229
229
|
* @returns {Promise}
|
|
230
230
|
*/
|
|
231
|
-
async createMembership(teamId, roles,
|
|
231
|
+
async createMembership(teamId, roles, email, userId, phone, url, name) {
|
|
232
232
|
const apiPath = '/teams/{teamId}/memberships'.replace('{teamId}', teamId);
|
|
233
233
|
let payload = {};
|
|
234
234
|
if (typeof teamId === 'undefined') {
|
|
@@ -239,10 +239,6 @@ class Teams extends Service {
|
|
|
239
239
|
throw new AppwriteException('Missing required parameter: "roles"');
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
-
if (typeof url === 'undefined') {
|
|
243
|
-
throw new AppwriteException('Missing required parameter: "url"');
|
|
244
|
-
}
|
|
245
|
-
|
|
246
242
|
|
|
247
243
|
if (typeof email !== 'undefined') {
|
|
248
244
|
payload['email'] = email;
|
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": "
|
|
5
|
+
"version": "11.0.0",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
7
7
|
"main": "./index.js",
|
|
8
8
|
"types": "./index.d.ts",
|