node-appwrite 6.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/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/{database/create-boolean-attribute.md → databases/create-email-attribute.md} +3 -3
  33. package/docs/examples/databases/create-enum-attribute.md +20 -0
  34. package/docs/examples/databases/create-float-attribute.md +20 -0
  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-float-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-email-attribute.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-enum-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-document.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/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/get-attribute.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/delete-collection.md → users/update-phone-verification.md} +3 -3
  130. package/docs/examples/{database/list-collections.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 +296 -121
  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 +103 -2
  138. package/lib/services/avatars.js +2 -0
  139. package/lib/services/{database.js → databases.js} +183 -87
  140. package/lib/services/functions.js +99 -41
  141. package/lib/services/health.js +2 -0
  142. package/lib/services/locale.js +2 -0
  143. package/lib/services/storage.js +108 -50
  144. package/lib/services/teams.js +2 -0
  145. package/lib/services/users.js +65 -1
  146. package/package.json +1 -1
  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:6.0.0',
14
- 'X-Appwrite-Response-Format' : '0.14.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
 
@@ -152,6 +154,44 @@ class Account extends Service {
152
154
  }, payload);
153
155
  }
154
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
+
155
195
  /**
156
196
  * Get Account Preferences
157
197
  *
@@ -437,8 +477,8 @@ class Account extends Service {
437
477
  * should redirect the user back to your app and allow you to complete the
438
478
  * verification process by verifying both the **userId** and **secret**
439
479
  * parameters. Learn more about how to [complete the verification
440
- * process](/docs/client/account#accountUpdateVerification). The verification
441
- * 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.
442
482
  *
443
483
  * Please note that in order to avoid a [Redirect
444
484
  * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md),
@@ -504,6 +544,67 @@ class Account extends Service {
504
544
  'content-type': 'application/json',
505
545
  }, payload);
506
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
+ }
507
608
  }
508
609
 
509
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