node-appwrite 5.1.0 → 7.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.
Files changed (148) hide show
  1. package/README.md +2 -2
  2. package/docs/examples/account/create-phone-verification.md +20 -0
  3. package/docs/examples/account/create-recovery.md +3 -3
  4. package/docs/examples/account/create-verification.md +3 -3
  5. package/docs/examples/account/delete-session.md +3 -3
  6. package/docs/examples/account/delete-sessions.md +3 -3
  7. package/docs/examples/account/get-logs.md +3 -3
  8. package/docs/examples/account/get-prefs.md +3 -3
  9. package/docs/examples/account/get-session.md +3 -3
  10. package/docs/examples/account/get-sessions.md +3 -3
  11. package/docs/examples/account/get.md +3 -3
  12. package/docs/examples/account/update-email.md +3 -3
  13. package/docs/examples/account/update-name.md +3 -3
  14. package/docs/examples/account/update-password.md +3 -3
  15. package/docs/examples/account/update-phone-verification.md +20 -0
  16. package/docs/examples/{database/create-ip-attribute.md → account/update-phone.md} +4 -4
  17. package/docs/examples/account/update-prefs.md +3 -3
  18. package/docs/examples/account/update-recovery.md +3 -3
  19. package/docs/examples/account/update-session.md +3 -3
  20. package/docs/examples/account/{delete.md → update-status.md} +3 -3
  21. package/docs/examples/account/update-verification.md +3 -3
  22. package/docs/examples/avatars/get-browser.md +3 -3
  23. package/docs/examples/avatars/get-credit-card.md +3 -3
  24. package/docs/examples/avatars/get-favicon.md +3 -3
  25. package/docs/examples/avatars/get-flag.md +3 -3
  26. package/docs/examples/avatars/get-image.md +3 -3
  27. package/docs/examples/avatars/get-initials.md +3 -3
  28. package/docs/examples/avatars/get-q-r.md +3 -3
  29. package/docs/examples/databases/create-boolean-attribute.md +20 -0
  30. package/docs/examples/{database → databases}/create-collection.md +3 -3
  31. package/docs/examples/databases/create-document.md +20 -0
  32. package/docs/examples/databases/create-email-attribute.md +20 -0
  33. package/docs/examples/databases/create-enum-attribute.md +20 -0
  34. package/docs/examples/{database → databases}/create-float-attribute.md +3 -3
  35. package/docs/examples/{database → databases}/create-index.md +3 -3
  36. package/docs/examples/{database → databases}/create-integer-attribute.md +3 -3
  37. package/docs/examples/{database/create-email-attribute.md → databases/create-ip-attribute.md} +3 -3
  38. package/docs/examples/{database → databases}/create-string-attribute.md +3 -3
  39. package/docs/examples/{database → databases}/create-url-attribute.md +3 -3
  40. package/docs/examples/{database/delete-attribute.md → databases/create.md} +3 -3
  41. package/docs/examples/databases/delete-attribute.md +20 -0
  42. package/docs/examples/databases/delete-collection.md +20 -0
  43. package/docs/examples/databases/delete-document.md +20 -0
  44. package/docs/examples/{database/create-document.md → databases/delete-index.md} +3 -3
  45. package/docs/examples/{database/delete-index.md → databases/delete.md} +3 -3
  46. package/docs/examples/databases/get-attribute.md +20 -0
  47. package/docs/examples/{database → databases}/get-collection.md +3 -3
  48. package/docs/examples/{database/delete-document.md → databases/get-document.md} +3 -3
  49. package/docs/examples/{database/create-boolean-attribute.md → databases/get-index.md} +3 -3
  50. package/docs/examples/{database/get-index.md → databases/get.md} +3 -3
  51. package/docs/examples/{database → databases}/list-attributes.md +3 -3
  52. package/docs/examples/databases/list-collections.md +20 -0
  53. package/docs/examples/{database/create-enum-attribute.md → databases/list-documents.md} +3 -3
  54. package/docs/examples/{database → databases}/list-indexes.md +3 -3
  55. package/docs/examples/{database/list-documents.md → databases/list.md} +3 -3
  56. package/docs/examples/{database → databases}/update-collection.md +3 -3
  57. package/docs/examples/{database → databases}/update-document.md +3 -3
  58. package/docs/examples/databases/update.md +20 -0
  59. package/docs/examples/functions/create-deployment.md +3 -3
  60. package/docs/examples/functions/create-execution.md +3 -3
  61. package/docs/examples/functions/create.md +3 -3
  62. package/docs/examples/functions/delete-deployment.md +3 -3
  63. package/docs/examples/functions/delete.md +3 -3
  64. package/docs/examples/functions/get-deployment.md +3 -3
  65. package/docs/examples/functions/get-execution.md +3 -3
  66. package/docs/examples/functions/get.md +3 -3
  67. package/docs/examples/functions/list-deployments.md +3 -3
  68. package/docs/examples/functions/list-executions.md +3 -3
  69. package/docs/examples/functions/list-runtimes.md +3 -3
  70. package/docs/examples/functions/list.md +3 -3
  71. package/docs/examples/functions/retry-build.md +3 -3
  72. package/docs/examples/functions/update-deployment.md +3 -3
  73. package/docs/examples/functions/update.md +3 -3
  74. package/docs/examples/health/get-antivirus.md +3 -3
  75. package/docs/examples/health/get-cache.md +3 -3
  76. package/docs/examples/health/get-d-b.md +3 -3
  77. package/docs/examples/health/get-queue-certificates.md +3 -3
  78. package/docs/examples/health/get-queue-functions.md +3 -3
  79. package/docs/examples/health/get-queue-logs.md +3 -3
  80. package/docs/examples/health/get-queue-webhooks.md +3 -3
  81. package/docs/examples/health/get-storage-local.md +3 -3
  82. package/docs/examples/health/get-time.md +3 -3
  83. package/docs/examples/health/get.md +3 -3
  84. package/docs/examples/locale/get-continents.md +3 -3
  85. package/docs/examples/locale/get-countries-e-u.md +3 -3
  86. package/docs/examples/locale/get-countries-phones.md +3 -3
  87. package/docs/examples/locale/get-countries.md +3 -3
  88. package/docs/examples/locale/get-currencies.md +3 -3
  89. package/docs/examples/locale/get-languages.md +3 -3
  90. package/docs/examples/locale/get.md +3 -3
  91. package/docs/examples/storage/create-bucket.md +3 -3
  92. package/docs/examples/storage/create-file.md +3 -3
  93. package/docs/examples/storage/delete-bucket.md +3 -3
  94. package/docs/examples/storage/delete-file.md +3 -3
  95. package/docs/examples/storage/get-bucket.md +3 -3
  96. package/docs/examples/storage/get-file-download.md +3 -3
  97. package/docs/examples/storage/get-file-preview.md +3 -3
  98. package/docs/examples/storage/get-file-view.md +3 -3
  99. package/docs/examples/storage/get-file.md +3 -3
  100. package/docs/examples/storage/list-buckets.md +3 -3
  101. package/docs/examples/storage/list-files.md +3 -3
  102. package/docs/examples/storage/update-bucket.md +3 -3
  103. package/docs/examples/storage/update-file.md +3 -3
  104. package/docs/examples/teams/create-membership.md +3 -3
  105. package/docs/examples/teams/create.md +3 -3
  106. package/docs/examples/teams/delete-membership.md +3 -3
  107. package/docs/examples/teams/delete.md +3 -3
  108. package/docs/examples/teams/get-membership.md +3 -3
  109. package/docs/examples/teams/get-memberships.md +3 -3
  110. package/docs/examples/teams/get.md +3 -3
  111. package/docs/examples/teams/list.md +3 -3
  112. package/docs/examples/teams/update-membership-roles.md +3 -3
  113. package/docs/examples/teams/update-membership-status.md +3 -3
  114. package/docs/examples/teams/update.md +3 -3
  115. package/docs/examples/users/create.md +3 -3
  116. package/docs/examples/users/delete-session.md +3 -3
  117. package/docs/examples/users/delete-sessions.md +3 -3
  118. package/docs/examples/users/delete.md +3 -3
  119. package/docs/examples/users/get-logs.md +3 -3
  120. package/docs/examples/{database/list-collections.md → users/get-memberships.md} +3 -3
  121. package/docs/examples/users/get-prefs.md +3 -3
  122. package/docs/examples/users/get-sessions.md +3 -3
  123. package/docs/examples/users/get.md +3 -3
  124. package/docs/examples/users/list.md +3 -3
  125. package/docs/examples/{database/delete-collection.md → users/update-email-verification.md} +3 -3
  126. package/docs/examples/users/update-email.md +3 -3
  127. package/docs/examples/users/update-name.md +3 -3
  128. package/docs/examples/users/update-password.md +3 -3
  129. package/docs/examples/{database/get-attribute.md → users/update-phone-verification.md} +3 -3
  130. package/docs/examples/{health/get-queue-usage.md → users/update-phone.md} +3 -3
  131. package/docs/examples/users/update-prefs.md +3 -3
  132. package/docs/examples/users/update-status.md +3 -3
  133. package/index.d.ts +375 -161
  134. package/index.js +4 -2
  135. package/lib/client.js +9 -3
  136. package/lib/inputFile.js +47 -0
  137. package/lib/services/account.js +127 -24
  138. package/lib/services/avatars.js +35 -3
  139. package/lib/services/{database.js → databases.js} +183 -89
  140. package/lib/services/functions.js +100 -42
  141. package/lib/services/health.js +2 -18
  142. package/lib/services/locale.js +2 -0
  143. package/lib/services/storage.js +108 -50
  144. package/lib/services/teams.js +2 -0
  145. package/lib/services/users.js +94 -3
  146. package/package.json +2 -2
  147. package/docs/examples/database/get-document.md +0 -20
  148. package/docs/examples/users/update-verification.md +0 -20
@@ -1,6 +1,8 @@
1
1
  const Service = require('../service.js');
2
2
  const AppwriteException = require('../exception.js');
3
+ const InputFile = require('../inputFile.js');
3
4
  const client = require('../client.js');
5
+ const Stream = require('stream');
4
6
  const { promisify } = require('util');
5
7
  const fs = require('fs');
6
8
 
@@ -130,7 +132,7 @@ class Functions extends Service {
130
132
  }
131
133
 
132
134
  /**
133
- * List the currently active function runtimes.
135
+ * List runtimes
134
136
  *
135
137
  * Get a list of all runtimes that are currently active on your instance.
136
138
  *
@@ -319,7 +321,7 @@ class Functions extends Service {
319
321
  *
320
322
  * @param {string} functionId
321
323
  * @param {string} entrypoint
322
- * @param {string} code
324
+ * @param {InputFile} code
323
325
  * @param {boolean} activate
324
326
  * @throws {AppwriteException}
325
327
  * @returns {Promise}
@@ -349,68 +351,124 @@ class Functions extends Service {
349
351
  }
350
352
 
351
353
  if (typeof code !== 'undefined') {
352
- payload['code'] = code.toString();
354
+ payload['code'] = code;
353
355
  }
354
356
 
355
357
  if (typeof activate !== 'undefined') {
356
358
  payload['activate'] = activate.toString();
357
359
  }
358
360
 
359
- const { size: size } = await promisify(fs.stat)(code);
361
+ const size = code.size;
360
362
 
361
- if (size <= client.CHUNK_SIZE) {
362
- payload['code'] = fs.createReadStream(code);
363
-
364
- return await this.client.call('post', path, {
365
- 'content-type': 'multipart/form-data',
366
- }, payload);
367
- } else {
368
- let id = undefined;
369
- let response = undefined;
363
+ const headers = {
364
+ 'content-type': 'multipart/form-data',
365
+ };
366
+
367
+ let id = undefined;
368
+ let response = undefined;
370
369
 
371
- let counter = 0;
372
- const totalCounters = Math.ceil(size / client.CHUNK_SIZE);
370
+ let chunksUploaded = 0;
373
371
 
374
- const headers = {
375
- 'content-type': 'multipart/form-data',
376
- };
377
372
 
373
+ let currentChunk = Buffer.from('');
374
+ let currentChunkSize = 0;
375
+ let currentChunkStart = 0;
378
376
 
379
- for (counter; counter < totalCounters; counter++) {
380
- const start = (counter * client.CHUNK_SIZE);
381
- const end = Math.min((((counter * client.CHUNK_SIZE) + client.CHUNK_SIZE) - 1), size);
377
+ const selfClient = this.client;
382
378
 
379
+ async function uploadChunk(lastUpload = false) {
380
+ if(chunksUploaded - 1 >= currentChunkStart / client.CHUNK_SIZE) {
381
+ return;
382
+ }
383
+
384
+ const start = currentChunkStart;
385
+ const end = Math.min(((start + client.CHUNK_SIZE) - 1), size);
386
+
387
+ if(!lastUpload || currentChunkStart !== 0) {
383
388
  headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
389
+ }
384
390
 
385
- if (id) {
386
- headers['x-appwrite-id'] = id;
387
- }
391
+ if (id) {
392
+ headers['x-appwrite-id'] = id;
393
+ }
394
+
395
+ const stream = Stream.Readable.from(currentChunk);
396
+ payload['code'] = { type: 'file', file: stream, filename: code.filename };
388
397
 
389
- const stream = fs.createReadStream(code, {
390
- start,
391
- end
398
+ response = await selfClient.call('post', path, headers, payload);
399
+
400
+ if (!id) {
401
+ id = response['$id'];
402
+ }
403
+
404
+ if (onProgress !== null) {
405
+ onProgress({
406
+ $id: response['$id'],
407
+ progress: Math.min((start+client.CHUNK_SIZE) * client.CHUNK_SIZE, size) / size * 100,
408
+ sizeUploaded: end+1,
409
+ chunksTotal: response['chunksTotal'],
410
+ chunksUploaded: response['chunksUploaded']
392
411
  });
393
- payload['code'] = stream;
412
+ }
413
+
414
+ currentChunkStart += client.CHUNK_SIZE;
415
+ }
394
416
 
395
- response = await this.client.call('post', path, headers, payload);
417
+ return await new Promise((resolve, reject) => {
418
+ const writeStream = new Stream.Writable();
419
+ writeStream._write = async (mainChunk, encoding, next) => {
420
+ // Segment incoming chunk into up to 5MB chunks
421
+ const mainChunkSize = Buffer.byteLength(mainChunk);
422
+ const chunksCount = Math.ceil(mainChunkSize / client.CHUNK_SIZE);
423
+ const chunks = [];
396
424
 
397
- if (!id) {
398
- id = response['$id'];
425
+ for(let i = 0; i < chunksCount; i++) {
426
+ const chunk = mainChunk.slice(i * client.CHUNK_SIZE, client.CHUNK_SIZE);
427
+ chunks.push(chunk);
399
428
  }
400
-
401
- if (onProgress !== null) {
402
- onProgress({
403
- $id: response['$id'],
404
- progress: Math.min((counter+1) * client.CHUNK_SIZE, size) / size * 100,
405
- sizeUploaded: end+1,
406
- chunksTotal: response['chunksTotal'],
407
- chunksUploaded: response['chunksUploaded']
408
- });
429
+
430
+ for (const chunk of chunks) {
431
+ const chunkSize = Buffer.byteLength(chunk);
432
+
433
+ if(chunkSize + currentChunkSize == client.CHUNK_SIZE) {
434
+ // Upload chunk
435
+ currentChunk = Buffer.concat([currentChunk, chunk]);
436
+ await uploadChunk();
437
+ currentChunk = Buffer.from('');
438
+ currentChunkSize = 0;
439
+ } else if(chunkSize + currentChunkSize > client.CHUNK_SIZE) {
440
+ // Upload chunk, put rest into next chunk
441
+ const bytesToUpload = client.CHUNK_SIZE - currentChunkSize;
442
+ const newChunkSection = chunk.slice(0, bytesToUpload);
443
+ currentChunk = Buffer.concat([currentChunk, newChunkSection]);
444
+ currentChunkSize = Buffer.byteLength(currentChunk);
445
+ await uploadChunk();
446
+ currentChunk = chunk.slice(bytesToUpload, undefined);
447
+ currentChunkSize = chunkSize - bytesToUpload;
448
+ } else {
449
+ // Append into current chunk
450
+ currentChunk = Buffer.concat([currentChunk, chunk]);
451
+ currentChunkSize = chunkSize + currentChunkSize;
452
+ }
409
453
  }
454
+
455
+ next();
410
456
  }
411
457
 
412
- return response;
413
- }
458
+ writeStream.on("finish", async () => {
459
+ if(currentChunkSize > 0) {
460
+ await uploadChunk(true);
461
+ }
462
+
463
+ resolve(response);
464
+ });
465
+
466
+ writeStream.on("error", (err) => {
467
+ reject(err);
468
+ });
469
+
470
+ code.stream.pipe(writeStream);
471
+ });
414
472
  }
415
473
 
416
474
  /**
@@ -1,6 +1,8 @@
1
1
  const Service = require('../service.js');
2
2
  const AppwriteException = require('../exception.js');
3
+ const InputFile = require('../inputFile.js');
3
4
  const client = require('../client.js');
5
+ const Stream = require('stream');
4
6
  const { promisify } = require('util');
5
7
  const fs = require('fs');
6
8
 
@@ -127,24 +129,6 @@ class Health extends Service {
127
129
  }, payload);
128
130
  }
129
131
 
130
- /**
131
- * Get Usage Queue
132
- *
133
- * Get the number of usage stats that are waiting to be processed in the
134
- * Appwrite internal queue server.
135
- *
136
- * @throws {AppwriteException}
137
- * @returns {Promise}
138
- */
139
- async getQueueUsage() {
140
- let path = '/health/queue/usage';
141
- let payload = {};
142
-
143
- return await this.client.call('get', path, {
144
- 'content-type': 'application/json',
145
- }, payload);
146
- }
147
-
148
132
  /**
149
133
  * Get Webhooks Queue
150
134
  *
@@ -1,6 +1,8 @@
1
1
  const Service = require('../service.js');
2
2
  const AppwriteException = require('../exception.js');
3
+ const InputFile = require('../inputFile.js');
3
4
  const client = require('../client.js');
5
+ const Stream = require('stream');
4
6
  const { promisify } = require('util');
5
7
  const fs = require('fs');
6
8
 
@@ -1,6 +1,8 @@
1
1
  const Service = require('../service.js');
2
2
  const AppwriteException = require('../exception.js');
3
+ const InputFile = require('../inputFile.js');
3
4
  const client = require('../client.js');
5
+ const Stream = require('stream');
4
6
  const { promisify } = require('util');
5
7
  const fs = require('fs');
6
8
 
@@ -331,7 +333,7 @@ class Storage extends Service {
331
333
  *
332
334
  * @param {string} bucketId
333
335
  * @param {string} fileId
334
- * @param {string} file
336
+ * @param {InputFile} file
335
337
  * @param {string[]} read
336
338
  * @param {string[]} write
337
339
  * @throws {AppwriteException}
@@ -358,7 +360,7 @@ class Storage extends Service {
358
360
  }
359
361
 
360
362
  if (typeof file !== 'undefined') {
361
- payload['file'] = file.toString();
363
+ payload['file'] = file;
362
364
  }
363
365
 
364
366
  if (typeof read !== 'undefined') {
@@ -369,68 +371,124 @@ class Storage extends Service {
369
371
  payload['write'] = write;
370
372
  }
371
373
 
372
- const { size: size } = await promisify(fs.stat)(file);
374
+ const size = file.size;
373
375
 
374
- if (size <= client.CHUNK_SIZE) {
375
- payload['file'] = fs.createReadStream(file);
376
-
377
- return await this.client.call('post', path, {
378
- 'content-type': 'multipart/form-data',
379
- }, payload);
380
- } else {
381
- let id = undefined;
382
- let response = undefined;
383
-
384
- let counter = 0;
385
- const totalCounters = Math.ceil(size / client.CHUNK_SIZE);
386
-
387
- const headers = {
388
- 'content-type': 'multipart/form-data',
389
- };
390
-
391
- if(fileId != 'unique()') {
392
- try {
393
- response = await this.client.call('get', path + '/' + fileId, headers);
394
- counter = response.chunksUploaded;
395
- } catch(e) {
396
- }
376
+ const headers = {
377
+ 'content-type': 'multipart/form-data',
378
+ };
379
+
380
+ let id = undefined;
381
+ let response = undefined;
382
+
383
+ let chunksUploaded = 0;
384
+
385
+ if(fileId != 'unique()') {
386
+ try {
387
+ response = await this.client.call('get', path + '/' + fileId, headers);
388
+ chunksUploaded = response.chunksUploaded;
389
+ } catch(e) {
397
390
  }
391
+ }
398
392
 
399
- for (counter; counter < totalCounters; counter++) {
400
- const start = (counter * client.CHUNK_SIZE);
401
- const end = Math.min((((counter * client.CHUNK_SIZE) + client.CHUNK_SIZE) - 1), size);
393
+ let currentChunk = Buffer.from('');
394
+ let currentChunkSize = 0;
395
+ let currentChunkStart = 0;
402
396
 
397
+ const selfClient = this.client;
398
+
399
+ async function uploadChunk(lastUpload = false) {
400
+ if(chunksUploaded - 1 >= currentChunkStart / client.CHUNK_SIZE) {
401
+ return;
402
+ }
403
+
404
+ const start = currentChunkStart;
405
+ const end = Math.min(((start + client.CHUNK_SIZE) - 1), size);
406
+
407
+ if(!lastUpload || currentChunkStart !== 0) {
403
408
  headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
409
+ }
404
410
 
405
- if (id) {
406
- headers['x-appwrite-id'] = id;
407
- }
411
+ if (id) {
412
+ headers['x-appwrite-id'] = id;
413
+ }
408
414
 
409
- const stream = fs.createReadStream(file, {
410
- start,
411
- end
415
+ const stream = Stream.Readable.from(currentChunk);
416
+ payload['file'] = { type: 'file', file: stream, filename: file.filename };
417
+
418
+ response = await selfClient.call('post', path, headers, payload);
419
+
420
+ if (!id) {
421
+ id = response['$id'];
422
+ }
423
+
424
+ if (onProgress !== null) {
425
+ onProgress({
426
+ $id: response['$id'],
427
+ progress: Math.min((start+client.CHUNK_SIZE) * client.CHUNK_SIZE, size) / size * 100,
428
+ sizeUploaded: end+1,
429
+ chunksTotal: response['chunksTotal'],
430
+ chunksUploaded: response['chunksUploaded']
412
431
  });
413
- payload['file'] = stream;
432
+ }
433
+
434
+ currentChunkStart += client.CHUNK_SIZE;
435
+ }
414
436
 
415
- response = await this.client.call('post', path, headers, payload);
437
+ return await new Promise((resolve, reject) => {
438
+ const writeStream = new Stream.Writable();
439
+ writeStream._write = async (mainChunk, encoding, next) => {
440
+ // Segment incoming chunk into up to 5MB chunks
441
+ const mainChunkSize = Buffer.byteLength(mainChunk);
442
+ const chunksCount = Math.ceil(mainChunkSize / client.CHUNK_SIZE);
443
+ const chunks = [];
416
444
 
417
- if (!id) {
418
- id = response['$id'];
445
+ for(let i = 0; i < chunksCount; i++) {
446
+ const chunk = mainChunk.slice(i * client.CHUNK_SIZE, client.CHUNK_SIZE);
447
+ chunks.push(chunk);
419
448
  }
420
-
421
- if (onProgress !== null) {
422
- onProgress({
423
- $id: response['$id'],
424
- progress: Math.min((counter+1) * client.CHUNK_SIZE, size) / size * 100,
425
- sizeUploaded: end+1,
426
- chunksTotal: response['chunksTotal'],
427
- chunksUploaded: response['chunksUploaded']
428
- });
449
+
450
+ for (const chunk of chunks) {
451
+ const chunkSize = Buffer.byteLength(chunk);
452
+
453
+ if(chunkSize + currentChunkSize == client.CHUNK_SIZE) {
454
+ // Upload chunk
455
+ currentChunk = Buffer.concat([currentChunk, chunk]);
456
+ await uploadChunk();
457
+ currentChunk = Buffer.from('');
458
+ currentChunkSize = 0;
459
+ } else if(chunkSize + currentChunkSize > client.CHUNK_SIZE) {
460
+ // Upload chunk, put rest into next chunk
461
+ const bytesToUpload = client.CHUNK_SIZE - currentChunkSize;
462
+ const newChunkSection = chunk.slice(0, bytesToUpload);
463
+ currentChunk = Buffer.concat([currentChunk, newChunkSection]);
464
+ currentChunkSize = Buffer.byteLength(currentChunk);
465
+ await uploadChunk();
466
+ currentChunk = chunk.slice(bytesToUpload, undefined);
467
+ currentChunkSize = chunkSize - bytesToUpload;
468
+ } else {
469
+ // Append into current chunk
470
+ currentChunk = Buffer.concat([currentChunk, chunk]);
471
+ currentChunkSize = chunkSize + currentChunkSize;
472
+ }
429
473
  }
474
+
475
+ next();
430
476
  }
431
477
 
432
- return response;
433
- }
478
+ writeStream.on("finish", async () => {
479
+ if(currentChunkSize > 0) {
480
+ await uploadChunk(true);
481
+ }
482
+
483
+ resolve(response);
484
+ });
485
+
486
+ writeStream.on("error", (err) => {
487
+ reject(err);
488
+ });
489
+
490
+ file.stream.pipe(writeStream);
491
+ });
434
492
  }
435
493
 
436
494
  /**
@@ -1,6 +1,8 @@
1
1
  const Service = require('../service.js');
2
2
  const AppwriteException = require('../exception.js');
3
+ const InputFile = require('../inputFile.js');
3
4
  const client = require('../client.js');
5
+ const Stream = require('stream');
4
6
  const { promisify } = require('util');
5
7
  const fs = require('fs');
6
8
 
@@ -1,6 +1,8 @@
1
1
  const Service = require('../service.js');
2
2
  const AppwriteException = require('../exception.js');
3
+ const InputFile = require('../inputFile.js');
3
4
  const client = require('../client.js');
5
+ const Stream = require('stream');
4
6
  const { promisify } = require('util');
5
7
  const fs = require('fs');
6
8
 
@@ -128,7 +130,11 @@ class Users extends Service {
128
130
  /**
129
131
  * Delete User
130
132
  *
131
- * Delete a user by its unique ID.
133
+ * Delete a user by its unique ID, thereby releasing it's ID. Since ID is
134
+ * released and can be reused, all user-related resources like documents or
135
+ * storage files should be deleted before user deletion. If you want to keep
136
+ * ID reserved, use the [updateStatus](/docs/server/users#usersUpdateStatus)
137
+ * endpoint instead.
132
138
  *
133
139
  * @param {string} userId
134
140
  * @throws {AppwriteException}
@@ -210,6 +216,28 @@ class Users extends Service {
210
216
  }, payload);
211
217
  }
212
218
 
219
+ /**
220
+ * Get User Memberships
221
+ *
222
+ * Get the user membership list by its unique ID.
223
+ *
224
+ * @param {string} userId
225
+ * @throws {AppwriteException}
226
+ * @returns {Promise}
227
+ */
228
+ async getMemberships(userId) {
229
+ if (typeof userId === 'undefined') {
230
+ throw new AppwriteException('Missing required parameter: "userId"');
231
+ }
232
+
233
+ let path = '/users/{userId}/memberships'.replace('{userId}', userId);
234
+ let payload = {};
235
+
236
+ return await this.client.call('get', path, {
237
+ 'content-type': 'application/json',
238
+ }, payload);
239
+ }
240
+
213
241
  /**
214
242
  * Update Name
215
243
  *
@@ -272,6 +300,37 @@ class Users extends Service {
272
300
  }, payload);
273
301
  }
274
302
 
303
+ /**
304
+ * Update Phone
305
+ *
306
+ * Update the user phone by its unique ID.
307
+ *
308
+ * @param {string} userId
309
+ * @param {string} number
310
+ * @throws {AppwriteException}
311
+ * @returns {Promise}
312
+ */
313
+ async updatePhone(userId, number) {
314
+ if (typeof userId === 'undefined') {
315
+ throw new AppwriteException('Missing required parameter: "userId"');
316
+ }
317
+
318
+ if (typeof number === 'undefined') {
319
+ throw new AppwriteException('Missing required parameter: "number"');
320
+ }
321
+
322
+ let path = '/users/{userId}/phone'.replace('{userId}', userId);
323
+ let payload = {};
324
+
325
+ if (typeof number !== 'undefined') {
326
+ payload['number'] = number;
327
+ }
328
+
329
+ return await this.client.call('patch', path, {
330
+ 'content-type': 'application/json',
331
+ }, payload);
332
+ }
333
+
275
334
  /**
276
335
  * Get User Preferences
277
336
  *
@@ -401,7 +460,8 @@ class Users extends Service {
401
460
  /**
402
461
  * Update User Status
403
462
  *
404
- * Update the user status by its unique ID.
463
+ * Update the user status by its unique ID. Use this endpoint as an
464
+ * alternative to deleting a user if you want to keep user's ID reserved.
405
465
  *
406
466
  * @param {string} userId
407
467
  * @param {boolean} status
@@ -439,7 +499,7 @@ class Users extends Service {
439
499
  * @throws {AppwriteException}
440
500
  * @returns {Promise}
441
501
  */
442
- async updateVerification(userId, emailVerification) {
502
+ async updateEmailVerification(userId, emailVerification) {
443
503
  if (typeof userId === 'undefined') {
444
504
  throw new AppwriteException('Missing required parameter: "userId"');
445
505
  }
@@ -459,6 +519,37 @@ class Users extends Service {
459
519
  'content-type': 'application/json',
460
520
  }, payload);
461
521
  }
522
+
523
+ /**
524
+ * Update Phone Verification
525
+ *
526
+ * Update the user phone verification status by its unique ID.
527
+ *
528
+ * @param {string} userId
529
+ * @param {boolean} phoneVerification
530
+ * @throws {AppwriteException}
531
+ * @returns {Promise}
532
+ */
533
+ async updatePhoneVerification(userId, phoneVerification) {
534
+ if (typeof userId === 'undefined') {
535
+ throw new AppwriteException('Missing required parameter: "userId"');
536
+ }
537
+
538
+ if (typeof phoneVerification === 'undefined') {
539
+ throw new AppwriteException('Missing required parameter: "phoneVerification"');
540
+ }
541
+
542
+ let path = '/users/{userId}/verification/phone'.replace('{userId}', userId);
543
+ let payload = {};
544
+
545
+ if (typeof phoneVerification !== 'undefined') {
546
+ payload['phoneVerification'] = phoneVerification;
547
+ }
548
+
549
+ return await this.client.call('patch', path, {
550
+ 'content-type': 'application/json',
551
+ }, payload);
552
+ }
462
553
  }
463
554
 
464
555
  module.exports = Users;
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.1.0",
5
+ "version": "7.0.1",
6
6
  "license": "BSD-3-Clause",
7
7
  "main": "./index.js",
8
8
  "types": "./index.d.ts",
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "devDependencies": {},
14
14
  "dependencies": {
15
- "axios": "^0.26.1",
15
+ "axios": "^0.27.2",
16
16
  "form-data": "^4.0.0"
17
17
  }
18
18
  }
@@ -1,20 +0,0 @@
1
- const sdk = require('node-appwrite');
2
-
3
- // Init SDK
4
- let client = new sdk.Client();
5
-
6
- let database = new sdk.Database(client);
7
-
8
- client
9
- .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
10
- .setProject('5df5acd0d48c2') // Your project ID
11
- .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
12
- ;
13
-
14
- let promise = database.getDocument('[COLLECTION_ID]', '[DOCUMENT_ID]');
15
-
16
- promise.then(function (response) {
17
- console.log(response);
18
- }, function (error) {
19
- console.log(error);
20
- });
@@ -1,20 +0,0 @@
1
- const sdk = require('node-appwrite');
2
-
3
- // Init SDK
4
- let client = new sdk.Client();
5
-
6
- let users = new sdk.Users(client);
7
-
8
- client
9
- .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
10
- .setProject('5df5acd0d48c2') // Your project ID
11
- .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
12
- ;
13
-
14
- let promise = users.updateVerification('[USER_ID]', false);
15
-
16
- promise.then(function (response) {
17
- console.log(response);
18
- }, function (error) {
19
- console.log(error);
20
- });