node-appwrite 2.4.0 → 4.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 (46) hide show
  1. package/.github/ISSUE_TEMPLATE/bug.yaml +82 -0
  2. package/.github/ISSUE_TEMPLATE/documentation.yaml +32 -0
  3. package/.github/ISSUE_TEMPLATE/feature.yaml +40 -0
  4. package/LICENSE +1 -1
  5. package/README.md +7 -7
  6. package/docs/examples/database/create-boolean-attribute.md +20 -0
  7. package/docs/examples/database/create-collection.md +1 -1
  8. package/docs/examples/database/create-document.md +1 -1
  9. package/docs/examples/database/create-email-attribute.md +20 -0
  10. package/docs/examples/database/create-enum-attribute.md +20 -0
  11. package/docs/examples/database/create-float-attribute.md +20 -0
  12. package/docs/examples/database/create-index.md +20 -0
  13. package/docs/examples/database/create-integer-attribute.md +20 -0
  14. package/docs/examples/database/create-ip-attribute.md +20 -0
  15. package/docs/examples/database/create-string-attribute.md +20 -0
  16. package/docs/examples/database/create-url-attribute.md +20 -0
  17. package/docs/examples/database/delete-attribute.md +20 -0
  18. package/docs/examples/database/delete-index.md +20 -0
  19. package/docs/examples/database/get-attribute.md +20 -0
  20. package/docs/examples/database/get-index.md +20 -0
  21. package/docs/examples/database/list-attributes.md +20 -0
  22. package/docs/examples/database/list-indexes.md +20 -0
  23. package/docs/examples/database/update-collection.md +1 -1
  24. package/docs/examples/functions/create-tag.md +1 -1
  25. package/docs/examples/functions/create.md +1 -1
  26. package/docs/examples/{health/get-queue-tasks.md → functions/list-runtimes.md} +2 -2
  27. package/docs/examples/health/{get-anti-virus.md → get-antivirus.md} +1 -1
  28. package/docs/examples/storage/create-file.md +1 -1
  29. package/docs/examples/teams/create.md +1 -1
  30. package/docs/examples/teams/get-membership.md +20 -0
  31. package/docs/examples/users/create.md +1 -1
  32. package/docs/examples/users/update-email.md +20 -0
  33. package/docs/examples/users/update-name.md +20 -0
  34. package/docs/examples/users/update-password.md +20 -0
  35. package/docs/examples/users/update-status.md +1 -1
  36. package/index.d.ts +1693 -235
  37. package/lib/client.js +5 -5
  38. package/lib/query.js +34 -0
  39. package/lib/services/account.js +18 -6
  40. package/lib/services/database.js +706 -47
  41. package/lib/services/functions.js +63 -12
  42. package/lib/services/health.js +4 -22
  43. package/lib/services/storage.js +21 -2
  44. package/lib/services/teams.js +93 -31
  45. package/lib/services/users.js +127 -5
  46. package/package.json +2 -2
package/lib/client.js CHANGED
@@ -6,11 +6,11 @@ const AppwriteException = require('./exception.js');
6
6
  class Client {
7
7
 
8
8
  constructor() {
9
- this.endpoint = 'https://appwrite.io/v1';
9
+ this.endpoint = 'https://HOSTNAME/v1';
10
10
  this.headers = {
11
11
  'content-type': '',
12
- 'x-sdk-version': 'appwrite:nodejs:2.4.0',
13
- 'X-Appwrite-Response-Format' : '0.9.0',
12
+ 'x-sdk-version': 'appwrite:nodejs:4.0.0',
13
+ 'X-Appwrite-Response-Format' : '0.12.0',
14
14
  };
15
15
  this.selfSigned = false;
16
16
  }
@@ -152,10 +152,10 @@ class Client {
152
152
  let response = await axios(options);
153
153
  return response.data;
154
154
  } catch(error) {
155
- if('response' in error) {
155
+ if('response' in error && error.response !== undefined) {
156
156
  if(error.response && 'data' in error.response) {
157
157
  if (typeof(error.response.data) === 'string') {
158
- throw new AppwriteException(error.response.data, error.response.status, error.response.data);
158
+ throw new AppwriteException(error.response.data, error.response.status, error.response.data);
159
159
  } else {
160
160
  throw new AppwriteException(error.response.data.message, error.response.status, error.response.data);
161
161
  }
package/lib/query.js ADDED
@@ -0,0 +1,34 @@
1
+ class Query {
2
+ static equal = (attribute, value) =>
3
+ Query.addQuery(attribute, "equal", value);
4
+
5
+ static notEqual = (attribute, value) =>
6
+ Query.addQuery(attribute, "notEqual", value);
7
+
8
+ static lesser = (attribute, value) =>
9
+ Query.addQuery(attribute, "lesser", value);
10
+
11
+ static lesserEqual = (attribute, value) =>
12
+ Query.addQuery(attribute, "lesserEqual", value);
13
+
14
+ static greater = (attribute, value) =>
15
+ Query.addQuery(attribute, "greater", value);
16
+
17
+ static greaterEqual = (attribute, value) =>
18
+ Query.addQuery(attribute, "greaterEqual", value);
19
+
20
+ static search = (attribute, value) =>
21
+ Query.addQuery(attribute, "search", value);
22
+
23
+ static addQuery = (attribute, oper, value) =>
24
+ value instanceof Array
25
+ ? `${attribute}.${oper}(${value
26
+ .map((v) => Query.parseValues(v))
27
+ .join(",")})`
28
+ : `${attribute}.${oper}(${Query.parseValues(value)})`;
29
+
30
+ static parseValues = (value) =>
31
+ typeof value === "string" || value instanceof String
32
+ ? `"${value}"`
33
+ : `${value}`;
34
+ }
@@ -45,11 +45,13 @@ class Account extends Service {
45
45
  * Update Account Email
46
46
  *
47
47
  * Update currently logged in user account email address. After changing user
48
- * address, user confirmation status is being reset and a new confirmation
49
- * mail is sent. For security measures, user password is required to complete
50
- * this request.
48
+ * address, the user confirmation status will get reset. A new confirmation
49
+ * email is not sent automatically however you can use the send confirmation
50
+ * email endpoint again to send the confirmation email. For security measures,
51
+ * user password is required to complete this request.
51
52
  * This endpoint can also be used to convert an anonymous account to a normal
52
53
  * one, by passing an email address and a new password.
54
+ *
53
55
  *
54
56
  * @param {string} email
55
57
  * @param {string} password
@@ -87,13 +89,23 @@ class Account extends Service {
87
89
  * Get currently logged in user list of latest security activity logs. Each
88
90
  * log returns user IP address, location and date and time of log.
89
91
  *
92
+ * @param {number} limit
93
+ * @param {number} offset
90
94
  * @throws {AppwriteException}
91
95
  * @returns {Promise}
92
96
  */
93
- async getLogs() {
97
+ async getLogs(limit, offset) {
94
98
  let path = '/account/logs';
95
99
  let payload = {};
96
100
 
101
+ if (typeof limit !== 'undefined') {
102
+ payload['limit'] = limit;
103
+ }
104
+
105
+ if (typeof offset !== 'undefined') {
106
+ payload['offset'] = offset;
107
+ }
108
+
97
109
  return await this.client.call('get', path, {
98
110
  'content-type': 'application/json',
99
111
  }, payload);
@@ -245,7 +257,7 @@ class Account extends Service {
245
257
  }
246
258
 
247
259
  /**
248
- * Complete Password Recovery
260
+ * Create Password Recovery (confirmation)
249
261
  *
250
262
  * Use this endpoint to complete the user account password reset. Both the
251
263
  * **userId** and **secret** arguments will be passed as query parameters to
@@ -429,7 +441,7 @@ class Account extends Service {
429
441
  }
430
442
 
431
443
  /**
432
- * Complete Email Verification
444
+ * Create Email Verification (confirmation)
433
445
  *
434
446
  * Use this endpoint to complete the user email verification process. Use both
435
447
  * the **userId** and **secret** parameters that were attached to your app URL