node-appwrite 5.0.0 → 7.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 (148) hide show
  1. package/README.md +2 -2
  2. package/docs/examples/account/create-phone-verification.md +20 -0
  3. package/docs/examples/account/create-recovery.md +3 -3
  4. package/docs/examples/account/create-verification.md +3 -3
  5. package/docs/examples/account/delete-session.md +3 -3
  6. package/docs/examples/account/delete-sessions.md +3 -3
  7. package/docs/examples/account/get-logs.md +3 -3
  8. package/docs/examples/account/get-prefs.md +3 -3
  9. package/docs/examples/account/get-session.md +3 -3
  10. package/docs/examples/account/get-sessions.md +3 -3
  11. package/docs/examples/account/get.md +3 -3
  12. package/docs/examples/account/update-email.md +3 -3
  13. package/docs/examples/account/update-name.md +3 -3
  14. package/docs/examples/account/update-password.md +3 -3
  15. package/docs/examples/account/update-phone-verification.md +20 -0
  16. package/docs/examples/{database/create-ip-attribute.md → account/update-phone.md} +4 -4
  17. package/docs/examples/account/update-prefs.md +3 -3
  18. package/docs/examples/account/update-recovery.md +3 -3
  19. package/docs/examples/account/update-session.md +3 -3
  20. package/docs/examples/account/{delete.md → update-status.md} +3 -3
  21. package/docs/examples/account/update-verification.md +3 -3
  22. package/docs/examples/avatars/get-browser.md +3 -3
  23. package/docs/examples/avatars/get-credit-card.md +3 -3
  24. package/docs/examples/avatars/get-favicon.md +3 -3
  25. package/docs/examples/avatars/get-flag.md +3 -3
  26. package/docs/examples/avatars/get-image.md +3 -3
  27. package/docs/examples/avatars/get-initials.md +3 -3
  28. package/docs/examples/avatars/get-q-r.md +3 -3
  29. package/docs/examples/databases/create-boolean-attribute.md +20 -0
  30. package/docs/examples/{database → databases}/create-collection.md +3 -3
  31. package/docs/examples/databases/create-document.md +20 -0
  32. package/docs/examples/databases/create-email-attribute.md +20 -0
  33. package/docs/examples/databases/create-enum-attribute.md +20 -0
  34. package/docs/examples/{database → databases}/create-float-attribute.md +3 -3
  35. package/docs/examples/{database → databases}/create-index.md +3 -3
  36. package/docs/examples/{database → databases}/create-integer-attribute.md +3 -3
  37. package/docs/examples/{database/create-email-attribute.md → databases/create-ip-attribute.md} +3 -3
  38. package/docs/examples/{database → databases}/create-string-attribute.md +3 -3
  39. package/docs/examples/{database → databases}/create-url-attribute.md +3 -3
  40. package/docs/examples/{database/delete-attribute.md → databases/create.md} +3 -3
  41. package/docs/examples/databases/delete-attribute.md +20 -0
  42. package/docs/examples/databases/delete-collection.md +20 -0
  43. package/docs/examples/databases/delete-document.md +20 -0
  44. package/docs/examples/{database/create-document.md → databases/delete-index.md} +3 -3
  45. package/docs/examples/{database/delete-index.md → databases/delete.md} +3 -3
  46. package/docs/examples/databases/get-attribute.md +20 -0
  47. package/docs/examples/{database → databases}/get-collection.md +3 -3
  48. package/docs/examples/{database/delete-document.md → databases/get-document.md} +3 -3
  49. package/docs/examples/{database/create-boolean-attribute.md → databases/get-index.md} +3 -3
  50. package/docs/examples/{database/get-index.md → databases/get.md} +3 -3
  51. package/docs/examples/{database → databases}/list-attributes.md +3 -3
  52. package/docs/examples/databases/list-collections.md +20 -0
  53. package/docs/examples/{database/create-enum-attribute.md → databases/list-documents.md} +3 -3
  54. package/docs/examples/{database → databases}/list-indexes.md +3 -3
  55. package/docs/examples/{database/list-documents.md → databases/list.md} +3 -3
  56. package/docs/examples/{database → databases}/update-collection.md +3 -3
  57. package/docs/examples/{database → databases}/update-document.md +3 -3
  58. package/docs/examples/databases/update.md +20 -0
  59. package/docs/examples/functions/create-deployment.md +3 -3
  60. package/docs/examples/functions/create-execution.md +3 -3
  61. package/docs/examples/functions/create.md +3 -3
  62. package/docs/examples/functions/delete-deployment.md +3 -3
  63. package/docs/examples/functions/delete.md +3 -3
  64. package/docs/examples/functions/get-deployment.md +3 -3
  65. package/docs/examples/functions/get-execution.md +3 -3
  66. package/docs/examples/functions/get.md +3 -3
  67. package/docs/examples/functions/list-deployments.md +3 -3
  68. package/docs/examples/functions/list-executions.md +3 -3
  69. package/docs/examples/functions/list-runtimes.md +3 -3
  70. package/docs/examples/functions/list.md +3 -3
  71. package/docs/examples/functions/retry-build.md +3 -3
  72. package/docs/examples/functions/update-deployment.md +3 -3
  73. package/docs/examples/functions/update.md +3 -3
  74. package/docs/examples/health/get-antivirus.md +3 -3
  75. package/docs/examples/health/get-cache.md +3 -3
  76. package/docs/examples/health/get-d-b.md +3 -3
  77. package/docs/examples/health/get-queue-certificates.md +3 -3
  78. package/docs/examples/health/get-queue-functions.md +3 -3
  79. package/docs/examples/health/get-queue-logs.md +3 -3
  80. package/docs/examples/health/get-queue-webhooks.md +3 -3
  81. package/docs/examples/health/get-storage-local.md +3 -3
  82. package/docs/examples/health/get-time.md +3 -3
  83. package/docs/examples/health/get.md +3 -3
  84. package/docs/examples/locale/get-continents.md +3 -3
  85. package/docs/examples/locale/get-countries-e-u.md +3 -3
  86. package/docs/examples/locale/get-countries-phones.md +3 -3
  87. package/docs/examples/locale/get-countries.md +3 -3
  88. package/docs/examples/locale/get-currencies.md +3 -3
  89. package/docs/examples/locale/get-languages.md +3 -3
  90. package/docs/examples/locale/get.md +3 -3
  91. package/docs/examples/storage/create-bucket.md +3 -3
  92. package/docs/examples/storage/create-file.md +3 -3
  93. package/docs/examples/storage/delete-bucket.md +3 -3
  94. package/docs/examples/storage/delete-file.md +3 -3
  95. package/docs/examples/storage/get-bucket.md +3 -3
  96. package/docs/examples/storage/get-file-download.md +3 -3
  97. package/docs/examples/storage/get-file-preview.md +3 -3
  98. package/docs/examples/storage/get-file-view.md +3 -3
  99. package/docs/examples/storage/get-file.md +3 -3
  100. package/docs/examples/storage/list-buckets.md +3 -3
  101. package/docs/examples/storage/list-files.md +3 -3
  102. package/docs/examples/storage/update-bucket.md +3 -3
  103. package/docs/examples/storage/update-file.md +3 -3
  104. package/docs/examples/teams/create-membership.md +3 -3
  105. package/docs/examples/teams/create.md +3 -3
  106. package/docs/examples/teams/delete-membership.md +3 -3
  107. package/docs/examples/teams/delete.md +3 -3
  108. package/docs/examples/teams/get-membership.md +3 -3
  109. package/docs/examples/teams/get-memberships.md +3 -3
  110. package/docs/examples/teams/get.md +3 -3
  111. package/docs/examples/teams/list.md +3 -3
  112. package/docs/examples/teams/update-membership-roles.md +3 -3
  113. package/docs/examples/teams/update-membership-status.md +3 -3
  114. package/docs/examples/teams/update.md +3 -3
  115. package/docs/examples/users/create.md +3 -3
  116. package/docs/examples/users/delete-session.md +3 -3
  117. package/docs/examples/users/delete-sessions.md +3 -3
  118. package/docs/examples/users/delete.md +3 -3
  119. package/docs/examples/users/get-logs.md +3 -3
  120. package/docs/examples/{database/list-collections.md → users/get-memberships.md} +3 -3
  121. package/docs/examples/users/get-prefs.md +3 -3
  122. package/docs/examples/users/get-sessions.md +3 -3
  123. package/docs/examples/users/get.md +3 -3
  124. package/docs/examples/users/list.md +3 -3
  125. package/docs/examples/{database/delete-collection.md → users/update-email-verification.md} +3 -3
  126. package/docs/examples/users/update-email.md +3 -3
  127. package/docs/examples/users/update-name.md +3 -3
  128. package/docs/examples/users/update-password.md +3 -3
  129. package/docs/examples/{database/get-attribute.md → users/update-phone-verification.md} +3 -3
  130. package/docs/examples/{health/get-queue-usage.md → users/update-phone.md} +3 -3
  131. package/docs/examples/users/update-prefs.md +3 -3
  132. package/docs/examples/users/update-status.md +3 -3
  133. package/index.d.ts +376 -162
  134. package/index.js +4 -2
  135. package/lib/client.js +9 -3
  136. package/lib/inputFile.js +47 -0
  137. package/lib/services/account.js +127 -24
  138. package/lib/services/avatars.js +35 -3
  139. package/lib/services/{database.js → databases.js} +183 -89
  140. package/lib/services/functions.js +114 -52
  141. package/lib/services/health.js +2 -18
  142. package/lib/services/locale.js +2 -0
  143. package/lib/services/storage.js +119 -50
  144. package/lib/services/teams.js +2 -0
  145. package/lib/services/users.js +94 -3
  146. package/package.json +2 -2
  147. package/docs/examples/database/get-document.md +0 -20
  148. package/docs/examples/users/update-verification.md +0 -20
package/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  const Client = require('./lib/client.js');
2
2
  const Query = require('./lib/query.js');
3
+ const InputFile = require('./lib/inputFile.js');
3
4
  const AppwriteException = require('./lib/exception.js');
4
5
  const Account = require('./lib/services/account.js');
5
6
  const Avatars = require('./lib/services/avatars.js');
6
- const Database = require('./lib/services/database.js');
7
+ const Databases = require('./lib/services/databases.js');
7
8
  const Functions = require('./lib/services/functions.js');
8
9
  const Health = require('./lib/services/health.js');
9
10
  const Locale = require('./lib/services/locale.js');
@@ -14,10 +15,11 @@ const Users = require('./lib/services/users.js');
14
15
  module.exports = {
15
16
  Client,
16
17
  Query,
18
+ InputFile,
17
19
  AppwriteException,
18
20
  Account,
19
21
  Avatars,
20
- Database,
22
+ Databases,
21
23
  Functions,
22
24
  Health,
23
25
  Locale,
package/lib/client.js CHANGED
@@ -10,8 +10,8 @@ class Client {
10
10
  this.endpoint = 'https://HOSTNAME/v1';
11
11
  this.headers = {
12
12
  'content-type': '',
13
- 'x-sdk-version': 'appwrite:nodejs:5.0.0',
14
- 'X-Appwrite-Response-Format' : '0.13.0',
13
+ 'x-sdk-version': 'appwrite:nodejs:7.0.0',
14
+ 'X-Appwrite-Response-Format' : '0.15.0',
15
15
  };
16
16
  this.selfSigned = false;
17
17
  }
@@ -130,7 +130,13 @@ class Client {
130
130
  let flatParams = Client.flatten(params);
131
131
 
132
132
  for (const key in flatParams) {
133
- form.append(key, flatParams[key])
133
+ const value = flatParams[key];
134
+
135
+ if(value && value.type && value.type === 'file') {
136
+ form.append(key, value.file, { filename: value.filename });
137
+ } else {
138
+ form.append(key, flatParams[key]);
139
+ }
134
140
  }
135
141
 
136
142
  headers = {
@@ -0,0 +1,47 @@
1
+ const { Readable } = require('stream');
2
+ const fs = require('fs');
3
+ const { promisify } = require('util');
4
+
5
+ class InputFile {
6
+ stream; // Content of file, readable stream
7
+ size; // Total final size of the file content
8
+ filename; // File name
9
+
10
+ static fromPath = (filePath, filename) => {
11
+ const stream = fs.createReadStream(filePath);
12
+ const { size } = fs.statSync(filePath);
13
+ return new InputFile(stream, filename, size);
14
+ };
15
+
16
+ static fromBuffer = (buffer, filename) => {
17
+ const stream = Readable.from(buffer.toString());
18
+ const size = Buffer.byteLength(buffer);
19
+ return new InputFile(stream, filename, size);
20
+ };
21
+
22
+ static fromBlob = (blob, filename) => {
23
+ const buffer = blob.arrayBuffer();
24
+ const stream = Readable.from(buffer.toString());
25
+ const size = Buffer.byteLength(buffer);
26
+ return new InputFile(stream, filename);
27
+ };
28
+
29
+ static fromStream = (stream, filename, size) => {
30
+ return new InputFile(stream, filename, size);
31
+ };
32
+
33
+ static fromPlainText = (content, filename) => {
34
+ const buffer = Buffer.from(content, "utf-8");
35
+ const stream = Readable.from(buffer.toString());
36
+ const size = Buffer.byteLength(buffer);
37
+ return new InputFile(stream, filename, size);
38
+ };
39
+
40
+ constructor(stream, filename, size) {
41
+ this.stream = stream;
42
+ this.filename = filename;
43
+ this.size = size;
44
+ }
45
+ }
46
+
47
+ module.exports = InputFile;
@@ -1,6 +1,8 @@
1
1
  const Service = require('../service.js');
2
2
  const AppwriteException = require('../exception.js');
3
+ const InputFile = require('../inputFile.js');
3
4
  const client = require('../client.js');
5
+ const Stream = require('stream');
4
6
  const { promisify } = require('util');
5
7
  const fs = require('fs');
6
8
 
@@ -23,27 +25,6 @@ class Account extends Service {
23
25
  }, payload);
24
26
  }
25
27
 
26
- /**
27
- * Delete Account
28
- *
29
- * Delete a currently logged in user account. Behind the scene, the user
30
- * record is not deleted but permanently blocked from any access. This is done
31
- * to avoid deleted accounts being overtaken by new users with the same email
32
- * address. Any user-related resources like documents or storage files should
33
- * be deleted separately.
34
- *
35
- * @throws {AppwriteException}
36
- * @returns {Promise}
37
- */
38
- async delete() {
39
- let path = '/account';
40
- let payload = {};
41
-
42
- return await this.client.call('delete', path, {
43
- 'content-type': 'application/json',
44
- }, payload);
45
- }
46
-
47
28
  /**
48
29
  * Update Account Email
49
30
  *
@@ -145,7 +126,7 @@ class Account extends Service {
145
126
  *
146
127
  * Update currently logged in user password. For validation, user is required
147
128
  * to pass in the new password, and the old password. For users created with
148
- * OAuth and Team Invites, oldPassword is optional.
129
+ * OAuth, Team Invites and Magic URL, oldPassword is optional.
149
130
  *
150
131
  * @param {string} password
151
132
  * @param {string} oldPassword
@@ -173,6 +154,44 @@ class Account extends Service {
173
154
  }, payload);
174
155
  }
175
156
 
157
+ /**
158
+ * Update Account Phone
159
+ *
160
+ * Update currently logged in user account phone number. After changing phone
161
+ * number, the user confirmation status will get reset. A new confirmation SMS
162
+ * is not sent automatically however you can use the phone confirmation
163
+ * endpoint again to send the confirmation SMS.
164
+ *
165
+ * @param {string} number
166
+ * @param {string} password
167
+ * @throws {AppwriteException}
168
+ * @returns {Promise}
169
+ */
170
+ async updatePhone(number, password) {
171
+ if (typeof number === 'undefined') {
172
+ throw new AppwriteException('Missing required parameter: "number"');
173
+ }
174
+
175
+ if (typeof password === 'undefined') {
176
+ throw new AppwriteException('Missing required parameter: "password"');
177
+ }
178
+
179
+ let path = '/account/phone';
180
+ let payload = {};
181
+
182
+ if (typeof number !== 'undefined') {
183
+ payload['number'] = number;
184
+ }
185
+
186
+ if (typeof password !== 'undefined') {
187
+ payload['password'] = password;
188
+ }
189
+
190
+ return await this.client.call('patch', path, {
191
+ 'content-type': 'application/json',
192
+ }, payload);
193
+ }
194
+
176
195
  /**
177
196
  * Get Account Preferences
178
197
  *
@@ -383,6 +402,10 @@ class Account extends Service {
383
402
  /**
384
403
  * Update Session (Refresh Tokens)
385
404
  *
405
+ * Access tokens have limited lifespan and expire to mitigate security risks.
406
+ * If session was created using an OAuth provider, this route can be used to
407
+ * "refresh" the access token.
408
+ *
386
409
  * @param {string} sessionId
387
410
  * @throws {AppwriteException}
388
411
  * @returns {Promise}
@@ -425,6 +448,25 @@ class Account extends Service {
425
448
  }, payload);
426
449
  }
427
450
 
451
+ /**
452
+ * Update Account Status
453
+ *
454
+ * Block the currently logged in user account. Behind the scene, the user
455
+ * record is not deleted but permanently blocked from any access. To
456
+ * completely delete a user, use the Users API instead.
457
+ *
458
+ * @throws {AppwriteException}
459
+ * @returns {Promise}
460
+ */
461
+ async updateStatus() {
462
+ let path = '/account/status';
463
+ let payload = {};
464
+
465
+ return await this.client.call('patch', path, {
466
+ 'content-type': 'application/json',
467
+ }, payload);
468
+ }
469
+
428
470
  /**
429
471
  * Create Email Verification
430
472
  *
@@ -435,8 +477,8 @@ class Account extends Service {
435
477
  * should redirect the user back to your app and allow you to complete the
436
478
  * verification process by verifying both the **userId** and **secret**
437
479
  * parameters. Learn more about how to [complete the verification
438
- * process](/docs/client/account#accountUpdateVerification). The verification
439
- * link sent to the user's email address is valid for 7 days.
480
+ * process](/docs/client/account#accountUpdateEmailVerification). The
481
+ * verification link sent to the user's email address is valid for 7 days.
440
482
  *
441
483
  * Please note that in order to avoid a [Redirect
442
484
  * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md),
@@ -502,6 +544,67 @@ class Account extends Service {
502
544
  'content-type': 'application/json',
503
545
  }, payload);
504
546
  }
547
+
548
+ /**
549
+ * Create Phone Verification
550
+ *
551
+ * Use this endpoint to send a verification message to your user's phone
552
+ * number to confirm they are the valid owners of that address. The provided
553
+ * secret should allow you to complete the verification process by verifying
554
+ * both the **userId** and **secret** parameters. Learn more about how to
555
+ * [complete the verification
556
+ * process](/docs/client/account#accountUpdatePhoneVerification). The
557
+ * verification link sent to the user's phone number is valid for 15 minutes.
558
+ *
559
+ * @throws {AppwriteException}
560
+ * @returns {Promise}
561
+ */
562
+ async createPhoneVerification() {
563
+ let path = '/account/verification/phone';
564
+ let payload = {};
565
+
566
+ return await this.client.call('post', path, {
567
+ 'content-type': 'application/json',
568
+ }, payload);
569
+ }
570
+
571
+ /**
572
+ * Create Phone Verification (confirmation)
573
+ *
574
+ * Use this endpoint to complete the user phone verification process. Use the
575
+ * **userId** and **secret** that were sent to your user's phone number to
576
+ * verify the user email ownership. If confirmed this route will return a 200
577
+ * status code.
578
+ *
579
+ * @param {string} userId
580
+ * @param {string} secret
581
+ * @throws {AppwriteException}
582
+ * @returns {Promise}
583
+ */
584
+ async updatePhoneVerification(userId, secret) {
585
+ if (typeof userId === 'undefined') {
586
+ throw new AppwriteException('Missing required parameter: "userId"');
587
+ }
588
+
589
+ if (typeof secret === 'undefined') {
590
+ throw new AppwriteException('Missing required parameter: "secret"');
591
+ }
592
+
593
+ let path = '/account/verification/phone';
594
+ let payload = {};
595
+
596
+ if (typeof userId !== 'undefined') {
597
+ payload['userId'] = userId;
598
+ }
599
+
600
+ if (typeof secret !== 'undefined') {
601
+ payload['secret'] = secret;
602
+ }
603
+
604
+ return await this.client.call('put', path, {
605
+ 'content-type': 'application/json',
606
+ }, payload);
607
+ }
505
608
  }
506
609
 
507
610
  module.exports = Account;
@@ -1,6 +1,8 @@
1
1
  const Service = require('../service.js');
2
2
  const AppwriteException = require('../exception.js');
3
+ const InputFile = require('../inputFile.js');
3
4
  const client = require('../client.js');
5
+ const Stream = require('stream');
4
6
  const { promisify } = require('util');
5
7
  const fs = require('fs');
6
8
 
@@ -10,9 +12,14 @@ class Avatars extends Service {
10
12
  * Get Browser Icon
11
13
  *
12
14
  * You can use this endpoint to show different browser icons to your users.
13
- * The code argument receives the browser code as it appears in your user
14
- * /account/sessions endpoint. Use width, height and quality arguments to
15
- * change the output settings.
15
+ * The code argument receives the browser code as it appears in your user [GET
16
+ * /account/sessions](/docs/client/account#accountGetSessions) endpoint. Use
17
+ * width, height and quality arguments to change the output settings.
18
+ *
19
+ * When one dimension is specified and the other is 0, the image is scaled
20
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
21
+ * image at source quality. If dimensions are not specified, the default size
22
+ * of image returned is 100x100px.
16
23
  *
17
24
  * @param {string} code
18
25
  * @param {number} width
@@ -52,6 +59,12 @@ class Avatars extends Service {
52
59
  * The credit card endpoint will return you the icon of the credit card
53
60
  * provider you need. Use width, height and quality arguments to change the
54
61
  * output settings.
62
+ *
63
+ * When one dimension is specified and the other is 0, the image is scaled
64
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
65
+ * image at source quality. If dimensions are not specified, the default size
66
+ * of image returned is 100x100px.
67
+ *
55
68
  *
56
69
  * @param {string} code
57
70
  * @param {number} width
@@ -119,6 +132,12 @@ class Avatars extends Service {
119
132
  * You can use this endpoint to show different country flags icons to your
120
133
  * users. The code argument receives the 2 letter country code. Use width,
121
134
  * height and quality arguments to change the output settings.
135
+ *
136
+ * When one dimension is specified and the other is 0, the image is scaled
137
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
138
+ * image at source quality. If dimensions are not specified, the default size
139
+ * of image returned is 100x100px.
140
+ *
122
141
  *
123
142
  * @param {string} code
124
143
  * @param {number} width
@@ -159,6 +178,12 @@ class Avatars extends Service {
159
178
  * you want. This endpoint is very useful if you need to crop and display
160
179
  * remote images in your app or in case you want to make sure a 3rd party
161
180
  * image is properly served using a TLS protocol.
181
+ *
182
+ * When one dimension is specified and the other is 0, the image is scaled
183
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
184
+ * image at source quality. If dimensions are not specified, the default size
185
+ * of image returned is 400x400px.
186
+ *
162
187
  *
163
188
  * @param {string} url
164
189
  * @param {number} width
@@ -204,6 +229,12 @@ class Avatars extends Service {
204
229
  * default, a random theme will be selected. The random theme will persist for
205
230
  * the user's initials when reloading the same theme will always return for
206
231
  * the same initials.
232
+ *
233
+ * When one dimension is specified and the other is 0, the image is scaled
234
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
235
+ * image at source quality. If dimensions are not specified, the default size
236
+ * of image returned is 100x100px.
237
+ *
207
238
  *
208
239
  * @param {string} name
209
240
  * @param {number} width
@@ -247,6 +278,7 @@ class Avatars extends Service {
247
278
  *
248
279
  * Converts a given plain text to a QR code image. You can use the query
249
280
  * parameters to change the size and style of the resulting image.
281
+ *
250
282
  *
251
283
  * @param {string} text
252
284
  * @param {number} size