node-appwrite 11.1.1 → 12.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 (297) hide show
  1. package/.travis.yml +2 -2
  2. package/LICENSE +1 -1
  3. package/README.md +6 -6
  4. package/docs/examples/account/create-anonymous-session.md +9 -0
  5. package/docs/examples/account/create-email-password-session.md +12 -0
  6. package/docs/examples/account/create-email-token.md +13 -0
  7. package/docs/examples/account/create-j-w-t.md +9 -0
  8. package/docs/examples/account/create-magic-u-r-l-token.md +14 -0
  9. package/docs/examples/account/create-mfa-authenticator.md +12 -0
  10. package/docs/examples/account/create-mfa-challenge.md +11 -0
  11. package/docs/examples/account/create-mfa-recovery-codes.md +10 -0
  12. package/docs/examples/account/create-o-auth2token.md +14 -0
  13. package/docs/examples/account/create-phone-token.md +12 -0
  14. package/docs/examples/account/create-phone-verification.md +4 -14
  15. package/docs/examples/account/create-recovery.md +7 -14
  16. package/docs/examples/account/create-session.md +12 -0
  17. package/docs/examples/account/create-verification.md +6 -14
  18. package/docs/examples/account/create.md +14 -0
  19. package/docs/examples/account/delete-identity.md +6 -14
  20. package/docs/examples/account/delete-mfa-authenticator.md +13 -0
  21. package/docs/examples/account/delete-session.md +6 -14
  22. package/docs/examples/account/delete-sessions.md +4 -14
  23. package/docs/examples/account/get-mfa-recovery-codes.md +10 -0
  24. package/docs/examples/account/get-prefs.md +4 -14
  25. package/docs/examples/account/get-session.md +6 -14
  26. package/docs/examples/account/get.md +4 -14
  27. package/docs/examples/account/list-identities.md +6 -14
  28. package/docs/examples/account/list-logs.md +6 -14
  29. package/docs/examples/account/list-mfa-factors.md +10 -0
  30. package/docs/examples/account/list-sessions.md +4 -14
  31. package/docs/examples/account/update-email.md +7 -14
  32. package/docs/examples/account/update-m-f-a.md +12 -0
  33. package/docs/examples/account/update-magic-u-r-l-session.md +12 -0
  34. package/docs/examples/account/update-mfa-authenticator.md +13 -0
  35. package/docs/examples/account/update-mfa-challenge.md +13 -0
  36. package/docs/examples/account/update-mfa-recovery-codes.md +10 -0
  37. package/docs/examples/account/update-name.md +6 -14
  38. package/docs/examples/account/update-password.md +7 -14
  39. package/docs/examples/account/update-phone-session.md +12 -0
  40. package/docs/examples/account/update-phone-verification.md +7 -14
  41. package/docs/examples/account/update-phone.md +7 -14
  42. package/docs/examples/account/update-prefs.md +6 -14
  43. package/docs/examples/account/update-recovery.md +8 -14
  44. package/docs/examples/account/update-session.md +6 -14
  45. package/docs/examples/account/update-status.md +4 -14
  46. package/docs/examples/account/update-verification.md +7 -14
  47. package/docs/examples/avatars/get-browser.md +9 -14
  48. package/docs/examples/avatars/get-credit-card.md +9 -14
  49. package/docs/examples/avatars/get-favicon.md +6 -14
  50. package/docs/examples/avatars/get-flag.md +9 -14
  51. package/docs/examples/avatars/get-image.md +8 -14
  52. package/docs/examples/avatars/get-initials.md +9 -14
  53. package/docs/examples/avatars/get-q-r.md +9 -14
  54. package/docs/examples/databases/create-boolean-attribute.md +11 -14
  55. package/docs/examples/databases/create-collection.md +11 -14
  56. package/docs/examples/databases/create-datetime-attribute.md +11 -14
  57. package/docs/examples/databases/create-document.md +10 -14
  58. package/docs/examples/databases/create-email-attribute.md +11 -14
  59. package/docs/examples/databases/create-enum-attribute.md +12 -14
  60. package/docs/examples/databases/create-float-attribute.md +13 -14
  61. package/docs/examples/databases/create-index.md +11 -14
  62. package/docs/examples/databases/create-integer-attribute.md +13 -14
  63. package/docs/examples/databases/create-ip-attribute.md +11 -14
  64. package/docs/examples/databases/create-relationship-attribute.md +13 -14
  65. package/docs/examples/databases/create-string-attribute.md +13 -14
  66. package/docs/examples/databases/create-url-attribute.md +11 -14
  67. package/docs/examples/databases/create.md +8 -14
  68. package/docs/examples/databases/delete-attribute.md +8 -14
  69. package/docs/examples/databases/delete-collection.md +7 -14
  70. package/docs/examples/databases/delete-document.md +8 -14
  71. package/docs/examples/databases/delete-index.md +8 -14
  72. package/docs/examples/databases/delete.md +6 -14
  73. package/docs/examples/databases/get-attribute.md +8 -14
  74. package/docs/examples/databases/get-collection.md +7 -14
  75. package/docs/examples/databases/get-document.md +9 -14
  76. package/docs/examples/databases/get-index.md +8 -14
  77. package/docs/examples/databases/get.md +6 -14
  78. package/docs/examples/databases/list-attributes.md +8 -14
  79. package/docs/examples/databases/list-collections.md +8 -14
  80. package/docs/examples/databases/list-documents.md +8 -14
  81. package/docs/examples/databases/list-indexes.md +8 -14
  82. package/docs/examples/databases/list.md +7 -14
  83. package/docs/examples/databases/update-boolean-attribute.md +10 -14
  84. package/docs/examples/databases/update-collection.md +11 -14
  85. package/docs/examples/databases/update-datetime-attribute.md +10 -14
  86. package/docs/examples/databases/update-document.md +10 -14
  87. package/docs/examples/databases/update-email-attribute.md +10 -14
  88. package/docs/examples/databases/update-enum-attribute.md +11 -14
  89. package/docs/examples/databases/update-float-attribute.md +12 -14
  90. package/docs/examples/databases/update-integer-attribute.md +12 -14
  91. package/docs/examples/databases/update-ip-attribute.md +10 -14
  92. package/docs/examples/databases/update-relationship-attribute.md +9 -14
  93. package/docs/examples/databases/update-string-attribute.md +10 -14
  94. package/docs/examples/databases/update-url-attribute.md +10 -14
  95. package/docs/examples/databases/update.md +8 -14
  96. package/docs/examples/functions/create-build.md +8 -14
  97. package/docs/examples/functions/create-deployment.md +10 -14
  98. package/docs/examples/functions/create-execution.md +11 -14
  99. package/docs/examples/functions/create-variable.md +8 -14
  100. package/docs/examples/functions/create.md +25 -14
  101. package/docs/examples/functions/delete-deployment.md +7 -14
  102. package/docs/examples/functions/delete-variable.md +7 -14
  103. package/docs/examples/functions/delete.md +6 -14
  104. package/docs/examples/functions/download-deployment.md +7 -14
  105. package/docs/examples/functions/get-deployment.md +7 -14
  106. package/docs/examples/functions/get-execution.md +7 -14
  107. package/docs/examples/functions/get-variable.md +7 -14
  108. package/docs/examples/functions/get.md +6 -14
  109. package/docs/examples/functions/list-deployments.md +8 -14
  110. package/docs/examples/functions/list-executions.md +8 -14
  111. package/docs/examples/functions/list-runtimes.md +4 -14
  112. package/docs/examples/functions/list-variables.md +6 -14
  113. package/docs/examples/functions/list.md +7 -14
  114. package/docs/examples/functions/update-deployment.md +7 -14
  115. package/docs/examples/functions/update-variable.md +9 -14
  116. package/docs/examples/functions/update.md +21 -14
  117. package/docs/examples/graphql/mutation.md +6 -14
  118. package/docs/examples/graphql/query.md +6 -14
  119. package/docs/examples/health/get-antivirus.md +4 -14
  120. package/docs/examples/health/get-cache.md +4 -14
  121. package/docs/examples/health/get-certificate.md +12 -0
  122. package/docs/examples/health/get-d-b.md +4 -14
  123. package/docs/examples/health/get-failed-jobs.md +13 -0
  124. package/docs/examples/health/get-pub-sub.md +4 -14
  125. package/docs/examples/health/get-queue-builds.md +6 -14
  126. package/docs/examples/health/get-queue-certificates.md +6 -14
  127. package/docs/examples/health/get-queue-databases.md +7 -14
  128. package/docs/examples/health/get-queue-deletes.md +6 -14
  129. package/docs/examples/health/get-queue-functions.md +6 -14
  130. package/docs/examples/health/get-queue-logs.md +6 -14
  131. package/docs/examples/health/get-queue-mails.md +6 -14
  132. package/docs/examples/health/get-queue-messaging.md +6 -14
  133. package/docs/examples/health/get-queue-migrations.md +6 -14
  134. package/docs/examples/health/get-queue-usage-dump.md +12 -0
  135. package/docs/examples/health/get-queue-usage.md +12 -0
  136. package/docs/examples/health/get-queue-webhooks.md +6 -14
  137. package/docs/examples/health/get-queue.md +4 -14
  138. package/docs/examples/health/get-storage-local.md +4 -14
  139. package/docs/examples/health/get-storage.md +10 -0
  140. package/docs/examples/health/get-time.md +4 -14
  141. package/docs/examples/health/get.md +4 -14
  142. package/docs/examples/locale/get.md +4 -14
  143. package/docs/examples/locale/list-codes.md +4 -14
  144. package/docs/examples/locale/list-continents.md +4 -14
  145. package/docs/examples/locale/list-countries-e-u.md +4 -14
  146. package/docs/examples/locale/list-countries-phones.md +4 -14
  147. package/docs/examples/locale/list-countries.md +4 -14
  148. package/docs/examples/locale/list-currencies.md +4 -14
  149. package/docs/examples/locale/list-languages.md +4 -14
  150. package/docs/examples/messaging/create-apns-provider.md +19 -0
  151. package/docs/examples/messaging/create-email.md +23 -0
  152. package/docs/examples/messaging/create-fcm-provider.md +15 -0
  153. package/docs/examples/messaging/create-mailgun-provider.md +21 -0
  154. package/docs/examples/messaging/create-msg91provider.md +17 -0
  155. package/docs/examples/messaging/create-push.md +27 -0
  156. package/docs/examples/messaging/create-sendgrid-provider.md +19 -0
  157. package/docs/examples/messaging/create-sms.md +18 -0
  158. package/docs/examples/messaging/create-smtp-provider.md +25 -0
  159. package/docs/examples/messaging/create-subscriber.md +14 -0
  160. package/docs/examples/messaging/create-telesign-provider.md +17 -0
  161. package/docs/examples/messaging/create-textmagic-provider.md +17 -0
  162. package/docs/examples/messaging/create-topic.md +14 -0
  163. package/docs/examples/messaging/create-twilio-provider.md +17 -0
  164. package/docs/examples/messaging/create-vonage-provider.md +17 -0
  165. package/docs/examples/messaging/delete-provider.md +12 -0
  166. package/docs/examples/messaging/delete-subscriber.md +13 -0
  167. package/docs/examples/messaging/delete-topic.md +12 -0
  168. package/docs/examples/messaging/delete.md +12 -0
  169. package/docs/examples/messaging/get-message.md +12 -0
  170. package/docs/examples/messaging/get-provider.md +12 -0
  171. package/docs/examples/messaging/get-subscriber.md +13 -0
  172. package/docs/examples/messaging/get-topic.md +12 -0
  173. package/docs/examples/messaging/list-message-logs.md +13 -0
  174. package/docs/examples/messaging/list-messages.md +13 -0
  175. package/docs/examples/messaging/list-provider-logs.md +13 -0
  176. package/docs/examples/messaging/list-providers.md +13 -0
  177. package/docs/examples/messaging/list-subscriber-logs.md +13 -0
  178. package/docs/examples/messaging/list-subscribers.md +14 -0
  179. package/docs/examples/messaging/list-targets.md +13 -0
  180. package/docs/examples/messaging/list-topic-logs.md +13 -0
  181. package/docs/examples/messaging/list-topics.md +13 -0
  182. package/docs/examples/messaging/update-apns-provider.md +19 -0
  183. package/docs/examples/messaging/update-email.md +22 -0
  184. package/docs/examples/messaging/update-fcm-provider.md +15 -0
  185. package/docs/examples/messaging/update-mailgun-provider.md +21 -0
  186. package/docs/examples/messaging/update-msg91provider.md +17 -0
  187. package/docs/examples/messaging/update-push.md +27 -0
  188. package/docs/examples/messaging/update-sendgrid-provider.md +19 -0
  189. package/docs/examples/messaging/update-sms.md +18 -0
  190. package/docs/examples/messaging/update-smtp-provider.md +25 -0
  191. package/docs/examples/messaging/update-telesign-provider.md +17 -0
  192. package/docs/examples/messaging/update-textmagic-provider.md +17 -0
  193. package/docs/examples/messaging/update-topic.md +14 -0
  194. package/docs/examples/messaging/update-twilio-provider.md +17 -0
  195. package/docs/examples/messaging/update-vonage-provider.md +17 -0
  196. package/docs/examples/storage/create-bucket.md +15 -14
  197. package/docs/examples/storage/create-file.md +9 -14
  198. package/docs/examples/storage/delete-bucket.md +6 -14
  199. package/docs/examples/storage/delete-file.md +7 -14
  200. package/docs/examples/storage/get-bucket.md +6 -14
  201. package/docs/examples/storage/get-file-download.md +7 -14
  202. package/docs/examples/storage/get-file-preview.md +18 -14
  203. package/docs/examples/storage/get-file-view.md +7 -14
  204. package/docs/examples/storage/get-file.md +7 -14
  205. package/docs/examples/storage/list-buckets.md +7 -14
  206. package/docs/examples/storage/list-files.md +8 -14
  207. package/docs/examples/storage/update-bucket.md +15 -14
  208. package/docs/examples/storage/update-file.md +9 -14
  209. package/docs/examples/teams/create-membership.md +12 -14
  210. package/docs/examples/teams/create.md +8 -14
  211. package/docs/examples/teams/delete-membership.md +7 -14
  212. package/docs/examples/teams/delete.md +6 -14
  213. package/docs/examples/teams/get-membership.md +7 -14
  214. package/docs/examples/teams/get-prefs.md +6 -14
  215. package/docs/examples/teams/get.md +6 -14
  216. package/docs/examples/teams/list-memberships.md +8 -14
  217. package/docs/examples/teams/list.md +7 -14
  218. package/docs/examples/teams/update-membership-status.md +9 -14
  219. package/docs/examples/teams/update-membership.md +8 -14
  220. package/docs/examples/teams/update-name.md +7 -14
  221. package/docs/examples/teams/update-prefs.md +7 -14
  222. package/docs/examples/users/create-argon2user.md +9 -14
  223. package/docs/examples/users/create-bcrypt-user.md +9 -14
  224. package/docs/examples/users/create-m-d5user.md +9 -14
  225. package/docs/examples/users/create-mfa-recovery-codes.md +12 -0
  226. package/docs/examples/users/create-p-h-pass-user.md +9 -14
  227. package/docs/examples/users/create-s-h-a-user.md +10 -14
  228. package/docs/examples/users/create-scrypt-modified-user.md +12 -14
  229. package/docs/examples/users/create-scrypt-user.md +14 -14
  230. package/docs/examples/users/create-session.md +12 -0
  231. package/docs/examples/users/create-target.md +17 -0
  232. package/docs/examples/users/create-token.md +14 -0
  233. package/docs/examples/users/create.md +10 -14
  234. package/docs/examples/users/delete-identity.md +6 -14
  235. package/docs/examples/users/delete-mfa-authenticator.md +13 -0
  236. package/docs/examples/users/delete-session.md +7 -14
  237. package/docs/examples/users/delete-sessions.md +6 -14
  238. package/docs/examples/users/delete-target.md +13 -0
  239. package/docs/examples/users/delete.md +6 -14
  240. package/docs/examples/users/get-mfa-recovery-codes.md +12 -0
  241. package/docs/examples/users/get-prefs.md +6 -14
  242. package/docs/examples/users/get-target.md +13 -0
  243. package/docs/examples/users/get.md +6 -14
  244. package/docs/examples/users/list-identities.md +7 -14
  245. package/docs/examples/users/list-logs.md +7 -14
  246. package/docs/examples/users/list-memberships.md +6 -14
  247. package/docs/examples/users/list-mfa-factors.md +12 -0
  248. package/docs/examples/users/list-sessions.md +6 -14
  249. package/docs/examples/users/list-targets.md +13 -0
  250. package/docs/examples/users/list.md +7 -14
  251. package/docs/examples/users/update-email-verification.md +7 -14
  252. package/docs/examples/users/update-email.md +7 -14
  253. package/docs/examples/users/update-labels.md +7 -14
  254. package/docs/examples/users/update-mfa-recovery-codes.md +12 -0
  255. package/docs/examples/users/update-mfa.md +13 -0
  256. package/docs/examples/users/update-name.md +7 -14
  257. package/docs/examples/users/update-password.md +7 -14
  258. package/docs/examples/users/update-phone-verification.md +7 -14
  259. package/docs/examples/users/update-phone.md +7 -14
  260. package/docs/examples/users/update-prefs.md +7 -14
  261. package/docs/examples/users/update-status.md +7 -14
  262. package/docs/examples/users/update-target.md +16 -0
  263. package/index.d.ts +2164 -81
  264. package/index.js +38 -0
  265. package/lib/client.js +107 -65
  266. package/lib/enums/authentication-factor.js +8 -0
  267. package/lib/enums/authenticator-type.js +5 -0
  268. package/lib/enums/browser.js +18 -0
  269. package/lib/enums/compression.js +7 -0
  270. package/lib/enums/credit-card.js +20 -0
  271. package/lib/enums/execution-method.js +10 -0
  272. package/lib/enums/flag.js +198 -0
  273. package/lib/enums/image-format.js +9 -0
  274. package/lib/enums/image-gravity.js +13 -0
  275. package/lib/enums/index-type.js +7 -0
  276. package/lib/enums/messaging-provider-type.js +7 -0
  277. package/lib/enums/name.js +17 -0
  278. package/lib/enums/o-auth-provider.js +43 -0
  279. package/lib/enums/password-hash.js +15 -0
  280. package/lib/enums/relation-mutate.js +7 -0
  281. package/lib/enums/relationship-type.js +8 -0
  282. package/lib/enums/runtime.js +48 -0
  283. package/lib/enums/smtp-encryption.js +7 -0
  284. package/lib/inputFile.js +88 -16
  285. package/lib/query.js +56 -38
  286. package/lib/services/account.js +722 -16
  287. package/lib/services/avatars.js +5 -3
  288. package/lib/services/databases.js +34 -4
  289. package/lib/services/functions.js +51 -87
  290. package/lib/services/graphql.js +2 -0
  291. package/lib/services/health.js +118 -0
  292. package/lib/services/locale.js +2 -0
  293. package/lib/services/messaging.js +2218 -0
  294. package/lib/services/storage.js +52 -88
  295. package/lib/services/teams.js +2 -0
  296. package/lib/services/users.js +405 -3
  297. package/package.json +2 -3
@@ -5,6 +5,8 @@ const client = require('../client.js');
5
5
  const Stream = require('stream');
6
6
  const { promisify } = require('util');
7
7
  const fs = require('fs');
8
+ const { File } = require('undici');
9
+ const Query = require('../query.js');
8
10
 
9
11
  class Account extends Service {
10
12
 
@@ -31,6 +33,61 @@ class Account extends Service {
31
33
  }, payload);
32
34
  }
33
35
 
36
+ /**
37
+ * Create account
38
+ *
39
+ * Use this endpoint to allow a new user to register a new account in your
40
+ * project. After the user registration completes successfully, you can use
41
+ * the
42
+ * [/account/verfication](https://appwrite.io/docs/references/cloud/client-web/account#createVerification)
43
+ * route to start verifying the user email address. To allow the new user to
44
+ * login to their new account, you need to create a new [account
45
+ * session](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession).
46
+ *
47
+ * @param {string} userId
48
+ * @param {string} email
49
+ * @param {string} password
50
+ * @param {string} name
51
+ * @throws {AppwriteException}
52
+ * @returns {Promise}
53
+ */
54
+ async create(userId, email, password, name) {
55
+ const apiPath = '/account';
56
+ let payload = {};
57
+ if (typeof userId === 'undefined') {
58
+ throw new AppwriteException('Missing required parameter: "userId"');
59
+ }
60
+
61
+ if (typeof email === 'undefined') {
62
+ throw new AppwriteException('Missing required parameter: "email"');
63
+ }
64
+
65
+ if (typeof password === 'undefined') {
66
+ throw new AppwriteException('Missing required parameter: "password"');
67
+ }
68
+
69
+
70
+ if (typeof userId !== 'undefined') {
71
+ payload['userId'] = userId;
72
+ }
73
+
74
+ if (typeof email !== 'undefined') {
75
+ payload['email'] = email;
76
+ }
77
+
78
+ if (typeof password !== 'undefined') {
79
+ payload['password'] = password;
80
+ }
81
+
82
+ if (typeof name !== 'undefined') {
83
+ payload['name'] = name;
84
+ }
85
+
86
+ return await this.client.call('post', apiPath, {
87
+ 'content-type': 'application/json',
88
+ }, payload);
89
+ }
90
+
34
91
  /**
35
92
  * Update email
36
93
  *
@@ -78,7 +135,7 @@ class Account extends Service {
78
135
  *
79
136
  * Get the list of identities for the currently logged in user.
80
137
  *
81
- * @param {string} queries
138
+ * @param {string[]} queries
82
139
  * @throws {AppwriteException}
83
140
  * @returns {Promise}
84
141
  */
@@ -96,7 +153,7 @@ class Account extends Service {
96
153
  }
97
154
 
98
155
  /**
99
- * Delete Identity
156
+ * Delete identity
100
157
  *
101
158
  * Delete an identity by its unique ID.
102
159
  *
@@ -117,6 +174,27 @@ class Account extends Service {
117
174
  }, payload);
118
175
  }
119
176
 
177
+ /**
178
+ * Create JWT
179
+ *
180
+ * Use this endpoint to create a JSON Web Token. You can use the resulting JWT
181
+ * to authenticate on behalf of the current user when working with the
182
+ * Appwrite server-side API and SDKs. The JWT secret is valid for 15 minutes
183
+ * from its creation and will be invalid if the user will logout in that time
184
+ * frame.
185
+ *
186
+ * @throws {AppwriteException}
187
+ * @returns {Promise}
188
+ */
189
+ async createJWT() {
190
+ const apiPath = '/account/jwt';
191
+ let payload = {};
192
+
193
+ return await this.client.call('post', apiPath, {
194
+ 'content-type': 'application/json',
195
+ }, payload);
196
+ }
197
+
120
198
  /**
121
199
  * List logs
122
200
  *
@@ -140,6 +218,266 @@ class Account extends Service {
140
218
  }, payload);
141
219
  }
142
220
 
221
+ /**
222
+ * Update MFA
223
+ *
224
+ * Enable or disable MFA on an account.
225
+ *
226
+ * @param {boolean} mfa
227
+ * @throws {AppwriteException}
228
+ * @returns {Promise}
229
+ */
230
+ async updateMFA(mfa) {
231
+ const apiPath = '/account/mfa';
232
+ let payload = {};
233
+ if (typeof mfa === 'undefined') {
234
+ throw new AppwriteException('Missing required parameter: "mfa"');
235
+ }
236
+
237
+
238
+ if (typeof mfa !== 'undefined') {
239
+ payload['mfa'] = mfa;
240
+ }
241
+
242
+ return await this.client.call('patch', apiPath, {
243
+ 'content-type': 'application/json',
244
+ }, payload);
245
+ }
246
+
247
+ /**
248
+ * Add Authenticator
249
+ *
250
+ * Add an authenticator app to be used as an MFA factor. Verify the
251
+ * authenticator using the [verify
252
+ * authenticator](/docs/references/cloud/client-web/account#verifyAuthenticator)
253
+ * method.
254
+ *
255
+ * @param {AuthenticatorType} type
256
+ * @throws {AppwriteException}
257
+ * @returns {Promise}
258
+ */
259
+ async createMfaAuthenticator(type) {
260
+ const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type);
261
+ let payload = {};
262
+ if (typeof type === 'undefined') {
263
+ throw new AppwriteException('Missing required parameter: "type"');
264
+ }
265
+
266
+
267
+ return await this.client.call('post', apiPath, {
268
+ 'content-type': 'application/json',
269
+ }, payload);
270
+ }
271
+
272
+ /**
273
+ * Verify Authenticator
274
+ *
275
+ * Verify an authenticator app after adding it using the [add
276
+ * authenticator](/docs/references/cloud/client-web/account#addAuthenticator)
277
+ * method.
278
+ *
279
+ * @param {AuthenticatorType} type
280
+ * @param {string} otp
281
+ * @throws {AppwriteException}
282
+ * @returns {Promise}
283
+ */
284
+ async updateMfaAuthenticator(type, otp) {
285
+ const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type);
286
+ let payload = {};
287
+ if (typeof type === 'undefined') {
288
+ throw new AppwriteException('Missing required parameter: "type"');
289
+ }
290
+
291
+ if (typeof otp === 'undefined') {
292
+ throw new AppwriteException('Missing required parameter: "otp"');
293
+ }
294
+
295
+
296
+ if (typeof otp !== 'undefined') {
297
+ payload['otp'] = otp;
298
+ }
299
+
300
+ return await this.client.call('put', apiPath, {
301
+ 'content-type': 'application/json',
302
+ }, payload);
303
+ }
304
+
305
+ /**
306
+ * Delete Authenticator
307
+ *
308
+ * Delete an authenticator for a user by ID.
309
+ *
310
+ * @param {AuthenticatorType} type
311
+ * @param {string} otp
312
+ * @throws {AppwriteException}
313
+ * @returns {Promise}
314
+ */
315
+ async deleteMfaAuthenticator(type, otp) {
316
+ const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type);
317
+ let payload = {};
318
+ if (typeof type === 'undefined') {
319
+ throw new AppwriteException('Missing required parameter: "type"');
320
+ }
321
+
322
+ if (typeof otp === 'undefined') {
323
+ throw new AppwriteException('Missing required parameter: "otp"');
324
+ }
325
+
326
+
327
+ if (typeof otp !== 'undefined') {
328
+ payload['otp'] = otp;
329
+ }
330
+
331
+ return await this.client.call('delete', apiPath, {
332
+ 'content-type': 'application/json',
333
+ }, payload);
334
+ }
335
+
336
+ /**
337
+ * Create 2FA Challenge
338
+ *
339
+ * Begin the process of MFA verification after sign-in. Finish the flow with
340
+ * [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge)
341
+ * method.
342
+ *
343
+ * @param {AuthenticationFactor} factor
344
+ * @throws {AppwriteException}
345
+ * @returns {Promise}
346
+ */
347
+ async createMfaChallenge(factor) {
348
+ const apiPath = '/account/mfa/challenge';
349
+ let payload = {};
350
+ if (typeof factor === 'undefined') {
351
+ throw new AppwriteException('Missing required parameter: "factor"');
352
+ }
353
+
354
+
355
+ if (typeof factor !== 'undefined') {
356
+ payload['factor'] = factor;
357
+ }
358
+
359
+ return await this.client.call('post', apiPath, {
360
+ 'content-type': 'application/json',
361
+ }, payload);
362
+ }
363
+
364
+ /**
365
+ * Create MFA Challenge (confirmation)
366
+ *
367
+ * Complete the MFA challenge by providing the one-time password. Finish the
368
+ * process of MFA verification by providing the one-time password. To begin
369
+ * the flow, use
370
+ * [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge)
371
+ * method.
372
+ *
373
+ * @param {string} challengeId
374
+ * @param {string} otp
375
+ * @throws {AppwriteException}
376
+ * @returns {Promise}
377
+ */
378
+ async updateMfaChallenge(challengeId, otp) {
379
+ const apiPath = '/account/mfa/challenge';
380
+ let payload = {};
381
+ if (typeof challengeId === 'undefined') {
382
+ throw new AppwriteException('Missing required parameter: "challengeId"');
383
+ }
384
+
385
+ if (typeof otp === 'undefined') {
386
+ throw new AppwriteException('Missing required parameter: "otp"');
387
+ }
388
+
389
+
390
+ if (typeof challengeId !== 'undefined') {
391
+ payload['challengeId'] = challengeId;
392
+ }
393
+
394
+ if (typeof otp !== 'undefined') {
395
+ payload['otp'] = otp;
396
+ }
397
+
398
+ return await this.client.call('put', apiPath, {
399
+ 'content-type': 'application/json',
400
+ }, payload);
401
+ }
402
+
403
+ /**
404
+ * List Factors
405
+ *
406
+ * List the factors available on the account to be used as a MFA challange.
407
+ *
408
+ * @throws {AppwriteException}
409
+ * @returns {Promise}
410
+ */
411
+ async listMfaFactors() {
412
+ const apiPath = '/account/mfa/factors';
413
+ let payload = {};
414
+
415
+ return await this.client.call('get', apiPath, {
416
+ 'content-type': 'application/json',
417
+ }, payload);
418
+ }
419
+
420
+ /**
421
+ * Get MFA Recovery Codes
422
+ *
423
+ * Get recovery codes that can be used as backup for MFA flow. Before getting
424
+ * codes, they must be generated using
425
+ * [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes)
426
+ * method. An OTP challenge is required to read recovery codes.
427
+ *
428
+ * @throws {AppwriteException}
429
+ * @returns {Promise}
430
+ */
431
+ async getMfaRecoveryCodes() {
432
+ const apiPath = '/account/mfa/recovery-codes';
433
+ let payload = {};
434
+
435
+ return await this.client.call('get', apiPath, {
436
+ 'content-type': 'application/json',
437
+ }, payload);
438
+ }
439
+
440
+ /**
441
+ * Create MFA Recovery Codes
442
+ *
443
+ * Generate recovery codes as backup for MFA flow. It's recommended to
444
+ * generate and show then immediately after user successfully adds their
445
+ * authehticator. Recovery codes can be used as a MFA verification type in
446
+ * [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge)
447
+ * method.
448
+ *
449
+ * @throws {AppwriteException}
450
+ * @returns {Promise}
451
+ */
452
+ async createMfaRecoveryCodes() {
453
+ const apiPath = '/account/mfa/recovery-codes';
454
+ let payload = {};
455
+
456
+ return await this.client.call('post', apiPath, {
457
+ 'content-type': 'application/json',
458
+ }, payload);
459
+ }
460
+
461
+ /**
462
+ * Regenerate MFA Recovery Codes
463
+ *
464
+ * Regenerate recovery codes that can be used as backup for MFA flow. Before
465
+ * regenerating codes, they must be first generated using
466
+ * [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes)
467
+ * method. An OTP challenge is required to regenreate recovery codes.
468
+ *
469
+ * @throws {AppwriteException}
470
+ * @returns {Promise}
471
+ */
472
+ async updateMfaRecoveryCodes() {
473
+ const apiPath = '/account/mfa/recovery-codes';
474
+ let payload = {};
475
+
476
+ return await this.client.call('patch', apiPath, {
477
+ 'content-type': 'application/json',
478
+ }, payload);
479
+ }
480
+
143
481
  /**
144
482
  * Update name
145
483
  *
@@ -342,11 +680,10 @@ class Account extends Service {
342
680
  * @param {string} userId
343
681
  * @param {string} secret
344
682
  * @param {string} password
345
- * @param {string} passwordAgain
346
683
  * @throws {AppwriteException}
347
684
  * @returns {Promise}
348
685
  */
349
- async updateRecovery(userId, secret, password, passwordAgain) {
686
+ async updateRecovery(userId, secret, password) {
350
687
  const apiPath = '/account/recovery';
351
688
  let payload = {};
352
689
  if (typeof userId === 'undefined') {
@@ -361,10 +698,6 @@ class Account extends Service {
361
698
  throw new AppwriteException('Missing required parameter: "password"');
362
699
  }
363
700
 
364
- if (typeof passwordAgain === 'undefined') {
365
- throw new AppwriteException('Missing required parameter: "passwordAgain"');
366
- }
367
-
368
701
 
369
702
  if (typeof userId !== 'undefined') {
370
703
  payload['userId'] = userId;
@@ -378,10 +711,6 @@ class Account extends Service {
378
711
  payload['password'] = password;
379
712
  }
380
713
 
381
- if (typeof passwordAgain !== 'undefined') {
382
- payload['passwordAgain'] = passwordAgain;
383
- }
384
-
385
714
  return await this.client.call('put', apiPath, {
386
715
  'content-type': 'application/json',
387
716
  }, payload);
@@ -423,6 +752,180 @@ class Account extends Service {
423
752
  }, payload);
424
753
  }
425
754
 
755
+ /**
756
+ * Create anonymous session
757
+ *
758
+ * Use this endpoint to allow a new user to register an anonymous account in
759
+ * your project. This route will also create a new session for the user. To
760
+ * allow the new user to convert an anonymous account to a normal account, you
761
+ * need to update its [email and
762
+ * password](https://appwrite.io/docs/references/cloud/client-web/account#updateEmail)
763
+ * or create an [OAuth2
764
+ * session](https://appwrite.io/docs/references/cloud/client-web/account#CreateOAuth2Session).
765
+ *
766
+ * @throws {AppwriteException}
767
+ * @returns {Promise}
768
+ */
769
+ async createAnonymousSession() {
770
+ const apiPath = '/account/sessions/anonymous';
771
+ let payload = {};
772
+
773
+ return await this.client.call('post', apiPath, {
774
+ 'content-type': 'application/json',
775
+ }, payload);
776
+ }
777
+
778
+ /**
779
+ * Create email password session
780
+ *
781
+ * Allow the user to login into their account by providing a valid email and
782
+ * password combination. This route will create a new session for the user.
783
+ *
784
+ * A user is limited to 10 active sessions at a time by default. [Learn more
785
+ * about session
786
+ * limits](https://appwrite.io/docs/authentication-security#limits).
787
+ *
788
+ * @param {string} email
789
+ * @param {string} password
790
+ * @throws {AppwriteException}
791
+ * @returns {Promise}
792
+ */
793
+ async createEmailPasswordSession(email, password) {
794
+ const apiPath = '/account/sessions/email';
795
+ let payload = {};
796
+ if (typeof email === 'undefined') {
797
+ throw new AppwriteException('Missing required parameter: "email"');
798
+ }
799
+
800
+ if (typeof password === 'undefined') {
801
+ throw new AppwriteException('Missing required parameter: "password"');
802
+ }
803
+
804
+
805
+ if (typeof email !== 'undefined') {
806
+ payload['email'] = email;
807
+ }
808
+
809
+ if (typeof password !== 'undefined') {
810
+ payload['password'] = password;
811
+ }
812
+
813
+ return await this.client.call('post', apiPath, {
814
+ 'content-type': 'application/json',
815
+ }, payload);
816
+ }
817
+
818
+ /**
819
+ * Update magic URL session
820
+ *
821
+ * Use this endpoint to create a session from token. Provide the **userId**
822
+ * and **secret** parameters from the successful response of authentication
823
+ * flows initiated by token creation. For example, magic URL and phone login.
824
+ *
825
+ * @param {string} userId
826
+ * @param {string} secret
827
+ * @throws {AppwriteException}
828
+ * @returns {Promise}
829
+ */
830
+ async updateMagicURLSession(userId, secret) {
831
+ const apiPath = '/account/sessions/magic-url';
832
+ let payload = {};
833
+ if (typeof userId === 'undefined') {
834
+ throw new AppwriteException('Missing required parameter: "userId"');
835
+ }
836
+
837
+ if (typeof secret === 'undefined') {
838
+ throw new AppwriteException('Missing required parameter: "secret"');
839
+ }
840
+
841
+
842
+ if (typeof userId !== 'undefined') {
843
+ payload['userId'] = userId;
844
+ }
845
+
846
+ if (typeof secret !== 'undefined') {
847
+ payload['secret'] = secret;
848
+ }
849
+
850
+ return await this.client.call('put', apiPath, {
851
+ 'content-type': 'application/json',
852
+ }, payload);
853
+ }
854
+
855
+ /**
856
+ * Update phone session
857
+ *
858
+ * Use this endpoint to create a session from token. Provide the **userId**
859
+ * and **secret** parameters from the successful response of authentication
860
+ * flows initiated by token creation. For example, magic URL and phone login.
861
+ *
862
+ * @param {string} userId
863
+ * @param {string} secret
864
+ * @throws {AppwriteException}
865
+ * @returns {Promise}
866
+ */
867
+ async updatePhoneSession(userId, secret) {
868
+ const apiPath = '/account/sessions/phone';
869
+ let payload = {};
870
+ if (typeof userId === 'undefined') {
871
+ throw new AppwriteException('Missing required parameter: "userId"');
872
+ }
873
+
874
+ if (typeof secret === 'undefined') {
875
+ throw new AppwriteException('Missing required parameter: "secret"');
876
+ }
877
+
878
+
879
+ if (typeof userId !== 'undefined') {
880
+ payload['userId'] = userId;
881
+ }
882
+
883
+ if (typeof secret !== 'undefined') {
884
+ payload['secret'] = secret;
885
+ }
886
+
887
+ return await this.client.call('put', apiPath, {
888
+ 'content-type': 'application/json',
889
+ }, payload);
890
+ }
891
+
892
+ /**
893
+ * Create session
894
+ *
895
+ * Use this endpoint to create a session from token. Provide the **userId**
896
+ * and **secret** parameters from the successful response of authentication
897
+ * flows initiated by token creation. For example, magic URL and phone login.
898
+ *
899
+ * @param {string} userId
900
+ * @param {string} secret
901
+ * @throws {AppwriteException}
902
+ * @returns {Promise}
903
+ */
904
+ async createSession(userId, secret) {
905
+ const apiPath = '/account/sessions/token';
906
+ let payload = {};
907
+ if (typeof userId === 'undefined') {
908
+ throw new AppwriteException('Missing required parameter: "userId"');
909
+ }
910
+
911
+ if (typeof secret === 'undefined') {
912
+ throw new AppwriteException('Missing required parameter: "secret"');
913
+ }
914
+
915
+
916
+ if (typeof userId !== 'undefined') {
917
+ payload['userId'] = userId;
918
+ }
919
+
920
+ if (typeof secret !== 'undefined') {
921
+ payload['secret'] = secret;
922
+ }
923
+
924
+ return await this.client.call('post', apiPath, {
925
+ 'content-type': 'application/json',
926
+ }, payload);
927
+ }
928
+
426
929
  /**
427
930
  * Get session
428
931
  *
@@ -447,11 +950,11 @@ class Account extends Service {
447
950
  }
448
951
 
449
952
  /**
450
- * Update OAuth session (refresh tokens)
953
+ * Update session
451
954
  *
452
- * Access tokens have limited lifespan and expire to mitigate security risks.
453
- * If session was created using an OAuth provider, this route can be used to
454
- * "refresh" the access token.
955
+ * Use this endpoint to extend a session's length. Extending a session is
956
+ * useful when session expiry is short. If the session was created using an
957
+ * OAuth provider, this endpoint refreshes the access token from the provider.
455
958
  *
456
959
  * @param {string} sessionId
457
960
  * @throws {AppwriteException}
@@ -515,6 +1018,209 @@ class Account extends Service {
515
1018
  }, payload);
516
1019
  }
517
1020
 
1021
+ /**
1022
+ * Create email token (OTP)
1023
+ *
1024
+ * Sends the user an email with a secret key for creating a session. If the
1025
+ * provided user ID has not be registered, a new user will be created. Use the
1026
+ * returned user ID and secret and submit a request to the [POST
1027
+ * /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession)
1028
+ * endpoint to complete the login process. The secret sent to the user's email
1029
+ * is valid for 15 minutes.
1030
+ *
1031
+ * A user is limited to 10 active sessions at a time by default. [Learn more
1032
+ * about session
1033
+ * limits](https://appwrite.io/docs/authentication-security#limits).
1034
+ *
1035
+ * @param {string} userId
1036
+ * @param {string} email
1037
+ * @param {boolean} phrase
1038
+ * @throws {AppwriteException}
1039
+ * @returns {Promise}
1040
+ */
1041
+ async createEmailToken(userId, email, phrase) {
1042
+ const apiPath = '/account/tokens/email';
1043
+ let payload = {};
1044
+ if (typeof userId === 'undefined') {
1045
+ throw new AppwriteException('Missing required parameter: "userId"');
1046
+ }
1047
+
1048
+ if (typeof email === 'undefined') {
1049
+ throw new AppwriteException('Missing required parameter: "email"');
1050
+ }
1051
+
1052
+
1053
+ if (typeof userId !== 'undefined') {
1054
+ payload['userId'] = userId;
1055
+ }
1056
+
1057
+ if (typeof email !== 'undefined') {
1058
+ payload['email'] = email;
1059
+ }
1060
+
1061
+ if (typeof phrase !== 'undefined') {
1062
+ payload['phrase'] = phrase;
1063
+ }
1064
+
1065
+ return await this.client.call('post', apiPath, {
1066
+ 'content-type': 'application/json',
1067
+ }, payload);
1068
+ }
1069
+
1070
+ /**
1071
+ * Create magic URL token
1072
+ *
1073
+ * Sends the user an email with a secret key for creating a session. If the
1074
+ * provided user ID has not been registered, a new user will be created. When
1075
+ * the user clicks the link in the email, the user is redirected back to the
1076
+ * URL you provided with the secret key and userId values attached to the URL
1077
+ * query string. Use the query string parameters to submit a request to the
1078
+ * [POST
1079
+ * /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession)
1080
+ * endpoint to complete the login process. The link sent to the user's email
1081
+ * address is valid for 1 hour. If you are on a mobile device you can leave
1082
+ * the URL parameter empty, so that the login completion will be handled by
1083
+ * your Appwrite instance by default.
1084
+ *
1085
+ * A user is limited to 10 active sessions at a time by default. [Learn more
1086
+ * about session
1087
+ * limits](https://appwrite.io/docs/authentication-security#limits).
1088
+ *
1089
+ *
1090
+ * @param {string} userId
1091
+ * @param {string} email
1092
+ * @param {string} url
1093
+ * @param {boolean} phrase
1094
+ * @throws {AppwriteException}
1095
+ * @returns {Promise}
1096
+ */
1097
+ async createMagicURLToken(userId, email, url, phrase) {
1098
+ const apiPath = '/account/tokens/magic-url';
1099
+ let payload = {};
1100
+ if (typeof userId === 'undefined') {
1101
+ throw new AppwriteException('Missing required parameter: "userId"');
1102
+ }
1103
+
1104
+ if (typeof email === 'undefined') {
1105
+ throw new AppwriteException('Missing required parameter: "email"');
1106
+ }
1107
+
1108
+
1109
+ if (typeof userId !== 'undefined') {
1110
+ payload['userId'] = userId;
1111
+ }
1112
+
1113
+ if (typeof email !== 'undefined') {
1114
+ payload['email'] = email;
1115
+ }
1116
+
1117
+ if (typeof url !== 'undefined') {
1118
+ payload['url'] = url;
1119
+ }
1120
+
1121
+ if (typeof phrase !== 'undefined') {
1122
+ payload['phrase'] = phrase;
1123
+ }
1124
+
1125
+ return await this.client.call('post', apiPath, {
1126
+ 'content-type': 'application/json',
1127
+ }, payload);
1128
+ }
1129
+
1130
+ /**
1131
+ * Create OAuth2 token
1132
+ *
1133
+ * Allow the user to login to their account using the OAuth2 provider of their
1134
+ * choice. Each OAuth2 provider should be enabled from the Appwrite console
1135
+ * first. Use the success and failure arguments to provide a redirect URL's
1136
+ * back to your app when login is completed.
1137
+ *
1138
+ * If authentication succeeds, `userId` and `secret` of a token will be
1139
+ * appended to the success URL as query parameters. These can be used to
1140
+ * create a new session using the [Create
1141
+ * session](https://appwrite.io/docs/references/cloud/client-web/account#createSession)
1142
+ * endpoint.
1143
+ *
1144
+ * A user is limited to 10 active sessions at a time by default. [Learn more
1145
+ * about session
1146
+ * limits](https://appwrite.io/docs/authentication-security#limits).
1147
+ *
1148
+ * @param {OAuthProvider} provider
1149
+ * @param {string} success
1150
+ * @param {string} failure
1151
+ * @param {string[]} scopes
1152
+ * @throws {AppwriteException}
1153
+ * @returns {Promise}
1154
+ */
1155
+ async createOAuth2Token(provider, success, failure, scopes) {
1156
+ const apiPath = '/account/tokens/oauth2/{provider}'.replace('{provider}', provider);
1157
+ let payload = {};
1158
+ if (typeof provider === 'undefined') {
1159
+ throw new AppwriteException('Missing required parameter: "provider"');
1160
+ }
1161
+
1162
+
1163
+ if (typeof success !== 'undefined') {
1164
+ payload['success'] = success;
1165
+ }
1166
+
1167
+ if (typeof failure !== 'undefined') {
1168
+ payload['failure'] = failure;
1169
+ }
1170
+
1171
+ if (typeof scopes !== 'undefined') {
1172
+ payload['scopes'] = scopes;
1173
+ }
1174
+
1175
+ return await this.client.call('get', apiPath, {
1176
+ 'content-type': 'application/json',
1177
+ }, payload, 'location');
1178
+ }
1179
+
1180
+ /**
1181
+ * Create phone token
1182
+ *
1183
+ * Sends the user an SMS with a secret key for creating a session. If the
1184
+ * provided user ID has not be registered, a new user will be created. Use the
1185
+ * returned user ID and secret and submit a request to the [POST
1186
+ * /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession)
1187
+ * endpoint to complete the login process. The secret sent to the user's phone
1188
+ * is valid for 15 minutes.
1189
+ *
1190
+ * A user is limited to 10 active sessions at a time by default. [Learn more
1191
+ * about session
1192
+ * limits](https://appwrite.io/docs/authentication-security#limits).
1193
+ *
1194
+ * @param {string} userId
1195
+ * @param {string} phone
1196
+ * @throws {AppwriteException}
1197
+ * @returns {Promise}
1198
+ */
1199
+ async createPhoneToken(userId, phone) {
1200
+ const apiPath = '/account/tokens/phone';
1201
+ let payload = {};
1202
+ if (typeof userId === 'undefined') {
1203
+ throw new AppwriteException('Missing required parameter: "userId"');
1204
+ }
1205
+
1206
+ if (typeof phone === 'undefined') {
1207
+ throw new AppwriteException('Missing required parameter: "phone"');
1208
+ }
1209
+
1210
+
1211
+ if (typeof userId !== 'undefined') {
1212
+ payload['userId'] = userId;
1213
+ }
1214
+
1215
+ if (typeof phone !== 'undefined') {
1216
+ payload['phone'] = phone;
1217
+ }
1218
+
1219
+ return await this.client.call('post', apiPath, {
1220
+ 'content-type': 'application/json',
1221
+ }, payload);
1222
+ }
1223
+
518
1224
  /**
519
1225
  * Create email verification
520
1226
  *