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
package/lib/client.js CHANGED
@@ -4,13 +4,14 @@ const FormData = require('form-data');
4
4
  const AppwriteException = require('./exception.js');
5
5
 
6
6
  class Client {
7
+ static CHUNK_SIZE = 5*1024*1024; // 5MB
7
8
 
8
9
  constructor() {
9
10
  this.endpoint = 'https://HOSTNAME/v1';
10
11
  this.headers = {
11
12
  'content-type': '',
12
- 'x-sdk-version': 'appwrite:nodejs:4.0.2',
13
- 'X-Appwrite-Response-Format' : '0.12.0',
13
+ 'x-sdk-version': 'appwrite:nodejs:6.0.0',
14
+ 'X-Appwrite-Response-Format' : '0.14.0',
14
15
  };
15
16
  this.selfSigned = false;
16
17
  }
@@ -115,7 +116,8 @@ class Client {
115
116
  process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
116
117
  }
117
118
 
118
- headers = Object.assign(this.headers, headers);
119
+
120
+ headers = Object.assign({}, this.headers, headers);
119
121
 
120
122
  let contentType = headers['content-type'].toLowerCase();
121
123
 
@@ -155,9 +157,9 @@ class Client {
155
157
  if('response' in error && error.response !== undefined) {
156
158
  if(error.response && 'data' in error.response) {
157
159
  if (typeof(error.response.data) === 'string') {
158
- throw new AppwriteException(error.response.data, error.response.status, error.response.data);
160
+ throw new AppwriteException(error.response.data, error.response.status, '', error.response.data);
159
161
  } else {
160
- throw new AppwriteException(error.response.data.message, error.response.status, error.response.data);
162
+ throw new AppwriteException(error.response.data.message, error.response.status, error.response.data.type, error.response.data);
161
163
  }
162
164
  } else {
163
165
  throw new AppwriteException(error.response.statusText, error.response.status, error.response.data);
package/lib/exception.js CHANGED
@@ -1,7 +1,8 @@
1
1
  class AppwriteException extends Error {
2
- constructor(message, code, response) {
2
+ constructor(message, code, type, response) {
3
3
  super(message);
4
4
  this.code = code;
5
+ this.type = type;
5
6
  this.response = response;
6
7
  }
7
8
  }
@@ -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 Account extends Service {
5
8
 
@@ -20,27 +23,6 @@ class Account extends Service {
20
23
  }, payload);
21
24
  }
22
25
 
23
- /**
24
- * Delete Account
25
- *
26
- * Delete a currently logged in user account. Behind the scene, the user
27
- * record is not deleted but permanently blocked from any access. This is done
28
- * to avoid deleted accounts being overtaken by new users with the same email
29
- * address. Any user-related resources like documents or storage files should
30
- * be deleted separately.
31
- *
32
- * @throws {AppwriteException}
33
- * @returns {Promise}
34
- */
35
- async delete() {
36
- let path = '/account';
37
- let payload = {};
38
-
39
- return await this.client.call('delete', path, {
40
- 'content-type': 'application/json',
41
- }, payload);
42
- }
43
-
44
26
  /**
45
27
  * Update Account Email
46
28
  *
@@ -142,7 +124,7 @@ class Account extends Service {
142
124
  *
143
125
  * Update currently logged in user password. For validation, user is required
144
126
  * to pass in the new password, and the old password. For users created with
145
- * OAuth and Team Invites, oldPassword is optional.
127
+ * OAuth, Team Invites and Magic URL, oldPassword is optional.
146
128
  *
147
129
  * @param {string} password
148
130
  * @param {string} oldPassword
@@ -377,12 +359,37 @@ class Account extends Service {
377
359
  }, payload);
378
360
  }
379
361
 
362
+ /**
363
+ * Update Session (Refresh Tokens)
364
+ *
365
+ * Access tokens have limited lifespan and expire to mitigate security risks.
366
+ * If session was created using an OAuth provider, this route can be used to
367
+ * "refresh" the access token.
368
+ *
369
+ * @param {string} sessionId
370
+ * @throws {AppwriteException}
371
+ * @returns {Promise}
372
+ */
373
+ async updateSession(sessionId) {
374
+ if (typeof sessionId === 'undefined') {
375
+ throw new AppwriteException('Missing required parameter: "sessionId"');
376
+ }
377
+
378
+ let path = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId);
379
+ let payload = {};
380
+
381
+ return await this.client.call('patch', path, {
382
+ 'content-type': 'application/json',
383
+ }, payload);
384
+ }
385
+
380
386
  /**
381
387
  * Delete Account Session
382
388
  *
383
389
  * Use this endpoint to log out the currently logged in user from all their
384
390
  * account sessions across all of their different devices. When using the
385
- * option id argument, only the session unique ID provider will be deleted.
391
+ * Session ID argument, only the unique session ID provided is deleted.
392
+ *
386
393
  *
387
394
  * @param {string} sessionId
388
395
  * @throws {AppwriteException}
@@ -401,6 +408,25 @@ class Account extends Service {
401
408
  }, payload);
402
409
  }
403
410
 
411
+ /**
412
+ * Update Account Status
413
+ *
414
+ * Block the currently logged in user account. Behind the scene, the user
415
+ * record is not deleted but permanently blocked from any access. To
416
+ * completely delete a user, use the Users API instead.
417
+ *
418
+ * @throws {AppwriteException}
419
+ * @returns {Promise}
420
+ */
421
+ async updateStatus() {
422
+ let path = '/account/status';
423
+ let payload = {};
424
+
425
+ return await this.client.call('patch', path, {
426
+ 'content-type': 'application/json',
427
+ }, payload);
428
+ }
429
+
404
430
  /**
405
431
  * Create Email Verification
406
432
  *
@@ -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 Avatars extends Service {
5
8
 
@@ -7,9 +10,14 @@ class Avatars extends Service {
7
10
  * Get Browser Icon
8
11
  *
9
12
  * You can use this endpoint to show different browser icons to your users.
10
- * The code argument receives the browser code as it appears in your user
11
- * /account/sessions endpoint. Use width, height and quality arguments to
12
- * change the output settings.
13
+ * The code argument receives the browser code as it appears in your user [GET
14
+ * /account/sessions](/docs/client/account#accountGetSessions) endpoint. Use
15
+ * width, height and quality arguments to change the output settings.
16
+ *
17
+ * When one dimension is specified and the other is 0, the image is scaled
18
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
19
+ * image at source quality. If dimensions are not specified, the default size
20
+ * of image returned is 100x100px.
13
21
  *
14
22
  * @param {string} code
15
23
  * @param {number} width
@@ -49,6 +57,12 @@ class Avatars extends Service {
49
57
  * The credit card endpoint will return you the icon of the credit card
50
58
  * provider you need. Use width, height and quality arguments to change the
51
59
  * output settings.
60
+ *
61
+ * When one dimension is specified and the other is 0, the image is scaled
62
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
63
+ * image at source quality. If dimensions are not specified, the default size
64
+ * of image returned is 100x100px.
65
+ *
52
66
  *
53
67
  * @param {string} code
54
68
  * @param {number} width
@@ -116,6 +130,12 @@ class Avatars extends Service {
116
130
  * You can use this endpoint to show different country flags icons to your
117
131
  * users. The code argument receives the 2 letter country code. Use width,
118
132
  * height and quality arguments to change the output settings.
133
+ *
134
+ * When one dimension is specified and the other is 0, the image is scaled
135
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
136
+ * image at source quality. If dimensions are not specified, the default size
137
+ * of image returned is 100x100px.
138
+ *
119
139
  *
120
140
  * @param {string} code
121
141
  * @param {number} width
@@ -156,6 +176,12 @@ class Avatars extends Service {
156
176
  * you want. This endpoint is very useful if you need to crop and display
157
177
  * remote images in your app or in case you want to make sure a 3rd party
158
178
  * image is properly served using a TLS protocol.
179
+ *
180
+ * When one dimension is specified and the other is 0, the image is scaled
181
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
182
+ * image at source quality. If dimensions are not specified, the default size
183
+ * of image returned is 400x400px.
184
+ *
159
185
  *
160
186
  * @param {string} url
161
187
  * @param {number} width
@@ -201,6 +227,12 @@ class Avatars extends Service {
201
227
  * default, a random theme will be selected. The random theme will persist for
202
228
  * the user's initials when reloading the same theme will always return for
203
229
  * the same initials.
230
+ *
231
+ * When one dimension is specified and the other is 0, the image is scaled
232
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
233
+ * image at source quality. If dimensions are not specified, the default size
234
+ * of image returned is 100x100px.
235
+ *
204
236
  *
205
237
  * @param {string} name
206
238
  * @param {number} width
@@ -244,6 +276,7 @@ class Avatars extends Service {
244
276
  *
245
277
  * Converts a given plain text to a QR code image. You can use the query
246
278
  * parameters to change the size and style of the resulting image.
279
+ *
247
280
  *
248
281
  * @param {string} text
249
282
  * @param {number} size
@@ -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 Database extends Service {
5
8
 
@@ -405,9 +408,9 @@ class Database extends Service {
405
408
  * @param {string} collectionId
406
409
  * @param {string} key
407
410
  * @param {boolean} required
408
- * @param {string} min
409
- * @param {string} max
410
- * @param {string} xdefault
411
+ * @param {number} min
412
+ * @param {number} max
413
+ * @param {number} xdefault
411
414
  * @param {boolean} array
412
415
  * @throws {AppwriteException}
413
416
  * @returns {Promise}
@@ -922,9 +925,7 @@ class Database extends Service {
922
925
  /**
923
926
  * Delete Document
924
927
  *
925
- * Delete a document by its unique ID. This endpoint deletes only the parent
926
- * documents, its attributes and relations to other documents. Child documents
927
- * **will not** be deleted.
928
+ * Delete a document by its unique ID.
928
929
  *
929
930
  * @param {string} collectionId
930
931
  * @param {string} documentId