node-appwrite 8.2.0 → 9.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/LICENSE +1 -1
- package/README.md +2 -2
- package/docs/examples/account/update-password.md +1 -1
- package/docs/examples/databases/create-relationship-attribute.md +20 -0
- package/docs/examples/databases/update-boolean-attribute.md +20 -0
- package/docs/examples/databases/update-datetime-attribute.md +20 -0
- package/docs/examples/databases/update-email-attribute.md +20 -0
- package/docs/examples/databases/update-enum-attribute.md +20 -0
- package/docs/examples/databases/update-float-attribute.md +20 -0
- package/docs/examples/databases/update-integer-attribute.md +20 -0
- package/docs/examples/databases/update-ip-attribute.md +20 -0
- package/docs/examples/databases/update-relationship-attribute.md +20 -0
- package/docs/examples/databases/update-string-attribute.md +20 -0
- package/docs/examples/databases/update-url-attribute.md +20 -0
- 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/docs/examples/teams/get-prefs.md +20 -0
- package/docs/examples/teams/{update.md → update-name.md} +1 -1
- package/docs/examples/teams/update-prefs.md +20 -0
- package/docs/examples/users/update-password.md +1 -1
- package/index.d.ts +334 -112
- package/lib/client.js +2 -1
- package/lib/inputFile.js +6 -8
- package/lib/query.js +18 -0
- package/lib/services/databases.js +720 -104
- package/lib/services/functions.js +45 -45
- package/lib/services/storage.js +43 -35
- package/lib/services/teams.js +87 -19
- package/package.json +6 -4
|
@@ -51,8 +51,8 @@ class Functions extends Service {
|
|
|
51
51
|
*
|
|
52
52
|
* @param {string} functionId
|
|
53
53
|
* @param {string} name
|
|
54
|
-
* @param {string[]} execute
|
|
55
54
|
* @param {string} runtime
|
|
55
|
+
* @param {string[]} execute
|
|
56
56
|
* @param {string[]} events
|
|
57
57
|
* @param {string} schedule
|
|
58
58
|
* @param {number} timeout
|
|
@@ -60,7 +60,7 @@ class Functions extends Service {
|
|
|
60
60
|
* @throws {AppwriteException}
|
|
61
61
|
* @returns {Promise}
|
|
62
62
|
*/
|
|
63
|
-
async create(functionId, name,
|
|
63
|
+
async create(functionId, name, runtime, execute, events, schedule, timeout, enabled) {
|
|
64
64
|
let path = '/functions';
|
|
65
65
|
let payload = {};
|
|
66
66
|
if (typeof functionId === 'undefined') {
|
|
@@ -71,10 +71,6 @@ class Functions extends Service {
|
|
|
71
71
|
throw new AppwriteException('Missing required parameter: "name"');
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
if (typeof execute === 'undefined') {
|
|
75
|
-
throw new AppwriteException('Missing required parameter: "execute"');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
74
|
if (typeof runtime === 'undefined') {
|
|
79
75
|
throw new AppwriteException('Missing required parameter: "runtime"');
|
|
80
76
|
}
|
|
@@ -182,10 +178,6 @@ class Functions extends Service {
|
|
|
182
178
|
throw new AppwriteException('Missing required parameter: "name"');
|
|
183
179
|
}
|
|
184
180
|
|
|
185
|
-
if (typeof execute === 'undefined') {
|
|
186
|
-
throw new AppwriteException('Missing required parameter: "execute"');
|
|
187
|
-
}
|
|
188
|
-
|
|
189
181
|
|
|
190
182
|
if (typeof name !== 'undefined') {
|
|
191
183
|
payload['name'] = name;
|
|
@@ -382,48 +374,56 @@ class Functions extends Service {
|
|
|
382
374
|
|
|
383
375
|
return await new Promise((resolve, reject) => {
|
|
384
376
|
const writeStream = new Stream.Writable();
|
|
385
|
-
writeStream._write = async (mainChunk, encoding,
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
377
|
+
writeStream._write = async (mainChunk, encoding, callback) => {
|
|
378
|
+
try {
|
|
379
|
+
// Segment incoming chunk into up to 5MB chunks
|
|
380
|
+
const mainChunkSize = Buffer.byteLength(mainChunk);
|
|
381
|
+
const chunksCount = Math.ceil(mainChunkSize / client.CHUNK_SIZE);
|
|
382
|
+
const chunks = [];
|
|
383
|
+
|
|
384
|
+
for(let i = 0; i < chunksCount; i++) {
|
|
385
|
+
const chunk = mainChunk.slice(i * client.CHUNK_SIZE, (i + 1) * client.CHUNK_SIZE);
|
|
386
|
+
chunks.push(chunk);
|
|
387
|
+
}
|
|
395
388
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
389
|
+
for (const chunk of chunks) {
|
|
390
|
+
const chunkSize = Buffer.byteLength(chunk);
|
|
391
|
+
|
|
392
|
+
if(chunkSize + currentChunkSize == client.CHUNK_SIZE) {
|
|
393
|
+
// Upload chunk
|
|
394
|
+
currentChunk = Buffer.concat([currentChunk, chunk]);
|
|
395
|
+
await uploadChunk();
|
|
396
|
+
currentChunk = Buffer.from('');
|
|
397
|
+
currentChunkSize = 0;
|
|
398
|
+
} else if(chunkSize + currentChunkSize > client.CHUNK_SIZE) {
|
|
399
|
+
// Upload chunk, put rest into next chunk
|
|
400
|
+
const bytesToUpload = client.CHUNK_SIZE - currentChunkSize;
|
|
401
|
+
const newChunkSection = chunk.slice(0, bytesToUpload);
|
|
402
|
+
currentChunk = Buffer.concat([currentChunk, newChunkSection]);
|
|
403
|
+
currentChunkSize = Buffer.byteLength(currentChunk);
|
|
404
|
+
await uploadChunk();
|
|
405
|
+
currentChunk = chunk.slice(bytesToUpload, undefined);
|
|
406
|
+
currentChunkSize = chunkSize - bytesToUpload;
|
|
407
|
+
} else {
|
|
408
|
+
// Append into current chunk
|
|
409
|
+
currentChunk = Buffer.concat([currentChunk, chunk]);
|
|
410
|
+
currentChunkSize = chunkSize + currentChunkSize;
|
|
411
|
+
}
|
|
418
412
|
}
|
|
419
|
-
}
|
|
420
413
|
|
|
421
|
-
|
|
414
|
+
callback();
|
|
415
|
+
} catch (e) {
|
|
416
|
+
callback(e);
|
|
417
|
+
}
|
|
422
418
|
}
|
|
423
419
|
|
|
424
420
|
writeStream.on("finish", async () => {
|
|
425
421
|
if(currentChunkSize > 0) {
|
|
426
|
-
|
|
422
|
+
try {
|
|
423
|
+
await uploadChunk(true);
|
|
424
|
+
} catch (e) {
|
|
425
|
+
reject(e);
|
|
426
|
+
}
|
|
427
427
|
}
|
|
428
428
|
|
|
429
429
|
resolve(response);
|
package/lib/services/storage.js
CHANGED
|
@@ -388,48 +388,56 @@ class Storage extends Service {
|
|
|
388
388
|
|
|
389
389
|
return await new Promise((resolve, reject) => {
|
|
390
390
|
const writeStream = new Stream.Writable();
|
|
391
|
-
writeStream._write = async (mainChunk, encoding,
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
391
|
+
writeStream._write = async (mainChunk, encoding, callback) => {
|
|
392
|
+
try {
|
|
393
|
+
// Segment incoming chunk into up to 5MB chunks
|
|
394
|
+
const mainChunkSize = Buffer.byteLength(mainChunk);
|
|
395
|
+
const chunksCount = Math.ceil(mainChunkSize / client.CHUNK_SIZE);
|
|
396
|
+
const chunks = [];
|
|
397
|
+
|
|
398
|
+
for(let i = 0; i < chunksCount; i++) {
|
|
399
|
+
const chunk = mainChunk.slice(i * client.CHUNK_SIZE, (i + 1) * client.CHUNK_SIZE);
|
|
400
|
+
chunks.push(chunk);
|
|
401
|
+
}
|
|
401
402
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
403
|
+
for (const chunk of chunks) {
|
|
404
|
+
const chunkSize = Buffer.byteLength(chunk);
|
|
405
|
+
|
|
406
|
+
if(chunkSize + currentChunkSize == client.CHUNK_SIZE) {
|
|
407
|
+
// Upload chunk
|
|
408
|
+
currentChunk = Buffer.concat([currentChunk, chunk]);
|
|
409
|
+
await uploadChunk();
|
|
410
|
+
currentChunk = Buffer.from('');
|
|
411
|
+
currentChunkSize = 0;
|
|
412
|
+
} else if(chunkSize + currentChunkSize > client.CHUNK_SIZE) {
|
|
413
|
+
// Upload chunk, put rest into next chunk
|
|
414
|
+
const bytesToUpload = client.CHUNK_SIZE - currentChunkSize;
|
|
415
|
+
const newChunkSection = chunk.slice(0, bytesToUpload);
|
|
416
|
+
currentChunk = Buffer.concat([currentChunk, newChunkSection]);
|
|
417
|
+
currentChunkSize = Buffer.byteLength(currentChunk);
|
|
418
|
+
await uploadChunk();
|
|
419
|
+
currentChunk = chunk.slice(bytesToUpload, undefined);
|
|
420
|
+
currentChunkSize = chunkSize - bytesToUpload;
|
|
421
|
+
} else {
|
|
422
|
+
// Append into current chunk
|
|
423
|
+
currentChunk = Buffer.concat([currentChunk, chunk]);
|
|
424
|
+
currentChunkSize = chunkSize + currentChunkSize;
|
|
425
|
+
}
|
|
424
426
|
}
|
|
425
|
-
}
|
|
426
427
|
|
|
427
|
-
|
|
428
|
+
callback();
|
|
429
|
+
} catch (e) {
|
|
430
|
+
callback(e);
|
|
431
|
+
}
|
|
428
432
|
}
|
|
429
433
|
|
|
430
434
|
writeStream.on("finish", async () => {
|
|
431
435
|
if(currentChunkSize > 0) {
|
|
432
|
-
|
|
436
|
+
try {
|
|
437
|
+
await uploadChunk(true);
|
|
438
|
+
} catch (e) {
|
|
439
|
+
reject(e);
|
|
440
|
+
}
|
|
433
441
|
}
|
|
434
442
|
|
|
435
443
|
resolve(response);
|
package/lib/services/teams.js
CHANGED
|
@@ -107,17 +107,16 @@ class Teams extends Service {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
/**
|
|
110
|
-
* Update
|
|
110
|
+
* Update Name
|
|
111
111
|
*
|
|
112
|
-
* Update
|
|
113
|
-
* team.
|
|
112
|
+
* Update the team's name by its unique ID.
|
|
114
113
|
*
|
|
115
114
|
* @param {string} teamId
|
|
116
115
|
* @param {string} name
|
|
117
116
|
* @throws {AppwriteException}
|
|
118
117
|
* @returns {Promise}
|
|
119
118
|
*/
|
|
120
|
-
async
|
|
119
|
+
async updateName(teamId, name) {
|
|
121
120
|
let path = '/teams/{teamId}'.replace('{teamId}', teamId);
|
|
122
121
|
let payload = {};
|
|
123
122
|
if (typeof teamId === 'undefined') {
|
|
@@ -197,41 +196,45 @@ class Teams extends Service {
|
|
|
197
196
|
/**
|
|
198
197
|
* Create Team Membership
|
|
199
198
|
*
|
|
200
|
-
* Invite a new member to join your team.
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
199
|
+
* Invite a new member to join your team. Provide an ID for existing users, or
|
|
200
|
+
* invite unregistered users using an email or phone number. If initiated from
|
|
201
|
+
* a Client SDK, Appwrite will send an email or sms with a link to join the
|
|
202
|
+
* team to the invited user, and an account will be created for them if one
|
|
203
|
+
* doesn't exist. If initiated from a Server SDK, the new member will be added
|
|
204
|
+
* automatically to the team.
|
|
205
205
|
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
206
|
+
* You only need to provide one of a user ID, email, or phone number. Appwrite
|
|
207
|
+
* will prioritize accepting the user ID > email > phone number if you provide
|
|
208
|
+
* more than one of these parameters.
|
|
209
|
+
*
|
|
210
|
+
* Use the `url` parameter to redirect the user from the invitation email to
|
|
211
|
+
* your app. After the user is redirected, use the [Update Team Membership
|
|
208
212
|
* Status](/docs/client/teams#teamsUpdateMembershipStatus) endpoint to allow
|
|
209
213
|
* the user to accept the invitation to the team.
|
|
210
214
|
*
|
|
211
215
|
* Please note that to avoid a [Redirect
|
|
212
216
|
* Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md)
|
|
213
|
-
* the only
|
|
214
|
-
*
|
|
217
|
+
* Appwrite will accept the only redirect URLs under the domains you have
|
|
218
|
+
* added as a platform on the Appwrite Console.
|
|
219
|
+
*
|
|
215
220
|
*
|
|
216
221
|
* @param {string} teamId
|
|
217
|
-
* @param {string} email
|
|
218
222
|
* @param {string[]} roles
|
|
219
223
|
* @param {string} url
|
|
224
|
+
* @param {string} email
|
|
225
|
+
* @param {string} userId
|
|
226
|
+
* @param {string} phone
|
|
220
227
|
* @param {string} name
|
|
221
228
|
* @throws {AppwriteException}
|
|
222
229
|
* @returns {Promise}
|
|
223
230
|
*/
|
|
224
|
-
async createMembership(teamId, email,
|
|
231
|
+
async createMembership(teamId, roles, url, email, userId, phone, name) {
|
|
225
232
|
let path = '/teams/{teamId}/memberships'.replace('{teamId}', teamId);
|
|
226
233
|
let payload = {};
|
|
227
234
|
if (typeof teamId === 'undefined') {
|
|
228
235
|
throw new AppwriteException('Missing required parameter: "teamId"');
|
|
229
236
|
}
|
|
230
237
|
|
|
231
|
-
if (typeof email === 'undefined') {
|
|
232
|
-
throw new AppwriteException('Missing required parameter: "email"');
|
|
233
|
-
}
|
|
234
|
-
|
|
235
238
|
if (typeof roles === 'undefined') {
|
|
236
239
|
throw new AppwriteException('Missing required parameter: "roles"');
|
|
237
240
|
}
|
|
@@ -245,6 +248,14 @@ class Teams extends Service {
|
|
|
245
248
|
payload['email'] = email;
|
|
246
249
|
}
|
|
247
250
|
|
|
251
|
+
if (typeof userId !== 'undefined') {
|
|
252
|
+
payload['userId'] = userId;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (typeof phone !== 'undefined') {
|
|
256
|
+
payload['phone'] = phone;
|
|
257
|
+
}
|
|
258
|
+
|
|
248
259
|
if (typeof roles !== 'undefined') {
|
|
249
260
|
payload['roles'] = roles;
|
|
250
261
|
}
|
|
@@ -407,6 +418,63 @@ class Teams extends Service {
|
|
|
407
418
|
'content-type': 'application/json',
|
|
408
419
|
}, payload);
|
|
409
420
|
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Get Team Preferences
|
|
424
|
+
*
|
|
425
|
+
* Get the team's shared preferences by its unique ID. If a preference doesn't
|
|
426
|
+
* need to be shared by all team members, prefer storing them in [user
|
|
427
|
+
* preferences](/docs/client/account#accountGetPrefs).
|
|
428
|
+
*
|
|
429
|
+
* @param {string} teamId
|
|
430
|
+
* @throws {AppwriteException}
|
|
431
|
+
* @returns {Promise}
|
|
432
|
+
*/
|
|
433
|
+
async getPrefs(teamId) {
|
|
434
|
+
let path = '/teams/{teamId}/prefs'.replace('{teamId}', teamId);
|
|
435
|
+
let payload = {};
|
|
436
|
+
if (typeof teamId === 'undefined') {
|
|
437
|
+
throw new AppwriteException('Missing required parameter: "teamId"');
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
return await this.client.call('get', path, {
|
|
442
|
+
'content-type': 'application/json',
|
|
443
|
+
}, payload);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Update Preferences
|
|
448
|
+
*
|
|
449
|
+
* Update the team's preferences by its unique ID. The object you pass is
|
|
450
|
+
* stored as is and replaces any previous value. The maximum allowed prefs
|
|
451
|
+
* size is 64kB and throws an error if exceeded.
|
|
452
|
+
*
|
|
453
|
+
* @param {string} teamId
|
|
454
|
+
* @param {object} prefs
|
|
455
|
+
* @throws {AppwriteException}
|
|
456
|
+
* @returns {Promise}
|
|
457
|
+
*/
|
|
458
|
+
async updatePrefs(teamId, prefs) {
|
|
459
|
+
let path = '/teams/{teamId}/prefs'.replace('{teamId}', teamId);
|
|
460
|
+
let payload = {};
|
|
461
|
+
if (typeof teamId === 'undefined') {
|
|
462
|
+
throw new AppwriteException('Missing required parameter: "teamId"');
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
if (typeof prefs === 'undefined') {
|
|
466
|
+
throw new AppwriteException('Missing required parameter: "prefs"');
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
if (typeof prefs !== 'undefined') {
|
|
471
|
+
payload['prefs'] = prefs;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
return await this.client.call('put', path, {
|
|
475
|
+
'content-type': 'application/json',
|
|
476
|
+
}, payload);
|
|
477
|
+
}
|
|
410
478
|
}
|
|
411
479
|
|
|
412
480
|
module.exports = Teams;
|
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": "9.0.0",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
7
7
|
"main": "./index.js",
|
|
8
8
|
"types": "./index.d.ts",
|
|
@@ -10,9 +10,11 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/appwrite/sdk-for-node"
|
|
12
12
|
},
|
|
13
|
-
"devDependencies": {
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@types/node": "^18.16.1"
|
|
15
|
+
},
|
|
14
16
|
"dependencies": {
|
|
15
|
-
"axios": "^1.
|
|
17
|
+
"axios": "^1.3.6",
|
|
16
18
|
"form-data": "^4.0.0"
|
|
17
19
|
}
|
|
18
|
-
}
|
|
20
|
+
}
|