node-appwrite 4.0.0 → 5.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/functions/{create-tag.md → create-deployment.md} +1 -1
  4. package/docs/examples/functions/{delete-tag.md → delete-deployment.md} +1 -1
  5. package/docs/examples/functions/{update-tag.md → get-deployment.md} +1 -1
  6. package/docs/examples/functions/{list-tags.md → list-deployments.md} +1 -1
  7. package/docs/examples/functions/retry-build.md +20 -0
  8. package/docs/examples/functions/{get-tag.md → update-deployment.md} +1 -1
  9. package/docs/examples/storage/create-bucket.md +20 -0
  10. package/docs/examples/storage/create-file.md +1 -1
  11. package/docs/examples/storage/delete-bucket.md +20 -0
  12. package/docs/examples/storage/delete-file.md +1 -1
  13. package/docs/examples/storage/get-bucket.md +20 -0
  14. package/docs/examples/storage/get-file-download.md +1 -1
  15. package/docs/examples/storage/get-file-preview.md +1 -1
  16. package/docs/examples/storage/get-file-view.md +1 -1
  17. package/docs/examples/storage/get-file.md +1 -1
  18. package/docs/examples/storage/list-buckets.md +20 -0
  19. package/docs/examples/storage/list-files.md +1 -1
  20. package/docs/examples/storage/update-bucket.md +20 -0
  21. package/docs/examples/storage/update-file.md +1 -1
  22. package/index.d.ts +411 -151
  23. package/index.js +3 -1
  24. package/lib/client.js +7 -5
  25. package/lib/exception.js +2 -1
  26. package/lib/query.js +2 -0
  27. package/lib/services/account.js +28 -3
  28. package/lib/services/avatars.js +3 -0
  29. package/lib/services/database.js +6 -3
  30. package/lib/services/functions.js +207 -116
  31. package/lib/services/health.js +3 -0
  32. package/lib/services/locale.js +3 -0
  33. package/lib/services/storage.js +379 -33
  34. package/lib/services/teams.js +7 -0
  35. package/lib/services/users.js +6 -2
  36. package/package.json +2 -2
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const Client = require('./lib/client.js');
2
+ const Query = require('./lib/query.js');
2
3
  const AppwriteException = require('./lib/exception.js');
3
4
  const Account = require('./lib/services/account.js');
4
5
  const Avatars = require('./lib/services/avatars.js');
@@ -12,6 +13,7 @@ const Users = require('./lib/services/users.js');
12
13
 
13
14
  module.exports = {
14
15
  Client,
16
+ Query,
15
17
  AppwriteException,
16
18
  Account,
17
19
  Avatars,
@@ -22,4 +24,4 @@ module.exports = {
22
24
  Storage,
23
25
  Teams,
24
26
  Users,
25
- };
27
+ };
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.0',
13
- 'X-Appwrite-Response-Format' : '0.12.0',
13
+ 'x-sdk-version': 'appwrite:nodejs:5.0.0',
14
+ 'X-Appwrite-Response-Format' : '0.13.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
  }
package/lib/query.js CHANGED
@@ -32,3 +32,5 @@ class Query {
32
32
  ? `"${value}"`
33
33
  : `${value}`;
34
34
  }
35
+
36
+ module.exports = Query;
@@ -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
 
@@ -190,8 +193,9 @@ class Account extends Service {
190
193
  /**
191
194
  * Update Account Preferences
192
195
  *
193
- * Update currently logged in user account preferences. You can pass only the
194
- * specific settings you wish to update.
196
+ * Update currently logged in user account preferences. The object you pass is
197
+ * stored as is, and replaces any previous value. The maximum allowed prefs
198
+ * size is 64kB and throws error if exceeded.
195
199
  *
196
200
  * @param {object} prefs
197
201
  * @throws {AppwriteException}
@@ -376,12 +380,33 @@ class Account extends Service {
376
380
  }, payload);
377
381
  }
378
382
 
383
+ /**
384
+ * Update Session (Refresh Tokens)
385
+ *
386
+ * @param {string} sessionId
387
+ * @throws {AppwriteException}
388
+ * @returns {Promise}
389
+ */
390
+ async updateSession(sessionId) {
391
+ if (typeof sessionId === 'undefined') {
392
+ throw new AppwriteException('Missing required parameter: "sessionId"');
393
+ }
394
+
395
+ let path = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId);
396
+ let payload = {};
397
+
398
+ return await this.client.call('patch', path, {
399
+ 'content-type': 'application/json',
400
+ }, payload);
401
+ }
402
+
379
403
  /**
380
404
  * Delete Account Session
381
405
  *
382
406
  * Use this endpoint to log out the currently logged in user from all their
383
407
  * account sessions across all of their different devices. When using the
384
- * option id argument, only the session unique ID provider will be deleted.
408
+ * Session ID argument, only the unique session ID provided is deleted.
409
+ *
385
410
  *
386
411
  * @param {string} sessionId
387
412
  * @throws {AppwriteException}
@@ -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
 
@@ -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}