node-appwrite 4.0.2 → 6.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.
Files changed (36) hide show
  1. package/README.md +2 -2
  2. package/docs/examples/account/update-session.md +20 -0
  3. package/docs/examples/account/{delete.md → update-status.md} +1 -1
  4. package/docs/examples/functions/{create-tag.md → create-deployment.md} +1 -1
  5. package/docs/examples/functions/{delete-tag.md → delete-deployment.md} +1 -1
  6. package/docs/examples/functions/{update-tag.md → get-deployment.md} +1 -1
  7. package/docs/examples/functions/{list-tags.md → list-deployments.md} +1 -1
  8. package/docs/examples/functions/retry-build.md +20 -0
  9. package/docs/examples/functions/{get-tag.md → update-deployment.md} +1 -1
  10. package/docs/examples/storage/create-bucket.md +20 -0
  11. package/docs/examples/storage/create-file.md +1 -1
  12. package/docs/examples/storage/delete-bucket.md +20 -0
  13. package/docs/examples/storage/delete-file.md +1 -1
  14. package/docs/examples/storage/get-bucket.md +20 -0
  15. package/docs/examples/storage/get-file-download.md +1 -1
  16. package/docs/examples/storage/get-file-preview.md +1 -1
  17. package/docs/examples/storage/get-file-view.md +1 -1
  18. package/docs/examples/storage/get-file.md +1 -1
  19. package/docs/examples/{health/get-queue-usage.md → storage/list-buckets.md} +2 -2
  20. package/docs/examples/storage/list-files.md +1 -1
  21. package/docs/examples/storage/update-bucket.md +20 -0
  22. package/docs/examples/storage/update-file.md +1 -1
  23. package/docs/examples/users/get-memberships.md +20 -0
  24. package/index.d.ts +485 -188
  25. package/lib/client.js +7 -5
  26. package/lib/exception.js +2 -1
  27. package/lib/services/account.js +49 -23
  28. package/lib/services/avatars.js +36 -3
  29. package/lib/services/database.js +7 -6
  30. package/lib/services/functions.js +213 -118
  31. package/lib/services/health.js +3 -18
  32. package/lib/services/locale.js +3 -0
  33. package/lib/services/storage.js +390 -33
  34. package/lib/services/teams.js +7 -0
  35. package/lib/services/users.js +32 -2
  36. package/package.json +2 -2
@@ -1,5 +1,8 @@
1
1
  const Service = require('../service.js');
2
2
  const AppwriteException = require('../exception.js');
3
+ const client = require('../client.js');
4
+ const { promisify } = require('util');
5
+ const fs = require('fs');
3
6
 
4
7
  class Functions extends Service {
5
8
 
@@ -127,9 +130,9 @@ class Functions extends Service {
127
130
  }
128
131
 
129
132
  /**
130
- * List the currently active function runtimes.
133
+ * List runtimes
131
134
  *
132
- * Get a list of all runtimes that are currently active in your project.
135
+ * Get a list of all runtimes that are currently active on your instance.
133
136
  *
134
137
  * @throws {AppwriteException}
135
138
  * @returns {Promise}
@@ -248,30 +251,33 @@ class Functions extends Service {
248
251
  }
249
252
 
250
253
  /**
251
- * List Executions
254
+ * List Deployments
252
255
  *
253
- * Get a list of all the current user function execution logs. You can use the
254
- * query params to filter your results. On admin mode, this endpoint will
255
- * return a list of all of the project's executions. [Learn more about
256
- * different API modes](/docs/admin).
256
+ * Get a list of all the project's code deployments. You can use the query
257
+ * params to filter your results.
257
258
  *
258
259
  * @param {string} functionId
260
+ * @param {string} search
259
261
  * @param {number} limit
260
262
  * @param {number} offset
261
- * @param {string} search
262
263
  * @param {string} cursor
263
264
  * @param {string} cursorDirection
265
+ * @param {string} orderType
264
266
  * @throws {AppwriteException}
265
267
  * @returns {Promise}
266
268
  */
267
- async listExecutions(functionId, limit, offset, search, cursor, cursorDirection) {
269
+ async listDeployments(functionId, search, limit, offset, cursor, cursorDirection, orderType) {
268
270
  if (typeof functionId === 'undefined') {
269
271
  throw new AppwriteException('Missing required parameter: "functionId"');
270
272
  }
271
273
 
272
- let path = '/functions/{functionId}/executions'.replace('{functionId}', functionId);
274
+ let path = '/functions/{functionId}/deployments'.replace('{functionId}', functionId);
273
275
  let payload = {};
274
276
 
277
+ if (typeof search !== 'undefined') {
278
+ payload['search'] = search;
279
+ }
280
+
275
281
  if (typeof limit !== 'undefined') {
276
282
  payload['limit'] = limit;
277
283
  }
@@ -280,10 +286,6 @@ class Functions extends Service {
280
286
  payload['offset'] = offset;
281
287
  }
282
288
 
283
- if (typeof search !== 'undefined') {
284
- payload['search'] = search;
285
- }
286
-
287
289
  if (typeof cursor !== 'undefined') {
288
290
  payload['cursor'] = cursor;
289
291
  }
@@ -292,61 +294,145 @@ class Functions extends Service {
292
294
  payload['cursorDirection'] = cursorDirection;
293
295
  }
294
296
 
297
+ if (typeof orderType !== 'undefined') {
298
+ payload['orderType'] = orderType;
299
+ }
300
+
295
301
  return await this.client.call('get', path, {
296
302
  'content-type': 'application/json',
297
303
  }, payload);
298
304
  }
299
305
 
300
306
  /**
301
- * Create Execution
307
+ * Create Deployment
302
308
  *
303
- * Trigger a function execution. The returned object will return you the
304
- * current execution status. You can ping the `Get Execution` endpoint to get
305
- * updates on the current execution status. Once this endpoint is called, your
306
- * function execution process will start asynchronously.
309
+ * Create a new function code deployment. Use this endpoint to upload a new
310
+ * version of your code function. To execute your newly uploaded code, you'll
311
+ * need to update the function's deployment to use your new deployment UID.
312
+ *
313
+ * This endpoint accepts a tar.gz file compressed with your code. Make sure to
314
+ * include any dependencies your code has within the compressed file. You can
315
+ * learn more about code packaging in the [Appwrite Cloud Functions
316
+ * tutorial](/docs/functions).
317
+ *
318
+ * Use the "command" param to set the entry point used to execute your code.
307
319
  *
308
320
  * @param {string} functionId
309
- * @param {string} data
321
+ * @param {string} entrypoint
322
+ * @param {string} code
323
+ * @param {boolean} activate
310
324
  * @throws {AppwriteException}
311
325
  * @returns {Promise}
312
326
  */
313
- async createExecution(functionId, data) {
327
+ async createDeployment(functionId, entrypoint, code, activate, onProgress = () => {}) {
314
328
  if (typeof functionId === 'undefined') {
315
329
  throw new AppwriteException('Missing required parameter: "functionId"');
316
330
  }
317
331
 
318
- let path = '/functions/{functionId}/executions'.replace('{functionId}', functionId);
332
+ if (typeof entrypoint === 'undefined') {
333
+ throw new AppwriteException('Missing required parameter: "entrypoint"');
334
+ }
335
+
336
+ if (typeof code === 'undefined') {
337
+ throw new AppwriteException('Missing required parameter: "code"');
338
+ }
339
+
340
+ if (typeof activate === 'undefined') {
341
+ throw new AppwriteException('Missing required parameter: "activate"');
342
+ }
343
+
344
+ let path = '/functions/{functionId}/deployments'.replace('{functionId}', functionId);
319
345
  let payload = {};
320
346
 
321
- if (typeof data !== 'undefined') {
322
- payload['data'] = data;
347
+ if (typeof entrypoint !== 'undefined') {
348
+ payload['entrypoint'] = entrypoint;
323
349
  }
324
350
 
325
- return await this.client.call('post', path, {
326
- 'content-type': 'application/json',
327
- }, payload);
351
+ if (typeof code !== 'undefined') {
352
+ payload['code'] = code.toString();
353
+ }
354
+
355
+ if (typeof activate !== 'undefined') {
356
+ payload['activate'] = activate.toString();
357
+ }
358
+
359
+ const { size: size } = await promisify(fs.stat)(code);
360
+
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;
370
+
371
+ let counter = 0;
372
+ const totalCounters = Math.ceil(size / client.CHUNK_SIZE);
373
+
374
+ const headers = {
375
+ 'content-type': 'multipart/form-data',
376
+ };
377
+
378
+
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);
382
+
383
+ headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
384
+
385
+ if (id) {
386
+ headers['x-appwrite-id'] = id;
387
+ }
388
+
389
+ const stream = fs.createReadStream(code, {
390
+ start,
391
+ end
392
+ });
393
+ payload['code'] = stream;
394
+
395
+ response = await this.client.call('post', path, headers, payload);
396
+
397
+ if (!id) {
398
+ id = response['$id'];
399
+ }
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
+ });
409
+ }
410
+ }
411
+
412
+ return response;
413
+ }
328
414
  }
329
415
 
330
416
  /**
331
- * Get Execution
417
+ * Get Deployment
332
418
  *
333
- * Get a function execution log by its unique ID.
419
+ * Get a code deployment by its unique ID.
334
420
  *
335
421
  * @param {string} functionId
336
- * @param {string} executionId
422
+ * @param {string} deploymentId
337
423
  * @throws {AppwriteException}
338
424
  * @returns {Promise}
339
425
  */
340
- async getExecution(functionId, executionId) {
426
+ async getDeployment(functionId, deploymentId) {
341
427
  if (typeof functionId === 'undefined') {
342
428
  throw new AppwriteException('Missing required parameter: "functionId"');
343
429
  }
344
430
 
345
- if (typeof executionId === 'undefined') {
346
- throw new AppwriteException('Missing required parameter: "executionId"');
431
+ if (typeof deploymentId === 'undefined') {
432
+ throw new AppwriteException('Missing required parameter: "deploymentId"');
347
433
  }
348
434
 
349
- let path = '/functions/{functionId}/executions/{executionId}'.replace('{functionId}', functionId).replace('{executionId}', executionId);
435
+ let path = '/functions/{functionId}/deployments/{deploymentId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId);
350
436
  let payload = {};
351
437
 
352
438
  return await this.client.call('get', path, {
@@ -355,190 +441,199 @@ class Functions extends Service {
355
441
  }
356
442
 
357
443
  /**
358
- * Update Function Tag
444
+ * Update Function Deployment
359
445
  *
360
- * Update the function code tag ID using the unique function ID. Use this
361
- * endpoint to switch the code tag that should be executed by the execution
362
- * endpoint.
446
+ * Update the function code deployment ID using the unique function ID. Use
447
+ * this endpoint to switch the code deployment that should be executed by the
448
+ * execution endpoint.
363
449
  *
364
450
  * @param {string} functionId
365
- * @param {string} tag
451
+ * @param {string} deploymentId
366
452
  * @throws {AppwriteException}
367
453
  * @returns {Promise}
368
454
  */
369
- async updateTag(functionId, tag) {
455
+ async updateDeployment(functionId, deploymentId) {
370
456
  if (typeof functionId === 'undefined') {
371
457
  throw new AppwriteException('Missing required parameter: "functionId"');
372
458
  }
373
459
 
374
- if (typeof tag === 'undefined') {
375
- throw new AppwriteException('Missing required parameter: "tag"');
460
+ if (typeof deploymentId === 'undefined') {
461
+ throw new AppwriteException('Missing required parameter: "deploymentId"');
376
462
  }
377
463
 
378
- let path = '/functions/{functionId}/tag'.replace('{functionId}', functionId);
464
+ let path = '/functions/{functionId}/deployments/{deploymentId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId);
379
465
  let payload = {};
380
466
 
381
- if (typeof tag !== 'undefined') {
382
- payload['tag'] = tag;
383
- }
384
-
385
467
  return await this.client.call('patch', path, {
386
468
  'content-type': 'application/json',
387
469
  }, payload);
388
470
  }
389
471
 
390
472
  /**
391
- * List Tags
473
+ * Delete Deployment
392
474
  *
393
- * Get a list of all the project's code tags. You can use the query params to
394
- * filter your results.
475
+ * Delete a code deployment by its unique ID.
395
476
  *
396
477
  * @param {string} functionId
397
- * @param {string} search
398
- * @param {number} limit
399
- * @param {number} offset
400
- * @param {string} cursor
401
- * @param {string} cursorDirection
402
- * @param {string} orderType
478
+ * @param {string} deploymentId
403
479
  * @throws {AppwriteException}
404
480
  * @returns {Promise}
405
481
  */
406
- async listTags(functionId, search, limit, offset, cursor, cursorDirection, orderType) {
482
+ async deleteDeployment(functionId, deploymentId) {
407
483
  if (typeof functionId === 'undefined') {
408
484
  throw new AppwriteException('Missing required parameter: "functionId"');
409
485
  }
410
486
 
411
- let path = '/functions/{functionId}/tags'.replace('{functionId}', functionId);
412
- let payload = {};
413
-
414
- if (typeof search !== 'undefined') {
415
- payload['search'] = search;
487
+ if (typeof deploymentId === 'undefined') {
488
+ throw new AppwriteException('Missing required parameter: "deploymentId"');
416
489
  }
417
490
 
418
- if (typeof limit !== 'undefined') {
419
- payload['limit'] = limit;
420
- }
491
+ let path = '/functions/{functionId}/deployments/{deploymentId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId);
492
+ let payload = {};
421
493
 
422
- if (typeof offset !== 'undefined') {
423
- payload['offset'] = offset;
424
- }
494
+ return await this.client.call('delete', path, {
495
+ 'content-type': 'application/json',
496
+ }, payload);
497
+ }
425
498
 
426
- if (typeof cursor !== 'undefined') {
427
- payload['cursor'] = cursor;
499
+ /**
500
+ * Retry Build
501
+ *
502
+ * @param {string} functionId
503
+ * @param {string} deploymentId
504
+ * @param {string} buildId
505
+ * @throws {AppwriteException}
506
+ * @returns {Promise}
507
+ */
508
+ async retryBuild(functionId, deploymentId, buildId) {
509
+ if (typeof functionId === 'undefined') {
510
+ throw new AppwriteException('Missing required parameter: "functionId"');
428
511
  }
429
512
 
430
- if (typeof cursorDirection !== 'undefined') {
431
- payload['cursorDirection'] = cursorDirection;
513
+ if (typeof deploymentId === 'undefined') {
514
+ throw new AppwriteException('Missing required parameter: "deploymentId"');
432
515
  }
433
516
 
434
- if (typeof orderType !== 'undefined') {
435
- payload['orderType'] = orderType;
517
+ if (typeof buildId === 'undefined') {
518
+ throw new AppwriteException('Missing required parameter: "buildId"');
436
519
  }
437
520
 
438
- return await this.client.call('get', path, {
521
+ let path = '/functions/{functionId}/deployments/{deploymentId}/builds/{buildId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId).replace('{buildId}', buildId);
522
+ let payload = {};
523
+
524
+ return await this.client.call('post', path, {
439
525
  'content-type': 'application/json',
440
526
  }, payload);
441
527
  }
442
528
 
443
529
  /**
444
- * Create Tag
530
+ * List Executions
445
531
  *
446
- * Create a new function code tag. Use this endpoint to upload a new version
447
- * of your code function. To execute your newly uploaded code, you'll need to
448
- * update the function's tag to use your new tag UID.
449
- *
450
- * This endpoint accepts a tar.gz file compressed with your code. Make sure to
451
- * include any dependencies your code has within the compressed file. You can
452
- * learn more about code packaging in the [Appwrite Cloud Functions
453
- * tutorial](/docs/functions).
454
- *
455
- * Use the "command" param to set the entry point used to execute your code.
532
+ * Get a list of all the current user function execution logs. You can use the
533
+ * query params to filter your results. On admin mode, this endpoint will
534
+ * return a list of all of the project's executions. [Learn more about
535
+ * different API modes](/docs/admin).
456
536
  *
457
537
  * @param {string} functionId
458
- * @param {string} command
459
- * @param {File} code
538
+ * @param {number} limit
539
+ * @param {number} offset
540
+ * @param {string} search
541
+ * @param {string} cursor
542
+ * @param {string} cursorDirection
460
543
  * @throws {AppwriteException}
461
544
  * @returns {Promise}
462
545
  */
463
- async createTag(functionId, command, code) {
546
+ async listExecutions(functionId, limit, offset, search, cursor, cursorDirection) {
464
547
  if (typeof functionId === 'undefined') {
465
548
  throw new AppwriteException('Missing required parameter: "functionId"');
466
549
  }
467
550
 
468
- if (typeof command === 'undefined') {
469
- throw new AppwriteException('Missing required parameter: "command"');
551
+ let path = '/functions/{functionId}/executions'.replace('{functionId}', functionId);
552
+ let payload = {};
553
+
554
+ if (typeof limit !== 'undefined') {
555
+ payload['limit'] = limit;
470
556
  }
471
557
 
472
- if (typeof code === 'undefined') {
473
- throw new AppwriteException('Missing required parameter: "code"');
558
+ if (typeof offset !== 'undefined') {
559
+ payload['offset'] = offset;
474
560
  }
475
561
 
476
- let path = '/functions/{functionId}/tags'.replace('{functionId}', functionId);
477
- let payload = {};
562
+ if (typeof search !== 'undefined') {
563
+ payload['search'] = search;
564
+ }
478
565
 
479
- if (typeof command !== 'undefined') {
480
- payload['command'] = command;
566
+ if (typeof cursor !== 'undefined') {
567
+ payload['cursor'] = cursor;
481
568
  }
482
569
 
483
- if (typeof code !== 'undefined') {
484
- payload['code'] = code;
570
+ if (typeof cursorDirection !== 'undefined') {
571
+ payload['cursorDirection'] = cursorDirection;
485
572
  }
486
573
 
487
- return await this.client.call('post', path, {
488
- 'content-type': 'multipart/form-data',
574
+ return await this.client.call('get', path, {
575
+ 'content-type': 'application/json',
489
576
  }, payload);
490
577
  }
491
578
 
492
579
  /**
493
- * Get Tag
580
+ * Create Execution
494
581
  *
495
- * Get a code tag by its unique ID.
582
+ * Trigger a function execution. The returned object will return you the
583
+ * current execution status. You can ping the `Get Execution` endpoint to get
584
+ * updates on the current execution status. Once this endpoint is called, your
585
+ * function execution process will start asynchronously.
496
586
  *
497
587
  * @param {string} functionId
498
- * @param {string} tagId
588
+ * @param {string} data
589
+ * @param {boolean} async
499
590
  * @throws {AppwriteException}
500
591
  * @returns {Promise}
501
592
  */
502
- async getTag(functionId, tagId) {
593
+ async createExecution(functionId, data, async) {
503
594
  if (typeof functionId === 'undefined') {
504
595
  throw new AppwriteException('Missing required parameter: "functionId"');
505
596
  }
506
597
 
507
- if (typeof tagId === 'undefined') {
508
- throw new AppwriteException('Missing required parameter: "tagId"');
598
+ let path = '/functions/{functionId}/executions'.replace('{functionId}', functionId);
599
+ let payload = {};
600
+
601
+ if (typeof data !== 'undefined') {
602
+ payload['data'] = data;
509
603
  }
510
604
 
511
- let path = '/functions/{functionId}/tags/{tagId}'.replace('{functionId}', functionId).replace('{tagId}', tagId);
512
- let payload = {};
605
+ if (typeof async !== 'undefined') {
606
+ payload['async'] = async;
607
+ }
513
608
 
514
- return await this.client.call('get', path, {
609
+ return await this.client.call('post', path, {
515
610
  'content-type': 'application/json',
516
611
  }, payload);
517
612
  }
518
613
 
519
614
  /**
520
- * Delete Tag
615
+ * Get Execution
521
616
  *
522
- * Delete a code tag by its unique ID.
617
+ * Get a function execution log by its unique ID.
523
618
  *
524
619
  * @param {string} functionId
525
- * @param {string} tagId
620
+ * @param {string} executionId
526
621
  * @throws {AppwriteException}
527
622
  * @returns {Promise}
528
623
  */
529
- async deleteTag(functionId, tagId) {
624
+ async getExecution(functionId, executionId) {
530
625
  if (typeof functionId === 'undefined') {
531
626
  throw new AppwriteException('Missing required parameter: "functionId"');
532
627
  }
533
628
 
534
- if (typeof tagId === 'undefined') {
535
- throw new AppwriteException('Missing required parameter: "tagId"');
629
+ if (typeof executionId === 'undefined') {
630
+ throw new AppwriteException('Missing required parameter: "executionId"');
536
631
  }
537
632
 
538
- let path = '/functions/{functionId}/tags/{tagId}'.replace('{functionId}', functionId).replace('{tagId}', tagId);
633
+ let path = '/functions/{functionId}/executions/{executionId}'.replace('{functionId}', functionId).replace('{executionId}', executionId);
539
634
  let payload = {};
540
635
 
541
- return await this.client.call('delete', path, {
636
+ return await this.client.call('get', path, {
542
637
  'content-type': 'application/json',
543
638
  }, payload);
544
639
  }
@@ -1,5 +1,8 @@
1
1
  const Service = require('../service.js');
2
2
  const AppwriteException = require('../exception.js');
3
+ const client = require('../client.js');
4
+ const { promisify } = require('util');
5
+ const fs = require('fs');
3
6
 
4
7
  class Health extends Service {
5
8
 
@@ -124,24 +127,6 @@ class Health extends Service {
124
127
  }, payload);
125
128
  }
126
129
 
127
- /**
128
- * Get Usage Queue
129
- *
130
- * Get the number of usage stats that are waiting to be processed in the
131
- * Appwrite internal queue server.
132
- *
133
- * @throws {AppwriteException}
134
- * @returns {Promise}
135
- */
136
- async getQueueUsage() {
137
- let path = '/health/queue/usage';
138
- let payload = {};
139
-
140
- return await this.client.call('get', path, {
141
- 'content-type': 'application/json',
142
- }, payload);
143
- }
144
-
145
130
  /**
146
131
  * Get Webhooks Queue
147
132
  *
@@ -1,5 +1,8 @@
1
1
  const Service = require('../service.js');
2
2
  const AppwriteException = require('../exception.js');
3
+ const client = require('../client.js');
4
+ const { promisify } = require('util');
5
+ const fs = require('fs');
3
6
 
4
7
  class Locale extends Service {
5
8