node-appwrite 2.4.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/.github/ISSUE_TEMPLATE/bug.yaml +82 -0
  2. package/.github/ISSUE_TEMPLATE/documentation.yaml +32 -0
  3. package/.github/ISSUE_TEMPLATE/feature.yaml +40 -0
  4. package/LICENSE +1 -1
  5. package/README.md +7 -7
  6. package/docs/examples/database/create-boolean-attribute.md +20 -0
  7. package/docs/examples/database/create-collection.md +1 -1
  8. package/docs/examples/database/create-document.md +1 -1
  9. package/docs/examples/database/create-email-attribute.md +20 -0
  10. package/docs/examples/database/create-enum-attribute.md +20 -0
  11. package/docs/examples/database/create-float-attribute.md +20 -0
  12. package/docs/examples/database/create-index.md +20 -0
  13. package/docs/examples/database/create-integer-attribute.md +20 -0
  14. package/docs/examples/database/create-ip-attribute.md +20 -0
  15. package/docs/examples/database/create-string-attribute.md +20 -0
  16. package/docs/examples/database/create-url-attribute.md +20 -0
  17. package/docs/examples/database/delete-attribute.md +20 -0
  18. package/docs/examples/database/delete-index.md +20 -0
  19. package/docs/examples/database/get-attribute.md +20 -0
  20. package/docs/examples/database/get-index.md +20 -0
  21. package/docs/examples/database/list-attributes.md +20 -0
  22. package/docs/examples/database/list-indexes.md +20 -0
  23. package/docs/examples/database/update-collection.md +1 -1
  24. package/docs/examples/functions/create-tag.md +1 -1
  25. package/docs/examples/functions/create.md +1 -1
  26. package/docs/examples/{health/get-queue-tasks.md → functions/list-runtimes.md} +2 -2
  27. package/docs/examples/health/{get-anti-virus.md → get-antivirus.md} +1 -1
  28. package/docs/examples/storage/create-file.md +1 -1
  29. package/docs/examples/teams/create.md +1 -1
  30. package/docs/examples/teams/get-membership.md +20 -0
  31. package/docs/examples/users/create.md +1 -1
  32. package/docs/examples/users/update-email.md +20 -0
  33. package/docs/examples/users/update-name.md +20 -0
  34. package/docs/examples/users/update-password.md +20 -0
  35. package/docs/examples/users/update-status.md +1 -1
  36. package/index.d.ts +1693 -235
  37. package/lib/client.js +5 -5
  38. package/lib/query.js +34 -0
  39. package/lib/services/account.js +18 -6
  40. package/lib/services/database.js +706 -47
  41. package/lib/services/functions.js +63 -12
  42. package/lib/services/health.js +4 -22
  43. package/lib/services/storage.js +21 -2
  44. package/lib/services/teams.js +93 -31
  45. package/lib/services/users.js +127 -5
  46. package/package.json +2 -2
@@ -12,11 +12,13 @@ class Functions extends Service {
12
12
  * @param {string} search
13
13
  * @param {number} limit
14
14
  * @param {number} offset
15
+ * @param {string} cursor
16
+ * @param {string} cursorDirection
15
17
  * @param {string} orderType
16
18
  * @throws {AppwriteException}
17
19
  * @returns {Promise}
18
20
  */
19
- async list(search, limit, offset, orderType) {
21
+ async list(search, limit, offset, cursor, cursorDirection, orderType) {
20
22
  let path = '/functions';
21
23
  let payload = {};
22
24
 
@@ -32,6 +34,14 @@ class Functions extends Service {
32
34
  payload['offset'] = offset;
33
35
  }
34
36
 
37
+ if (typeof cursor !== 'undefined') {
38
+ payload['cursor'] = cursor;
39
+ }
40
+
41
+ if (typeof cursorDirection !== 'undefined') {
42
+ payload['cursorDirection'] = cursorDirection;
43
+ }
44
+
35
45
  if (typeof orderType !== 'undefined') {
36
46
  payload['orderType'] = orderType;
37
47
  }
@@ -48,6 +58,7 @@ class Functions extends Service {
48
58
  * [permissions](/docs/permissions) to allow different project users or team
49
59
  * with access to execute the function using the client API.
50
60
  *
61
+ * @param {string} functionId
51
62
  * @param {string} name
52
63
  * @param {string[]} execute
53
64
  * @param {string} runtime
@@ -58,7 +69,11 @@ class Functions extends Service {
58
69
  * @throws {AppwriteException}
59
70
  * @returns {Promise}
60
71
  */
61
- async create(name, execute, runtime, vars, events, schedule, timeout) {
72
+ async create(functionId, name, execute, runtime, vars, events, schedule, timeout) {
73
+ if (typeof functionId === 'undefined') {
74
+ throw new AppwriteException('Missing required parameter: "functionId"');
75
+ }
76
+
62
77
  if (typeof name === 'undefined') {
63
78
  throw new AppwriteException('Missing required parameter: "name"');
64
79
  }
@@ -74,6 +89,10 @@ class Functions extends Service {
74
89
  let path = '/functions';
75
90
  let payload = {};
76
91
 
92
+ if (typeof functionId !== 'undefined') {
93
+ payload['functionId'] = functionId;
94
+ }
95
+
77
96
  if (typeof name !== 'undefined') {
78
97
  payload['name'] = name;
79
98
  }
@@ -107,6 +126,23 @@ class Functions extends Service {
107
126
  }, payload);
108
127
  }
109
128
 
129
+ /**
130
+ * List the currently active function runtimes.
131
+ *
132
+ * Get a list of all runtimes that are currently active in your project.
133
+ *
134
+ * @throws {AppwriteException}
135
+ * @returns {Promise}
136
+ */
137
+ async listRuntimes() {
138
+ let path = '/functions/runtimes';
139
+ let payload = {};
140
+
141
+ return await this.client.call('get', path, {
142
+ 'content-type': 'application/json',
143
+ }, payload);
144
+ }
145
+
110
146
  /**
111
147
  * Get Function
112
148
  *
@@ -220,14 +256,15 @@ class Functions extends Service {
220
256
  * different API modes](/docs/admin).
221
257
  *
222
258
  * @param {string} functionId
223
- * @param {string} search
224
259
  * @param {number} limit
225
260
  * @param {number} offset
226
- * @param {string} orderType
261
+ * @param {string} search
262
+ * @param {string} cursor
263
+ * @param {string} cursorDirection
227
264
  * @throws {AppwriteException}
228
265
  * @returns {Promise}
229
266
  */
230
- async listExecutions(functionId, search, limit, offset, orderType) {
267
+ async listExecutions(functionId, limit, offset, search, cursor, cursorDirection) {
231
268
  if (typeof functionId === 'undefined') {
232
269
  throw new AppwriteException('Missing required parameter: "functionId"');
233
270
  }
@@ -235,10 +272,6 @@ class Functions extends Service {
235
272
  let path = '/functions/{functionId}/executions'.replace('{functionId}', functionId);
236
273
  let payload = {};
237
274
 
238
- if (typeof search !== 'undefined') {
239
- payload['search'] = search;
240
- }
241
-
242
275
  if (typeof limit !== 'undefined') {
243
276
  payload['limit'] = limit;
244
277
  }
@@ -247,8 +280,16 @@ class Functions extends Service {
247
280
  payload['offset'] = offset;
248
281
  }
249
282
 
250
- if (typeof orderType !== 'undefined') {
251
- payload['orderType'] = orderType;
283
+ if (typeof search !== 'undefined') {
284
+ payload['search'] = search;
285
+ }
286
+
287
+ if (typeof cursor !== 'undefined') {
288
+ payload['cursor'] = cursor;
289
+ }
290
+
291
+ if (typeof cursorDirection !== 'undefined') {
292
+ payload['cursorDirection'] = cursorDirection;
252
293
  }
253
294
 
254
295
  return await this.client.call('get', path, {
@@ -356,11 +397,13 @@ class Functions extends Service {
356
397
  * @param {string} search
357
398
  * @param {number} limit
358
399
  * @param {number} offset
400
+ * @param {string} cursor
401
+ * @param {string} cursorDirection
359
402
  * @param {string} orderType
360
403
  * @throws {AppwriteException}
361
404
  * @returns {Promise}
362
405
  */
363
- async listTags(functionId, search, limit, offset, orderType) {
406
+ async listTags(functionId, search, limit, offset, cursor, cursorDirection, orderType) {
364
407
  if (typeof functionId === 'undefined') {
365
408
  throw new AppwriteException('Missing required parameter: "functionId"');
366
409
  }
@@ -380,6 +423,14 @@ class Functions extends Service {
380
423
  payload['offset'] = offset;
381
424
  }
382
425
 
426
+ if (typeof cursor !== 'undefined') {
427
+ payload['cursor'] = cursor;
428
+ }
429
+
430
+ if (typeof cursorDirection !== 'undefined') {
431
+ payload['cursorDirection'] = cursorDirection;
432
+ }
433
+
383
434
  if (typeof orderType !== 'undefined') {
384
435
  payload['orderType'] = orderType;
385
436
  }
@@ -21,14 +21,14 @@ class Health extends Service {
21
21
  }
22
22
 
23
23
  /**
24
- * Get Anti virus
24
+ * Get Antivirus
25
25
  *
26
- * Check the Appwrite Anti Virus server is up and connection is successful.
26
+ * Check the Appwrite Antivirus server is up and connection is successful.
27
27
  *
28
28
  * @throws {AppwriteException}
29
29
  * @returns {Promise}
30
30
  */
31
- async getAntiVirus() {
31
+ async getAntivirus() {
32
32
  let path = '/health/anti-virus';
33
33
  let payload = {};
34
34
 
@@ -73,7 +73,7 @@ class Health extends Service {
73
73
  }
74
74
 
75
75
  /**
76
- * Get Certificate Queue
76
+ * Get Certificates Queue
77
77
  *
78
78
  * Get the number of certificates that are waiting to be issued against
79
79
  * [Letsencrypt](https://letsencrypt.org/) in the Appwrite internal queue
@@ -124,24 +124,6 @@ class Health extends Service {
124
124
  }, payload);
125
125
  }
126
126
 
127
- /**
128
- * Get Tasks Queue
129
- *
130
- * Get the number of tasks that are waiting to be processed in the Appwrite
131
- * internal queue server.
132
- *
133
- * @throws {AppwriteException}
134
- * @returns {Promise}
135
- */
136
- async getQueueTasks() {
137
- let path = '/health/queue/tasks';
138
- let payload = {};
139
-
140
- return await this.client.call('get', path, {
141
- 'content-type': 'application/json',
142
- }, payload);
143
- }
144
-
145
127
  /**
146
128
  * Get Usage Queue
147
129
  *
@@ -13,11 +13,13 @@ class Storage extends Service {
13
13
  * @param {string} search
14
14
  * @param {number} limit
15
15
  * @param {number} offset
16
+ * @param {string} cursor
17
+ * @param {string} cursorDirection
16
18
  * @param {string} orderType
17
19
  * @throws {AppwriteException}
18
20
  * @returns {Promise}
19
21
  */
20
- async listFiles(search, limit, offset, orderType) {
22
+ async listFiles(search, limit, offset, cursor, cursorDirection, orderType) {
21
23
  let path = '/storage/files';
22
24
  let payload = {};
23
25
 
@@ -33,6 +35,14 @@ class Storage extends Service {
33
35
  payload['offset'] = offset;
34
36
  }
35
37
 
38
+ if (typeof cursor !== 'undefined') {
39
+ payload['cursor'] = cursor;
40
+ }
41
+
42
+ if (typeof cursorDirection !== 'undefined') {
43
+ payload['cursorDirection'] = cursorDirection;
44
+ }
45
+
36
46
  if (typeof orderType !== 'undefined') {
37
47
  payload['orderType'] = orderType;
38
48
  }
@@ -49,13 +59,18 @@ class Storage extends Service {
49
59
  * assigned to read and write access unless he has passed custom values for
50
60
  * read and write arguments.
51
61
  *
62
+ * @param {string} fileId
52
63
  * @param {File} file
53
64
  * @param {string[]} read
54
65
  * @param {string[]} write
55
66
  * @throws {AppwriteException}
56
67
  * @returns {Promise}
57
68
  */
58
- async createFile(file, read, write) {
69
+ async createFile(fileId, file, read, write) {
70
+ if (typeof fileId === 'undefined') {
71
+ throw new AppwriteException('Missing required parameter: "fileId"');
72
+ }
73
+
59
74
  if (typeof file === 'undefined') {
60
75
  throw new AppwriteException('Missing required parameter: "file"');
61
76
  }
@@ -63,6 +78,10 @@ class Storage extends Service {
63
78
  let path = '/storage/files';
64
79
  let payload = {};
65
80
 
81
+ if (typeof fileId !== 'undefined') {
82
+ payload['fileId'] = fileId;
83
+ }
84
+
66
85
  if (typeof file !== 'undefined') {
67
86
  payload['file'] = file;
68
87
  }
@@ -6,19 +6,22 @@ class Teams extends Service {
6
6
  /**
7
7
  * List Teams
8
8
  *
9
- * Get a list of all the current user teams. You can use the query params to
10
- * filter your results. On admin mode, this endpoint will return a list of all
11
- * of the project's teams. [Learn more about different API
12
- * modes](/docs/admin).
9
+ * Get a list of all the teams in which the current user is a member. You can
10
+ * use the parameters to filter your results.
11
+ *
12
+ * In admin mode, this endpoint returns a list of all the teams in the current
13
+ * project. [Learn more about different API modes](/docs/admin).
13
14
  *
14
15
  * @param {string} search
15
16
  * @param {number} limit
16
17
  * @param {number} offset
18
+ * @param {string} cursor
19
+ * @param {string} cursorDirection
17
20
  * @param {string} orderType
18
21
  * @throws {AppwriteException}
19
22
  * @returns {Promise}
20
23
  */
21
- async list(search, limit, offset, orderType) {
24
+ async list(search, limit, offset, cursor, cursorDirection, orderType) {
22
25
  let path = '/teams';
23
26
  let payload = {};
24
27
 
@@ -34,6 +37,14 @@ class Teams extends Service {
34
37
  payload['offset'] = offset;
35
38
  }
36
39
 
40
+ if (typeof cursor !== 'undefined') {
41
+ payload['cursor'] = cursor;
42
+ }
43
+
44
+ if (typeof cursorDirection !== 'undefined') {
45
+ payload['cursorDirection'] = cursorDirection;
46
+ }
47
+
37
48
  if (typeof orderType !== 'undefined') {
38
49
  payload['orderType'] = orderType;
39
50
  }
@@ -47,16 +58,20 @@ class Teams extends Service {
47
58
  * Create Team
48
59
  *
49
60
  * Create a new team. The user who creates the team will automatically be
50
- * assigned as the owner of the team. The team owner can invite new members,
51
- * who will be able add new owners and update or delete the team from your
52
- * project.
61
+ * assigned as the owner of the team. Only the users with the owner role can
62
+ * invite new members, add new owners and delete or update the team.
53
63
  *
64
+ * @param {string} teamId
54
65
  * @param {string} name
55
66
  * @param {string[]} roles
56
67
  * @throws {AppwriteException}
57
68
  * @returns {Promise}
58
69
  */
59
- async create(name, roles) {
70
+ async create(teamId, name, roles) {
71
+ if (typeof teamId === 'undefined') {
72
+ throw new AppwriteException('Missing required parameter: "teamId"');
73
+ }
74
+
60
75
  if (typeof name === 'undefined') {
61
76
  throw new AppwriteException('Missing required parameter: "name"');
62
77
  }
@@ -64,6 +79,10 @@ class Teams extends Service {
64
79
  let path = '/teams';
65
80
  let payload = {};
66
81
 
82
+ if (typeof teamId !== 'undefined') {
83
+ payload['teamId'] = teamId;
84
+ }
85
+
67
86
  if (typeof name !== 'undefined') {
68
87
  payload['name'] = name;
69
88
  }
@@ -80,8 +99,7 @@ class Teams extends Service {
80
99
  /**
81
100
  * Get Team
82
101
  *
83
- * Get a team by its unique ID. All team members have read access for this
84
- * resource.
102
+ * Get a team by its ID. All team members have read access for this resource.
85
103
  *
86
104
  * @param {string} teamId
87
105
  * @throws {AppwriteException}
@@ -103,8 +121,8 @@ class Teams extends Service {
103
121
  /**
104
122
  * Update Team
105
123
  *
106
- * Update a team by its unique ID. Only team owners have write access for this
107
- * resource.
124
+ * Update a team using its ID. Only members with the owner role can update the
125
+ * team.
108
126
  *
109
127
  * @param {string} teamId
110
128
  * @param {string} name
@@ -135,8 +153,8 @@ class Teams extends Service {
135
153
  /**
136
154
  * Delete Team
137
155
  *
138
- * Delete a team by its unique ID. Only team owners have write access for this
139
- * resource.
156
+ * Delete a team using its ID. Only team members with the owner role can
157
+ * delete the team.
140
158
  *
141
159
  * @param {string} teamId
142
160
  * @throws {AppwriteException}
@@ -158,18 +176,20 @@ class Teams extends Service {
158
176
  /**
159
177
  * Get Team Memberships
160
178
  *
161
- * Get a team members by the team unique ID. All team members have read access
162
- * for this list of resources.
179
+ * Use this endpoint to list a team's members using the team's ID. All team
180
+ * members have read access to this endpoint.
163
181
  *
164
182
  * @param {string} teamId
165
183
  * @param {string} search
166
184
  * @param {number} limit
167
185
  * @param {number} offset
186
+ * @param {string} cursor
187
+ * @param {string} cursorDirection
168
188
  * @param {string} orderType
169
189
  * @throws {AppwriteException}
170
190
  * @returns {Promise}
171
191
  */
172
- async getMemberships(teamId, search, limit, offset, orderType) {
192
+ async getMemberships(teamId, search, limit, offset, cursor, cursorDirection, orderType) {
173
193
  if (typeof teamId === 'undefined') {
174
194
  throw new AppwriteException('Missing required parameter: "teamId"');
175
195
  }
@@ -189,6 +209,14 @@ class Teams extends Service {
189
209
  payload['offset'] = offset;
190
210
  }
191
211
 
212
+ if (typeof cursor !== 'undefined') {
213
+ payload['cursor'] = cursor;
214
+ }
215
+
216
+ if (typeof cursorDirection !== 'undefined') {
217
+ payload['cursorDirection'] = cursorDirection;
218
+ }
219
+
192
220
  if (typeof orderType !== 'undefined') {
193
221
  payload['orderType'] = orderType;
194
222
  }
@@ -201,19 +229,21 @@ class Teams extends Service {
201
229
  /**
202
230
  * Create Team Membership
203
231
  *
204
- * Use this endpoint to invite a new member to join your team. An email with a
205
- * link to join the team will be sent to the new member email address if the
206
- * member doesn't exist in the project it will be created automatically.
232
+ * Invite a new member to join your team. If initiated from the client SDK, an
233
+ * email with a link to join the team will be sent to the member's email
234
+ * address and an account will be created for them should they not be signed
235
+ * up already. If initiated from server-side SDKs, the new member will
236
+ * automatically be added to the team.
207
237
  *
208
- * Use the 'URL' parameter to redirect the user from the invitation email back
238
+ * Use the 'url' parameter to redirect the user from the invitation email back
209
239
  * to your app. When the user is redirected, use the [Update Team Membership
210
240
  * Status](/docs/client/teams#teamsUpdateMembershipStatus) endpoint to allow
211
- * the user to accept the invitation to the team.
241
+ * the user to accept the invitation to the team.
212
242
  *
213
- * Please note that in order to avoid a [Redirect
214
- * Attacks](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md)
243
+ * Please note that to avoid a [Redirect
244
+ * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md)
215
245
  * the only valid redirect URL's are the once from domains you have set when
216
- * added your platforms in the console interface.
246
+ * adding your platforms in the console interface.
217
247
  *
218
248
  * @param {string} teamId
219
249
  * @param {string} email
@@ -247,10 +277,6 @@ class Teams extends Service {
247
277
  payload['email'] = email;
248
278
  }
249
279
 
250
- if (typeof name !== 'undefined') {
251
- payload['name'] = name;
252
- }
253
-
254
280
  if (typeof roles !== 'undefined') {
255
281
  payload['roles'] = roles;
256
282
  }
@@ -259,14 +285,50 @@ class Teams extends Service {
259
285
  payload['url'] = url;
260
286
  }
261
287
 
288
+ if (typeof name !== 'undefined') {
289
+ payload['name'] = name;
290
+ }
291
+
262
292
  return await this.client.call('post', path, {
263
293
  'content-type': 'application/json',
264
294
  }, payload);
265
295
  }
266
296
 
297
+ /**
298
+ * Get Team Membership
299
+ *
300
+ * Get a team member by the membership unique id. All team members have read
301
+ * access for this resource.
302
+ *
303
+ * @param {string} teamId
304
+ * @param {string} membershipId
305
+ * @throws {AppwriteException}
306
+ * @returns {Promise}
307
+ */
308
+ async getMembership(teamId, membershipId) {
309
+ if (typeof teamId === 'undefined') {
310
+ throw new AppwriteException('Missing required parameter: "teamId"');
311
+ }
312
+
313
+ if (typeof membershipId === 'undefined') {
314
+ throw new AppwriteException('Missing required parameter: "membershipId"');
315
+ }
316
+
317
+ let path = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId);
318
+ let payload = {};
319
+
320
+ return await this.client.call('get', path, {
321
+ 'content-type': 'application/json',
322
+ }, payload);
323
+ }
324
+
267
325
  /**
268
326
  * Update Membership Roles
269
327
  *
328
+ * Modify the roles of a team member. Only team members with the owner role
329
+ * have access to this endpoint. Learn more about [roles and
330
+ * permissions](/docs/permissions).
331
+ *
270
332
  * @param {string} teamId
271
333
  * @param {string} membershipId
272
334
  * @param {string[]} roles
@@ -331,7 +393,7 @@ class Teams extends Service {
331
393
  * Update Team Membership Status
332
394
  *
333
395
  * Use this endpoint to allow a user to accept an invitation to join a team
334
- * after being redirected back to your app from the invitation email recieved
396
+ * after being redirected back to your app from the invitation email received
335
397
  * by the user.
336
398
  *
337
399
  * @param {string} teamId