appwrite-cli 12.0.0 → 13.0.0-rc.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 (283) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +2 -2
  3. package/dist/index.d.ts +3 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +145 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/lib/client.d.ts +89 -0
  8. package/dist/lib/client.d.ts.map +1 -0
  9. package/dist/lib/client.js +227 -0
  10. package/dist/lib/client.js.map +1 -0
  11. package/dist/lib/commands/account.d.ts +379 -0
  12. package/dist/lib/commands/account.d.ts.map +1 -0
  13. package/dist/lib/commands/account.js +1228 -0
  14. package/dist/lib/commands/account.js.map +1 -0
  15. package/dist/lib/commands/console.d.ts +20 -0
  16. package/dist/lib/commands/console.d.ts.map +1 -0
  17. package/dist/lib/commands/console.js +78 -0
  18. package/dist/lib/commands/console.js.map +1 -0
  19. package/dist/lib/commands/databases.d.ts +732 -0
  20. package/dist/lib/commands/databases.d.ts.map +1 -0
  21. package/dist/lib/commands/databases.js +2196 -0
  22. package/dist/lib/commands/databases.js.map +1 -0
  23. package/dist/lib/commands/functions.d.ts +310 -0
  24. package/dist/lib/commands/functions.d.ts.map +1 -0
  25. package/dist/lib/commands/functions.js +1100 -0
  26. package/dist/lib/commands/functions.js.map +1 -0
  27. package/dist/lib/commands/generic.d.ts +17 -0
  28. package/dist/lib/commands/generic.d.ts.map +1 -0
  29. package/dist/lib/commands/generic.js +279 -0
  30. package/dist/lib/commands/generic.js.map +1 -0
  31. package/dist/lib/commands/graphql.d.ts +19 -0
  32. package/dist/lib/commands/graphql.d.ts.map +1 -0
  33. package/dist/lib/commands/graphql.js +77 -0
  34. package/dist/lib/commands/graphql.js.map +1 -0
  35. package/dist/lib/commands/health.d.ts +153 -0
  36. package/dist/lib/commands/health.d.ts.map +1 -0
  37. package/dist/lib/commands/health.js +464 -0
  38. package/dist/lib/commands/health.js.map +1 -0
  39. package/dist/lib/commands/init.d.ts +3 -0
  40. package/dist/lib/commands/init.d.ts.map +1 -0
  41. package/dist/lib/commands/init.js +518 -0
  42. package/dist/lib/commands/init.js.map +1 -0
  43. package/dist/lib/commands/locale.d.ts +53 -0
  44. package/dist/lib/commands/locale.d.ts.map +1 -0
  45. package/dist/lib/commands/locale.js +165 -0
  46. package/dist/lib/commands/locale.js.map +1 -0
  47. package/dist/lib/commands/messaging.d.ts +588 -0
  48. package/dist/lib/commands/messaging.d.ts.map +1 -0
  49. package/dist/lib/commands/messaging.js +2042 -0
  50. package/dist/lib/commands/messaging.js.map +1 -0
  51. package/dist/lib/commands/migrations.d.ts +150 -0
  52. package/dist/lib/commands/migrations.d.ts.map +1 -0
  53. package/dist/lib/commands/migrations.js +524 -0
  54. package/dist/lib/commands/migrations.js.map +1 -0
  55. package/dist/lib/commands/organizations.d.ts +11 -0
  56. package/dist/lib/commands/organizations.d.ts.map +1 -0
  57. package/dist/lib/commands/organizations.js +31 -0
  58. package/dist/lib/commands/organizations.js.map +1 -0
  59. package/dist/lib/commands/project.d.ts +53 -0
  60. package/dist/lib/commands/project.d.ts.map +1 -0
  61. package/dist/lib/commands/project.js +176 -0
  62. package/dist/lib/commands/project.js.map +1 -0
  63. package/dist/lib/commands/projects.d.ts +516 -0
  64. package/dist/lib/commands/projects.d.ts.map +1 -0
  65. package/dist/lib/commands/projects.js +1590 -0
  66. package/dist/lib/commands/projects.js.map +1 -0
  67. package/dist/lib/commands/proxy.d.ts +71 -0
  68. package/dist/lib/commands/proxy.d.ts.map +1 -0
  69. package/dist/lib/commands/proxy.js +240 -0
  70. package/dist/lib/commands/proxy.js.map +1 -0
  71. package/dist/lib/commands/pull.d.ts +8 -0
  72. package/dist/lib/commands/pull.d.ts.map +1 -0
  73. package/dist/lib/commands/pull.js +455 -0
  74. package/dist/lib/commands/pull.js.map +1 -0
  75. package/dist/lib/commands/push.d.ts +4 -0
  76. package/dist/lib/commands/push.d.ts.map +1 -0
  77. package/dist/lib/commands/push.js +2154 -0
  78. package/dist/lib/commands/push.js.map +1 -0
  79. package/dist/lib/commands/run.d.ts +3 -0
  80. package/dist/lib/commands/run.d.ts.map +1 -0
  81. package/dist/lib/commands/run.js +287 -0
  82. package/dist/lib/commands/run.js.map +1 -0
  83. package/dist/lib/commands/sites.d.ts +296 -0
  84. package/dist/lib/commands/sites.d.ts.map +1 -0
  85. package/dist/lib/commands/sites.js +1046 -0
  86. package/dist/lib/commands/sites.js.map +1 -0
  87. package/dist/lib/commands/storage.d.ts +170 -0
  88. package/dist/lib/commands/storage.d.ts.map +1 -0
  89. package/dist/lib/commands/storage.js +651 -0
  90. package/dist/lib/commands/storage.js.map +1 -0
  91. package/dist/lib/commands/tables-db.d.ts +728 -0
  92. package/dist/lib/commands/tables-db.d.ts.map +1 -0
  93. package/dist/lib/commands/tables-db.js +2198 -0
  94. package/dist/lib/commands/tables-db.js.map +1 -0
  95. package/dist/lib/commands/teams.d.ts +129 -0
  96. package/dist/lib/commands/teams.d.ts.map +1 -0
  97. package/dist/lib/commands/teams.js +403 -0
  98. package/dist/lib/commands/teams.js.map +1 -0
  99. package/dist/lib/commands/tokens.d.ts +48 -0
  100. package/dist/lib/commands/tokens.d.ts.map +1 -0
  101. package/dist/lib/commands/tokens.js +156 -0
  102. package/dist/lib/commands/tokens.js.map +1 -0
  103. package/dist/lib/commands/types.d.ts +3 -0
  104. package/dist/lib/commands/types.d.ts.map +1 -0
  105. package/dist/lib/commands/types.js +155 -0
  106. package/dist/lib/commands/types.js.map +1 -0
  107. package/dist/lib/commands/update.d.ts +3 -0
  108. package/dist/lib/commands/update.d.ts.map +1 -0
  109. package/dist/lib/commands/update.js +202 -0
  110. package/dist/lib/commands/update.js.map +1 -0
  111. package/dist/lib/commands/users.d.ts +382 -0
  112. package/dist/lib/commands/users.d.ts.map +1 -0
  113. package/dist/lib/commands/users.js +1195 -0
  114. package/dist/lib/commands/users.js.map +1 -0
  115. package/dist/lib/commands/vcs.d.ts +92 -0
  116. package/dist/lib/commands/vcs.d.ts.map +1 -0
  117. package/dist/lib/commands/vcs.js +276 -0
  118. package/dist/lib/commands/vcs.js.map +1 -0
  119. package/dist/lib/config.d.ts +118 -0
  120. package/dist/lib/config.d.ts.map +1 -0
  121. package/{lib → dist/lib}/config.js +204 -325
  122. package/dist/lib/config.js.map +1 -0
  123. package/dist/lib/emulation/docker.d.ts +15 -0
  124. package/dist/lib/emulation/docker.d.ts.map +1 -0
  125. package/dist/lib/emulation/docker.js +220 -0
  126. package/dist/lib/emulation/docker.js.map +1 -0
  127. package/dist/lib/emulation/utils.d.ts +29 -0
  128. package/dist/lib/emulation/utils.d.ts.map +1 -0
  129. package/dist/lib/emulation/utils.js +168 -0
  130. package/dist/lib/emulation/utils.js.map +1 -0
  131. package/dist/lib/exception.d.ts +8 -0
  132. package/dist/lib/exception.d.ts.map +1 -0
  133. package/dist/lib/exception.js +16 -0
  134. package/dist/lib/exception.js.map +1 -0
  135. package/dist/lib/id.d.ts +7 -0
  136. package/dist/lib/id.d.ts.map +1 -0
  137. package/dist/lib/id.js +32 -0
  138. package/dist/lib/id.js.map +1 -0
  139. package/dist/lib/paginate.d.ts +10 -0
  140. package/dist/lib/paginate.d.ts.map +1 -0
  141. package/{lib → dist/lib}/paginate.js +9 -15
  142. package/dist/lib/paginate.js.map +1 -0
  143. package/dist/lib/parser.d.ts +18 -0
  144. package/dist/lib/parser.d.ts.map +1 -0
  145. package/dist/lib/parser.js +237 -0
  146. package/dist/lib/parser.js.map +1 -0
  147. package/dist/lib/questions.d.ts +59 -0
  148. package/dist/lib/questions.d.ts.map +1 -0
  149. package/dist/lib/questions.js +995 -0
  150. package/dist/lib/questions.js.map +1 -0
  151. package/dist/lib/sdks.d.ts +4 -0
  152. package/dist/lib/sdks.d.ts.map +1 -0
  153. package/dist/lib/sdks.js +51 -0
  154. package/dist/lib/sdks.js.map +1 -0
  155. package/dist/lib/spinner.d.ts +28 -0
  156. package/dist/lib/spinner.d.ts.map +1 -0
  157. package/{lib → dist/lib}/spinner.js +34 -45
  158. package/dist/lib/spinner.js.map +1 -0
  159. package/dist/lib/type-generation/attribute.d.ts +17 -0
  160. package/dist/lib/type-generation/attribute.d.ts.map +1 -0
  161. package/dist/lib/type-generation/attribute.js +19 -0
  162. package/dist/lib/type-generation/attribute.js.map +1 -0
  163. package/dist/lib/type-generation/languages/csharp.d.ts +7 -0
  164. package/dist/lib/type-generation/languages/csharp.d.ts.map +1 -0
  165. package/dist/lib/type-generation/languages/csharp.js +180 -0
  166. package/dist/lib/type-generation/languages/csharp.js.map +1 -0
  167. package/dist/lib/type-generation/languages/dart.d.ts +8 -0
  168. package/dist/lib/type-generation/languages/dart.d.ts.map +1 -0
  169. package/dist/lib/type-generation/languages/dart.js +197 -0
  170. package/dist/lib/type-generation/languages/dart.js.map +1 -0
  171. package/dist/lib/type-generation/languages/java.d.ts +7 -0
  172. package/dist/lib/type-generation/languages/java.d.ts.map +1 -0
  173. package/dist/lib/type-generation/languages/java.js +140 -0
  174. package/dist/lib/type-generation/languages/java.js.map +1 -0
  175. package/dist/lib/type-generation/languages/javascript.d.ts +9 -0
  176. package/dist/lib/type-generation/languages/javascript.d.ts.map +1 -0
  177. package/dist/lib/type-generation/languages/javascript.js +108 -0
  178. package/dist/lib/type-generation/languages/javascript.js.map +1 -0
  179. package/dist/lib/type-generation/languages/kotlin.d.ts +7 -0
  180. package/dist/lib/type-generation/languages/kotlin.d.ts.map +1 -0
  181. package/dist/lib/type-generation/languages/kotlin.js +95 -0
  182. package/dist/lib/type-generation/languages/kotlin.js.map +1 -0
  183. package/dist/lib/type-generation/languages/language.d.ts +43 -0
  184. package/dist/lib/type-generation/languages/language.d.ts.map +1 -0
  185. package/dist/lib/type-generation/languages/language.js +82 -0
  186. package/dist/lib/type-generation/languages/language.js.map +1 -0
  187. package/dist/lib/type-generation/languages/php.d.ts +7 -0
  188. package/dist/lib/type-generation/languages/php.d.ts.map +1 -0
  189. package/dist/lib/type-generation/languages/php.js +116 -0
  190. package/dist/lib/type-generation/languages/php.js.map +1 -0
  191. package/dist/lib/type-generation/languages/swift.d.ts +7 -0
  192. package/dist/lib/type-generation/languages/swift.d.ts.map +1 -0
  193. package/dist/lib/type-generation/languages/swift.js +179 -0
  194. package/dist/lib/type-generation/languages/swift.js.map +1 -0
  195. package/dist/lib/type-generation/languages/typescript.d.ts +9 -0
  196. package/dist/lib/type-generation/languages/typescript.d.ts.map +1 -0
  197. package/dist/lib/type-generation/languages/typescript.js +112 -0
  198. package/dist/lib/type-generation/languages/typescript.js.map +1 -0
  199. package/dist/lib/types.d.ts +133 -0
  200. package/dist/lib/types.d.ts.map +1 -0
  201. package/dist/lib/types.js +3 -0
  202. package/dist/lib/types.js.map +1 -0
  203. package/dist/lib/utils.d.ts +15 -0
  204. package/dist/lib/utils.d.ts.map +1 -0
  205. package/{lib → dist/lib}/utils.js +74 -120
  206. package/dist/lib/utils.js.map +1 -0
  207. package/dist/lib/validations.d.ts +2 -0
  208. package/dist/lib/validations.d.ts.map +1 -0
  209. package/dist/lib/validations.js +20 -0
  210. package/dist/lib/validations.js.map +1 -0
  211. package/docs/examples/databases/upsert-document.md +1 -2
  212. package/index.ts +152 -0
  213. package/install.ps1 +2 -5
  214. package/install.sh +1 -2
  215. package/lib/client.ts +259 -0
  216. package/lib/commands/{account.js → account.ts} +410 -664
  217. package/lib/commands/console.ts +112 -0
  218. package/lib/commands/{databases.js → databases.ts} +818 -1136
  219. package/lib/commands/{functions.js → functions.ts} +381 -526
  220. package/lib/commands/{generic.js → generic.ts} +47 -39
  221. package/lib/commands/graphql.ts +110 -0
  222. package/lib/commands/{health.js → health.ts} +168 -284
  223. package/lib/commands/{init.js → init.ts} +68 -66
  224. package/lib/commands/{locale.js → locale.ts} +75 -121
  225. package/lib/commands/{messaging.js → messaging.ts} +699 -937
  226. package/lib/commands/{migrations.js → migrations.ts} +182 -258
  227. package/lib/commands/organizations.ts +46 -0
  228. package/lib/commands/{project.js → project.ts} +75 -111
  229. package/lib/commands/{projects.js → projects.ts} +587 -843
  230. package/lib/commands/{proxy.js → proxy.ts} +94 -140
  231. package/lib/commands/{pull.js → pull.ts} +54 -44
  232. package/lib/commands/{push.js → push.ts} +235 -191
  233. package/lib/commands/{run.js → run.ts} +61 -55
  234. package/lib/commands/{sites.js → sites.ts} +364 -504
  235. package/lib/commands/{storage.js → storage.ts} +216 -292
  236. package/lib/commands/{tables-db.js → tables-db.ts} +817 -1126
  237. package/lib/commands/{teams.js → teams.ts} +162 -236
  238. package/lib/commands/{tokens.js → tokens.ts} +70 -99
  239. package/lib/commands/{types.js → types.ts} +37 -35
  240. package/lib/commands/{update.js → update.ts} +25 -27
  241. package/lib/commands/{users.js → users.ts} +426 -644
  242. package/lib/commands/{vcs.js → vcs.ts} +122 -173
  243. package/lib/config.ts +854 -0
  244. package/lib/emulation/{docker.js → docker.ts} +39 -38
  245. package/lib/emulation/utils.ts +193 -0
  246. package/lib/exception.ts +20 -0
  247. package/lib/{id.js → id.ts} +5 -5
  248. package/lib/paginate.ts +63 -0
  249. package/lib/parser.ts +238 -0
  250. package/lib/{questions.js → questions.ts} +148 -156
  251. package/lib/sdks.ts +55 -0
  252. package/lib/spinner.ts +118 -0
  253. package/lib/type-generation/attribute.ts +17 -0
  254. package/lib/type-generation/languages/{csharp.js → csharp.ts} +59 -48
  255. package/lib/type-generation/languages/{dart.js → dart.ts} +91 -80
  256. package/lib/type-generation/languages/{java.js → java.ts} +58 -47
  257. package/lib/type-generation/languages/javascript.ts +111 -0
  258. package/lib/type-generation/languages/kotlin.ts +96 -0
  259. package/lib/type-generation/languages/language.ts +119 -0
  260. package/lib/type-generation/languages/{php.js → php.ts} +55 -48
  261. package/lib/type-generation/languages/{swift.js → swift.ts} +59 -48
  262. package/lib/type-generation/languages/typescript.ts +116 -0
  263. package/lib/types.ts +150 -0
  264. package/lib/utils.ts +322 -0
  265. package/lib/validations.ts +17 -0
  266. package/package.json +21 -12
  267. package/scoop/appwrite.config.json +3 -3
  268. package/tsconfig.json +30 -0
  269. package/index.js +0 -147
  270. package/lib/client.js +0 -254
  271. package/lib/commands/console.js +0 -127
  272. package/lib/commands/graphql.js +0 -126
  273. package/lib/commands/organizations.js +0 -48
  274. package/lib/emulation/utils.js +0 -186
  275. package/lib/exception.js +0 -9
  276. package/lib/parser.js +0 -250
  277. package/lib/sdks.js +0 -60
  278. package/lib/type-generation/attribute.js +0 -16
  279. package/lib/type-generation/languages/javascript.js +0 -102
  280. package/lib/type-generation/languages/kotlin.js +0 -85
  281. package/lib/type-generation/languages/language.js +0 -125
  282. package/lib/type-generation/languages/typescript.js +0 -107
  283. package/lib/validations.js +0 -17
package/tsconfig.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "lib": ["ES2020"],
6
+ "outDir": "./dist",
7
+ "rootDir": "./",
8
+ "strict": false,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "resolveJsonModule": true,
13
+ "declaration": true,
14
+ "declarationMap": true,
15
+ "sourceMap": true,
16
+ "moduleResolution": "node",
17
+ "allowSyntheticDefaultImports": true,
18
+ "types": ["node"],
19
+ "noEmitOnError": false,
20
+ "noImplicitAny": false
21
+ },
22
+ "include": [
23
+ "**/*.ts"
24
+ ],
25
+ "exclude": [
26
+ "node_modules",
27
+ "dist",
28
+ "build"
29
+ ]
30
+ }
package/index.js DELETED
@@ -1,147 +0,0 @@
1
- #! /usr/bin/env node
2
-
3
- /** Required to set max width of the help commands */
4
- const oldWidth = process.stdout.columns
5
- process.stdout.columns = 100
6
- /** ---------------------------------------------- */
7
-
8
- const program = require("commander");
9
- const chalk = require("chalk");
10
- const { version } = require("./package.json");
11
- const { commandDescriptions, cliConfig } = require("./lib/parser");
12
- const { client } = require("./lib/commands/generic");
13
- const { getLatestVersion, compareVersions } = require("./lib/utils");
14
- const inquirer = require("inquirer");
15
- const { login, logout, whoami, migrate, register } = require("./lib/commands/generic");
16
- const { init } = require("./lib/commands/init");
17
- const { types } = require("./lib/commands/types");
18
- const { pull } = require("./lib/commands/pull");
19
- const { run } = require("./lib/commands/run");
20
- const { push, deploy } = require("./lib/commands/push");
21
- const { update } = require("./lib/commands/update");
22
- const { account } = require("./lib/commands/account");
23
- const { console } = require("./lib/commands/console");
24
- const { databases } = require("./lib/commands/databases");
25
- const { functions } = require("./lib/commands/functions");
26
- const { graphql } = require("./lib/commands/graphql");
27
- const { health } = require("./lib/commands/health");
28
- const { locale } = require("./lib/commands/locale");
29
- const { messaging } = require("./lib/commands/messaging");
30
- const { migrations } = require("./lib/commands/migrations");
31
- const { project } = require("./lib/commands/project");
32
- const { projects } = require("./lib/commands/projects");
33
- const { proxy } = require("./lib/commands/proxy");
34
- const { sites } = require("./lib/commands/sites");
35
- const { storage } = require("./lib/commands/storage");
36
- const { tablesDB } = require("./lib/commands/tables-db");
37
- const { teams } = require("./lib/commands/teams");
38
- const { tokens } = require("./lib/commands/tokens");
39
- const { users } = require("./lib/commands/users");
40
- const { vcs } = require("./lib/commands/vcs");
41
-
42
- inquirer.registerPrompt('search-list', require('inquirer-search-list'));
43
-
44
- /**
45
- * Check for updates and show version information
46
- */
47
- async function checkVersion() {
48
- process.stdout.write(chalk.bold(`appwrite version ${version}`) + '\n');
49
-
50
- try {
51
- const latestVersion = await getLatestVersion();
52
- const comparison = compareVersions(version, latestVersion);
53
-
54
- if (comparison > 0) {
55
- // Current version is older than latest
56
- process.stdout.write(chalk.yellow(`\n⚠️ A newer version is available: ${chalk.bold(latestVersion)}`) + '\n');
57
- process.stdout.write(chalk.cyan(`💡 Run '${chalk.bold('appwrite update')}' to update to the latest version.`) + '\n');
58
- } else if (comparison === 0) {
59
- process.stdout.write(chalk.green('\n✅ You are running the latest version!') + '\n');
60
- } else {
61
- // Current version is newer than latest (pre-release/dev)
62
- process.stdout.write(chalk.blue('\n🚀 You are running a pre-release or development version.') + '\n');
63
- }
64
- } catch (error) {
65
- // Silently fail version check, just show current version
66
- process.stdout.write(chalk.gray('\n(Unable to check for updates)') + '\n');
67
- }
68
- }
69
-
70
- // Intercept version flag before Commander.js processes it
71
- if (process.argv.includes('-v') || process.argv.includes('--version')) {
72
- (async () => {
73
- await checkVersion();
74
- process.exit(0);
75
- })();
76
- return;
77
- }
78
-
79
- program
80
- .description(commandDescriptions['main'])
81
- .configureHelp({
82
- helpWidth: process.stdout.columns || 80,
83
- sortSubcommands: true,
84
- })
85
- .helpOption('-h, --help', "Display help for command")
86
- .version(version, "-v, --version", "Output the version number")
87
- .option("-V, --verbose", "Show complete error log")
88
- .option("-j, --json", "Output in JSON format")
89
- .hook('preAction', migrate)
90
- .option("-f,--force", "Flag to confirm all warnings")
91
- .option("-a,--all", "Flag to push all resources")
92
- .option("--id [id...]", "Flag to pass a list of ids for a given action")
93
- .option("--report", "Enable reporting in case of CLI errors")
94
- .on("option:json", () => {
95
- cliConfig.json = true;
96
- })
97
- .on("option:verbose", () => {
98
- cliConfig.verbose = true;
99
- })
100
- .on("option:report", function() {
101
- cliConfig.report = true;
102
- cliConfig.reportData = { data: this };
103
- })
104
- .on("option:force", () => {
105
- cliConfig.force = true;
106
- })
107
- .on("option:all", () => {
108
- cliConfig.all = true;
109
- })
110
- .on("option:id", function() {
111
- cliConfig.ids = this.opts().id;
112
- })
113
- .showSuggestionAfterError()
114
- .addCommand(whoami)
115
- .addCommand(register)
116
- .addCommand(login)
117
- .addCommand(init)
118
- .addCommand(pull)
119
- .addCommand(push)
120
- .addCommand(types)
121
- .addCommand(deploy)
122
- .addCommand(run)
123
- .addCommand(update)
124
- .addCommand(logout)
125
- .addCommand(account)
126
- .addCommand(console)
127
- .addCommand(databases)
128
- .addCommand(functions)
129
- .addCommand(graphql)
130
- .addCommand(health)
131
- .addCommand(locale)
132
- .addCommand(messaging)
133
- .addCommand(migrations)
134
- .addCommand(project)
135
- .addCommand(projects)
136
- .addCommand(proxy)
137
- .addCommand(sites)
138
- .addCommand(storage)
139
- .addCommand(tablesDB)
140
- .addCommand(teams)
141
- .addCommand(tokens)
142
- .addCommand(users)
143
- .addCommand(vcs)
144
- .addCommand(client)
145
- .parse(process.argv);
146
-
147
- process.stdout.columns = oldWidth;
package/lib/client.js DELETED
@@ -1,254 +0,0 @@
1
- const os = require('os');
2
- const https = require("https");
3
- const { fetch, FormData, Agent } = require("undici");
4
- const JSONbig = require("json-bigint")({ storeAsString: false });
5
- const AppwriteException = require("./exception.js");
6
- const { globalConfig } = require("./config.js");
7
- const chalk = require("chalk");
8
-
9
- class Client {
10
- CHUNK_SIZE = 5*1024*1024; // 5MB
11
-
12
- constructor() {
13
- this.endpoint = 'https://cloud.appwrite.io/v1';
14
- this.headers = {
15
- 'content-type': '',
16
- 'x-sdk-name': 'Command Line',
17
- 'x-sdk-platform': 'console',
18
- 'x-sdk-language': 'cli',
19
- 'x-sdk-version': '12.0.0',
20
- 'user-agent' : `AppwriteCLI/12.0.0 (${os.type()} ${os.version()}; ${os.arch()})`,
21
- 'X-Appwrite-Response-Format' : '1.8.0',
22
- };
23
- }
24
-
25
- /**
26
- * Set Cookie
27
- *
28
- * Your cookie
29
- *
30
- * @param {string} cookie
31
- *
32
- * @return self
33
- */
34
- setCookie(cookie) {
35
- this.addHeader("cookie", cookie);
36
-
37
- return this;
38
- }
39
-
40
- /**
41
- * Set Project
42
- *
43
- * Your project ID
44
- *
45
- * @param {string} project
46
- *
47
- * @return self
48
- */
49
- setProject(project) {
50
- this.addHeader('X-Appwrite-Project', project);
51
-
52
- return this;
53
- }
54
-
55
- /**
56
- * Set Key
57
- *
58
- * Your secret API key
59
- *
60
- * @param {string} key
61
- *
62
- * @return self
63
- */
64
- setKey(key) {
65
- this.addHeader('X-Appwrite-Key', key);
66
-
67
- return this;
68
- }
69
-
70
- /**
71
- * Set JWT
72
- *
73
- * Your secret JSON Web Token
74
- *
75
- * @param {string} jwt
76
- *
77
- * @return self
78
- */
79
- setJWT(jwt) {
80
- this.addHeader('X-Appwrite-JWT', jwt);
81
-
82
- return this;
83
- }
84
-
85
- /**
86
- * Set Locale
87
- *
88
- * @param {string} locale
89
- *
90
- * @return self
91
- */
92
- setLocale(locale) {
93
- this.addHeader('X-Appwrite-Locale', locale);
94
-
95
- return this;
96
- }
97
-
98
- /**
99
- * Set Mode
100
- *
101
- * @param {string} mode
102
- *
103
- * @return self
104
- */
105
- setMode(mode) {
106
- this.addHeader('X-Appwrite-Mode', mode);
107
-
108
- return this;
109
- }
110
-
111
- /**
112
- * Set self signed.
113
- *
114
- * @param {bool} status
115
- *
116
- * @return this
117
- */
118
- setSelfSigned(status) {
119
- this.selfSigned = status;
120
-
121
- return this;
122
- }
123
-
124
- /**
125
- * Set endpoint.
126
- *
127
- * @param {string} endpoint
128
- *
129
- * @return this
130
- */
131
- setEndpoint(endpoint) {
132
- if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
133
- throw new AppwriteException('Invalid endpoint URL: ' + endpoint);
134
- }
135
-
136
- this.endpoint = endpoint;
137
- return this;
138
- }
139
-
140
- /**
141
- * @param {string} key
142
- * @param {string} value
143
- */
144
- addHeader(key, value) {
145
- this.headers[key.toLowerCase()] = value;
146
-
147
- return this;
148
- }
149
-
150
- async call(method, path = "", headers = {}, params = {}, responseType = "json") {
151
- headers = {...this.headers, ...headers};
152
- const url = new URL(this.endpoint + path);
153
-
154
- let body = undefined;
155
-
156
- if (method.toUpperCase() === "GET") {
157
- url.search = new URLSearchParams(Client.flatten(params)).toString();
158
- } else if (headers["content-type"]?.toLowerCase().startsWith("multipart/form-data")) {
159
- delete headers["content-type"];
160
- const formData = new FormData();
161
-
162
- const flatParams = Client.flatten(params);
163
-
164
- for (const [key, value] of Object.entries(flatParams)) {
165
- if (value && value.type && value.type === "file") {
166
- formData.append(key, value.file, value.filename);
167
- } else {
168
- formData.append(key, value);
169
- }
170
- }
171
-
172
- body = formData;
173
- } else {
174
- body = JSONbig.stringify(params);
175
- }
176
-
177
- let response = undefined;
178
- try {
179
- response = await fetch(url.toString(), {
180
- method: method.toUpperCase(),
181
- headers,
182
- body,
183
- dispatcher: new Agent({
184
- connect: {
185
- rejectUnauthorized: !this.selfSigned,
186
- },
187
- }),
188
- });
189
- } catch (error) {
190
- throw new AppwriteException(error.message);
191
- }
192
-
193
- if (response.status >= 400) {
194
- const text = await response.text();
195
- let json = undefined;
196
- try {
197
- json = JSON.parse(text);
198
- } catch (error) {
199
- throw new AppwriteException(text, response.status, "", text);
200
- }
201
-
202
- if (path !== '/account' && json.code === 401 && json.type === 'user_more_factors_required') {
203
- console.log(`${chalk.cyan.bold("ℹ Info")} ${chalk.cyan("Unusable account found, removing...")}`);
204
-
205
- const current = globalConfig.getCurrentSession();
206
- globalConfig.setCurrentSession('');
207
- globalConfig.removeSession(current);
208
- }
209
- throw new AppwriteException(json.message, json.code, json.type, text);
210
- }
211
-
212
- if (responseType === "arraybuffer") {
213
- const data = await response.arrayBuffer();
214
- return data;
215
- }
216
-
217
- let cookies = response.headers.getSetCookie();
218
- if (cookies && cookies.length > 0) {
219
- for (const cookie of cookies) {
220
- if (cookie.startsWith('a_session_console=')) {
221
- globalConfig.setCookie(cookie);
222
- }
223
- }
224
- }
225
-
226
- const text = await response.text();
227
- let json = undefined;
228
- try {
229
- json = JSONbig.parse(text);
230
- } catch (error) {
231
- return text;
232
- }
233
- return json;
234
- }
235
-
236
- static flatten(data, prefix = '') {
237
- let output = {};
238
-
239
- for (const key in data) {
240
- let value = data[key];
241
- let finalKey = prefix ? prefix + '[' + key +']' : key;
242
-
243
- if (Array.isArray(value)) {
244
- output = Object.assign(output, Client.flatten(value, finalKey)); // @todo: handle name collision here if needed
245
- } else {
246
- output[finalKey] = value;
247
- }
248
- }
249
-
250
- return output;
251
- }
252
- }
253
-
254
- module.exports = Client;
@@ -1,127 +0,0 @@
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, showConsoleLink } = require('../utils.js');
8
- const { Command } = require('commander');
9
- const { sdkForProject, sdkForConsole } = require('../sdks')
10
- const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log, warn } = require('../parser')
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
- }
37
-
38
- const console = new Command("console").description(commandDescriptions['console'] ?? '').configureHelp({
39
- helpWidth: process.stdout.columns || 80
40
- })
41
-
42
- /**
43
- * @typedef {Object} ConsoleGetResourceRequestParams
44
- * @property {string} value Resource value.
45
- * @property {ConsoleResourceType} type Resource type.
46
- * @property {boolean} overrideForCli
47
- * @property {boolean} parseOutput
48
- * @property {libClient | undefined} sdk
49
- */
50
-
51
- /**
52
- * @param {ConsoleGetResourceRequestParams} params
53
- */
54
- const consoleGetResource = async ({value,type,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => {
55
- let client = !sdk ? await sdkForProject() :
56
- sdk;
57
- let apiPath = '/console/resources';
58
- let payload = {};
59
- if (typeof value !== 'undefined') {
60
- payload['value'] = value;
61
- }
62
- if (typeof type !== 'undefined') {
63
- payload['type'] = type;
64
- }
65
-
66
- let response = undefined;
67
-
68
- response = await client.call('get', apiPath, {
69
- }, payload);
70
-
71
- if (parseOutput) {
72
- if(console) {
73
- showConsoleLink('console', 'getResource');
74
- } else {
75
- parse(response)
76
- }
77
- }
78
-
79
- return response;
80
-
81
- }
82
- /**
83
- * @typedef {Object} ConsoleVariablesRequestParams
84
- * @property {boolean} overrideForCli
85
- * @property {boolean} parseOutput
86
- * @property {libClient | undefined} sdk
87
- */
88
-
89
- /**
90
- * @param {ConsoleVariablesRequestParams} params
91
- */
92
- const consoleVariables = async ({parseOutput = true, overrideForCli = false, sdk = undefined}) => {
93
- let client = !sdk ? await sdkForProject() :
94
- sdk;
95
- let apiPath = '/console/variables';
96
- let payload = {};
97
-
98
- let response = undefined;
99
-
100
- response = await client.call('get', apiPath, {
101
- }, payload);
102
-
103
- if (parseOutput) {
104
- parse(response)
105
- }
106
-
107
- return response;
108
-
109
- }
110
- console
111
- .command(`get-resource`)
112
- .description(`Check if a resource ID is available.`)
113
- .requiredOption(`--value <value>`, `Resource value.`)
114
- .requiredOption(`--type <type>`, `Resource type.`)
115
- .option(`--console`, `Get the resource console url`)
116
- .action(actionRunner(consoleGetResource))
117
-
118
- console
119
- .command(`variables`)
120
- .description(`Get all Environment Variables that are relevant for the console.`)
121
- .action(actionRunner(consoleVariables))
122
-
123
- module.exports = {
124
- console,
125
- consoleGetResource,
126
- consoleVariables
127
- };
@@ -1,126 +0,0 @@
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, showConsoleLink } = require('../utils.js');
8
- const { Command } = require('commander');
9
- const { sdkForProject, sdkForConsole } = require('../sdks')
10
- const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log, warn } = require('../parser')
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
- }
37
-
38
- const graphql = new Command("graphql").description(commandDescriptions['graphql'] ?? '').configureHelp({
39
- helpWidth: process.stdout.columns || 80
40
- })
41
-
42
- /**
43
- * @typedef {Object} GraphqlQueryRequestParams
44
- * @property {object} query The query or queries to execute.
45
- * @property {boolean} overrideForCli
46
- * @property {boolean} parseOutput
47
- * @property {libClient | undefined} sdk
48
- */
49
-
50
- /**
51
- * @param {GraphqlQueryRequestParams} params
52
- */
53
- const graphqlQuery = async ({query,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
54
- let client = !sdk ? await sdkForProject() :
55
- sdk;
56
- let apiPath = '/graphql';
57
- let payload = {};
58
- if (typeof query !== 'undefined') {
59
- payload['query'] = JSON.parse(query);
60
- }
61
-
62
- let response = undefined;
63
-
64
- response = await client.call('post', apiPath, {
65
- 'x-sdk-graphql': 'true',
66
- 'content-type': 'application/json',
67
- }, payload);
68
-
69
- if (parseOutput) {
70
- parse(response)
71
- }
72
-
73
- return response;
74
-
75
- }
76
- /**
77
- * @typedef {Object} GraphqlMutationRequestParams
78
- * @property {object} query The query or queries to execute.
79
- * @property {boolean} overrideForCli
80
- * @property {boolean} parseOutput
81
- * @property {libClient | undefined} sdk
82
- */
83
-
84
- /**
85
- * @param {GraphqlMutationRequestParams} params
86
- */
87
- const graphqlMutation = async ({query,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
88
- let client = !sdk ? await sdkForProject() :
89
- sdk;
90
- let apiPath = '/graphql/mutation';
91
- let payload = {};
92
- if (typeof query !== 'undefined') {
93
- payload['query'] = JSON.parse(query);
94
- }
95
-
96
- let response = undefined;
97
-
98
- response = await client.call('post', apiPath, {
99
- 'x-sdk-graphql': 'true',
100
- 'content-type': 'application/json',
101
- }, payload);
102
-
103
- if (parseOutput) {
104
- parse(response)
105
- }
106
-
107
- return response;
108
-
109
- }
110
- graphql
111
- .command(`query`)
112
- .description(`Execute a GraphQL mutation.`)
113
- .requiredOption(`--query <query>`, `The query or queries to execute.`)
114
- .action(actionRunner(graphqlQuery))
115
-
116
- graphql
117
- .command(`mutation`)
118
- .description(`Execute a GraphQL mutation.`)
119
- .requiredOption(`--query <query>`, `The query or queries to execute.`)
120
- .action(actionRunner(graphqlMutation))
121
-
122
- module.exports = {
123
- graphql,
124
- graphqlQuery,
125
- graphqlMutation
126
- };