appwrite-cli 12.0.1 → 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 +4 -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} +408 -662
  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} +118 -174
  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 -57
  255. package/lib/type-generation/languages/{dart.js → dart.ts} +91 -89
  256. package/lib/type-generation/languages/{java.js → java.ts} +58 -56
  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 -53
  261. package/lib/type-generation/languages/{swift.js → swift.ts} +59 -57
  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 -19
  279. package/lib/type-generation/languages/javascript.js +0 -111
  280. package/lib/type-generation/languages/kotlin.js +0 -94
  281. package/lib/type-generation/languages/language.js +0 -125
  282. package/lib/type-generation/languages/typescript.js +0 -116
  283. package/lib/validations.js +0 -17
package/index.ts ADDED
@@ -0,0 +1,152 @@
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
+ import program = require('commander');
9
+ import chalk = require('chalk');
10
+ const { version } = require('../package.json');
11
+ import { commandDescriptions, cliConfig } from './lib/parser';
12
+ import { client } from './lib/commands/generic';
13
+ import { getLatestVersion, compareVersions } from './lib/utils';
14
+ import inquirer = require('inquirer');
15
+ import { login, logout, whoami, migrate, register } from './lib/commands/generic';
16
+ import { init } from './lib/commands/init';
17
+ import { types } from './lib/commands/types';
18
+ import { pull } from './lib/commands/pull';
19
+ import { run } from './lib/commands/run';
20
+ import { push, deploy } from './lib/commands/push';
21
+ import { update } from './lib/commands/update';
22
+ import { account } from './lib/commands/account';
23
+ import { console } from './lib/commands/console';
24
+ import { databases } from './lib/commands/databases';
25
+ import { functions } from './lib/commands/functions';
26
+ import { graphql } from './lib/commands/graphql';
27
+ import { health } from './lib/commands/health';
28
+ import { locale } from './lib/commands/locale';
29
+ import { messaging } from './lib/commands/messaging';
30
+ import { migrations } from './lib/commands/migrations';
31
+ import { project } from './lib/commands/project';
32
+ import { projects } from './lib/commands/projects';
33
+ import { proxy } from './lib/commands/proxy';
34
+ import { sites } from './lib/commands/sites';
35
+ import { storage } from './lib/commands/storage';
36
+ import { tablesDB } from './lib/commands/tables-db';
37
+ import { teams } from './lib/commands/teams';
38
+ import { tokens } from './lib/commands/tokens';
39
+ import { users } from './lib/commands/users';
40
+ import { vcs } from './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(): Promise<void> {
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(
57
+ chalk.yellow(`\n⚠️ A newer version is available: ${chalk.bold(latestVersion)}`) + '\n'
58
+ );
59
+ process.stdout.write(
60
+ chalk.cyan(
61
+ `💡 Run '${chalk.bold('appwrite update')}' to update to the latest version.`
62
+ ) + '\n'
63
+ );
64
+ } else if (comparison === 0) {
65
+ process.stdout.write(chalk.green('\n✅ You are running the latest version!') + '\n');
66
+ } else {
67
+ // Current version is newer than latest (pre-release/dev)
68
+ process.stdout.write(chalk.blue('\n🚀 You are running a pre-release or development version.') + '\n');
69
+ }
70
+ } catch (error) {
71
+ // Silently fail version check, just show current version
72
+ process.stdout.write(chalk.gray('\n(Unable to check for updates)') + '\n');
73
+ }
74
+ }
75
+
76
+ // Intercept version flag before Commander.js processes it
77
+ if (process.argv.includes('-v') || process.argv.includes('--version')) {
78
+ (async () => {
79
+ await checkVersion();
80
+ process.exit(0);
81
+ })();
82
+ } else {
83
+ program
84
+ .description(commandDescriptions['main'])
85
+ .configureHelp({
86
+ helpWidth: process.stdout.columns || 80,
87
+ sortSubcommands: true,
88
+ })
89
+ .helpOption('-h, --help', 'Display help for command')
90
+ .version(version, '-v, --version', 'Output the version number')
91
+ .option('-V, --verbose', 'Show complete error log')
92
+ .option('-j, --json', 'Output in JSON format')
93
+ .hook('preAction', migrate)
94
+ .option('-f,--force', 'Flag to confirm all warnings')
95
+ .option('-a,--all', 'Flag to push all resources')
96
+ .option('--id [id...]', 'Flag to pass a list of ids for a given action')
97
+ .option('--report', 'Enable reporting in case of CLI errors')
98
+ .on('option:json', () => {
99
+ cliConfig.json = true;
100
+ })
101
+ .on('option:verbose', () => {
102
+ cliConfig.verbose = true;
103
+ })
104
+ .on('option:report', function () {
105
+ cliConfig.report = true;
106
+ cliConfig.reportData = { data: this };
107
+ })
108
+ .on('option:force', () => {
109
+ cliConfig.force = true;
110
+ })
111
+ .on('option:all', () => {
112
+ cliConfig.all = true;
113
+ })
114
+ .on('option:id', function () {
115
+ cliConfig.ids = (this as any).opts().id;
116
+ })
117
+ .showSuggestionAfterError()
118
+ .addCommand(whoami)
119
+ .addCommand(register)
120
+ .addCommand(login)
121
+ .addCommand(init)
122
+ .addCommand(pull)
123
+ .addCommand(push)
124
+ .addCommand(types)
125
+ .addCommand(deploy)
126
+ .addCommand(run)
127
+ .addCommand(update)
128
+ .addCommand(logout)
129
+ .addCommand(account)
130
+ .addCommand(console)
131
+ .addCommand(databases)
132
+ .addCommand(functions)
133
+ .addCommand(graphql)
134
+ .addCommand(health)
135
+ .addCommand(locale)
136
+ .addCommand(messaging)
137
+ .addCommand(migrations)
138
+ .addCommand(project)
139
+ .addCommand(projects)
140
+ .addCommand(proxy)
141
+ .addCommand(sites)
142
+ .addCommand(storage)
143
+ .addCommand(tablesDB)
144
+ .addCommand(teams)
145
+ .addCommand(tokens)
146
+ .addCommand(users)
147
+ .addCommand(vcs)
148
+ .addCommand(client)
149
+ .parse(process.argv);
150
+
151
+ process.stdout.columns = oldWidth;
152
+ }
package/install.ps1 CHANGED
@@ -13,8 +13,8 @@
13
13
  # You can use "View source" of this page to see the full script.
14
14
 
15
15
  # REPO
16
- $GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/12.0.1/appwrite-cli-win-x64.exe"
17
- $GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/12.0.1/appwrite-cli-win-arm64.exe"
16
+ $GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/13.0.0-rc.1/appwrite-cli-win-x64.exe"
17
+ $GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/13.0.0-rc.1/appwrite-cli-win-arm64.exe"
18
18
 
19
19
  $APPWRITE_BINARY_NAME = "appwrite.exe"
20
20
 
@@ -41,7 +41,6 @@ function Greeting {
41
41
  Write-Host "Welcome to the Appwrite CLI install shield."
42
42
  }
43
43
 
44
-
45
44
  function CheckSystemInfo {
46
45
  Write-Host "[1/4] Getting System Info ..."
47
46
  if ((Get-ExecutionPolicy) -gt 'RemoteSigned' -or (Get-ExecutionPolicy) -eq 'ByPass') {
@@ -66,7 +65,6 @@ function DownloadBinary {
66
65
  Move-Item $APPWRITE_DOWNLOAD_DIR $APPWRITE_INSTALL_PATH
67
66
  }
68
67
 
69
-
70
68
  function Install {
71
69
  Write-Host "[3/4] Starting installation ..."
72
70
 
@@ -89,7 +87,6 @@ function InstallCompleted {
89
87
  Write-Host "As first step, you can login to your Appwrite account using 'appwrite login'"
90
88
  }
91
89
 
92
-
93
90
  Greeting
94
91
  CheckSystemInfo
95
92
  DownloadBinary
package/install.sh CHANGED
@@ -39,7 +39,6 @@ RED='\033[0;31m'
39
39
  GREEN='\033[0;32m'
40
40
  NC='\033[0m' # No Color
41
41
 
42
-
43
42
  greeting() {
44
43
  echo -e "${RED}"
45
44
  cat << "EOF"
@@ -97,7 +96,7 @@ printSuccess() {
97
96
  downloadBinary() {
98
97
  echo "[2/4] Downloading executable for $OS ($ARCH) ..."
99
98
 
100
- GITHUB_LATEST_VERSION="12.0.1"
99
+ GITHUB_LATEST_VERSION="13.0.0-rc.1"
101
100
  GITHUB_FILE="appwrite-cli-${OS}-${ARCH}"
102
101
  GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE"
103
102
 
package/lib/client.ts ADDED
@@ -0,0 +1,259 @@
1
+ import os = require('os');
2
+ import { fetch, FormData, Agent } from 'undici';
3
+ import JSONbig = require('json-bigint');
4
+ import AppwriteException = require('./exception');
5
+ import { globalConfig } from './config';
6
+ import chalk = require('chalk');
7
+ import type { Headers, RequestParams, ResponseType, FileUpload } from './types';
8
+
9
+ const JSONBigInt = JSONbig({ storeAsString: false });
10
+
11
+ class Client {
12
+ private readonly CHUNK_SIZE = 5 * 1024 * 1024; // 5MB
13
+ private endpoint: string;
14
+ private headers: Headers;
15
+ private selfSigned: boolean;
16
+
17
+ constructor() {
18
+ this.endpoint = 'https://cloud.appwrite.io/v1';
19
+ this.selfSigned = false;
20
+ this.headers = {
21
+ 'content-type': '',
22
+ 'x-sdk-name': 'Command Line',
23
+ 'x-sdk-platform': 'console',
24
+ 'x-sdk-language': 'cli',
25
+ 'x-sdk-version': '13.0.0-rc.1',
26
+ 'user-agent': `AppwriteCLI/13.0.0-rc.1 (${os.type()} ${os.version()}; ${os.arch()})`,
27
+ 'X-Appwrite-Response-Format': '1.8.0',
28
+ };
29
+ }
30
+
31
+ /**
32
+ * Set Cookie
33
+ *
34
+ * Your cookie
35
+ *
36
+ * @param {string} cookie
37
+ *
38
+ * @return self
39
+ */
40
+ setCookie(cookie: string): this {
41
+ this.addHeader('cookie', cookie);
42
+ return this;
43
+ }
44
+
45
+ /**
46
+ * Set Project
47
+ *
48
+ * Your project ID
49
+ *
50
+ * @param {string} project
51
+ *
52
+ * @return self
53
+ */
54
+ setProject(project: string): this {
55
+ this.addHeader('X-Appwrite-Project', project);
56
+ return this;
57
+ }
58
+
59
+ /**
60
+ * Set Key
61
+ *
62
+ * Your secret API key
63
+ *
64
+ * @param {string} key
65
+ *
66
+ * @return self
67
+ */
68
+ setKey(key: string): this {
69
+ this.addHeader('X-Appwrite-Key', key);
70
+ return this;
71
+ }
72
+
73
+ /**
74
+ * Set JWT
75
+ *
76
+ * Your secret JSON Web Token
77
+ *
78
+ * @param {string} jwt
79
+ *
80
+ * @return self
81
+ */
82
+ setJWT(jwt: string): this {
83
+ this.addHeader('X-Appwrite-JWT', jwt);
84
+ return this;
85
+ }
86
+
87
+ /**
88
+ * Set Locale
89
+ *
90
+ * @param {string} locale
91
+ *
92
+ * @return self
93
+ */
94
+ setLocale(locale: string): this {
95
+ this.addHeader('X-Appwrite-Locale', locale);
96
+ return this;
97
+ }
98
+
99
+ /**
100
+ * Set Mode
101
+ *
102
+ * @param {string} mode
103
+ *
104
+ * @return self
105
+ */
106
+ setMode(mode: string): this {
107
+ this.addHeader('X-Appwrite-Mode', mode);
108
+ return this;
109
+ }
110
+
111
+ /**
112
+ * Set self signed.
113
+ *
114
+ * @param {bool} status
115
+ *
116
+ * @return this
117
+ */
118
+ setSelfSigned(status: boolean): this {
119
+ this.selfSigned = status;
120
+ return this;
121
+ }
122
+
123
+ /**
124
+ * Set endpoint.
125
+ *
126
+ * @param {string} endpoint
127
+ *
128
+ * @return this
129
+ */
130
+ setEndpoint(endpoint: string): this {
131
+ if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
132
+ throw new AppwriteException('Invalid endpoint URL: ' + endpoint);
133
+ }
134
+
135
+ this.endpoint = endpoint;
136
+ return this;
137
+ }
138
+
139
+ /**
140
+ * @param {string} key
141
+ * @param {string} value
142
+ */
143
+ addHeader(key: string, value: string): this {
144
+ this.headers[key.toLowerCase()] = value;
145
+ return this;
146
+ }
147
+
148
+ async call<T = unknown>(
149
+ method: string,
150
+ path: string = '',
151
+ headers: Headers = {},
152
+ params: RequestParams = {},
153
+ responseType: ResponseType = 'json'
154
+ ): Promise<T> {
155
+ const mergedHeaders: Headers = { ...this.headers, ...headers };
156
+ const url = new URL(this.endpoint + path);
157
+
158
+ let body: FormData | string | undefined = undefined;
159
+
160
+ if (method.toUpperCase() === 'GET') {
161
+ url.search = new URLSearchParams(Client.flatten(params) as Record<string, string>).toString();
162
+ } else if (mergedHeaders['content-type']?.toLowerCase().startsWith('multipart/form-data')) {
163
+ delete mergedHeaders['content-type'];
164
+ const formData = new FormData();
165
+
166
+ const flatParams = Client.flatten(params);
167
+
168
+ for (const [key, value] of Object.entries(flatParams)) {
169
+ if (value && typeof value === 'object' && 'type' in value && value.type === 'file') {
170
+ const fileUpload = value as FileUpload;
171
+ formData.append(key, fileUpload.file as any, fileUpload.filename);
172
+ } else {
173
+ formData.append(key, value as string);
174
+ }
175
+ }
176
+
177
+ body = formData;
178
+ } else {
179
+ body = JSONBigInt.stringify(params);
180
+ }
181
+
182
+ let response: Awaited<ReturnType<typeof fetch>> | undefined = undefined;
183
+ try {
184
+ response = await fetch(url.toString(), {
185
+ method: method.toUpperCase(),
186
+ headers: mergedHeaders,
187
+ body,
188
+ dispatcher: new Agent({
189
+ connect: {
190
+ rejectUnauthorized: !this.selfSigned,
191
+ },
192
+ }),
193
+ });
194
+ } catch (error) {
195
+ throw new AppwriteException((error as Error).message);
196
+ }
197
+
198
+ if (response.status >= 400) {
199
+ const text = await response.text();
200
+ let json: { message?: string; code?: number; type?: string } | undefined = undefined;
201
+ try {
202
+ json = JSON.parse(text);
203
+ } catch (error) {
204
+ throw new AppwriteException(text, response.status, '', text);
205
+ }
206
+
207
+ if (path !== '/account' && json.code === 401 && json.type === 'user_more_factors_required') {
208
+ console.log(`${chalk.cyan.bold('ℹ Info')} ${chalk.cyan('Unusable account found, removing...')}`);
209
+
210
+ const current = globalConfig.getCurrentSession();
211
+ globalConfig.setCurrentSession('');
212
+ globalConfig.removeSession(current);
213
+ }
214
+ throw new AppwriteException(json.message || text, json.code, json.type, text);
215
+ }
216
+
217
+ if (responseType === 'arraybuffer') {
218
+ const data = await response.arrayBuffer();
219
+ return data as T;
220
+ }
221
+
222
+ const cookies = response.headers.getSetCookie();
223
+ if (cookies && cookies.length > 0) {
224
+ for (const cookie of cookies) {
225
+ if (cookie.startsWith('a_session_console=')) {
226
+ globalConfig.setCookie(cookie);
227
+ }
228
+ }
229
+ }
230
+
231
+ const text = await response.text();
232
+ let json: T | undefined = undefined;
233
+ try {
234
+ json = JSONBigInt.parse(text);
235
+ } catch (error) {
236
+ return text as T;
237
+ }
238
+ return json as T;
239
+ }
240
+
241
+ static flatten(data: RequestParams, prefix: string = ''): Record<string, unknown> {
242
+ let output: Record<string, unknown> = {};
243
+
244
+ for (const key in data) {
245
+ const value = data[key];
246
+ const finalKey = prefix ? prefix + '[' + key + ']' : key;
247
+
248
+ if (Array.isArray(value)) {
249
+ output = { ...output, ...Client.flatten(value as unknown as RequestParams, finalKey) };
250
+ } else {
251
+ output[finalKey] = value;
252
+ }
253
+ }
254
+
255
+ return output;
256
+ }
257
+ }
258
+
259
+ export = Client;