appwrite-cli 4.1.0 → 4.2.1

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 (38) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +3 -3
  3. package/docs/examples/health/get-queue-builds.md +2 -0
  4. package/docs/examples/health/get-queue-certificates.md +2 -1
  5. package/docs/examples/health/get-queue-databases.md +3 -0
  6. package/docs/examples/health/get-queue-deletes.md +2 -0
  7. package/docs/examples/health/get-queue-functions.md +2 -1
  8. package/docs/examples/health/get-queue-logs.md +2 -1
  9. package/docs/examples/health/get-queue-mails.md +2 -0
  10. package/docs/examples/health/get-queue-messaging.md +2 -0
  11. package/docs/examples/health/get-queue-migrations.md +2 -0
  12. package/docs/examples/health/get-queue-webhooks.md +2 -1
  13. package/install.ps1 +2 -2
  14. package/install.sh +1 -1
  15. package/lib/client.js +61 -74
  16. package/lib/commands/account.js +564 -210
  17. package/lib/commands/assistant.js +42 -7
  18. package/lib/commands/avatars.js +199 -83
  19. package/lib/commands/console.js +42 -3
  20. package/lib/commands/databases.js +991 -562
  21. package/lib/commands/deploy.js +170 -99
  22. package/lib/commands/functions.js +564 -294
  23. package/lib/commands/graphql.js +58 -11
  24. package/lib/commands/health.js +496 -26
  25. package/lib/commands/init.js +11 -23
  26. package/lib/commands/locale.js +154 -17
  27. package/lib/commands/migrations.js +328 -147
  28. package/lib/commands/project.js +128 -33
  29. package/lib/commands/projects.js +788 -411
  30. package/lib/commands/proxy.js +113 -28
  31. package/lib/commands/storage.js +438 -223
  32. package/lib/commands/teams.js +284 -108
  33. package/lib/commands/users.js +559 -271
  34. package/lib/commands/vcs.js +186 -53
  35. package/lib/paginate.js +51 -0
  36. package/lib/questions.js +7 -10
  37. package/package.json +9 -9
  38. package/scoop/appwrite.json +3 -3
@@ -9,219 +9,352 @@ const { Command } = require('commander');
9
9
  const { sdkForProject, sdkForConsole } = require('../sdks')
10
10
  const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser')
11
11
  const { localConfig, globalConfig } = require("../config");
12
+ const { File } = require('undici');
13
+ const { ReadableStream } = require('stream/web');
14
+
15
+ /**
16
+ * @param {fs.ReadStream} readStream
17
+ * @returns {ReadableStream}
18
+ */
19
+ function convertReadStreamToReadableStream(readStream) {
20
+ return new ReadableStream({
21
+ start(controller) {
22
+ readStream.on("data", (chunk) => {
23
+ controller.enqueue(chunk);
24
+ });
25
+ readStream.on("end", () => {
26
+ controller.close();
27
+ });
28
+ readStream.on("error", (err) => {
29
+ controller.error(err);
30
+ });
31
+ },
32
+ cancel() {
33
+ readStream.destroy();
34
+ },
35
+ });
36
+ }
12
37
 
13
38
  const vcs = new Command("vcs").description(commandDescriptions['vcs']).configureHelp({
14
39
  helpWidth: process.stdout.columns || 80
15
40
  })
16
41
 
42
+ /**
43
+ * @typedef {Object} VcsListRepositoriesRequestParams
44
+ * @property {string} installationId Installation Id
45
+ * @property {string} search Search term to filter your list results. Max length: 256 chars.
46
+ * @property {boolean} parseOutput
47
+ * @property {libClient | undefined} sdk
48
+ */
49
+
50
+ /**
51
+ * @param {VcsListRepositoriesRequestParams} params
52
+ */
17
53
  const vcsListRepositories = async ({ installationId, search, parseOutput = true, sdk = undefined}) => {
18
- /* @param {string} installationId */
19
- /* @param {string} search */
20
-
21
54
  let client = !sdk ? await sdkForProject() : sdk;
55
+
22
56
  let apiPath = '/vcs/github/installations/{installationId}/providerRepositories'.replace('{installationId}', installationId);
23
57
  let payload = {};
24
-
25
- /** Query Params */
26
58
  if (typeof search !== 'undefined') {
27
59
  payload['search'] = search;
28
60
  }
61
+
62
+
29
63
  let response = undefined;
64
+
30
65
  response = await client.call('get', apiPath, {
31
66
  'content-type': 'application/json',
32
67
  }, payload);
68
+
33
69
 
34
70
  if (parseOutput) {
35
71
  parse(response)
36
72
  success()
37
73
  }
74
+
38
75
  return response;
39
76
  }
40
77
 
78
+ /**
79
+ * @typedef {Object} VcsCreateRepositoryRequestParams
80
+ * @property {string} installationId Installation Id
81
+ * @property {string} name Repository name (slug)
82
+ * @property {boolean} xprivate Mark repository public or private
83
+ * @property {boolean} parseOutput
84
+ * @property {libClient | undefined} sdk
85
+ */
86
+
87
+ /**
88
+ * @param {VcsCreateRepositoryRequestParams} params
89
+ */
41
90
  const vcsCreateRepository = async ({ installationId, name, xprivate, parseOutput = true, sdk = undefined}) => {
42
- /* @param {string} installationId */
43
- /* @param {string} name */
44
- /* @param {boolean} xprivate */
45
-
46
91
  let client = !sdk ? await sdkForProject() : sdk;
92
+
47
93
  let apiPath = '/vcs/github/installations/{installationId}/providerRepositories'.replace('{installationId}', installationId);
48
94
  let payload = {};
49
-
50
- /** Body Params */
51
-
52
95
  if (typeof name !== 'undefined') {
53
96
  payload['name'] = name;
54
97
  }
55
-
56
-
57
98
  if (typeof xprivate !== 'undefined') {
58
99
  payload['private'] = xprivate;
59
100
  }
60
101
 
102
+
61
103
  let response = undefined;
104
+
62
105
  response = await client.call('post', apiPath, {
63
106
  'content-type': 'application/json',
64
107
  }, payload);
108
+
65
109
 
66
110
  if (parseOutput) {
67
111
  parse(response)
68
112
  success()
69
113
  }
114
+
70
115
  return response;
71
116
  }
72
117
 
118
+ /**
119
+ * @typedef {Object} VcsGetRepositoryRequestParams
120
+ * @property {string} installationId Installation Id
121
+ * @property {string} providerRepositoryId Repository Id
122
+ * @property {boolean} parseOutput
123
+ * @property {libClient | undefined} sdk
124
+ */
125
+
126
+ /**
127
+ * @param {VcsGetRepositoryRequestParams} params
128
+ */
73
129
  const vcsGetRepository = async ({ installationId, providerRepositoryId, parseOutput = true, sdk = undefined}) => {
74
- /* @param {string} installationId */
75
- /* @param {string} providerRepositoryId */
76
-
77
130
  let client = !sdk ? await sdkForProject() : sdk;
131
+
78
132
  let apiPath = '/vcs/github/installations/{installationId}/providerRepositories/{providerRepositoryId}'.replace('{installationId}', installationId).replace('{providerRepositoryId}', providerRepositoryId);
79
133
  let payload = {};
134
+
135
+
80
136
  let response = undefined;
137
+
81
138
  response = await client.call('get', apiPath, {
82
139
  'content-type': 'application/json',
83
140
  }, payload);
141
+
84
142
 
85
143
  if (parseOutput) {
86
144
  parse(response)
87
145
  success()
88
146
  }
147
+
89
148
  return response;
90
149
  }
91
150
 
151
+ /**
152
+ * @typedef {Object} VcsListRepositoryBranchesRequestParams
153
+ * @property {string} installationId Installation Id
154
+ * @property {string} providerRepositoryId Repository Id
155
+ * @property {boolean} parseOutput
156
+ * @property {libClient | undefined} sdk
157
+ */
158
+
159
+ /**
160
+ * @param {VcsListRepositoryBranchesRequestParams} params
161
+ */
92
162
  const vcsListRepositoryBranches = async ({ installationId, providerRepositoryId, parseOutput = true, sdk = undefined}) => {
93
- /* @param {string} installationId */
94
- /* @param {string} providerRepositoryId */
95
-
96
163
  let client = !sdk ? await sdkForProject() : sdk;
164
+
97
165
  let apiPath = '/vcs/github/installations/{installationId}/providerRepositories/{providerRepositoryId}/branches'.replace('{installationId}', installationId).replace('{providerRepositoryId}', providerRepositoryId);
98
166
  let payload = {};
167
+
168
+
99
169
  let response = undefined;
170
+
100
171
  response = await client.call('get', apiPath, {
101
172
  'content-type': 'application/json',
102
173
  }, payload);
174
+
103
175
 
104
176
  if (parseOutput) {
105
177
  parse(response)
106
178
  success()
107
179
  }
180
+
108
181
  return response;
109
182
  }
110
183
 
184
+ /**
185
+ * @typedef {Object} VcsCreateRepositoryDetectionRequestParams
186
+ * @property {string} installationId Installation Id
187
+ * @property {string} providerRepositoryId Repository Id
188
+ * @property {string} providerRootDirectory Path to Root Directory
189
+ * @property {boolean} parseOutput
190
+ * @property {libClient | undefined} sdk
191
+ */
192
+
193
+ /**
194
+ * @param {VcsCreateRepositoryDetectionRequestParams} params
195
+ */
111
196
  const vcsCreateRepositoryDetection = async ({ installationId, providerRepositoryId, providerRootDirectory, parseOutput = true, sdk = undefined}) => {
112
- /* @param {string} installationId */
113
- /* @param {string} providerRepositoryId */
114
- /* @param {string} providerRootDirectory */
115
-
116
197
  let client = !sdk ? await sdkForProject() : sdk;
198
+
117
199
  let apiPath = '/vcs/github/installations/{installationId}/providerRepositories/{providerRepositoryId}/detection'.replace('{installationId}', installationId).replace('{providerRepositoryId}', providerRepositoryId);
118
200
  let payload = {};
119
-
120
- /** Body Params */
121
-
122
201
  if (typeof providerRootDirectory !== 'undefined') {
123
202
  payload['providerRootDirectory'] = providerRootDirectory;
124
203
  }
125
204
 
205
+
126
206
  let response = undefined;
207
+
127
208
  response = await client.call('post', apiPath, {
128
209
  'content-type': 'application/json',
129
210
  }, payload);
211
+
130
212
 
131
213
  if (parseOutput) {
132
214
  parse(response)
133
215
  success()
134
216
  }
217
+
135
218
  return response;
136
219
  }
137
220
 
221
+ /**
222
+ * @typedef {Object} VcsUpdateExternalDeploymentsRequestParams
223
+ * @property {string} installationId Installation Id
224
+ * @property {string} repositoryId VCS Repository Id
225
+ * @property {string} providerPullRequestId GitHub Pull Request Id
226
+ * @property {boolean} parseOutput
227
+ * @property {libClient | undefined} sdk
228
+ */
229
+
230
+ /**
231
+ * @param {VcsUpdateExternalDeploymentsRequestParams} params
232
+ */
138
233
  const vcsUpdateExternalDeployments = async ({ installationId, repositoryId, providerPullRequestId, parseOutput = true, sdk = undefined}) => {
139
- /* @param {string} installationId */
140
- /* @param {string} repositoryId */
141
- /* @param {string} providerPullRequestId */
142
-
143
234
  let client = !sdk ? await sdkForProject() : sdk;
235
+
144
236
  let apiPath = '/vcs/github/installations/{installationId}/repositories/{repositoryId}'.replace('{installationId}', installationId).replace('{repositoryId}', repositoryId);
145
237
  let payload = {};
146
-
147
- /** Body Params */
148
-
149
238
  if (typeof providerPullRequestId !== 'undefined') {
150
239
  payload['providerPullRequestId'] = providerPullRequestId;
151
240
  }
152
241
 
242
+
153
243
  let response = undefined;
244
+
154
245
  response = await client.call('patch', apiPath, {
155
246
  'content-type': 'application/json',
156
247
  }, payload);
248
+
157
249
 
158
250
  if (parseOutput) {
159
251
  parse(response)
160
252
  success()
161
253
  }
254
+
162
255
  return response;
163
256
  }
164
257
 
258
+ /**
259
+ * @typedef {Object} VcsListInstallationsRequestParams
260
+ * @property {string[]} queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: provider, organization
261
+ * @property {string} search Search term to filter your list results. Max length: 256 chars.
262
+ * @property {boolean} parseOutput
263
+ * @property {libClient | undefined} sdk
264
+ */
265
+
266
+ /**
267
+ * @param {VcsListInstallationsRequestParams} params
268
+ */
165
269
  const vcsListInstallations = async ({ queries, search, parseOutput = true, sdk = undefined}) => {
166
- /* @param {string[]} queries */
167
- /* @param {string} search */
168
-
169
270
  let client = !sdk ? await sdkForProject() : sdk;
271
+
170
272
  let apiPath = '/vcs/installations';
171
273
  let payload = {};
172
-
173
- /** Query Params */
174
274
  if (typeof queries !== 'undefined') {
175
275
  payload['queries'] = queries;
176
276
  }
177
277
  if (typeof search !== 'undefined') {
178
278
  payload['search'] = search;
179
279
  }
280
+
281
+
180
282
  let response = undefined;
283
+
181
284
  response = await client.call('get', apiPath, {
182
285
  'content-type': 'application/json',
183
286
  }, payload);
287
+
184
288
 
185
289
  if (parseOutput) {
186
290
  parse(response)
187
291
  success()
188
292
  }
293
+
189
294
  return response;
190
295
  }
191
296
 
192
- const vcsGetInstallation = async ({ installationId, parseOutput = true, sdk = undefined}) => {
193
- /* @param {string} installationId */
297
+ /**
298
+ * @typedef {Object} VcsGetInstallationRequestParams
299
+ * @property {string} installationId Installation Id
300
+ * @property {boolean} parseOutput
301
+ * @property {libClient | undefined} sdk
302
+ */
194
303
 
304
+ /**
305
+ * @param {VcsGetInstallationRequestParams} params
306
+ */
307
+ const vcsGetInstallation = async ({ installationId, parseOutput = true, sdk = undefined}) => {
195
308
  let client = !sdk ? await sdkForProject() : sdk;
309
+
196
310
  let apiPath = '/vcs/installations/{installationId}'.replace('{installationId}', installationId);
197
311
  let payload = {};
312
+
313
+
198
314
  let response = undefined;
315
+
199
316
  response = await client.call('get', apiPath, {
200
317
  'content-type': 'application/json',
201
318
  }, payload);
319
+
202
320
 
203
321
  if (parseOutput) {
204
322
  parse(response)
205
323
  success()
206
324
  }
325
+
207
326
  return response;
208
327
  }
209
328
 
210
- const vcsDeleteInstallation = async ({ installationId, parseOutput = true, sdk = undefined}) => {
211
- /* @param {string} installationId */
329
+ /**
330
+ * @typedef {Object} VcsDeleteInstallationRequestParams
331
+ * @property {string} installationId Installation Id
332
+ * @property {boolean} parseOutput
333
+ * @property {libClient | undefined} sdk
334
+ */
212
335
 
336
+ /**
337
+ * @param {VcsDeleteInstallationRequestParams} params
338
+ */
339
+ const vcsDeleteInstallation = async ({ installationId, parseOutput = true, sdk = undefined}) => {
213
340
  let client = !sdk ? await sdkForProject() : sdk;
341
+
214
342
  let apiPath = '/vcs/installations/{installationId}'.replace('{installationId}', installationId);
215
343
  let payload = {};
344
+
345
+
216
346
  let response = undefined;
347
+
217
348
  response = await client.call('delete', apiPath, {
218
349
  'content-type': 'application/json',
219
350
  }, payload);
351
+
220
352
 
221
353
  if (parseOutput) {
222
354
  parse(response)
223
355
  success()
224
356
  }
357
+
225
358
  return response;
226
359
  }
227
360
 
@@ -293,13 +426,13 @@ vcs
293
426
 
294
427
  module.exports = {
295
428
  vcs,
296
- vcsListRepositories,
297
- vcsCreateRepository,
298
- vcsGetRepository,
299
- vcsListRepositoryBranches,
300
- vcsCreateRepositoryDetection,
301
- vcsUpdateExternalDeployments,
302
- vcsListInstallations,
303
- vcsGetInstallation,
304
- vcsDeleteInstallation
305
- };
429
+ vcsListRepositories,
430
+ vcsCreateRepository,
431
+ vcsGetRepository,
432
+ vcsListRepositoryBranches,
433
+ vcsCreateRepositoryDetection,
434
+ vcsUpdateExternalDeployments,
435
+ vcsListInstallations,
436
+ vcsGetInstallation,
437
+ vcsDeleteInstallation
438
+ };
@@ -0,0 +1,51 @@
1
+ const paginate = async (action, args = {}, limit = 100, wrapper = '') => {
2
+ let pageNumber = 0;
3
+ let results = [];
4
+ let total = 0;
5
+
6
+ while (true) {
7
+ const offset = pageNumber * limit;
8
+
9
+ // Merge the limit and offset into the args
10
+ const response = await action({
11
+ ...args,
12
+ queries: [
13
+ `limit(${limit})`,
14
+ `offset(${offset})`
15
+ ]
16
+ });
17
+
18
+ if (wrapper === '') {
19
+ if (response.length === 0) {
20
+ break;
21
+ }
22
+ results = results.concat(response);
23
+ } else {
24
+ if (response[wrapper].length === 0) {
25
+ break;
26
+ }
27
+ results = results.concat(response[wrapper]);
28
+ }
29
+
30
+ total = response.total;
31
+
32
+ if (results.length >= total) {
33
+ break;
34
+ }
35
+
36
+ pageNumber++;
37
+ }
38
+
39
+ if (wrapper === '') {
40
+ return results;
41
+ }
42
+
43
+ return {
44
+ [wrapper]: results,
45
+ total,
46
+ };
47
+ }
48
+
49
+ module.exports = {
50
+ paginate
51
+ };
package/lib/questions.js CHANGED
@@ -309,13 +309,12 @@ const questionsDeployCollections = [
309
309
  if (collections.length === 0) {
310
310
  throw new Error("No collections found in the current directory. Run `appwrite init collection` to fetch all your collections.");
311
311
  }
312
- let choices = collections.map((collection, idx) => {
312
+ return collections.map(collection => {
313
313
  return {
314
314
  name: `${collection.name} (${collection['databaseId']} - ${collection['$id']})`,
315
315
  value: `${collection['databaseId']}|${collection['$id']}`
316
316
  }
317
- })
318
- return choices;
317
+ });
319
318
  }
320
319
  },
321
320
  {
@@ -335,13 +334,12 @@ const questionsDeployBuckets = [
335
334
  if (buckets.length === 0) {
336
335
  throw new Error("No buckets found in the current directory. Run `appwrite init bucket` to fetch all your buckets.");
337
336
  }
338
- let choices = buckets.map((bucket, idx) => {
337
+ return buckets.map(bucket => {
339
338
  return {
340
339
  name: `${bucket.name} (${bucket['$id']})`,
341
340
  value: bucket.$id
342
341
  }
343
- })
344
- return choices;
342
+ });
345
343
  }
346
344
  },
347
345
  {
@@ -359,7 +357,7 @@ const questionsGetEntrypoint = [
359
357
  default: null,
360
358
  validate(value) {
361
359
  if (!value) {
362
- return "Please enter your enrtypoint";
360
+ return "Please enter your entrypoint";
363
361
  }
364
362
  return true;
365
363
  }
@@ -376,13 +374,12 @@ const questionsDeployTeams = [
376
374
  if (teams.length === 0) {
377
375
  throw new Error("No teams found in the current directory. Run `appwrite init team` to fetch all your teams.");
378
376
  }
379
- let choices = teams.map((team, idx) => {
377
+ return teams.map(team => {
380
378
  return {
381
379
  name: `${team.name} (${team['$id']})`,
382
380
  value: team.$id
383
381
  }
384
- })
385
- return choices;
382
+ });
386
383
  }
387
384
  },
388
385
  {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "appwrite-cli",
3
3
  "homepage": "https://appwrite.io/support",
4
4
  "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API",
5
- "version": "4.1.0",
5
+ "version": "4.2.1",
6
6
  "license": "BSD-3-Clause",
7
7
  "main": "index.js",
8
8
  "bin": {
@@ -14,15 +14,15 @@
14
14
  },
15
15
  "scripts": {
16
16
  "test": "echo \"Error: no test specified\" && exit 1",
17
- "linux-x64": "pkg -t node16-linux-x64 -o build/appwrite-cli-linux-x64 package.json",
18
- "linux-arm64": "pkg -t node16-linux-arm64 -o build/appwrite-cli-linux-arm64 package.json",
19
- "mac-x64": "pkg -t node16-macos-x64 -o build/appwrite-cli-darwin-x64 package.json",
20
- "mac-arm64": "pkg -t node16-macos-arm64 -o build/appwrite-cli-darwin-arm64 package.json",
21
- "windows-x64": "pkg -t node16-win-x64 -o build/appwrite-cli-win-x64.exe package.json",
22
- "windows-arm64": "pkg -t node16-win-arm64 -o build/appwrite-cli-win-arm64.exe package.json"
17
+ "linux-x64": "pkg -t node18-linux-x64 -o build/appwrite-cli-linux-x64 package.json",
18
+ "linux-arm64": "pkg -t node18-linux-arm64 -o build/appwrite-cli-linux-arm64 package.json",
19
+ "mac-x64": "pkg -t node18-macos-x64 -o build/appwrite-cli-darwin-x64 package.json",
20
+ "mac-arm64": "pkg -t node18-macos-arm64 -o build/appwrite-cli-darwin-arm64 package.json",
21
+ "windows-x64": "pkg -t node18-win-x64 -o build/appwrite-cli-win-x64.exe package.json",
22
+ "windows-arm64": "pkg -t node18-win-arm64 -o build/appwrite-cli-win-arm64.exe package.json"
23
23
  },
24
24
  "dependencies": {
25
- "axios": "1.5.0",
25
+ "undici": "^5.28.2",
26
26
  "chalk": "4.1.2",
27
27
  "cli-table3": "^0.6.2",
28
28
  "commander": "^9.2.0",
@@ -33,7 +33,7 @@
33
33
  "ignore": "^5.2.0"
34
34
  },
35
35
  "devDependencies": {
36
- "pkg": "5.5.1"
36
+ "pkg": "5.8.1"
37
37
  },
38
38
  "pkg": {
39
39
  "scripts": [
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/ScoopInstaller/Scoop/master/schema.json",
3
- "version": "4.1.0",
3
+ "version": "4.2.1",
4
4
  "description": "The Appwrite CLI is a command-line application that allows you to interact with Appwrite and perform server-side tasks using your terminal.",
5
5
  "homepage": "https://github.com/appwrite/sdk-for-cli",
6
6
  "license": "BSD-3-Clause",
7
7
  "architecture": {
8
8
  "64bit": {
9
- "url": "https://github.com/appwrite/sdk-for-cli/releases/download/4.1.0/appwrite-cli-win-x64.exe",
9
+ "url": "https://github.com/appwrite/sdk-for-cli/releases/download/4.2.1/appwrite-cli-win-x64.exe",
10
10
  "bin": [
11
11
  [
12
12
  "appwrite-cli-win-x64.exe",
@@ -15,7 +15,7 @@
15
15
  ]
16
16
  },
17
17
  "arm64": {
18
- "url": "https://github.com/appwrite/sdk-for-cli/releases/download/4.1.0/appwrite-cli-win-arm64.exe",
18
+ "url": "https://github.com/appwrite/sdk-for-cli/releases/download/4.2.1/appwrite-cli-win-arm64.exe",
19
19
  "bin": [
20
20
  [
21
21
  "appwrite-cli-win-arm64.exe",