appwrite-cli 1.1.1 → 2.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 (60) hide show
  1. package/Formula/appwrite.rb +1 -1
  2. package/LICENSE.md +2 -2
  3. package/README.md +4 -4
  4. package/docs/examples/account/create-phone-session.md +1 -1
  5. package/docs/examples/account/create.md +1 -1
  6. package/docs/examples/account/update-password.md +1 -1
  7. package/docs/examples/account/update-phone.md +1 -1
  8. package/docs/examples/console/variables.md +1 -0
  9. package/docs/examples/databases/create-relationship-attribute.md +9 -0
  10. package/docs/examples/databases/get-document.md +2 -1
  11. package/docs/examples/databases/update-boolean-attribute.md +6 -0
  12. package/docs/examples/databases/update-datetime-attribute.md +6 -0
  13. package/docs/examples/databases/update-email-attribute.md +6 -0
  14. package/docs/examples/databases/update-enum-attribute.md +7 -0
  15. package/docs/examples/databases/update-float-attribute.md +8 -0
  16. package/docs/examples/databases/update-integer-attribute.md +8 -0
  17. package/docs/examples/databases/update-ip-attribute.md +6 -0
  18. package/docs/examples/databases/update-relationship-attribute.md +5 -0
  19. package/docs/examples/databases/update-string-attribute.md +6 -0
  20. package/docs/examples/databases/update-url-attribute.md +6 -0
  21. package/docs/examples/functions/{retry-build.md → create-build.md} +1 -1
  22. package/docs/examples/functions/create.md +1 -1
  23. package/docs/examples/functions/update.md +1 -1
  24. package/docs/examples/graphql/mutation.md +2 -0
  25. package/docs/examples/graphql/query.md +2 -0
  26. package/docs/examples/projects/create.md +1 -0
  27. package/docs/examples/projects/update-auth-duration.md +3 -0
  28. package/docs/examples/projects/update-auth-password-dictionary.md +3 -0
  29. package/docs/examples/projects/update-auth-password-history.md +3 -0
  30. package/docs/examples/projects/update-auth-sessions-limit.md +3 -0
  31. package/docs/examples/projects/update-o-auth2.md +1 -0
  32. package/docs/examples/teams/create-membership.md +3 -1
  33. package/docs/examples/teams/get-prefs.md +2 -0
  34. package/docs/examples/teams/{update.md → update-name.md} +1 -1
  35. package/docs/examples/teams/update-prefs.md +3 -0
  36. package/docs/examples/users/update-password.md +1 -1
  37. package/docs/examples/users/update-phone.md +1 -1
  38. package/index.js +16 -1
  39. package/install.ps1 +2 -2
  40. package/install.sh +1 -1
  41. package/lib/client.js +7 -7
  42. package/lib/commands/account.js +46 -11
  43. package/lib/commands/avatars.js +3 -1
  44. package/lib/commands/console.js +44 -0
  45. package/lib/commands/databases.js +735 -109
  46. package/lib/commands/deploy.js +350 -141
  47. package/lib/commands/functions.js +44 -16
  48. package/lib/commands/generic.js +15 -3
  49. package/lib/commands/graphql.js +85 -0
  50. package/lib/commands/health.js +3 -1
  51. package/lib/commands/init.js +224 -162
  52. package/lib/commands/locale.js +3 -1
  53. package/lib/commands/projects.js +223 -9
  54. package/lib/commands/storage.js +43 -13
  55. package/lib/commands/teams.js +107 -19
  56. package/lib/commands/users.js +62 -11
  57. package/lib/config.js +122 -5
  58. package/lib/parser.js +7 -2
  59. package/lib/questions.js +311 -257
  60. package/package.json +1 -1
@@ -10,7 +10,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
12
 
13
- const functions = new Command("functions").description(commandDescriptions['functions'])
13
+ const functions = new Command("functions").description(commandDescriptions['functions']).configureHelp({
14
+ helpWidth: process.stdout.columns || 80
15
+ })
14
16
 
15
17
  const functionsList = async ({ queries, search, parseOutput = true, sdk = undefined}) => {
16
18
  /* @param {string[]} queries */
@@ -39,11 +41,11 @@ const functionsList = async ({ queries, search, parseOutput = true, sdk = undefi
39
41
  return response;
40
42
  }
41
43
 
42
- const functionsCreate = async ({ functionId, name, execute, runtime, events, schedule, timeout, enabled, parseOutput = true, sdk = undefined}) => {
44
+ const functionsCreate = async ({ functionId, name, runtime, execute, events, schedule, timeout, enabled, parseOutput = true, sdk = undefined}) => {
43
45
  /* @param {string} functionId */
44
46
  /* @param {string} name */
45
- /* @param {string[]} execute */
46
47
  /* @param {string} runtime */
48
+ /* @param {string[]} execute */
47
49
  /* @param {string[]} events */
48
50
  /* @param {string} schedule */
49
51
  /* @param {number} timeout */
@@ -54,34 +56,44 @@ const functionsCreate = async ({ functionId, name, execute, runtime, events, sch
54
56
  let payload = {};
55
57
 
56
58
  /** Body Params */
59
+
57
60
  if (typeof functionId !== 'undefined') {
58
61
  payload['functionId'] = functionId;
59
62
  }
60
63
 
64
+
61
65
  if (typeof name !== 'undefined') {
62
66
  payload['name'] = name;
63
67
  }
64
68
 
69
+ execute = execute === true ? [] : execute;
70
+
65
71
  if (typeof execute !== 'undefined') {
66
72
  payload['execute'] = execute;
67
73
  }
68
74
 
75
+
69
76
  if (typeof runtime !== 'undefined') {
70
77
  payload['runtime'] = runtime;
71
78
  }
72
79
 
80
+ events = events === true ? [] : events;
81
+
73
82
  if (typeof events !== 'undefined') {
74
83
  payload['events'] = events;
75
84
  }
76
85
 
86
+
77
87
  if (typeof schedule !== 'undefined') {
78
88
  payload['schedule'] = schedule;
79
89
  }
80
90
 
91
+
81
92
  if (typeof timeout !== 'undefined') {
82
93
  payload['timeout'] = timeout;
83
94
  }
84
95
 
96
+
85
97
  if (typeof enabled !== 'undefined') {
86
98
  payload['enabled'] = enabled;
87
99
  }
@@ -170,26 +182,34 @@ const functionsUpdate = async ({ functionId, name, execute, events, schedule, ti
170
182
  let payload = {};
171
183
 
172
184
  /** Body Params */
185
+
173
186
  if (typeof name !== 'undefined') {
174
187
  payload['name'] = name;
175
188
  }
176
189
 
190
+ execute = execute === true ? [] : execute;
191
+
177
192
  if (typeof execute !== 'undefined') {
178
193
  payload['execute'] = execute;
179
194
  }
180
195
 
196
+ events = events === true ? [] : events;
197
+
181
198
  if (typeof events !== 'undefined') {
182
199
  payload['events'] = events;
183
200
  }
184
201
 
202
+
185
203
  if (typeof schedule !== 'undefined') {
186
204
  payload['schedule'] = schedule;
187
205
  }
188
206
 
207
+
189
208
  if (typeof timeout !== 'undefined') {
190
209
  payload['timeout'] = timeout;
191
210
  }
192
211
 
212
+
193
213
  if (typeof enabled !== 'undefined') {
194
214
  payload['enabled'] = enabled;
195
215
  }
@@ -263,6 +283,7 @@ const functionsCreateDeployment = async ({ functionId, entrypoint, code, activat
263
283
  let payload = {};
264
284
 
265
285
  /** Body Params */
286
+
266
287
  if (typeof entrypoint !== 'undefined') {
267
288
  payload['entrypoint'] = entrypoint;
268
289
  }
@@ -298,6 +319,7 @@ const functionsCreateDeployment = async ({ functionId, entrypoint, code, activat
298
319
  code = archivePath;
299
320
  }
300
321
 
322
+
301
323
  if (typeof activate !== 'undefined') {
302
324
  payload['activate'] = activate.toString();
303
325
  }
@@ -426,7 +448,7 @@ const functionsDeleteDeployment = async ({ functionId, deploymentId, parseOutput
426
448
  return response;
427
449
  }
428
450
 
429
- const functionsRetryBuild = async ({ functionId, deploymentId, buildId, parseOutput = true, sdk = undefined}) => {
451
+ const functionsCreateBuild = async ({ functionId, deploymentId, buildId, parseOutput = true, sdk = undefined}) => {
430
452
  /* @param {string} functionId */
431
453
  /* @param {string} deploymentId */
432
454
  /* @param {string} buildId */
@@ -484,10 +506,12 @@ const functionsCreateExecution = async ({ functionId, data, async, parseOutput =
484
506
  let payload = {};
485
507
 
486
508
  /** Body Params */
509
+
487
510
  if (typeof data !== 'undefined') {
488
511
  payload['data'] = data;
489
512
  }
490
513
 
514
+
491
515
  if (typeof async !== 'undefined') {
492
516
  payload['async'] = async;
493
517
  }
@@ -575,10 +599,12 @@ const functionsCreateVariable = async ({ functionId, key, value, parseOutput = t
575
599
  let payload = {};
576
600
 
577
601
  /** Body Params */
602
+
578
603
  if (typeof key !== 'undefined') {
579
604
  payload['key'] = key;
580
605
  }
581
606
 
607
+
582
608
  if (typeof value !== 'undefined') {
583
609
  payload['value'] = value;
584
610
  }
@@ -625,10 +651,12 @@ const functionsUpdateVariable = async ({ functionId, variableId, key, value, par
625
651
  let payload = {};
626
652
 
627
653
  /** Body Params */
654
+
628
655
  if (typeof key !== 'undefined') {
629
656
  payload['key'] = key;
630
657
  }
631
658
 
659
+
632
660
  if (typeof value !== 'undefined') {
633
661
  payload['value'] = value;
634
662
  }
@@ -668,18 +696,18 @@ const functionsDeleteVariable = async ({ functionId, variableId, parseOutput = t
668
696
  functions
669
697
  .command(`list`)
670
698
  .description(`Get a list of all the project's functions. You can use the query params to filter your results.`)
671
- .option(`--queries <queries...>`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, enabled, runtime, deployment, schedule, scheduleNext, schedulePrevious, timeout`)
699
+ .option(`--queries [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: name, enabled, runtime, deployment, schedule, scheduleNext, schedulePrevious, timeout`)
672
700
  .option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`)
673
701
  .action(actionRunner(functionsList))
674
702
 
675
703
  functions
676
704
  .command(`create`)
677
705
  .description(`Create a new function. You can pass a list of [permissions](/docs/permissions) to allow different project users or team with access to execute the function using the client API.`)
678
- .requiredOption(`--functionId <functionId>`, `Function ID. Choose your own unique ID or pass the string "unique()" to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`)
706
+ .requiredOption(`--functionId <functionId>`, `Function ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`)
679
707
  .requiredOption(`--name <name>`, `Function name. Max length: 128 chars.`)
680
- .requiredOption(`--execute <execute...>`, `An array of strings with execution roles. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 64 characters long.`)
681
708
  .requiredOption(`--runtime <runtime>`, `Execution runtime.`)
682
- .option(`--events <events...>`, `Events list. Maximum of 100 events are allowed.`)
709
+ .option(`--execute [execute...]`, `An array of strings with execution roles. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 64 characters long.`)
710
+ .option(`--events [events...]`, `Events list. Maximum of 100 events are allowed.`)
683
711
  .option(`--schedule <schedule>`, `Schedule CRON syntax.`)
684
712
  .option(`--timeout <timeout>`, `Function maximum execution time in seconds.`, parseInteger)
685
713
  .option(`--enabled <enabled>`, `Is function enabled?`, parseBool)
@@ -707,8 +735,8 @@ functions
707
735
  .description(`Update function by its unique ID.`)
708
736
  .requiredOption(`--functionId <functionId>`, `Function ID.`)
709
737
  .requiredOption(`--name <name>`, `Function name. Max length: 128 chars.`)
710
- .requiredOption(`--execute <execute...>`, `An array of strings with execution roles. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 64 characters long.`)
711
- .option(`--events <events...>`, `Events list. Maximum of 100 events are allowed.`)
738
+ .option(`--execute [execute...]`, `An array of strings with execution roles. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 64 characters long.`)
739
+ .option(`--events [events...]`, `Events list. Maximum of 100 events are allowed.`)
712
740
  .option(`--schedule <schedule>`, `Schedule CRON syntax.`)
713
741
  .option(`--timeout <timeout>`, `Maximum execution time in seconds.`, parseInteger)
714
742
  .option(`--enabled <enabled>`, `Is function enabled?`, parseBool)
@@ -724,7 +752,7 @@ functions
724
752
  .command(`listDeployments`)
725
753
  .description(`Get a list of all the project's code deployments. You can use the query params to filter your results.`)
726
754
  .requiredOption(`--functionId <functionId>`, `Function ID.`)
727
- .option(`--queries <queries...>`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: entrypoint, size, buildId, activate`)
755
+ .option(`--queries [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: entrypoint, size, buildId, activate`)
728
756
  .option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`)
729
757
  .action(actionRunner(functionsListDeployments))
730
758
 
@@ -759,18 +787,18 @@ functions
759
787
  .action(actionRunner(functionsDeleteDeployment))
760
788
 
761
789
  functions
762
- .command(`retryBuild`)
790
+ .command(`createBuild`)
763
791
  .description(``)
764
792
  .requiredOption(`--functionId <functionId>`, `Function ID.`)
765
793
  .requiredOption(`--deploymentId <deploymentId>`, `Deployment ID.`)
766
794
  .requiredOption(`--buildId <buildId>`, `Build unique ID.`)
767
- .action(actionRunner(functionsRetryBuild))
795
+ .action(actionRunner(functionsCreateBuild))
768
796
 
769
797
  functions
770
798
  .command(`listExecutions`)
771
- .description(`Get a list of all the current user function execution logs. You can use the query params to filter your results. On admin mode, this endpoint will return a list of all of the project's executions. [Learn more about different API modes](/docs/admin).`)
799
+ .description(`Get a list of all the current user function execution logs. You can use the query params to filter your results.`)
772
800
  .requiredOption(`--functionId <functionId>`, `Function ID.`)
773
- .option(`--queries <queries...>`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: trigger, status, statusCode, duration`)
801
+ .option(`--queries [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: trigger, status, statusCode, duration`)
774
802
  .option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`)
775
803
  .action(actionRunner(functionsListExecutions))
776
804
 
@@ -848,7 +876,7 @@ module.exports = {
848
876
  functionsGetDeployment,
849
877
  functionsUpdateDeployment,
850
878
  functionsDeleteDeployment,
851
- functionsRetryBuild,
879
+ functionsCreateBuild,
852
880
  functionsListExecutions,
853
881
  functionsCreateExecution,
854
882
  functionsGetExecution,
@@ -9,6 +9,9 @@ const { accountCreateEmailSession, accountDeleteSession } = require("./account")
9
9
 
10
10
  const login = new Command("login")
11
11
  .description(commandDescriptions['login'])
12
+ .configureHelp({
13
+ helpWidth: process.stdout.columns || 80
14
+ })
12
15
  .action(actionRunner(async () => {
13
16
  const answers = await inquirer.prompt(questionsLogin)
14
17
 
@@ -26,6 +29,9 @@ const login = new Command("login")
26
29
 
27
30
  const logout = new Command("logout")
28
31
  .description(commandDescriptions['logout'])
32
+ .configureHelp({
33
+ helpWidth: process.stdout.columns || 80
34
+ })
29
35
  .action(actionRunner(async () => {
30
36
  let client = await sdkForConsole();
31
37
 
@@ -41,6 +47,9 @@ const logout = new Command("logout")
41
47
 
42
48
  const client = new Command("client")
43
49
  .description(commandDescriptions['client'])
50
+ .configureHelp({
51
+ helpWidth: process.stdout.columns || 80
52
+ })
44
53
  .option("--selfSigned <value>", "Configure the CLI to use a self-signed certificate ( true or false )", parseBool)
45
54
  .option("--endpoint <endpoint>", "Set your Appwrite server endpoint")
46
55
  .option("--projectId <projectId>", "Set your Appwrite project ID")
@@ -69,13 +78,16 @@ const client = new Command("client")
69
78
  if (url.protocol !== "http:" && url.protocol !== "https:") {
70
79
  throw new Error();
71
80
  }
72
-
81
+
73
82
  let client = new Client().setEndpoint(endpoint);
83
+ if (selfSigned || globalConfig.getSelfSigned()) {
84
+ client.setSelfSigned(true);
85
+ }
74
86
  let response = await client.call('GET', '/health/version');
75
- if(!response.version) {
87
+ if (!response.version) {
76
88
  throw new Error();
77
89
  }
78
-
90
+
79
91
  globalConfig.setEndpoint(endpoint);
80
92
  } catch (_) {
81
93
  throw new Error("Invalid endpoint or your Appwrite server is not running as expected.");
@@ -0,0 +1,85 @@
1
+ const fs = require('fs');
2
+ const pathLib = require('path');
3
+ const tar = require("tar");
4
+ const ignore = require("ignore");
5
+ const { promisify } = require('util');
6
+ const libClient = require('../client.js');
7
+ const { getAllFiles } = require('../utils.js');
8
+ const { Command } = require('commander');
9
+ const { sdkForProject, sdkForConsole } = require('../sdks')
10
+ const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser')
11
+ const { localConfig, globalConfig } = require("../config");
12
+
13
+ const graphql = new Command("graphql").description(commandDescriptions['graphql']).configureHelp({
14
+ helpWidth: process.stdout.columns || 80
15
+ })
16
+
17
+ const graphqlQuery = async ({ query, parseOutput = true, sdk = undefined}) => {
18
+ /* @param {object} query */
19
+
20
+ let client = !sdk ? await sdkForProject() : sdk;
21
+ let path = '/graphql';
22
+ let payload = {};
23
+
24
+ /** Body Params */
25
+ if (typeof query !== 'undefined') {
26
+ payload['query'] = JSON.parse(query);
27
+ }
28
+
29
+ let response = undefined;
30
+ response = await client.call('post', path, {
31
+ 'x-sdk-graphql': 'true',
32
+ 'content-type': 'application/json',
33
+ }, payload);
34
+
35
+ if (parseOutput) {
36
+ parse(response)
37
+ success()
38
+ }
39
+ return response;
40
+ }
41
+
42
+ const graphqlMutation = async ({ query, parseOutput = true, sdk = undefined}) => {
43
+ /* @param {object} query */
44
+
45
+ let client = !sdk ? await sdkForProject() : sdk;
46
+ let path = '/graphql/mutation';
47
+ let payload = {};
48
+
49
+ /** Body Params */
50
+ if (typeof query !== 'undefined') {
51
+ payload['query'] = JSON.parse(query);
52
+ }
53
+
54
+ let response = undefined;
55
+ response = await client.call('post', path, {
56
+ 'x-sdk-graphql': 'true',
57
+ 'content-type': 'application/json',
58
+ }, payload);
59
+
60
+ if (parseOutput) {
61
+ parse(response)
62
+ success()
63
+ }
64
+ return response;
65
+ }
66
+
67
+
68
+ graphql
69
+ .command(`query`)
70
+ .description(`Execute a GraphQL mutation.`)
71
+ .requiredOption(`--query <query>`, `The query or queries to execute.`)
72
+ .action(actionRunner(graphqlQuery))
73
+
74
+ graphql
75
+ .command(`mutation`)
76
+ .description(`Execute a GraphQL mutation.`)
77
+ .requiredOption(`--query <query>`, `The query or queries to execute.`)
78
+ .action(actionRunner(graphqlMutation))
79
+
80
+
81
+ module.exports = {
82
+ graphql,
83
+ graphqlQuery,
84
+ graphqlMutation
85
+ };
@@ -10,7 +10,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
12
 
13
- const health = new Command("health").description(commandDescriptions['health'])
13
+ const health = new Command("health").description(commandDescriptions['health']).configureHelp({
14
+ helpWidth: process.stdout.columns || 80
15
+ })
14
16
 
15
17
  const healthGet = async ({ parseOutput = true, sdk = undefined}) => {
16
18