node-appwrite 7.0.0 → 8.0.0-RC1

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 (69) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +2 -2
  3. package/docs/examples/databases/create-boolean-attribute.md +2 -2
  4. package/docs/examples/databases/create-collection.md +2 -2
  5. package/docs/examples/databases/create-datetime-attribute.md +20 -0
  6. package/docs/examples/databases/create-document.md +2 -2
  7. package/docs/examples/databases/create-email-attribute.md +2 -2
  8. package/docs/examples/databases/create-enum-attribute.md +2 -2
  9. package/docs/examples/databases/create-float-attribute.md +2 -2
  10. package/docs/examples/databases/create-index.md +2 -2
  11. package/docs/examples/databases/create-integer-attribute.md +2 -2
  12. package/docs/examples/databases/create-ip-attribute.md +2 -2
  13. package/docs/examples/databases/create-string-attribute.md +2 -2
  14. package/docs/examples/databases/create-url-attribute.md +2 -2
  15. package/docs/examples/databases/create.md +2 -2
  16. package/docs/examples/databases/delete-attribute.md +2 -2
  17. package/docs/examples/databases/delete-collection.md +2 -2
  18. package/docs/examples/databases/delete-document.md +2 -2
  19. package/docs/examples/databases/delete-index.md +2 -2
  20. package/docs/examples/databases/delete.md +2 -2
  21. package/docs/examples/databases/get-attribute.md +2 -2
  22. package/docs/examples/databases/get-collection.md +2 -2
  23. package/docs/examples/databases/get-document.md +2 -2
  24. package/docs/examples/databases/get-index.md +2 -2
  25. package/docs/examples/databases/get.md +2 -2
  26. package/docs/examples/databases/list-attributes.md +2 -2
  27. package/docs/examples/databases/list-collections.md +2 -2
  28. package/docs/examples/databases/list-documents.md +2 -2
  29. package/docs/examples/databases/list-indexes.md +2 -2
  30. package/docs/examples/databases/list.md +1 -1
  31. package/docs/examples/databases/update-collection.md +2 -2
  32. package/docs/examples/databases/update-document.md +2 -2
  33. package/docs/examples/databases/update.md +2 -2
  34. package/docs/examples/functions/create-deployment.md +1 -1
  35. package/docs/examples/functions/create-variable.md +20 -0
  36. package/docs/examples/functions/create.md +1 -1
  37. package/docs/examples/functions/delete-variable.md +20 -0
  38. package/docs/examples/functions/get-variable.md +20 -0
  39. package/docs/examples/functions/list-variables.md +20 -0
  40. package/docs/examples/functions/update-variable.md +20 -0
  41. package/docs/examples/functions/update.md +1 -1
  42. package/docs/examples/storage/create-bucket.md +1 -1
  43. package/docs/examples/storage/create-file.md +1 -1
  44. package/docs/examples/storage/update-bucket.md +1 -1
  45. package/docs/examples/users/create-argon2user.md +20 -0
  46. package/docs/examples/users/create-bcrypt-user.md +20 -0
  47. package/docs/examples/users/create-m-d5user.md +20 -0
  48. package/docs/examples/users/create-p-h-pass-user.md +20 -0
  49. package/docs/examples/users/create-s-h-a-user.md +20 -0
  50. package/docs/examples/users/create-scrypt-modified-user.md +20 -0
  51. package/docs/examples/users/create-scrypt-user.md +20 -0
  52. package/docs/examples/users/create.md +1 -1
  53. package/index.d.ts +703 -235
  54. package/index.js +6 -0
  55. package/lib/client.js +5 -2
  56. package/lib/id.js +12 -0
  57. package/lib/permission.js +24 -0
  58. package/lib/query.js +30 -12
  59. package/lib/role.js +25 -0
  60. package/lib/services/account.js +53 -52
  61. package/lib/services/avatars.js +22 -20
  62. package/lib/services/databases.js +385 -243
  63. package/lib/services/functions.js +220 -110
  64. package/lib/services/health.js +7 -1
  65. package/lib/services/locale.js +7 -1
  66. package/lib/services/storage.js +78 -129
  67. package/lib/services/teams.js +39 -73
  68. package/lib/services/users.js +482 -63
  69. package/package.json +1 -1
@@ -8,47 +8,33 @@ const fs = require('fs');
8
8
 
9
9
  class Storage extends Service {
10
10
 
11
+ constructor(client)
12
+ {
13
+ super(client);
14
+ }
15
+
16
+
11
17
  /**
12
18
  * List buckets
13
19
  *
14
20
  * Get a list of all the storage buckets. You can use the query params to
15
21
  * filter your results.
16
22
  *
23
+ * @param {string[]} queries
17
24
  * @param {string} search
18
- * @param {number} limit
19
- * @param {number} offset
20
- * @param {string} cursor
21
- * @param {string} cursorDirection
22
- * @param {string} orderType
23
25
  * @throws {AppwriteException}
24
26
  * @returns {Promise}
25
27
  */
26
- async listBuckets(search, limit, offset, cursor, cursorDirection, orderType) {
28
+ async listBuckets(queries, search) {
27
29
  let path = '/storage/buckets';
28
30
  let payload = {};
29
31
 
30
- if (typeof search !== 'undefined') {
31
- payload['search'] = search;
32
- }
33
-
34
- if (typeof limit !== 'undefined') {
35
- payload['limit'] = limit;
36
- }
37
-
38
- if (typeof offset !== 'undefined') {
39
- payload['offset'] = offset;
40
- }
41
-
42
- if (typeof cursor !== 'undefined') {
43
- payload['cursor'] = cursor;
44
- }
45
-
46
- if (typeof cursorDirection !== 'undefined') {
47
- payload['cursorDirection'] = cursorDirection;
32
+ if (typeof queries !== 'undefined') {
33
+ payload['queries'] = queries;
48
34
  }
49
35
 
50
- if (typeof orderType !== 'undefined') {
51
- payload['orderType'] = orderType;
36
+ if (typeof search !== 'undefined') {
37
+ payload['search'] = search;
52
38
  }
53
39
 
54
40
  return await this.client.call('get', path, {
@@ -63,18 +49,20 @@ class Storage extends Service {
63
49
  *
64
50
  * @param {string} bucketId
65
51
  * @param {string} name
66
- * @param {string} permission
67
- * @param {string[]} read
68
- * @param {string[]} write
52
+ * @param {string[]} permissions
53
+ * @param {boolean} fileSecurity
69
54
  * @param {boolean} enabled
70
55
  * @param {number} maximumFileSize
71
56
  * @param {string[]} allowedFileExtensions
57
+ * @param {string} compression
72
58
  * @param {boolean} encryption
73
59
  * @param {boolean} antivirus
74
60
  * @throws {AppwriteException}
75
61
  * @returns {Promise}
76
62
  */
77
- async createBucket(bucketId, name, permission, read, write, enabled, maximumFileSize, allowedFileExtensions, encryption, antivirus) {
63
+ async createBucket(bucketId, name, permissions, fileSecurity, enabled, maximumFileSize, allowedFileExtensions, compression, encryption, antivirus) {
64
+ let path = '/storage/buckets';
65
+ let payload = {};
78
66
  if (typeof bucketId === 'undefined') {
79
67
  throw new AppwriteException('Missing required parameter: "bucketId"');
80
68
  }
@@ -83,12 +71,6 @@ class Storage extends Service {
83
71
  throw new AppwriteException('Missing required parameter: "name"');
84
72
  }
85
73
 
86
- if (typeof permission === 'undefined') {
87
- throw new AppwriteException('Missing required parameter: "permission"');
88
- }
89
-
90
- let path = '/storage/buckets';
91
- let payload = {};
92
74
 
93
75
  if (typeof bucketId !== 'undefined') {
94
76
  payload['bucketId'] = bucketId;
@@ -98,16 +80,12 @@ class Storage extends Service {
98
80
  payload['name'] = name;
99
81
  }
100
82
 
101
- if (typeof permission !== 'undefined') {
102
- payload['permission'] = permission;
83
+ if (typeof permissions !== 'undefined') {
84
+ payload['permissions'] = permissions;
103
85
  }
104
86
 
105
- if (typeof read !== 'undefined') {
106
- payload['read'] = read;
107
- }
108
-
109
- if (typeof write !== 'undefined') {
110
- payload['write'] = write;
87
+ if (typeof fileSecurity !== 'undefined') {
88
+ payload['fileSecurity'] = fileSecurity;
111
89
  }
112
90
 
113
91
  if (typeof enabled !== 'undefined') {
@@ -122,6 +100,10 @@ class Storage extends Service {
122
100
  payload['allowedFileExtensions'] = allowedFileExtensions;
123
101
  }
124
102
 
103
+ if (typeof compression !== 'undefined') {
104
+ payload['compression'] = compression;
105
+ }
106
+
125
107
  if (typeof encryption !== 'undefined') {
126
108
  payload['encryption'] = encryption;
127
109
  }
@@ -146,12 +128,12 @@ class Storage extends Service {
146
128
  * @returns {Promise}
147
129
  */
148
130
  async getBucket(bucketId) {
131
+ let path = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId);
132
+ let payload = {};
149
133
  if (typeof bucketId === 'undefined') {
150
134
  throw new AppwriteException('Missing required parameter: "bucketId"');
151
135
  }
152
136
 
153
- let path = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId);
154
- let payload = {};
155
137
 
156
138
  return await this.client.call('get', path, {
157
139
  'content-type': 'application/json',
@@ -165,18 +147,20 @@ class Storage extends Service {
165
147
  *
166
148
  * @param {string} bucketId
167
149
  * @param {string} name
168
- * @param {string} permission
169
- * @param {string[]} read
170
- * @param {string[]} write
150
+ * @param {string[]} permissions
151
+ * @param {boolean} fileSecurity
171
152
  * @param {boolean} enabled
172
153
  * @param {number} maximumFileSize
173
154
  * @param {string[]} allowedFileExtensions
155
+ * @param {string} compression
174
156
  * @param {boolean} encryption
175
157
  * @param {boolean} antivirus
176
158
  * @throws {AppwriteException}
177
159
  * @returns {Promise}
178
160
  */
179
- async updateBucket(bucketId, name, permission, read, write, enabled, maximumFileSize, allowedFileExtensions, encryption, antivirus) {
161
+ async updateBucket(bucketId, name, permissions, fileSecurity, enabled, maximumFileSize, allowedFileExtensions, compression, encryption, antivirus) {
162
+ let path = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId);
163
+ let payload = {};
180
164
  if (typeof bucketId === 'undefined') {
181
165
  throw new AppwriteException('Missing required parameter: "bucketId"');
182
166
  }
@@ -185,27 +169,17 @@ class Storage extends Service {
185
169
  throw new AppwriteException('Missing required parameter: "name"');
186
170
  }
187
171
 
188
- if (typeof permission === 'undefined') {
189
- throw new AppwriteException('Missing required parameter: "permission"');
190
- }
191
-
192
- let path = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId);
193
- let payload = {};
194
172
 
195
173
  if (typeof name !== 'undefined') {
196
174
  payload['name'] = name;
197
175
  }
198
176
 
199
- if (typeof permission !== 'undefined') {
200
- payload['permission'] = permission;
177
+ if (typeof permissions !== 'undefined') {
178
+ payload['permissions'] = permissions;
201
179
  }
202
180
 
203
- if (typeof read !== 'undefined') {
204
- payload['read'] = read;
205
- }
206
-
207
- if (typeof write !== 'undefined') {
208
- payload['write'] = write;
181
+ if (typeof fileSecurity !== 'undefined') {
182
+ payload['fileSecurity'] = fileSecurity;
209
183
  }
210
184
 
211
185
  if (typeof enabled !== 'undefined') {
@@ -220,6 +194,10 @@ class Storage extends Service {
220
194
  payload['allowedFileExtensions'] = allowedFileExtensions;
221
195
  }
222
196
 
197
+ if (typeof compression !== 'undefined') {
198
+ payload['compression'] = compression;
199
+ }
200
+
223
201
  if (typeof encryption !== 'undefined') {
224
202
  payload['encryption'] = encryption;
225
203
  }
@@ -243,12 +221,12 @@ class Storage extends Service {
243
221
  * @returns {Promise}
244
222
  */
245
223
  async deleteBucket(bucketId) {
224
+ let path = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId);
225
+ let payload = {};
246
226
  if (typeof bucketId === 'undefined') {
247
227
  throw new AppwriteException('Missing required parameter: "bucketId"');
248
228
  }
249
229
 
250
- let path = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId);
251
- let payload = {};
252
230
 
253
231
  return await this.client.call('delete', path, {
254
232
  'content-type': 'application/json',
@@ -263,45 +241,25 @@ class Storage extends Service {
263
241
  * project's files. [Learn more about different API modes](/docs/admin).
264
242
  *
265
243
  * @param {string} bucketId
244
+ * @param {string[]} queries
266
245
  * @param {string} search
267
- * @param {number} limit
268
- * @param {number} offset
269
- * @param {string} cursor
270
- * @param {string} cursorDirection
271
- * @param {string} orderType
272
246
  * @throws {AppwriteException}
273
247
  * @returns {Promise}
274
248
  */
275
- async listFiles(bucketId, search, limit, offset, cursor, cursorDirection, orderType) {
276
- if (typeof bucketId === 'undefined') {
277
- throw new AppwriteException('Missing required parameter: "bucketId"');
278
- }
279
-
249
+ async listFiles(bucketId, queries, search) {
280
250
  let path = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
281
251
  let payload = {};
282
-
283
- if (typeof search !== 'undefined') {
284
- payload['search'] = search;
285
- }
286
-
287
- if (typeof limit !== 'undefined') {
288
- payload['limit'] = limit;
289
- }
290
-
291
- if (typeof offset !== 'undefined') {
292
- payload['offset'] = offset;
252
+ if (typeof bucketId === 'undefined') {
253
+ throw new AppwriteException('Missing required parameter: "bucketId"');
293
254
  }
294
255
 
295
- if (typeof cursor !== 'undefined') {
296
- payload['cursor'] = cursor;
297
- }
298
256
 
299
- if (typeof cursorDirection !== 'undefined') {
300
- payload['cursorDirection'] = cursorDirection;
257
+ if (typeof queries !== 'undefined') {
258
+ payload['queries'] = queries;
301
259
  }
302
260
 
303
- if (typeof orderType !== 'undefined') {
304
- payload['orderType'] = orderType;
261
+ if (typeof search !== 'undefined') {
262
+ payload['search'] = search;
305
263
  }
306
264
 
307
265
  return await this.client.call('get', path, {
@@ -314,8 +272,8 @@ class Storage extends Service {
314
272
  *
315
273
  * Create a new file. Before using this route, you should create a new bucket
316
274
  * resource using either a [server
317
- * integration](/docs/server/database#storageCreateBucket) API or directly
318
- * from your Appwrite console.
275
+ * integration](/docs/server/storage#storageCreateBucket) API or directly from
276
+ * your Appwrite console.
319
277
  *
320
278
  * Larger files should be uploaded using multiple requests with the
321
279
  * [content-range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range)
@@ -334,12 +292,13 @@ class Storage extends Service {
334
292
  * @param {string} bucketId
335
293
  * @param {string} fileId
336
294
  * @param {InputFile} file
337
- * @param {string[]} read
338
- * @param {string[]} write
295
+ * @param {string[]} permissions
339
296
  * @throws {AppwriteException}
340
297
  * @returns {Promise}
341
298
  */
342
- async createFile(bucketId, fileId, file, read, write, onProgress = () => {}) {
299
+ async createFile(bucketId, fileId, file, permissions, onProgress = () => {}) {
300
+ let path = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
301
+ let payload = {};
343
302
  if (typeof bucketId === 'undefined') {
344
303
  throw new AppwriteException('Missing required parameter: "bucketId"');
345
304
  }
@@ -352,8 +311,6 @@ class Storage extends Service {
352
311
  throw new AppwriteException('Missing required parameter: "file"');
353
312
  }
354
313
 
355
- let path = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
356
- let payload = {};
357
314
 
358
315
  if (typeof fileId !== 'undefined') {
359
316
  payload['fileId'] = fileId;
@@ -363,12 +320,8 @@ class Storage extends Service {
363
320
  payload['file'] = file;
364
321
  }
365
322
 
366
- if (typeof read !== 'undefined') {
367
- payload['read'] = read;
368
- }
369
-
370
- if (typeof write !== 'undefined') {
371
- payload['write'] = write;
323
+ if (typeof permissions !== 'undefined') {
324
+ payload['permissions'] = permissions;
372
325
  }
373
326
 
374
327
  const size = file.size;
@@ -489,6 +442,7 @@ class Storage extends Service {
489
442
 
490
443
  file.stream.pipe(writeStream);
491
444
  });
445
+
492
446
  }
493
447
 
494
448
  /**
@@ -503,6 +457,8 @@ class Storage extends Service {
503
457
  * @returns {Promise}
504
458
  */
505
459
  async getFile(bucketId, fileId) {
460
+ let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
461
+ let payload = {};
506
462
  if (typeof bucketId === 'undefined') {
507
463
  throw new AppwriteException('Missing required parameter: "bucketId"');
508
464
  }
@@ -511,8 +467,6 @@ class Storage extends Service {
511
467
  throw new AppwriteException('Missing required parameter: "fileId"');
512
468
  }
513
469
 
514
- let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
515
- let payload = {};
516
470
 
517
471
  return await this.client.call('get', path, {
518
472
  'content-type': 'application/json',
@@ -527,12 +481,13 @@ class Storage extends Service {
527
481
  *
528
482
  * @param {string} bucketId
529
483
  * @param {string} fileId
530
- * @param {string[]} read
531
- * @param {string[]} write
484
+ * @param {string[]} permissions
532
485
  * @throws {AppwriteException}
533
486
  * @returns {Promise}
534
487
  */
535
- async updateFile(bucketId, fileId, read, write) {
488
+ async updateFile(bucketId, fileId, permissions) {
489
+ let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
490
+ let payload = {};
536
491
  if (typeof bucketId === 'undefined') {
537
492
  throw new AppwriteException('Missing required parameter: "bucketId"');
538
493
  }
@@ -541,15 +496,9 @@ class Storage extends Service {
541
496
  throw new AppwriteException('Missing required parameter: "fileId"');
542
497
  }
543
498
 
544
- let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
545
- let payload = {};
546
-
547
- if (typeof read !== 'undefined') {
548
- payload['read'] = read;
549
- }
550
499
 
551
- if (typeof write !== 'undefined') {
552
- payload['write'] = write;
500
+ if (typeof permissions !== 'undefined') {
501
+ payload['permissions'] = permissions;
553
502
  }
554
503
 
555
504
  return await this.client.call('put', path, {
@@ -569,6 +518,8 @@ class Storage extends Service {
569
518
  * @returns {Promise}
570
519
  */
571
520
  async deleteFile(bucketId, fileId) {
521
+ let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
522
+ let payload = {};
572
523
  if (typeof bucketId === 'undefined') {
573
524
  throw new AppwriteException('Missing required parameter: "bucketId"');
574
525
  }
@@ -577,8 +528,6 @@ class Storage extends Service {
577
528
  throw new AppwriteException('Missing required parameter: "fileId"');
578
529
  }
579
530
 
580
- let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
581
- let payload = {};
582
531
 
583
532
  return await this.client.call('delete', path, {
584
533
  'content-type': 'application/json',
@@ -598,6 +547,8 @@ class Storage extends Service {
598
547
  * @returns {Promise}
599
548
  */
600
549
  async getFileDownload(bucketId, fileId) {
550
+ let path = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
551
+ let payload = {};
601
552
  if (typeof bucketId === 'undefined') {
602
553
  throw new AppwriteException('Missing required parameter: "bucketId"');
603
554
  }
@@ -606,8 +557,6 @@ class Storage extends Service {
606
557
  throw new AppwriteException('Missing required parameter: "fileId"');
607
558
  }
608
559
 
609
- let path = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
610
- let payload = {};
611
560
 
612
561
  return await this.client.call('get', path, {
613
562
  'content-type': 'application/json',
@@ -640,6 +589,8 @@ class Storage extends Service {
640
589
  * @returns {Promise}
641
590
  */
642
591
  async getFilePreview(bucketId, fileId, width, height, gravity, quality, borderWidth, borderColor, borderRadius, opacity, rotation, background, output) {
592
+ let path = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
593
+ let payload = {};
643
594
  if (typeof bucketId === 'undefined') {
644
595
  throw new AppwriteException('Missing required parameter: "bucketId"');
645
596
  }
@@ -648,8 +599,6 @@ class Storage extends Service {
648
599
  throw new AppwriteException('Missing required parameter: "fileId"');
649
600
  }
650
601
 
651
- let path = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
652
- let payload = {};
653
602
 
654
603
  if (typeof width !== 'undefined') {
655
604
  payload['width'] = width;
@@ -713,6 +662,8 @@ class Storage extends Service {
713
662
  * @returns {Promise}
714
663
  */
715
664
  async getFileView(bucketId, fileId) {
665
+ let path = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
666
+ let payload = {};
716
667
  if (typeof bucketId === 'undefined') {
717
668
  throw new AppwriteException('Missing required parameter: "bucketId"');
718
669
  }
@@ -721,8 +672,6 @@ class Storage extends Service {
721
672
  throw new AppwriteException('Missing required parameter: "fileId"');
722
673
  }
723
674
 
724
- let path = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
725
- let payload = {};
726
675
 
727
676
  return await this.client.call('get', path, {
728
677
  'content-type': 'application/json',
@@ -730,4 +679,4 @@ class Storage extends Service {
730
679
  }
731
680
  }
732
681
 
733
- module.exports = Storage;
682
+ module.exports = Storage;