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 Storage extends Service {
10
12
 
@@ -54,7 +56,7 @@ class Storage extends Service {
54
56
  * @param {boolean} enabled
55
57
  * @param {number} maximumFileSize
56
58
  * @param {string[]} allowedFileExtensions
57
- * @param {string} compression
59
+ * @param {Compression} compression
58
60
  * @param {boolean} encryption
59
61
  * @param {boolean} antivirus
60
62
  * @throws {AppwriteException}
@@ -152,7 +154,7 @@ class Storage extends Service {
152
154
  * @param {boolean} enabled
153
155
  * @param {number} maximumFileSize
154
156
  * @param {string[]} allowedFileExtensions
155
- * @param {string} compression
157
+ * @param {Compression} compression
156
158
  * @param {boolean} encryption
157
159
  * @param {boolean} antivirus
158
160
  * @throws {AppwriteException}
@@ -292,6 +294,7 @@ class Storage extends Service {
292
294
  * @param {string} fileId
293
295
  * @param {InputFile} file
294
296
  * @param {string[]} permissions
297
+ * @param {CallableFunction} onProgress
295
298
  * @throws {AppwriteException}
296
299
  * @returns {Promise}
297
300
  */
@@ -323,8 +326,9 @@ class Storage extends Service {
323
326
  payload['permissions'] = permissions;
324
327
  }
325
328
 
326
- const size = file.size;
327
329
 
330
+ const size = file.size;
331
+
328
332
  const apiHeaders = {
329
333
  'content-type': 'multipart/form-data',
330
334
  };
@@ -342,118 +346,78 @@ class Storage extends Service {
342
346
  }
343
347
  }
344
348
 
345
- let currentChunk = Buffer.from('');
346
- let currentChunkSize = 0;
347
- let currentChunkStart = 0;
348
-
349
- const selfClient = this.client;
349
+ let currentChunk = 1;
350
+ let currentPosition = 0;
351
+ let uploadableChunk = new Uint8Array(client.CHUNK_SIZE);
352
+
350
353
 
351
- async function uploadChunk(lastUpload = false) {
352
- if(chunksUploaded - 1 >= currentChunkStart / client.CHUNK_SIZE) {
354
+ const uploadChunk = async (lastUpload = false) => {
355
+ if(currentChunk <= chunksUploaded) {
353
356
  return;
354
357
  }
355
-
356
- const start = currentChunkStart;
357
- const end = currentChunkStart + currentChunkSize - 1;
358
358
 
359
- if(!lastUpload || currentChunkStart !== 0) {
359
+ const start = ((currentChunk - 1) * client.CHUNK_SIZE);
360
+ let end = start + currentPosition - 1;
361
+
362
+ if(!lastUpload || currentChunk !== 1) {
360
363
  apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
361
364
  }
362
365
 
366
+ let uploadableChunkTrimmed;
367
+
368
+ if(currentPosition + 1 >= client.CHUNK_SIZE) {
369
+ uploadableChunkTrimmed = uploadableChunk;
370
+ } else {
371
+ uploadableChunkTrimmed = new Uint8Array(currentPosition);
372
+ for(let i = 0; i <= currentPosition; i++) {
373
+ uploadableChunkTrimmed[i] = uploadableChunk[i];
374
+ }
375
+ }
376
+
363
377
  if (id) {
364
378
  apiHeaders['x-appwrite-id'] = id;
365
379
  }
366
380
 
367
- payload['file'] = {
368
- type: 'file',
369
- file: currentChunk,
370
- filename: file.filename,
371
- size: currentChunkSize
372
- };
381
+ payload['file'] = { type: 'file', file: new File([uploadableChunkTrimmed], file.filename), filename: file.filename };
373
382
 
374
- response = await selfClient.call('post', apiPath, apiHeaders, payload);
383
+ response = await this.client.call('post', apiPath, apiHeaders, payload);
375
384
 
376
385
  if (!id) {
377
386
  id = response['$id'];
378
387
  }
379
-
388
+
380
389
  if (onProgress !== null) {
381
390
  onProgress({
382
391
  $id: response['$id'],
383
- progress: Math.min((start+client.CHUNK_SIZE) * client.CHUNK_SIZE, size) / size * 100,
392
+ progress: Math.min((currentChunk) * client.CHUNK_SIZE, size) / size * 100,
384
393
  sizeUploaded: end+1,
385
394
  chunksTotal: response['chunksTotal'],
386
395
  chunksUploaded: response['chunksUploaded']
387
396
  });
388
397
  }
389
398
 
390
- currentChunkStart += client.CHUNK_SIZE;
391
- }
392
-
393
- return await new Promise((resolve, reject) => {
394
- const writeStream = new Stream.Writable();
395
- writeStream._write = async (mainChunk, encoding, callback) => {
396
- try {
397
- // Segment incoming chunk into up to 5MB chunks
398
- const mainChunkSize = Buffer.byteLength(mainChunk);
399
- const chunksCount = Math.ceil(mainChunkSize / client.CHUNK_SIZE);
400
- const chunks = [];
401
-
402
- for(let i = 0; i < chunksCount; i++) {
403
- const chunk = mainChunk.slice(i * client.CHUNK_SIZE, (i + 1) * client.CHUNK_SIZE);
404
- chunks.push(chunk);
405
- }
406
-
407
- for (const chunk of chunks) {
408
- const chunkSize = Buffer.byteLength(chunk);
409
-
410
- if(chunkSize + currentChunkSize == client.CHUNK_SIZE) {
411
- // Upload chunk
412
- currentChunk = Buffer.concat([currentChunk, chunk]);
413
- currentChunkSize = Buffer.byteLength(currentChunk);
414
- await uploadChunk();
415
- currentChunk = Buffer.from('');
416
- currentChunkSize = 0;
417
- } else if(chunkSize + currentChunkSize > client.CHUNK_SIZE) {
418
- // Upload chunk, put rest into next chunk
419
- const bytesToUpload = client.CHUNK_SIZE - currentChunkSize;
420
- const newChunkSection = chunk.slice(0, bytesToUpload);
421
- currentChunk = Buffer.concat([currentChunk, newChunkSection]);
422
- currentChunkSize = Buffer.byteLength(currentChunk);
423
- await uploadChunk();
424
- currentChunk = chunk.slice(bytesToUpload, undefined);
425
- currentChunkSize = chunkSize - bytesToUpload;
426
- } else {
427
- // Append into current chunk
428
- currentChunk = Buffer.concat([currentChunk, chunk]);
429
- currentChunkSize = chunkSize + currentChunkSize;
430
- }
431
- }
432
-
433
- callback();
434
- } catch (e) {
435
- callback(e);
399
+ uploadableChunk = new Uint8Array(client.CHUNK_SIZE);
400
+ currentChunk++;
401
+ currentPosition = 0;
402
+ }
403
+
404
+ for await (const chunk of file.stream) {
405
+ for(const b of chunk) {
406
+ uploadableChunk[currentPosition] = b;
407
+
408
+ currentPosition++;
409
+ if(currentPosition >= client.CHUNK_SIZE) {
410
+ await uploadChunk();
411
+ currentPosition = 0;
436
412
  }
437
413
  }
414
+ }
438
415
 
439
- writeStream.on("finish", async () => {
440
- if(currentChunkSize > 0) {
441
- try {
442
- await uploadChunk(true);
443
- } catch (e) {
444
- reject(e);
445
- }
446
- }
447
-
448
- resolve(response);
449
- });
416
+ if (currentPosition > 0) { // Check if there's any remaining data for the last chunk
417
+ await uploadChunk(true);
418
+ }
450
419
 
451
- writeStream.on("error", (err) => {
452
- reject(err);
453
- });
454
-
455
- file.stream.pipe(writeStream);
456
- });
420
+ return response;
457
421
 
458
422
  }
459
423
 
@@ -593,7 +557,7 @@ class Storage extends Service {
593
557
  * @param {string} fileId
594
558
  * @param {number} width
595
559
  * @param {number} height
596
- * @param {string} gravity
560
+ * @param {ImageGravity} gravity
597
561
  * @param {number} quality
598
562
  * @param {number} borderWidth
599
563
  * @param {string} borderColor
@@ -601,7 +565,7 @@ class Storage extends Service {
601
565
  * @param {number} opacity
602
566
  * @param {number} rotation
603
567
  * @param {string} background
604
- * @param {string} output
568
+ * @param {ImageFormat} output
605
569
  * @throws {AppwriteException}
606
570
  * @returns {Promise}
607
571
  */
@@ -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 Teams extends Service {
10
12
 
@@ -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 Users extends Service {
10
12
 
@@ -197,7 +199,7 @@ class Users extends Service {
197
199
  *
198
200
  * Get identities for all users.
199
201
  *
200
- * @param {string} queries
202
+ * @param {string[]} queries
201
203
  * @param {string} search
202
204
  * @throws {AppwriteException}
203
205
  * @returns {Promise}
@@ -220,7 +222,7 @@ class Users extends Service {
220
222
  }
221
223
 
222
224
  /**
223
- * Delete Identity
225
+ * Delete identity
224
226
  *
225
227
  * Delete an identity by its unique ID.
226
228
  *
@@ -533,7 +535,7 @@ class Users extends Service {
533
535
  * @param {string} userId
534
536
  * @param {string} email
535
537
  * @param {string} password
536
- * @param {string} passwordVersion
538
+ * @param {PasswordHash} passwordVersion
537
539
  * @param {string} name
538
540
  * @throws {AppwriteException}
539
541
  * @returns {Promise}
@@ -744,6 +746,161 @@ class Users extends Service {
744
746
  }, payload);
745
747
  }
746
748
 
749
+ /**
750
+ * Update MFA
751
+ *
752
+ * Enable or disable MFA on a user account.
753
+ *
754
+ * @param {string} userId
755
+ * @param {boolean} mfa
756
+ * @throws {AppwriteException}
757
+ * @returns {Promise}
758
+ */
759
+ async updateMfa(userId, mfa) {
760
+ const apiPath = '/users/{userId}/mfa'.replace('{userId}', userId);
761
+ let payload = {};
762
+ if (typeof userId === 'undefined') {
763
+ throw new AppwriteException('Missing required parameter: "userId"');
764
+ }
765
+
766
+ if (typeof mfa === 'undefined') {
767
+ throw new AppwriteException('Missing required parameter: "mfa"');
768
+ }
769
+
770
+
771
+ if (typeof mfa !== 'undefined') {
772
+ payload['mfa'] = mfa;
773
+ }
774
+
775
+ return await this.client.call('patch', apiPath, {
776
+ 'content-type': 'application/json',
777
+ }, payload);
778
+ }
779
+
780
+ /**
781
+ * Delete Authenticator
782
+ *
783
+ * Delete an authenticator app.
784
+ *
785
+ * @param {string} userId
786
+ * @param {AuthenticatorType} type
787
+ * @throws {AppwriteException}
788
+ * @returns {Promise}
789
+ */
790
+ async deleteMfaAuthenticator(userId, type) {
791
+ const apiPath = '/users/{userId}/mfa/authenticators/{type}'.replace('{userId}', userId).replace('{type}', type);
792
+ let payload = {};
793
+ if (typeof userId === 'undefined') {
794
+ throw new AppwriteException('Missing required parameter: "userId"');
795
+ }
796
+
797
+ if (typeof type === 'undefined') {
798
+ throw new AppwriteException('Missing required parameter: "type"');
799
+ }
800
+
801
+
802
+ return await this.client.call('delete', apiPath, {
803
+ 'content-type': 'application/json',
804
+ }, payload);
805
+ }
806
+
807
+ /**
808
+ * List Factors
809
+ *
810
+ * List the factors available on the account to be used as a MFA challange.
811
+ *
812
+ * @param {string} userId
813
+ * @throws {AppwriteException}
814
+ * @returns {Promise}
815
+ */
816
+ async listMfaFactors(userId) {
817
+ const apiPath = '/users/{userId}/mfa/factors'.replace('{userId}', userId);
818
+ let payload = {};
819
+ if (typeof userId === 'undefined') {
820
+ throw new AppwriteException('Missing required parameter: "userId"');
821
+ }
822
+
823
+
824
+ return await this.client.call('get', apiPath, {
825
+ 'content-type': 'application/json',
826
+ }, payload);
827
+ }
828
+
829
+ /**
830
+ * Get MFA Recovery Codes
831
+ *
832
+ * Get recovery codes that can be used as backup for MFA flow by User ID.
833
+ * Before getting codes, they must be generated using
834
+ * [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes)
835
+ * method.
836
+ *
837
+ * @param {string} userId
838
+ * @throws {AppwriteException}
839
+ * @returns {Promise}
840
+ */
841
+ async getMfaRecoveryCodes(userId) {
842
+ const apiPath = '/users/{userId}/mfa/recovery-codes'.replace('{userId}', userId);
843
+ let payload = {};
844
+ if (typeof userId === 'undefined') {
845
+ throw new AppwriteException('Missing required parameter: "userId"');
846
+ }
847
+
848
+
849
+ return await this.client.call('get', apiPath, {
850
+ 'content-type': 'application/json',
851
+ }, payload);
852
+ }
853
+
854
+ /**
855
+ * Regenerate MFA Recovery Codes
856
+ *
857
+ * Regenerate recovery codes that can be used as backup for MFA flow by User
858
+ * ID. Before regenerating codes, they must be first generated using
859
+ * [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes)
860
+ * method.
861
+ *
862
+ * @param {string} userId
863
+ * @throws {AppwriteException}
864
+ * @returns {Promise}
865
+ */
866
+ async updateMfaRecoveryCodes(userId) {
867
+ const apiPath = '/users/{userId}/mfa/recovery-codes'.replace('{userId}', userId);
868
+ let payload = {};
869
+ if (typeof userId === 'undefined') {
870
+ throw new AppwriteException('Missing required parameter: "userId"');
871
+ }
872
+
873
+
874
+ return await this.client.call('put', apiPath, {
875
+ 'content-type': 'application/json',
876
+ }, payload);
877
+ }
878
+
879
+ /**
880
+ * Create MFA Recovery Codes
881
+ *
882
+ * Generate recovery codes used as backup for MFA flow for User ID. Recovery
883
+ * codes can be used as a MFA verification type in
884
+ * [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge)
885
+ * method by client SDK.
886
+ *
887
+ * @param {string} userId
888
+ * @throws {AppwriteException}
889
+ * @returns {Promise}
890
+ */
891
+ async createMfaRecoveryCodes(userId) {
892
+ const apiPath = '/users/{userId}/mfa/recovery-codes'.replace('{userId}', userId);
893
+ let payload = {};
894
+ if (typeof userId === 'undefined') {
895
+ throw new AppwriteException('Missing required parameter: "userId"');
896
+ }
897
+
898
+
899
+ return await this.client.call('patch', apiPath, {
900
+ 'content-type': 'application/json',
901
+ }, payload);
902
+ }
903
+
747
904
  /**
748
905
  * Update name
749
906
  *
@@ -914,6 +1071,33 @@ class Users extends Service {
914
1071
  }, payload);
915
1072
  }
916
1073
 
1074
+ /**
1075
+ * Create session
1076
+ *
1077
+ * Creates a session for a user. Returns an immediately usable session object.
1078
+ *
1079
+ * If you want to generate a token for a custom authentication flow, use the
1080
+ * [POST
1081
+ * /users/{userId}/tokens](https://appwrite.io/docs/server/users#createToken)
1082
+ * endpoint.
1083
+ *
1084
+ * @param {string} userId
1085
+ * @throws {AppwriteException}
1086
+ * @returns {Promise}
1087
+ */
1088
+ async createSession(userId) {
1089
+ const apiPath = '/users/{userId}/sessions'.replace('{userId}', userId);
1090
+ let payload = {};
1091
+ if (typeof userId === 'undefined') {
1092
+ throw new AppwriteException('Missing required parameter: "userId"');
1093
+ }
1094
+
1095
+
1096
+ return await this.client.call('post', apiPath, {
1097
+ 'content-type': 'application/json',
1098
+ }, payload);
1099
+ }
1100
+
917
1101
  /**
918
1102
  * Delete user sessions
919
1103
  *
@@ -995,6 +1179,224 @@ class Users extends Service {
995
1179
  }, payload);
996
1180
  }
997
1181
 
1182
+ /**
1183
+ * List User Targets
1184
+ *
1185
+ * List the messaging targets that are associated with a user.
1186
+ *
1187
+ * @param {string} userId
1188
+ * @param {string[]} queries
1189
+ * @throws {AppwriteException}
1190
+ * @returns {Promise}
1191
+ */
1192
+ async listTargets(userId, queries) {
1193
+ const apiPath = '/users/{userId}/targets'.replace('{userId}', userId);
1194
+ let payload = {};
1195
+ if (typeof userId === 'undefined') {
1196
+ throw new AppwriteException('Missing required parameter: "userId"');
1197
+ }
1198
+
1199
+
1200
+ if (typeof queries !== 'undefined') {
1201
+ payload['queries'] = queries;
1202
+ }
1203
+
1204
+ return await this.client.call('get', apiPath, {
1205
+ 'content-type': 'application/json',
1206
+ }, payload);
1207
+ }
1208
+
1209
+ /**
1210
+ * Create User Target
1211
+ *
1212
+ * Create a messaging target.
1213
+ *
1214
+ * @param {string} userId
1215
+ * @param {string} targetId
1216
+ * @param {MessagingProviderType} providerType
1217
+ * @param {string} identifier
1218
+ * @param {string} providerId
1219
+ * @param {string} name
1220
+ * @throws {AppwriteException}
1221
+ * @returns {Promise}
1222
+ */
1223
+ async createTarget(userId, targetId, providerType, identifier, providerId, name) {
1224
+ const apiPath = '/users/{userId}/targets'.replace('{userId}', userId);
1225
+ let payload = {};
1226
+ if (typeof userId === 'undefined') {
1227
+ throw new AppwriteException('Missing required parameter: "userId"');
1228
+ }
1229
+
1230
+ if (typeof targetId === 'undefined') {
1231
+ throw new AppwriteException('Missing required parameter: "targetId"');
1232
+ }
1233
+
1234
+ if (typeof providerType === 'undefined') {
1235
+ throw new AppwriteException('Missing required parameter: "providerType"');
1236
+ }
1237
+
1238
+ if (typeof identifier === 'undefined') {
1239
+ throw new AppwriteException('Missing required parameter: "identifier"');
1240
+ }
1241
+
1242
+
1243
+ if (typeof targetId !== 'undefined') {
1244
+ payload['targetId'] = targetId;
1245
+ }
1246
+
1247
+ if (typeof providerType !== 'undefined') {
1248
+ payload['providerType'] = providerType;
1249
+ }
1250
+
1251
+ if (typeof identifier !== 'undefined') {
1252
+ payload['identifier'] = identifier;
1253
+ }
1254
+
1255
+ if (typeof providerId !== 'undefined') {
1256
+ payload['providerId'] = providerId;
1257
+ }
1258
+
1259
+ if (typeof name !== 'undefined') {
1260
+ payload['name'] = name;
1261
+ }
1262
+
1263
+ return await this.client.call('post', apiPath, {
1264
+ 'content-type': 'application/json',
1265
+ }, payload);
1266
+ }
1267
+
1268
+ /**
1269
+ * Get User Target
1270
+ *
1271
+ * Get a user's push notification target by ID.
1272
+ *
1273
+ * @param {string} userId
1274
+ * @param {string} targetId
1275
+ * @throws {AppwriteException}
1276
+ * @returns {Promise}
1277
+ */
1278
+ async getTarget(userId, targetId) {
1279
+ const apiPath = '/users/{userId}/targets/{targetId}'.replace('{userId}', userId).replace('{targetId}', targetId);
1280
+ let payload = {};
1281
+ if (typeof userId === 'undefined') {
1282
+ throw new AppwriteException('Missing required parameter: "userId"');
1283
+ }
1284
+
1285
+ if (typeof targetId === 'undefined') {
1286
+ throw new AppwriteException('Missing required parameter: "targetId"');
1287
+ }
1288
+
1289
+
1290
+ return await this.client.call('get', apiPath, {
1291
+ 'content-type': 'application/json',
1292
+ }, payload);
1293
+ }
1294
+
1295
+ /**
1296
+ * Update User target
1297
+ *
1298
+ * Update a messaging target.
1299
+ *
1300
+ * @param {string} userId
1301
+ * @param {string} targetId
1302
+ * @param {string} identifier
1303
+ * @param {string} providerId
1304
+ * @param {string} name
1305
+ * @throws {AppwriteException}
1306
+ * @returns {Promise}
1307
+ */
1308
+ async updateTarget(userId, targetId, identifier, providerId, name) {
1309
+ const apiPath = '/users/{userId}/targets/{targetId}'.replace('{userId}', userId).replace('{targetId}', targetId);
1310
+ let payload = {};
1311
+ if (typeof userId === 'undefined') {
1312
+ throw new AppwriteException('Missing required parameter: "userId"');
1313
+ }
1314
+
1315
+ if (typeof targetId === 'undefined') {
1316
+ throw new AppwriteException('Missing required parameter: "targetId"');
1317
+ }
1318
+
1319
+
1320
+ if (typeof identifier !== 'undefined') {
1321
+ payload['identifier'] = identifier;
1322
+ }
1323
+
1324
+ if (typeof providerId !== 'undefined') {
1325
+ payload['providerId'] = providerId;
1326
+ }
1327
+
1328
+ if (typeof name !== 'undefined') {
1329
+ payload['name'] = name;
1330
+ }
1331
+
1332
+ return await this.client.call('patch', apiPath, {
1333
+ 'content-type': 'application/json',
1334
+ }, payload);
1335
+ }
1336
+
1337
+ /**
1338
+ * Delete user target
1339
+ *
1340
+ * Delete a messaging target.
1341
+ *
1342
+ * @param {string} userId
1343
+ * @param {string} targetId
1344
+ * @throws {AppwriteException}
1345
+ * @returns {Promise}
1346
+ */
1347
+ async deleteTarget(userId, targetId) {
1348
+ const apiPath = '/users/{userId}/targets/{targetId}'.replace('{userId}', userId).replace('{targetId}', targetId);
1349
+ let payload = {};
1350
+ if (typeof userId === 'undefined') {
1351
+ throw new AppwriteException('Missing required parameter: "userId"');
1352
+ }
1353
+
1354
+ if (typeof targetId === 'undefined') {
1355
+ throw new AppwriteException('Missing required parameter: "targetId"');
1356
+ }
1357
+
1358
+
1359
+ return await this.client.call('delete', apiPath, {
1360
+ 'content-type': 'application/json',
1361
+ }, payload);
1362
+ }
1363
+
1364
+ /**
1365
+ * Create token
1366
+ *
1367
+ * Returns a token with a secret key for creating a session. If the provided
1368
+ * user ID has not be registered, a new user will be created. Use the returned
1369
+ * user ID and secret and submit a request to the [PUT
1370
+ * /account/sessions/custom](https://appwrite.io/docs/references/cloud/client-web/account#updateCustomSession)
1371
+ * endpoint to complete the login process.
1372
+ *
1373
+ * @param {string} userId
1374
+ * @param {number} length
1375
+ * @param {number} expire
1376
+ * @throws {AppwriteException}
1377
+ * @returns {Promise}
1378
+ */
1379
+ async createToken(userId, length, expire) {
1380
+ const apiPath = '/users/{userId}/tokens'.replace('{userId}', userId);
1381
+ let payload = {};
1382
+ if (typeof userId === 'undefined') {
1383
+ throw new AppwriteException('Missing required parameter: "userId"');
1384
+ }
1385
+
1386
+
1387
+ if (typeof length !== 'undefined') {
1388
+ payload['length'] = length;
1389
+ }
1390
+
1391
+ if (typeof expire !== 'undefined') {
1392
+ payload['expire'] = expire;
1393
+ }
1394
+
1395
+ return await this.client.call('post', apiPath, {
1396
+ 'content-type': 'application/json',
1397
+ }, payload);
1398
+ }
1399
+
998
1400
  /**
999
1401
  * Update email verification
1000
1402
  *