stepzen 0.0.0-experimental-94cb99b-20220608
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/LICENSE +21 -0
- package/README.md +229 -0
- package/bin/run +5 -0
- package/bin/run.cmd +3 -0
- package/lib/commands/deploy.d.ts +18 -0
- package/lib/commands/deploy.js +57 -0
- package/lib/commands/import.d.ts +105 -0
- package/lib/commands/import.js +368 -0
- package/lib/commands/init.d.ts +17 -0
- package/lib/commands/init.js +28 -0
- package/lib/commands/lint.d.ts +12 -0
- package/lib/commands/lint.js +27 -0
- package/lib/commands/list.d.ts +15 -0
- package/lib/commands/list.js +44 -0
- package/lib/commands/login.d.ts +14 -0
- package/lib/commands/login.js +74 -0
- package/lib/commands/logout.d.ts +9 -0
- package/lib/commands/logout.js +18 -0
- package/lib/commands/start.d.ts +19 -0
- package/lib/commands/start.js +101 -0
- package/lib/commands/transpile.d.ts +21 -0
- package/lib/commands/transpile.js +49 -0
- package/lib/commands/upload.d.ts +24 -0
- package/lib/commands/upload.js +73 -0
- package/lib/commands/validate.d.ts +14 -0
- package/lib/commands/validate.js +34 -0
- package/lib/commands/whoami.d.ts +14 -0
- package/lib/commands/whoami.js +70 -0
- package/lib/generate/curl2sdl.d.ts +55 -0
- package/lib/generate/curl2sdl.js +191 -0
- package/lib/generate/graphql2sdl.d.ts +23 -0
- package/lib/generate/graphql2sdl.js +64 -0
- package/lib/generate/helpers.d.ts +31 -0
- package/lib/generate/helpers.js +254 -0
- package/lib/generate/index.d.ts +11 -0
- package/lib/generate/index.js +102 -0
- package/lib/hooks/prerun/check-upgrade.d.ts +9 -0
- package/lib/hooks/prerun/check-upgrade.js +117 -0
- package/lib/hooks/prerun/ensure-config-file.d.ts +3 -0
- package/lib/hooks/prerun/ensure-config-file.js +28 -0
- package/lib/hooks/prerun/ensure-permissions.d.ts +3 -0
- package/lib/hooks/prerun/ensure-permissions.js +20 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +6 -0
- package/lib/shared/actions.d.ts +4 -0
- package/lib/shared/actions.js +47 -0
- package/lib/shared/configuration.d.ts +24 -0
- package/lib/shared/configuration.js +133 -0
- package/lib/shared/constants.d.ts +13 -0
- package/lib/shared/constants.js +33 -0
- package/lib/shared/curl-parser.d.ts +24 -0
- package/lib/shared/curl-parser.js +189 -0
- package/lib/shared/errors.d.ts +5 -0
- package/lib/shared/errors.js +18 -0
- package/lib/shared/header-params-parser.d.ts +7 -0
- package/lib/shared/header-params-parser.js +110 -0
- package/lib/shared/header.d.ts +32 -0
- package/lib/shared/header.js +44 -0
- package/lib/shared/moniker.d.ts +4 -0
- package/lib/shared/moniker.js +645 -0
- package/lib/shared/path-params-parser.d.ts +7 -0
- package/lib/shared/path-params-parser.js +83 -0
- package/lib/shared/stepzen-sdk.d.ts +110 -0
- package/lib/shared/stepzen-sdk.js +207 -0
- package/lib/shared/types.d.ts +44 -0
- package/lib/shared/types.js +3 -0
- package/lib/shared/utils.d.ts +19 -0
- package/lib/shared/utils.js +93 -0
- package/lib/shared/validation.d.ts +2 -0
- package/lib/shared/validation.js +41 -0
- package/lib/shared/workspace.d.ts +10 -0
- package/lib/shared/workspace.js +165 -0
- package/lib/shared/zen-command.d.ts +18 -0
- package/lib/shared/zen-command.js +115 -0
- package/lib/start/console.d.ts +11 -0
- package/lib/start/console.js +51 -0
- package/lib/start/deploy.d.ts +6 -0
- package/lib/start/deploy.js +114 -0
- package/lib/start/index.d.ts +2 -0
- package/lib/start/index.js +10 -0
- package/oclif.manifest.json +1 -0
- package/package.json +136 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const fs = require("fs-extra");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const inquirer = require("inquirer");
|
|
8
|
+
const command_1 = require("@oclif/command");
|
|
9
|
+
const errors_1 = require("@oclif/errors");
|
|
10
|
+
const transpiler_1 = require("@stepzen/transpiler");
|
|
11
|
+
const core_1 = require("@oclif/core");
|
|
12
|
+
const generate_1 = require("../generate");
|
|
13
|
+
const utils_1 = require("../shared/utils");
|
|
14
|
+
const helpers_1 = require("../generate/helpers");
|
|
15
|
+
const curl2sdl_1 = require("../generate/curl2sdl");
|
|
16
|
+
const curl_parser_1 = require("../shared/curl-parser");
|
|
17
|
+
const zen_command_1 = require("../shared/zen-command");
|
|
18
|
+
const graphql2sdl_1 = require("../generate/graphql2sdl");
|
|
19
|
+
const constants_1 = require("../shared/constants");
|
|
20
|
+
const path_params_parser_1 = require("../shared/path-params-parser");
|
|
21
|
+
const header_params_parser_1 = require("../shared/header-params-parser");
|
|
22
|
+
const header_1 = require("../shared/header");
|
|
23
|
+
class Import extends zen_command_1.default {
|
|
24
|
+
async run() {
|
|
25
|
+
const { args, argv, flags } = this.parseWorkaround();
|
|
26
|
+
// Get a list of schemas you're asking for
|
|
27
|
+
const schema = (0, helpers_1.getSchema)(args.schema);
|
|
28
|
+
// Get or create a StepZen workspace (possibly interactive)
|
|
29
|
+
const workspace = await this.ensureStepZenWorkspace({ directory: flags.dir });
|
|
30
|
+
// Define a sane onConflict behaviour (possibly interactive)
|
|
31
|
+
const onConflict = await this.ensureOnConflictBehavior(workspace, schema, flags);
|
|
32
|
+
this.warnAboutIgnoredFlags(schema, flags);
|
|
33
|
+
const headers = this.parseHeaderFlags(flags.header, flags['header-param']);
|
|
34
|
+
// Select an import execution flow:
|
|
35
|
+
// - v1 with `stepzen/engines` and cloud function
|
|
36
|
+
// - v2 with the graphqlize service
|
|
37
|
+
let result;
|
|
38
|
+
if (schema === 'curl') {
|
|
39
|
+
// LATER: offload the check to the graphqlize service or fetch
|
|
40
|
+
// the list of supported data sources and compare agains it.
|
|
41
|
+
this.log(chalk.yellow(`NOTE: ${chalk.bold('stepzen import curl')} is a ${chalk.bold('new')} feature.`));
|
|
42
|
+
this.log(chalk.yellow('If you have any issues, please check if they have been addressed ' +
|
|
43
|
+
'in the latest version, or reach out to StepZen on Discord: ' +
|
|
44
|
+
constants_1.STEPZEN_DISCORD_URL));
|
|
45
|
+
let curl2sdlOptions;
|
|
46
|
+
const fixedOptions = {
|
|
47
|
+
name: flags.name,
|
|
48
|
+
source: workspace.schema,
|
|
49
|
+
onConflict,
|
|
50
|
+
};
|
|
51
|
+
const editableOptions = {
|
|
52
|
+
queryName: flags['query-name'],
|
|
53
|
+
rootType: flags['query-type'],
|
|
54
|
+
typePrefix: flags.prefix,
|
|
55
|
+
pathParams: flags['path-params'],
|
|
56
|
+
};
|
|
57
|
+
if (argv.length === 1) {
|
|
58
|
+
// no parameters given: start an interactive prompt
|
|
59
|
+
console.log();
|
|
60
|
+
console.log('This command introspects the response of a REST endpoint and generates' +
|
|
61
|
+
' a GraphQL schema allowing you to access this endpoint through your ' +
|
|
62
|
+
'StepZen API. curl syntax is supported so that you copy and paste a ' +
|
|
63
|
+
'curl command instead of the URL.');
|
|
64
|
+
console.log();
|
|
65
|
+
const curlAnswers = await (0, curl2sdl_1.askCurlQuestions)(editableOptions);
|
|
66
|
+
curl2sdlOptions = Object.assign(Object.assign(Object.assign({}, fixedOptions), curlAnswers), {
|
|
67
|
+
// include boths headers passed via flags and headers entered interactively
|
|
68
|
+
headers: headers.concat(curlAnswers.curlArgs.headers) });
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
// run non-interative
|
|
72
|
+
const argsOrError = (0, curl_parser_1.parseCurlArgv)(argv);
|
|
73
|
+
if ('error' in argsOrError) {
|
|
74
|
+
throw new errors_1.CLIError(argsOrError.error);
|
|
75
|
+
}
|
|
76
|
+
const parsedPathParamsOrError = (0, path_params_parser_1.parsePathParamsPattern)(argsOrError.url, flags['path-params']);
|
|
77
|
+
if ('error' in parsedPathParamsOrError) {
|
|
78
|
+
throw new errors_1.CLIError(parsedPathParamsOrError.error);
|
|
79
|
+
}
|
|
80
|
+
const maybeDuplicateParamsMessage = (0, curl2sdl_1.makeDuplicateParamsMessage)(headers, parsedPathParamsOrError, argsOrError.url);
|
|
81
|
+
if (maybeDuplicateParamsMessage) {
|
|
82
|
+
throw new errors_1.CLIError(maybeDuplicateParamsMessage);
|
|
83
|
+
}
|
|
84
|
+
curl2sdlOptions = Object.assign(Object.assign(Object.assign({}, fixedOptions), editableOptions), { pathParams: parsedPathParamsOrError, headers: headers, curlArgs: argsOrError });
|
|
85
|
+
}
|
|
86
|
+
core_1.CliUx.ux.action.start('Starting');
|
|
87
|
+
const resultOrError = await (0, curl2sdl_1.curl2sdl)(curl2sdlOptions);
|
|
88
|
+
core_1.CliUx.ux.action.stop();
|
|
89
|
+
if ('error' in resultOrError) {
|
|
90
|
+
this.log('A problem occured while processing your import. ' +
|
|
91
|
+
'Please check that the given cURL command is valid.');
|
|
92
|
+
this.log(resultOrError.error);
|
|
93
|
+
this.exit();
|
|
94
|
+
}
|
|
95
|
+
result = resultOrError.outPath;
|
|
96
|
+
}
|
|
97
|
+
else if (schema === 'graphql') {
|
|
98
|
+
const editableOptions = {
|
|
99
|
+
typePrefix: flags.prefix,
|
|
100
|
+
headers: headers,
|
|
101
|
+
};
|
|
102
|
+
let answers;
|
|
103
|
+
if (argv.length === 1) {
|
|
104
|
+
// interactive
|
|
105
|
+
answers = await (0, graphql2sdl_1.askGraphQLQuestions)(editableOptions);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
// non-interactive
|
|
109
|
+
answers = Object.assign(Object.assign({}, editableOptions), { endpoint: argv[1] });
|
|
110
|
+
}
|
|
111
|
+
const fixedOptions = {
|
|
112
|
+
name: flags.name,
|
|
113
|
+
source: workspace.schema,
|
|
114
|
+
onConflict,
|
|
115
|
+
};
|
|
116
|
+
const options = Object.assign(Object.assign({}, fixedOptions), answers);
|
|
117
|
+
core_1.CliUx.ux.action.start('Starting');
|
|
118
|
+
const resultOrError = await (0, graphql2sdl_1.graphql2sdl)(options);
|
|
119
|
+
core_1.CliUx.ux.action.stop();
|
|
120
|
+
if ('error' in resultOrError) {
|
|
121
|
+
this.log('A problem occured while processing your import.');
|
|
122
|
+
this.log(resultOrError.error);
|
|
123
|
+
this.exit();
|
|
124
|
+
}
|
|
125
|
+
result = resultOrError.outPath;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
// Map flag names to the properties defined for sql engines in:
|
|
129
|
+
// https://github.com/steprz/generator-engines/blob/main/generator/src/shared/sql.ts
|
|
130
|
+
// If/when the number of property-to-answer mappings increase, create a dictionary
|
|
131
|
+
// { schema: { flag: field } } and build the below map based on this (a
|
|
132
|
+
// dictionary also enables a generic solution to the warning about ignored flags).
|
|
133
|
+
let preAnswered = {};
|
|
134
|
+
if (schema === 'mysql' || schema === 'postgresql') {
|
|
135
|
+
const asKeyValue = (key, flag) => flag === undefined ? {} : { [key]: flag };
|
|
136
|
+
preAnswered = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, asKeyValue('host', flags['db-host'])), asKeyValue('user', flags['db-user'])), asKeyValue('password', flags['db-password'])), asKeyValue('database', flags['db-database'])), asKeyValue('schema', flags['db-schema']));
|
|
137
|
+
}
|
|
138
|
+
// Let's go!
|
|
139
|
+
result = await (0, generate_1.default)({
|
|
140
|
+
schema,
|
|
141
|
+
name: flags.name,
|
|
142
|
+
onConflict,
|
|
143
|
+
source: workspace.schema,
|
|
144
|
+
preAnswered,
|
|
145
|
+
});
|
|
146
|
+
// Validate
|
|
147
|
+
await (0, transpiler_1.validate)(result, {
|
|
148
|
+
extensions: await (0, utils_1.getStepZenExtensions)(),
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
// Housekeeping
|
|
152
|
+
fs.copySync(result, workspace.schema);
|
|
153
|
+
fs.removeSync(result);
|
|
154
|
+
// Nice message
|
|
155
|
+
this.log(chalk.green(`Successfully imported schema ${chalk.bold(schema)} from StepZen`));
|
|
156
|
+
}
|
|
157
|
+
async ensureOnConflictBehavior(workspace, schema, flags) {
|
|
158
|
+
const featureFlag = process.env.STEPZEN_DETECT_NAME_CONFLICTS;
|
|
159
|
+
if (featureFlag === undefined || featureFlag.toLowerCase() === 'false') {
|
|
160
|
+
return 'append';
|
|
161
|
+
}
|
|
162
|
+
const name = flags.name || schema;
|
|
163
|
+
const hasConflict = fs.existsSync(path.join(workspace.schema, name));
|
|
164
|
+
if (!hasConflict) {
|
|
165
|
+
return 'append';
|
|
166
|
+
}
|
|
167
|
+
// No `--name` is given (i.e. naming is automatic)
|
|
168
|
+
// Using the default name is going to lead to a conflict, and it should
|
|
169
|
+
// be resolved by inventing a new unique name for the new schema.
|
|
170
|
+
if (!flags.name) {
|
|
171
|
+
return 'append';
|
|
172
|
+
}
|
|
173
|
+
// `--name` is given and (i.e. naming is namaged by the user)
|
|
174
|
+
// There is a naming conflict.
|
|
175
|
+
// The user has explicitly asked to overwrite the existing schema.
|
|
176
|
+
if (flags.overwrite) {
|
|
177
|
+
return 'overwrite';
|
|
178
|
+
}
|
|
179
|
+
// `--name` is given and (i.e. naming is namaged by the user)
|
|
180
|
+
// There is a naming conflict.
|
|
181
|
+
// The user has NOT given an explicit permission to overwrite the existing
|
|
182
|
+
// schema.
|
|
183
|
+
// In an interactive mode the CLI asks them for a confirmation.
|
|
184
|
+
// In a non-interactive mode the CLI throws an error.
|
|
185
|
+
if (flags['non-interactive']) {
|
|
186
|
+
throw new errors_1.CLIError(`A schema named ${chalk.bold(flags.name)} already exists in this workspace. Add an ${chalk.bold('--overwrite')} flag to overwrite it.`);
|
|
187
|
+
}
|
|
188
|
+
this.log(`A schema named ${chalk.bold(flags.name)} already exists in this workspace. Would you like to overwrite it?`);
|
|
189
|
+
const answers = await inquirer.prompt([
|
|
190
|
+
{
|
|
191
|
+
name: 'overwrite',
|
|
192
|
+
type: 'confirm',
|
|
193
|
+
default: false,
|
|
194
|
+
message: `Overwrite ${flags.name}?`,
|
|
195
|
+
},
|
|
196
|
+
]);
|
|
197
|
+
if (answers.overwrite) {
|
|
198
|
+
return 'overwrite';
|
|
199
|
+
}
|
|
200
|
+
this.exit();
|
|
201
|
+
}
|
|
202
|
+
// notify the user about any ignored flags
|
|
203
|
+
warnAboutIgnoredFlags(schema, usedFlags) {
|
|
204
|
+
Import.flagsForSchemas.forEach(({ flags, schemas }) => {
|
|
205
|
+
if (!schemas.includes(schema)) {
|
|
206
|
+
Object.keys(flags).forEach(flag => {
|
|
207
|
+
if (Object.prototype.hasOwnProperty.call(usedFlags, flag)) {
|
|
208
|
+
this.log(chalk.gray(`The ${chalk.bold(`--${flag}`)} flag only applies when importing ${schemas
|
|
209
|
+
.map(schema => chalk.bold(schema))
|
|
210
|
+
.join(', ')}. It will be ignored now.`));
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
// Correct the value for the 'header-param' flag to work around the oclif's
|
|
217
|
+
// parser issue with multi-value flags: https://github.com/oclif/oclif/issues/261
|
|
218
|
+
parseWorkaround() {
|
|
219
|
+
const argv = this.argv;
|
|
220
|
+
const parsed = this.parse(Import, argv);
|
|
221
|
+
const fixFlag = (flag) => {
|
|
222
|
+
if (parsed.flags[flag]) {
|
|
223
|
+
// Every ['--flag', value] pair in the argv array should match
|
|
224
|
+
// only one value in the flag's value list.
|
|
225
|
+
const matchedIndices = new Set();
|
|
226
|
+
// For each value in the flag's value list, find the original
|
|
227
|
+
// ['--flag', value] pair in the argv array.
|
|
228
|
+
for (let i = 0; i < parsed.flags[flag].length; i++) {
|
|
229
|
+
const value = parsed.flags[flag][i];
|
|
230
|
+
const flagIdx = argv.findIndex((arg, idx) => {
|
|
231
|
+
const spaceDelimMatch = (arg === `--${flag}` ||
|
|
232
|
+
(Import.flags[flag].char &&
|
|
233
|
+
arg === `-${Import.flags[flag].char}`)) &&
|
|
234
|
+
idx < argv.length &&
|
|
235
|
+
argv[idx + 1] === value;
|
|
236
|
+
const eqlDelimMatch = arg === `--${flag}=${value}`;
|
|
237
|
+
return ((spaceDelimMatch || eqlDelimMatch) && !matchedIndices.has(idx));
|
|
238
|
+
});
|
|
239
|
+
// If not found, that means the given value was associated with the
|
|
240
|
+
// `flag` incorrectly. In that case, it's moved from `flags` to `argv` in
|
|
241
|
+
// the parsed output.
|
|
242
|
+
if (flagIdx === -1) {
|
|
243
|
+
parsed.flags[flag].splice(i, 1);
|
|
244
|
+
i -= 1; // compensate for the .splice() call above
|
|
245
|
+
parsed.argv.push(value);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
matchedIndices.add(flagIdx);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
fixFlag('header');
|
|
254
|
+
fixFlag('header-param');
|
|
255
|
+
return parsed;
|
|
256
|
+
}
|
|
257
|
+
parseHeaderFlags(headerFlagValues, headerParamFlagValues) {
|
|
258
|
+
const headers = [];
|
|
259
|
+
if (headerFlagValues) {
|
|
260
|
+
headerFlagValues.forEach(value => {
|
|
261
|
+
const headerOrError = (0, header_1.parseHeader)(value);
|
|
262
|
+
if (headerOrError && 'error' in headerOrError) {
|
|
263
|
+
throw new errors_1.CLIError(headerOrError.error);
|
|
264
|
+
}
|
|
265
|
+
// A `null` from parseCurlHeaderString() means a header should NOT be
|
|
266
|
+
// sent. This is not supported by zenserv / the introspection service
|
|
267
|
+
// so the CLI simply omits such headers
|
|
268
|
+
if (headerOrError) {
|
|
269
|
+
headers.push(headerOrError); // header
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
const headersOrError = (0, header_params_parser_1.makeHeaders)(headers, headerParamFlagValues);
|
|
274
|
+
if ('error' in headersOrError) {
|
|
275
|
+
throw new errors_1.CLIError(headersOrError.error);
|
|
276
|
+
}
|
|
277
|
+
return headersOrError;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
exports.default = Import;
|
|
281
|
+
Import.description = 'import a schema for an external data source or a API endpoint to your GraphQL API';
|
|
282
|
+
Import.commonIntrospectionFlags = {
|
|
283
|
+
prefix: command_1.flags.string({
|
|
284
|
+
description: '[curl, graphql] prefix to add every type in the generated schema.',
|
|
285
|
+
}),
|
|
286
|
+
header: command_1.flags.string({
|
|
287
|
+
char: 'H',
|
|
288
|
+
description: `[curl, graphql] specifies a request header to pass` +
|
|
289
|
+
`\n` +
|
|
290
|
+
`\nExample:` +
|
|
291
|
+
`\nstepzen import curl https://example.com/api/customers \\` +
|
|
292
|
+
`\n\t-H ${chalk.bold('"Authorization: apikey SecretAPIKeyValue"')}`,
|
|
293
|
+
multiple: true,
|
|
294
|
+
}),
|
|
295
|
+
'header-param': command_1.flags.string({
|
|
296
|
+
description: `[curl, graphql] specifies a parameter in a header value.` +
|
|
297
|
+
` Can be formed by taking a ${chalk.bold('-H, --header')} flag and replacing the` +
|
|
298
|
+
` variable part of the header value with a ${chalk.bold('$paramName')} placeholder. Repeat this flag once for each header with a parameter.` +
|
|
299
|
+
`\n` +
|
|
300
|
+
`\nExample:` +
|
|
301
|
+
`\nstepzen import curl https://example.com/api/customers \\` +
|
|
302
|
+
`\n\t-H "Authorization: apikey SecretAPIKeyValue" \\` +
|
|
303
|
+
`\n\t--header-param 'Authorization: apikey ${chalk.bold('$apikey')}'`,
|
|
304
|
+
multiple: true,
|
|
305
|
+
}),
|
|
306
|
+
};
|
|
307
|
+
Import.curlFlags = {
|
|
308
|
+
'query-name': command_1.flags.string({
|
|
309
|
+
description: '[curl] property name to add to the Query type as a way to' +
|
|
310
|
+
' access the imported cURL endpoint.',
|
|
311
|
+
}),
|
|
312
|
+
'query-type': command_1.flags.string({
|
|
313
|
+
description: '[curl] name for the type returned by the cURL endpoint in the ' +
|
|
314
|
+
`generated schema. The name specified by ${chalk.bold('--query-type')} is not prefixed by ${chalk.bold('--prefix')} if both flags are present.`,
|
|
315
|
+
}),
|
|
316
|
+
'path-params': command_1.flags.string({
|
|
317
|
+
description: `[curl] specifies path parameters in the URL path.` +
|
|
318
|
+
` Can be formed by taking the original path and replacing the` +
|
|
319
|
+
` variable segments with ${chalk.bold('$paramName')} placeholders.` +
|
|
320
|
+
`\n` +
|
|
321
|
+
`\nExample:` +
|
|
322
|
+
`\nstepzen import curl https://example.com/users/jane/posts/12` +
|
|
323
|
+
` --path-params` +
|
|
324
|
+
` '/users/${chalk.bold('$userId')}/posts/${chalk.bold('$postId')}'`,
|
|
325
|
+
}),
|
|
326
|
+
};
|
|
327
|
+
Import.sqlFlags = {
|
|
328
|
+
'db-host': command_1.flags.string({
|
|
329
|
+
description: '[mysql, postgresql] database host',
|
|
330
|
+
}),
|
|
331
|
+
'db-user': command_1.flags.string({
|
|
332
|
+
description: '[mysql, postgresql] database user name',
|
|
333
|
+
}),
|
|
334
|
+
'db-password': command_1.flags.string({
|
|
335
|
+
description: '[mysql, postgresql] database password',
|
|
336
|
+
}),
|
|
337
|
+
'db-database': command_1.flags.string({
|
|
338
|
+
description: '[mysql, postgresql] name of database to import',
|
|
339
|
+
}),
|
|
340
|
+
};
|
|
341
|
+
Import.postgresqlFlags = {
|
|
342
|
+
'db-schema': command_1.flags.string({
|
|
343
|
+
description: '[postgresql] database schema',
|
|
344
|
+
}),
|
|
345
|
+
};
|
|
346
|
+
Import.flagsForSchemas = [
|
|
347
|
+
{ flags: Import.commonIntrospectionFlags, schemas: ['curl', 'graphql'] },
|
|
348
|
+
{ flags: Import.curlFlags, schemas: ['curl'] },
|
|
349
|
+
{ flags: Import.sqlFlags, schemas: ['mysql', 'postgresql'] },
|
|
350
|
+
{ flags: Import.postgresqlFlags, schemas: ['postgresql'] },
|
|
351
|
+
];
|
|
352
|
+
Import.flags = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, zen_command_1.default.flags), { dir: command_1.flags.string({ description: 'working directory' }), help: command_1.flags.help({ char: 'h' }), silent: command_1.flags.boolean({ hidden: true }), name: command_1.flags.string({
|
|
353
|
+
description: 'Subfolder inside the workspace folder to save the imported' +
|
|
354
|
+
' schema files to. Defaults to the name of the imported schema.',
|
|
355
|
+
}), overwrite: command_1.flags.boolean({
|
|
356
|
+
description: 'Overwrite any existing schema with the same name. Cannot be used' +
|
|
357
|
+
' without also providing a --name flag.',
|
|
358
|
+
dependsOn: ['name'],
|
|
359
|
+
hidden: true,
|
|
360
|
+
}) }), Import.commonIntrospectionFlags), Import.curlFlags), Import.sqlFlags), Import.postgresqlFlags);
|
|
361
|
+
Import.args = [
|
|
362
|
+
{
|
|
363
|
+
name: 'schema',
|
|
364
|
+
required: true,
|
|
365
|
+
},
|
|
366
|
+
];
|
|
367
|
+
// allow any number of arguments to support `import curl [url] [curl flags and options]`
|
|
368
|
+
Import.strict = false;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { flags } from '@oclif/command';
|
|
2
|
+
import ZenCommand from '../shared/zen-command';
|
|
3
|
+
export default class Init extends ZenCommand {
|
|
4
|
+
static description: string;
|
|
5
|
+
static hidden: boolean;
|
|
6
|
+
static flags: {
|
|
7
|
+
endpoint: flags.IOptionFlag<string | undefined>;
|
|
8
|
+
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
9
|
+
yes: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
10
|
+
'non-interactive': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
11
|
+
};
|
|
12
|
+
static args: {
|
|
13
|
+
hidden: boolean;
|
|
14
|
+
name: string;
|
|
15
|
+
}[];
|
|
16
|
+
run(): Promise<import("../shared/types").Workspace>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const command_1 = require("@oclif/command");
|
|
5
|
+
const workspace_1 = require("../shared/workspace");
|
|
6
|
+
const zen_command_1 = require("../shared/zen-command");
|
|
7
|
+
class Init extends zen_command_1.default {
|
|
8
|
+
async run() {
|
|
9
|
+
const { args, flags } = this.parse(Init);
|
|
10
|
+
const created = await (0, workspace_1.initWorkspace)({
|
|
11
|
+
directory: args.directory,
|
|
12
|
+
endpoint: flags.endpoint,
|
|
13
|
+
yes: flags.yes,
|
|
14
|
+
});
|
|
15
|
+
this.log(`Created a StepZen workspace in ${created.directory}`);
|
|
16
|
+
return created;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.default = Init;
|
|
20
|
+
Init.description = 'stepzen init';
|
|
21
|
+
Init.hidden = true;
|
|
22
|
+
Init.flags = Object.assign(Object.assign({}, zen_command_1.default.flags), { endpoint: command_1.flags.string({ hidden: true }), help: command_1.flags.help({ char: 'h' }), yes: command_1.flags.boolean({ default: false, hidden: true }) });
|
|
23
|
+
Init.args = [
|
|
24
|
+
{
|
|
25
|
+
hidden: true,
|
|
26
|
+
name: 'directory',
|
|
27
|
+
},
|
|
28
|
+
];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { flags } from '@oclif/command';
|
|
2
|
+
import ZenCommand from '../shared/zen-command';
|
|
3
|
+
export default class Init extends ZenCommand {
|
|
4
|
+
static description: string;
|
|
5
|
+
static hidden: boolean;
|
|
6
|
+
static flags: {
|
|
7
|
+
dir: flags.IOptionFlag<string | undefined>;
|
|
8
|
+
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
9
|
+
'non-interactive': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
10
|
+
};
|
|
11
|
+
run(): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const command_1 = require("@oclif/command");
|
|
5
|
+
const transpiler_1 = require("@stepzen/transpiler");
|
|
6
|
+
const utils_1 = require("../shared/utils");
|
|
7
|
+
const zen_command_1 = require("../shared/zen-command");
|
|
8
|
+
class Init extends zen_command_1.default {
|
|
9
|
+
async run() {
|
|
10
|
+
const { flags } = this.parse(Init);
|
|
11
|
+
// Get the correct directory
|
|
12
|
+
const directory = (0, utils_1.getDirectory)(flags.dir);
|
|
13
|
+
this.log(directory);
|
|
14
|
+
// Take over console.log
|
|
15
|
+
console.log = (msg) => {
|
|
16
|
+
let formatted = msg;
|
|
17
|
+
formatted = formatted.replace(/ +/g, ' ');
|
|
18
|
+
this.log(formatted);
|
|
19
|
+
};
|
|
20
|
+
// Lint
|
|
21
|
+
await (0, transpiler_1.lint)(directory);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.default = Init;
|
|
25
|
+
Init.description = 'StepZen lint';
|
|
26
|
+
Init.hidden = true;
|
|
27
|
+
Init.flags = Object.assign(Object.assign({}, zen_command_1.default.flags), { dir: command_1.flags.string({ hidden: true }), help: command_1.flags.help({ char: 'h' }) });
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import ZenCommand from '../shared/zen-command';
|
|
2
|
+
export default class List extends ZenCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
6
|
+
'non-interactive': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
7
|
+
};
|
|
8
|
+
static args: {
|
|
9
|
+
name: string;
|
|
10
|
+
required: boolean;
|
|
11
|
+
description: string;
|
|
12
|
+
options: string[];
|
|
13
|
+
}[];
|
|
14
|
+
run(): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
// This file contains the code for the `stepzen list` command.
|
|
5
|
+
// The list command is used to retrieve the name and other metadata
|
|
6
|
+
// of resources stored within a stepzen account.
|
|
7
|
+
// You can use list to retrieve configurationsets and schemas.
|
|
8
|
+
const command_1 = require("@oclif/command");
|
|
9
|
+
const errors_1 = require("@oclif/errors");
|
|
10
|
+
const actions_1 = require("../shared/actions");
|
|
11
|
+
const zen_command_1 = require("../shared/zen-command");
|
|
12
|
+
class List extends zen_command_1.default {
|
|
13
|
+
async run() {
|
|
14
|
+
var _a;
|
|
15
|
+
const { args } = this.parse(List);
|
|
16
|
+
await this.ensureStepZenAccount();
|
|
17
|
+
const response = await (0, actions_1.list)(args.type);
|
|
18
|
+
if (response.success) {
|
|
19
|
+
if (((_a = response.results) === null || _a === void 0 ? void 0 : _a.length) === 0) {
|
|
20
|
+
// Success, but no results
|
|
21
|
+
this.log('No results.');
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
// Success. The server returns a list of results.
|
|
25
|
+
this.log(`${JSON.stringify(response.results, null, ' ')}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
// Error. Exit, and output the server's error response
|
|
30
|
+
throw new errors_1.CLIError(JSON.stringify(response.errors) || 'An error occurred.');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.default = List;
|
|
35
|
+
List.description = 'list your items';
|
|
36
|
+
List.flags = Object.assign(Object.assign({}, zen_command_1.default.flags), { help: command_1.flags.help({ char: 'h' }) });
|
|
37
|
+
List.args = [
|
|
38
|
+
{
|
|
39
|
+
name: 'type',
|
|
40
|
+
required: true,
|
|
41
|
+
description: 'type',
|
|
42
|
+
options: ['configurationsets', 'schemas'],
|
|
43
|
+
},
|
|
44
|
+
];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { flags } from '@oclif/command';
|
|
2
|
+
import ZenCommand from '../shared/zen-command';
|
|
3
|
+
export default class Login extends ZenCommand {
|
|
4
|
+
static description: string;
|
|
5
|
+
static flags: {
|
|
6
|
+
account: flags.IOptionFlag<string | undefined>;
|
|
7
|
+
adminkey: flags.IOptionFlag<string | undefined>;
|
|
8
|
+
public: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
9
|
+
config: flags.IOptionFlag<string | undefined>;
|
|
10
|
+
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
11
|
+
'non-interactive': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
12
|
+
};
|
|
13
|
+
run(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
// This file contains the code for the `stepzen login` command.
|
|
5
|
+
// Stepzen login checks that credentials presented are good and
|
|
6
|
+
// subsequently changes the identity of the logged in account.
|
|
7
|
+
const command_1 = require("@oclif/command");
|
|
8
|
+
const core_1 = require("@oclif/core");
|
|
9
|
+
const chalk = require("chalk");
|
|
10
|
+
const configuration_1 = require("../shared/configuration");
|
|
11
|
+
const stepzen_sdk_1 = require("../shared/stepzen-sdk");
|
|
12
|
+
const zen_command_1 = require("../shared/zen-command");
|
|
13
|
+
class Login extends zen_command_1.default {
|
|
14
|
+
async run() {
|
|
15
|
+
const { flags } = this.parse(Login);
|
|
16
|
+
let configuration;
|
|
17
|
+
if (flags.public) {
|
|
18
|
+
const { uuid } = await (0, configuration_1.readConfiguration)();
|
|
19
|
+
configuration = await stepzen_sdk_1.default.createAnonymousAccount(uuid);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
let account;
|
|
23
|
+
let adminkey;
|
|
24
|
+
// If the --config flag is provided, try and log in using the details in the file
|
|
25
|
+
if (flags.config) {
|
|
26
|
+
const config = await (0, configuration_1.importConfiguration)(flags.config);
|
|
27
|
+
account = config.account;
|
|
28
|
+
adminkey = config.adminkey;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
// Check if the --account flag is provided, and if not prompt the user for an account name
|
|
32
|
+
if (flags.account) {
|
|
33
|
+
account = flags.account;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
account = await core_1.CliUx.ux.prompt('What is your account name?');
|
|
37
|
+
}
|
|
38
|
+
// Check if the --adminkey flag is provided, and if not prompt the user for an admin key.
|
|
39
|
+
if (flags.adminkey === undefined) {
|
|
40
|
+
adminkey = await core_1.CliUx.ux.prompt('What is your admin key?', {
|
|
41
|
+
required: false,
|
|
42
|
+
type: 'hide',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
adminkey = flags.adminkey;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
configuration = await stepzen_sdk_1.default.login(adminkey, account);
|
|
50
|
+
}
|
|
51
|
+
// Change the default account.
|
|
52
|
+
(0, configuration_1.writeCredentialsToConfigFile)(configuration);
|
|
53
|
+
this.log(`You have successfully logged in as ${chalk.bold(configuration.account)}.`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.default = Login;
|
|
57
|
+
Login.description = 'log in to StepZen';
|
|
58
|
+
Login.flags = Object.assign(Object.assign({}, zen_command_1.default.flags), { account: command_1.flags.string({
|
|
59
|
+
char: 'a',
|
|
60
|
+
exclusive: ['config', 'public'],
|
|
61
|
+
hidden: true,
|
|
62
|
+
}), adminkey: command_1.flags.string({
|
|
63
|
+
char: 'k',
|
|
64
|
+
exclusive: ['config', 'public'],
|
|
65
|
+
hidden: true,
|
|
66
|
+
}), public: command_1.flags.boolean({
|
|
67
|
+
description: 'Create a public anonymous StepZen account and use it. This is handy' +
|
|
68
|
+
' for trying StepZen out, but it not suitable for handling private' +
|
|
69
|
+
' data as all endpoints created with a public account will be public.',
|
|
70
|
+
exclusive: ['config', 'account', 'adminkey'],
|
|
71
|
+
}), config: command_1.flags.string({
|
|
72
|
+
exclusive: ['account', 'adminkey', 'public'],
|
|
73
|
+
hidden: true,
|
|
74
|
+
}), help: command_1.flags.help({ char: 'h' }) });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import ZenCommand from '../shared/zen-command';
|
|
2
|
+
export default class Logout extends ZenCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
6
|
+
'non-interactive': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
7
|
+
};
|
|
8
|
+
run(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
// This file contains the code for the `stepzen logout` command.
|
|
5
|
+
// The logout command removes the entry in the login file.
|
|
6
|
+
const command_1 = require("@oclif/command");
|
|
7
|
+
const configuration_1 = require("../shared/configuration");
|
|
8
|
+
const zen_command_1 = require("../shared/zen-command");
|
|
9
|
+
class Logout extends zen_command_1.default {
|
|
10
|
+
async run() {
|
|
11
|
+
// Remove the configuration from the login file.
|
|
12
|
+
(0, configuration_1.removeCredentialsFromConfigFile)();
|
|
13
|
+
this.log('You have been logged out.');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.default = Logout;
|
|
17
|
+
Logout.description = 'log out of StepZen';
|
|
18
|
+
Logout.flags = Object.assign(Object.assign({}, zen_command_1.default.flags), { help: command_1.flags.help({ char: 'h' }) });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { flags } from '@oclif/command';
|
|
2
|
+
import ZenCommand from '../shared/zen-command';
|
|
3
|
+
export default class Start extends ZenCommand {
|
|
4
|
+
static description: string;
|
|
5
|
+
static flags: {
|
|
6
|
+
dir: flags.IOptionFlag<string | undefined>;
|
|
7
|
+
endpoint: flags.IOptionFlag<string | undefined>;
|
|
8
|
+
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
9
|
+
'no-console': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
10
|
+
'no-dashboard': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
11
|
+
'no-init': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
12
|
+
'no-validate': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
13
|
+
'no-watcher': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
14
|
+
port: import("@oclif/parser/lib/flags").IOptionFlag<number>;
|
|
15
|
+
'non-interactive': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
16
|
+
};
|
|
17
|
+
static args: never[];
|
|
18
|
+
run(): Promise<void>;
|
|
19
|
+
}
|