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.
- package/CHANGELOG.md +4 -0
- package/README.md +2 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +145 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/client.d.ts +89 -0
- package/dist/lib/client.d.ts.map +1 -0
- package/dist/lib/client.js +227 -0
- package/dist/lib/client.js.map +1 -0
- package/dist/lib/commands/account.d.ts +379 -0
- package/dist/lib/commands/account.d.ts.map +1 -0
- package/dist/lib/commands/account.js +1228 -0
- package/dist/lib/commands/account.js.map +1 -0
- package/dist/lib/commands/console.d.ts +20 -0
- package/dist/lib/commands/console.d.ts.map +1 -0
- package/dist/lib/commands/console.js +78 -0
- package/dist/lib/commands/console.js.map +1 -0
- package/dist/lib/commands/databases.d.ts +732 -0
- package/dist/lib/commands/databases.d.ts.map +1 -0
- package/dist/lib/commands/databases.js +2196 -0
- package/dist/lib/commands/databases.js.map +1 -0
- package/dist/lib/commands/functions.d.ts +310 -0
- package/dist/lib/commands/functions.d.ts.map +1 -0
- package/dist/lib/commands/functions.js +1100 -0
- package/dist/lib/commands/functions.js.map +1 -0
- package/dist/lib/commands/generic.d.ts +17 -0
- package/dist/lib/commands/generic.d.ts.map +1 -0
- package/dist/lib/commands/generic.js +279 -0
- package/dist/lib/commands/generic.js.map +1 -0
- package/dist/lib/commands/graphql.d.ts +19 -0
- package/dist/lib/commands/graphql.d.ts.map +1 -0
- package/dist/lib/commands/graphql.js +77 -0
- package/dist/lib/commands/graphql.js.map +1 -0
- package/dist/lib/commands/health.d.ts +153 -0
- package/dist/lib/commands/health.d.ts.map +1 -0
- package/dist/lib/commands/health.js +464 -0
- package/dist/lib/commands/health.js.map +1 -0
- package/dist/lib/commands/init.d.ts +3 -0
- package/dist/lib/commands/init.d.ts.map +1 -0
- package/dist/lib/commands/init.js +518 -0
- package/dist/lib/commands/init.js.map +1 -0
- package/dist/lib/commands/locale.d.ts +53 -0
- package/dist/lib/commands/locale.d.ts.map +1 -0
- package/dist/lib/commands/locale.js +165 -0
- package/dist/lib/commands/locale.js.map +1 -0
- package/dist/lib/commands/messaging.d.ts +588 -0
- package/dist/lib/commands/messaging.d.ts.map +1 -0
- package/dist/lib/commands/messaging.js +2042 -0
- package/dist/lib/commands/messaging.js.map +1 -0
- package/dist/lib/commands/migrations.d.ts +150 -0
- package/dist/lib/commands/migrations.d.ts.map +1 -0
- package/dist/lib/commands/migrations.js +524 -0
- package/dist/lib/commands/migrations.js.map +1 -0
- package/dist/lib/commands/organizations.d.ts +11 -0
- package/dist/lib/commands/organizations.d.ts.map +1 -0
- package/dist/lib/commands/organizations.js +31 -0
- package/dist/lib/commands/organizations.js.map +1 -0
- package/dist/lib/commands/project.d.ts +53 -0
- package/dist/lib/commands/project.d.ts.map +1 -0
- package/dist/lib/commands/project.js +176 -0
- package/dist/lib/commands/project.js.map +1 -0
- package/dist/lib/commands/projects.d.ts +516 -0
- package/dist/lib/commands/projects.d.ts.map +1 -0
- package/dist/lib/commands/projects.js +1590 -0
- package/dist/lib/commands/projects.js.map +1 -0
- package/dist/lib/commands/proxy.d.ts +71 -0
- package/dist/lib/commands/proxy.d.ts.map +1 -0
- package/dist/lib/commands/proxy.js +240 -0
- package/dist/lib/commands/proxy.js.map +1 -0
- package/dist/lib/commands/pull.d.ts +8 -0
- package/dist/lib/commands/pull.d.ts.map +1 -0
- package/dist/lib/commands/pull.js +455 -0
- package/dist/lib/commands/pull.js.map +1 -0
- package/dist/lib/commands/push.d.ts +4 -0
- package/dist/lib/commands/push.d.ts.map +1 -0
- package/dist/lib/commands/push.js +2154 -0
- package/dist/lib/commands/push.js.map +1 -0
- package/dist/lib/commands/run.d.ts +3 -0
- package/dist/lib/commands/run.d.ts.map +1 -0
- package/dist/lib/commands/run.js +287 -0
- package/dist/lib/commands/run.js.map +1 -0
- package/dist/lib/commands/sites.d.ts +296 -0
- package/dist/lib/commands/sites.d.ts.map +1 -0
- package/dist/lib/commands/sites.js +1046 -0
- package/dist/lib/commands/sites.js.map +1 -0
- package/dist/lib/commands/storage.d.ts +170 -0
- package/dist/lib/commands/storage.d.ts.map +1 -0
- package/dist/lib/commands/storage.js +651 -0
- package/dist/lib/commands/storage.js.map +1 -0
- package/dist/lib/commands/tables-db.d.ts +728 -0
- package/dist/lib/commands/tables-db.d.ts.map +1 -0
- package/dist/lib/commands/tables-db.js +2198 -0
- package/dist/lib/commands/tables-db.js.map +1 -0
- package/dist/lib/commands/teams.d.ts +129 -0
- package/dist/lib/commands/teams.d.ts.map +1 -0
- package/dist/lib/commands/teams.js +403 -0
- package/dist/lib/commands/teams.js.map +1 -0
- package/dist/lib/commands/tokens.d.ts +48 -0
- package/dist/lib/commands/tokens.d.ts.map +1 -0
- package/dist/lib/commands/tokens.js +156 -0
- package/dist/lib/commands/tokens.js.map +1 -0
- package/dist/lib/commands/types.d.ts +3 -0
- package/dist/lib/commands/types.d.ts.map +1 -0
- package/dist/lib/commands/types.js +155 -0
- package/dist/lib/commands/types.js.map +1 -0
- package/dist/lib/commands/update.d.ts +3 -0
- package/dist/lib/commands/update.d.ts.map +1 -0
- package/dist/lib/commands/update.js +202 -0
- package/dist/lib/commands/update.js.map +1 -0
- package/dist/lib/commands/users.d.ts +382 -0
- package/dist/lib/commands/users.d.ts.map +1 -0
- package/dist/lib/commands/users.js +1195 -0
- package/dist/lib/commands/users.js.map +1 -0
- package/dist/lib/commands/vcs.d.ts +92 -0
- package/dist/lib/commands/vcs.d.ts.map +1 -0
- package/dist/lib/commands/vcs.js +276 -0
- package/dist/lib/commands/vcs.js.map +1 -0
- package/dist/lib/config.d.ts +118 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/{lib → dist/lib}/config.js +204 -325
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/emulation/docker.d.ts +15 -0
- package/dist/lib/emulation/docker.d.ts.map +1 -0
- package/dist/lib/emulation/docker.js +220 -0
- package/dist/lib/emulation/docker.js.map +1 -0
- package/dist/lib/emulation/utils.d.ts +29 -0
- package/dist/lib/emulation/utils.d.ts.map +1 -0
- package/dist/lib/emulation/utils.js +168 -0
- package/dist/lib/emulation/utils.js.map +1 -0
- package/dist/lib/exception.d.ts +8 -0
- package/dist/lib/exception.d.ts.map +1 -0
- package/dist/lib/exception.js +16 -0
- package/dist/lib/exception.js.map +1 -0
- package/dist/lib/id.d.ts +7 -0
- package/dist/lib/id.d.ts.map +1 -0
- package/dist/lib/id.js +32 -0
- package/dist/lib/id.js.map +1 -0
- package/dist/lib/paginate.d.ts +10 -0
- package/dist/lib/paginate.d.ts.map +1 -0
- package/{lib → dist/lib}/paginate.js +9 -15
- package/dist/lib/paginate.js.map +1 -0
- package/dist/lib/parser.d.ts +18 -0
- package/dist/lib/parser.d.ts.map +1 -0
- package/dist/lib/parser.js +237 -0
- package/dist/lib/parser.js.map +1 -0
- package/dist/lib/questions.d.ts +59 -0
- package/dist/lib/questions.d.ts.map +1 -0
- package/dist/lib/questions.js +995 -0
- package/dist/lib/questions.js.map +1 -0
- package/dist/lib/sdks.d.ts +4 -0
- package/dist/lib/sdks.d.ts.map +1 -0
- package/dist/lib/sdks.js +51 -0
- package/dist/lib/sdks.js.map +1 -0
- package/dist/lib/spinner.d.ts +28 -0
- package/dist/lib/spinner.d.ts.map +1 -0
- package/{lib → dist/lib}/spinner.js +34 -45
- package/dist/lib/spinner.js.map +1 -0
- package/dist/lib/type-generation/attribute.d.ts +17 -0
- package/dist/lib/type-generation/attribute.d.ts.map +1 -0
- package/dist/lib/type-generation/attribute.js +19 -0
- package/dist/lib/type-generation/attribute.js.map +1 -0
- package/dist/lib/type-generation/languages/csharp.d.ts +7 -0
- package/dist/lib/type-generation/languages/csharp.d.ts.map +1 -0
- package/dist/lib/type-generation/languages/csharp.js +180 -0
- package/dist/lib/type-generation/languages/csharp.js.map +1 -0
- package/dist/lib/type-generation/languages/dart.d.ts +8 -0
- package/dist/lib/type-generation/languages/dart.d.ts.map +1 -0
- package/dist/lib/type-generation/languages/dart.js +197 -0
- package/dist/lib/type-generation/languages/dart.js.map +1 -0
- package/dist/lib/type-generation/languages/java.d.ts +7 -0
- package/dist/lib/type-generation/languages/java.d.ts.map +1 -0
- package/dist/lib/type-generation/languages/java.js +140 -0
- package/dist/lib/type-generation/languages/java.js.map +1 -0
- package/dist/lib/type-generation/languages/javascript.d.ts +9 -0
- package/dist/lib/type-generation/languages/javascript.d.ts.map +1 -0
- package/dist/lib/type-generation/languages/javascript.js +108 -0
- package/dist/lib/type-generation/languages/javascript.js.map +1 -0
- package/dist/lib/type-generation/languages/kotlin.d.ts +7 -0
- package/dist/lib/type-generation/languages/kotlin.d.ts.map +1 -0
- package/dist/lib/type-generation/languages/kotlin.js +95 -0
- package/dist/lib/type-generation/languages/kotlin.js.map +1 -0
- package/dist/lib/type-generation/languages/language.d.ts +43 -0
- package/dist/lib/type-generation/languages/language.d.ts.map +1 -0
- package/dist/lib/type-generation/languages/language.js +82 -0
- package/dist/lib/type-generation/languages/language.js.map +1 -0
- package/dist/lib/type-generation/languages/php.d.ts +7 -0
- package/dist/lib/type-generation/languages/php.d.ts.map +1 -0
- package/dist/lib/type-generation/languages/php.js +116 -0
- package/dist/lib/type-generation/languages/php.js.map +1 -0
- package/dist/lib/type-generation/languages/swift.d.ts +7 -0
- package/dist/lib/type-generation/languages/swift.d.ts.map +1 -0
- package/dist/lib/type-generation/languages/swift.js +179 -0
- package/dist/lib/type-generation/languages/swift.js.map +1 -0
- package/dist/lib/type-generation/languages/typescript.d.ts +9 -0
- package/dist/lib/type-generation/languages/typescript.d.ts.map +1 -0
- package/dist/lib/type-generation/languages/typescript.js +112 -0
- package/dist/lib/type-generation/languages/typescript.js.map +1 -0
- package/dist/lib/types.d.ts +133 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +3 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utils.d.ts +15 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/{lib → dist/lib}/utils.js +74 -120
- package/dist/lib/utils.js.map +1 -0
- package/dist/lib/validations.d.ts +2 -0
- package/dist/lib/validations.d.ts.map +1 -0
- package/dist/lib/validations.js +20 -0
- package/dist/lib/validations.js.map +1 -0
- package/docs/examples/databases/upsert-document.md +1 -2
- package/index.ts +152 -0
- package/install.ps1 +2 -5
- package/install.sh +1 -2
- package/lib/client.ts +259 -0
- package/lib/commands/{account.js → account.ts} +408 -662
- package/lib/commands/console.ts +112 -0
- package/lib/commands/{databases.js → databases.ts} +818 -1136
- package/lib/commands/{functions.js → functions.ts} +381 -526
- package/lib/commands/{generic.js → generic.ts} +47 -39
- package/lib/commands/graphql.ts +110 -0
- package/lib/commands/{health.js → health.ts} +168 -284
- package/lib/commands/{init.js → init.ts} +68 -66
- package/lib/commands/{locale.js → locale.ts} +75 -121
- package/lib/commands/{messaging.js → messaging.ts} +699 -937
- package/lib/commands/{migrations.js → migrations.ts} +182 -258
- package/lib/commands/organizations.ts +46 -0
- package/lib/commands/{project.js → project.ts} +75 -111
- package/lib/commands/{projects.js → projects.ts} +587 -843
- package/lib/commands/{proxy.js → proxy.ts} +94 -140
- package/lib/commands/{pull.js → pull.ts} +54 -44
- package/lib/commands/{push.js → push.ts} +235 -191
- package/lib/commands/{run.js → run.ts} +61 -55
- package/lib/commands/{sites.js → sites.ts} +364 -504
- package/lib/commands/{storage.js → storage.ts} +216 -292
- package/lib/commands/{tables-db.js → tables-db.ts} +817 -1126
- package/lib/commands/{teams.js → teams.ts} +162 -236
- package/lib/commands/{tokens.js → tokens.ts} +70 -99
- package/lib/commands/{types.js → types.ts} +37 -35
- package/lib/commands/{update.js → update.ts} +25 -27
- package/lib/commands/{users.js → users.ts} +426 -644
- package/lib/commands/{vcs.js → vcs.ts} +118 -174
- package/lib/config.ts +854 -0
- package/lib/emulation/{docker.js → docker.ts} +39 -38
- package/lib/emulation/utils.ts +193 -0
- package/lib/exception.ts +20 -0
- package/lib/{id.js → id.ts} +5 -5
- package/lib/paginate.ts +63 -0
- package/lib/parser.ts +238 -0
- package/lib/{questions.js → questions.ts} +148 -156
- package/lib/sdks.ts +55 -0
- package/lib/spinner.ts +118 -0
- package/lib/type-generation/attribute.ts +17 -0
- package/lib/type-generation/languages/{csharp.js → csharp.ts} +59 -57
- package/lib/type-generation/languages/{dart.js → dart.ts} +91 -89
- package/lib/type-generation/languages/{java.js → java.ts} +58 -56
- package/lib/type-generation/languages/javascript.ts +111 -0
- package/lib/type-generation/languages/kotlin.ts +96 -0
- package/lib/type-generation/languages/language.ts +119 -0
- package/lib/type-generation/languages/{php.js → php.ts} +55 -53
- package/lib/type-generation/languages/{swift.js → swift.ts} +59 -57
- package/lib/type-generation/languages/typescript.ts +116 -0
- package/lib/types.ts +150 -0
- package/lib/utils.ts +322 -0
- package/lib/validations.ts +17 -0
- package/package.json +21 -12
- package/scoop/appwrite.config.json +3 -3
- package/tsconfig.json +30 -0
- package/index.js +0 -147
- package/lib/client.js +0 -254
- package/lib/commands/console.js +0 -127
- package/lib/commands/graphql.js +0 -126
- package/lib/commands/organizations.js +0 -48
- package/lib/emulation/utils.js +0 -186
- package/lib/exception.js +0 -9
- package/lib/parser.js +0 -250
- package/lib/sdks.js +0 -60
- package/lib/type-generation/attribute.js +0 -19
- package/lib/type-generation/languages/javascript.js +0 -111
- package/lib/type-generation/languages/kotlin.js +0 -94
- package/lib/type-generation/languages/language.js +0 -125
- package/lib/type-generation/languages/typescript.js +0 -116
- package/lib/validations.js +0 -17
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import Client from '../client';
|
|
4
|
+
import { sdkForConsole } from '../sdks';
|
|
5
|
+
import { globalConfig, localConfig } from '../config';
|
|
6
|
+
import { actionRunner, success, parseBool, commandDescriptions, error, parse, hint, log, drawTable, cliConfig } from '../parser';
|
|
7
|
+
import ID from '../id';
|
|
8
|
+
import { questionsLogin, questionsLogout, questionsListFactors, questionsMFAChallenge } from '../questions';
|
|
9
|
+
import { accountUpdateMFAChallenge, accountCreateMFAChallenge, accountGet, accountCreateEmailPasswordSession, accountDeleteSession } from './account';
|
|
10
10
|
|
|
11
11
|
const DEFAULT_ENDPOINT = 'https://cloud.appwrite.io/v1';
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
interface LoginCommandOptions {
|
|
14
|
+
email?: string;
|
|
15
|
+
password?: string;
|
|
16
|
+
endpoint?: string;
|
|
17
|
+
mfa?: string;
|
|
18
|
+
code?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const loginCommand = async ({ email, password, endpoint, mfa, code }: LoginCommandOptions): Promise<void> => {
|
|
14
22
|
const oldCurrent = globalConfig.getCurrentSession();
|
|
15
23
|
|
|
16
24
|
const configEndpoint = (endpoint ?? globalConfig.getEndpoint()) || DEFAULT_ENDPOINT;
|
|
@@ -67,8 +75,8 @@ const loginCommand = async ({ email, password, endpoint, mfa, code }) => {
|
|
|
67
75
|
sdk: client,
|
|
68
76
|
parseOutput: false
|
|
69
77
|
});
|
|
70
|
-
} catch (
|
|
71
|
-
if (
|
|
78
|
+
} catch (err: any) {
|
|
79
|
+
if (err.response === 'user_more_factors_required') {
|
|
72
80
|
const { factor } = mfa ? { factor: mfa } : await inquirer.prompt(questionsListFactors);
|
|
73
81
|
|
|
74
82
|
const challenge = await accountCreateMFAChallenge({
|
|
@@ -93,10 +101,10 @@ const loginCommand = async ({ email, password, endpoint, mfa, code }) => {
|
|
|
93
101
|
} else {
|
|
94
102
|
globalConfig.removeSession(id);
|
|
95
103
|
globalConfig.setCurrentSession(oldCurrent);
|
|
96
|
-
if (endpoint !== DEFAULT_ENDPOINT &&
|
|
104
|
+
if (endpoint !== DEFAULT_ENDPOINT && err.response === 'user_invalid_credentials') {
|
|
97
105
|
log('Use the --endpoint option for self-hosted instances')
|
|
98
106
|
}
|
|
99
|
-
throw
|
|
107
|
+
throw err;
|
|
100
108
|
}
|
|
101
109
|
}
|
|
102
110
|
|
|
@@ -104,7 +112,7 @@ const loginCommand = async ({ email, password, endpoint, mfa, code }) => {
|
|
|
104
112
|
hint("Next you can create or link to your project using 'appwrite init project'");
|
|
105
113
|
};
|
|
106
114
|
|
|
107
|
-
const whoami = new Command("whoami")
|
|
115
|
+
export const whoami = new Command("whoami")
|
|
108
116
|
.description(commandDescriptions['whoami'])
|
|
109
117
|
.action(actionRunner(async () => {
|
|
110
118
|
if (globalConfig.getEndpoint() === '' || globalConfig.getCookie() === '') {
|
|
@@ -144,13 +152,13 @@ const whoami = new Command("whoami")
|
|
|
144
152
|
drawTable(data)
|
|
145
153
|
}));
|
|
146
154
|
|
|
147
|
-
const register = new Command("register")
|
|
155
|
+
export const register = new Command("register")
|
|
148
156
|
.description(commandDescriptions['register'])
|
|
149
157
|
.action(actionRunner(async () => {
|
|
150
158
|
log('Visit https://cloud.appwrite.io/register to create an account')
|
|
151
159
|
}));
|
|
152
160
|
|
|
153
|
-
const login = new Command("login")
|
|
161
|
+
export const login = new Command("login")
|
|
154
162
|
.description(commandDescriptions['login'])
|
|
155
163
|
.option(`--email [email]`, `User email`)
|
|
156
164
|
.option(`--password [password]`, `User password`)
|
|
@@ -162,7 +170,7 @@ const login = new Command("login")
|
|
|
162
170
|
})
|
|
163
171
|
.action(actionRunner(loginCommand));
|
|
164
172
|
|
|
165
|
-
const deleteSession = async (accountId) => {
|
|
173
|
+
const deleteSession = async (accountId: string): Promise<void> => {
|
|
166
174
|
try {
|
|
167
175
|
let client = await sdkForConsole();
|
|
168
176
|
|
|
@@ -178,7 +186,7 @@ const deleteSession = async (accountId) => {
|
|
|
178
186
|
}
|
|
179
187
|
}
|
|
180
188
|
|
|
181
|
-
const logout = new Command("logout")
|
|
189
|
+
export const logout = new Command("logout")
|
|
182
190
|
.description(commandDescriptions['logout'])
|
|
183
191
|
.configureHelp({
|
|
184
192
|
helpWidth: process.stdout.columns || 80
|
|
@@ -210,8 +218,8 @@ const logout = new Command("logout")
|
|
|
210
218
|
|
|
211
219
|
const remainingSessions = globalConfig.getSessions();
|
|
212
220
|
|
|
213
|
-
if (remainingSessions.length > 0 && remainingSessions.filter(session => session.id === current).length !== 1) {
|
|
214
|
-
const accountId = remainingSessions
|
|
221
|
+
if (remainingSessions.length > 0 && remainingSessions.filter((session: any) => session.id === current).length !== 1) {
|
|
222
|
+
const accountId = remainingSessions[0].id;
|
|
215
223
|
globalConfig.setCurrentSession(accountId);
|
|
216
224
|
|
|
217
225
|
success(`Current account is ${accountId}`);
|
|
@@ -222,7 +230,16 @@ const logout = new Command("logout")
|
|
|
222
230
|
success("Logging out");
|
|
223
231
|
}));
|
|
224
232
|
|
|
225
|
-
|
|
233
|
+
interface ClientCommandOptions {
|
|
234
|
+
selfSigned?: boolean;
|
|
235
|
+
endpoint?: string;
|
|
236
|
+
projectId?: string;
|
|
237
|
+
key?: string;
|
|
238
|
+
debug?: boolean;
|
|
239
|
+
reset?: boolean;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export const client = new Command("client")
|
|
226
243
|
.description(commandDescriptions['client'])
|
|
227
244
|
.configureHelp({
|
|
228
245
|
helpWidth: process.stdout.columns || 80
|
|
@@ -233,7 +250,7 @@ const client = new Command("client")
|
|
|
233
250
|
.option("-k, --key <key>", "Set your Appwrite server's API key")
|
|
234
251
|
.option("-d, --debug", "Print CLI debug information")
|
|
235
252
|
.option("-r, --reset", "Reset the CLI configuration")
|
|
236
|
-
.action(actionRunner(async ({ selfSigned, endpoint, projectId, key, debug, reset }, command) => {
|
|
253
|
+
.action(actionRunner(async ({ selfSigned, endpoint, projectId, key, debug, reset }: ClientCommandOptions, command: Command) => {
|
|
237
254
|
if (selfSigned == undefined && endpoint == undefined && projectId == undefined && key == undefined && debug == undefined && reset == undefined) {
|
|
238
255
|
command.help()
|
|
239
256
|
}
|
|
@@ -257,12 +274,12 @@ const client = new Command("client")
|
|
|
257
274
|
throw new Error();
|
|
258
275
|
}
|
|
259
276
|
|
|
260
|
-
let
|
|
261
|
-
|
|
277
|
+
let clientInstance = new Client().setEndpoint(endpoint);
|
|
278
|
+
clientInstance.setProject('console');
|
|
262
279
|
if (selfSigned || globalConfig.getSelfSigned()) {
|
|
263
|
-
|
|
280
|
+
clientInstance.setSelfSigned(true);
|
|
264
281
|
}
|
|
265
|
-
let response = await
|
|
282
|
+
let response = await clientInstance.call('GET', '/health/version');
|
|
266
283
|
if (!response.version) {
|
|
267
284
|
throw new Error();
|
|
268
285
|
}
|
|
@@ -289,7 +306,7 @@ const client = new Command("client")
|
|
|
289
306
|
if (reset !== undefined) {
|
|
290
307
|
const sessions = globalConfig.getSessions();
|
|
291
308
|
|
|
292
|
-
for (let accountId of sessions.map(session => session.id)) {
|
|
309
|
+
for (let accountId of sessions.map((session: any) => session.id)) {
|
|
293
310
|
globalConfig.setCurrentSession(accountId);
|
|
294
311
|
await deleteSession(accountId);
|
|
295
312
|
}
|
|
@@ -298,7 +315,7 @@ const client = new Command("client")
|
|
|
298
315
|
success("Setting client")
|
|
299
316
|
}));
|
|
300
317
|
|
|
301
|
-
const migrate = async () => {
|
|
318
|
+
export const migrate = async (): Promise<void> => {
|
|
302
319
|
if (!globalConfig.has('endpoint') || !globalConfig.has('cookie')) {
|
|
303
320
|
return;
|
|
304
321
|
}
|
|
@@ -317,14 +334,5 @@ const migrate = async () => {
|
|
|
317
334
|
globalConfig.setCurrentSession(id);
|
|
318
335
|
globalConfig.delete('endpoint');
|
|
319
336
|
globalConfig.delete('cookie');
|
|
320
|
-
|
|
321
337
|
}
|
|
322
|
-
|
|
323
|
-
loginCommand,
|
|
324
|
-
whoami,
|
|
325
|
-
register,
|
|
326
|
-
login,
|
|
327
|
-
logout,
|
|
328
|
-
migrate,
|
|
329
|
-
client
|
|
330
|
-
};
|
|
338
|
+
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import fs = require('fs');
|
|
2
|
+
import pathLib = require('path');
|
|
3
|
+
import tar = require('tar');
|
|
4
|
+
import ignore = require('ignore');
|
|
5
|
+
import { promisify } from 'util';
|
|
6
|
+
import Client from '../client';
|
|
7
|
+
import { getAllFiles, showConsoleLink } from '../utils';
|
|
8
|
+
import { Command } from 'commander';
|
|
9
|
+
import { sdkForProject, sdkForConsole } from '../sdks';
|
|
10
|
+
import { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log, warn } from '../parser';
|
|
11
|
+
import { localConfig, globalConfig } from '../config';
|
|
12
|
+
import { File } from 'undici';
|
|
13
|
+
import { ReadableStream } from 'stream/web';
|
|
14
|
+
|
|
15
|
+
function convertReadStreamToReadableStream(readStream: fs.ReadStream): ReadableStream {
|
|
16
|
+
return new ReadableStream({
|
|
17
|
+
start(controller) {
|
|
18
|
+
readStream.on("data", (chunk: Buffer) => {
|
|
19
|
+
controller.enqueue(chunk);
|
|
20
|
+
});
|
|
21
|
+
readStream.on("end", () => {
|
|
22
|
+
controller.close();
|
|
23
|
+
});
|
|
24
|
+
readStream.on("error", (err: Error) => {
|
|
25
|
+
controller.error(err);
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
cancel() {
|
|
29
|
+
readStream.destroy();
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const graphql = new Command("graphql").description(commandDescriptions['graphql'] ?? '').configureHelp({
|
|
35
|
+
helpWidth: process.stdout.columns || 80
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
interface GraphqlQueryRequestParams {
|
|
39
|
+
query: object;
|
|
40
|
+
overrideForCli?: boolean;
|
|
41
|
+
parseOutput?: boolean;
|
|
42
|
+
sdk?: Client;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const graphqlQuery = async ({query,parseOutput = true, overrideForCli = false, sdk = undefined}: GraphqlQueryRequestParams): Promise<any> => {
|
|
46
|
+
let client = !sdk ? await sdkForProject() :
|
|
47
|
+
sdk;
|
|
48
|
+
let apiPath = '/graphql';
|
|
49
|
+
let payload = {};
|
|
50
|
+
if (typeof query !== 'undefined') {
|
|
51
|
+
payload['query'] = JSON.parse(query);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let response = undefined;
|
|
55
|
+
|
|
56
|
+
response = await client.call('post', apiPath, {
|
|
57
|
+
'x-sdk-graphql': 'true',
|
|
58
|
+
'content-type': 'application/json',
|
|
59
|
+
}, payload);
|
|
60
|
+
|
|
61
|
+
if (parseOutput) {
|
|
62
|
+
parse(response)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return response;
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
interface GraphqlMutationRequestParams {
|
|
69
|
+
query: object;
|
|
70
|
+
overrideForCli?: boolean;
|
|
71
|
+
parseOutput?: boolean;
|
|
72
|
+
sdk?: Client;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const graphqlMutation = async ({query,parseOutput = true, overrideForCli = false, sdk = undefined}: GraphqlMutationRequestParams): Promise<any> => {
|
|
76
|
+
let client = !sdk ? await sdkForProject() :
|
|
77
|
+
sdk;
|
|
78
|
+
let apiPath = '/graphql/mutation';
|
|
79
|
+
let payload = {};
|
|
80
|
+
if (typeof query !== 'undefined') {
|
|
81
|
+
payload['query'] = JSON.parse(query);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let response = undefined;
|
|
85
|
+
|
|
86
|
+
response = await client.call('post', apiPath, {
|
|
87
|
+
'x-sdk-graphql': 'true',
|
|
88
|
+
'content-type': 'application/json',
|
|
89
|
+
}, payload);
|
|
90
|
+
|
|
91
|
+
if (parseOutput) {
|
|
92
|
+
parse(response)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return response;
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
graphql
|
|
99
|
+
.command(`query`)
|
|
100
|
+
.description(`Execute a GraphQL mutation.`)
|
|
101
|
+
.requiredOption(`--query <query>`, `The query or queries to execute.`)
|
|
102
|
+
.action(actionRunner(graphqlQuery))
|
|
103
|
+
|
|
104
|
+
graphql
|
|
105
|
+
.command(`mutation`)
|
|
106
|
+
.description(`Execute a GraphQL mutation.`)
|
|
107
|
+
.requiredOption(`--query <query>`, `The query or queries to execute.`)
|
|
108
|
+
.action(actionRunner(graphqlMutation))
|
|
109
|
+
|
|
110
|
+
|