stepzen 0.9.38 → 0.9.39-beta.2
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/README.md +11 -4
- package/lib/commands/import.d.ts +1 -0
- package/lib/commands/import.js +80 -15
- package/lib/commands/login.js +6 -6
- package/lib/commands/whoami.js +23 -15
- package/lib/generate/curl2sdl.d.ts +16 -0
- package/lib/generate/curl2sdl.js +137 -0
- package/lib/generate/index.d.ts +1 -1
- package/lib/generate/index.js +7 -5
- package/lib/shared/actions.d.ts +1 -1
- package/lib/shared/actions.js +12 -4
- package/lib/shared/configuration.d.ts +0 -1
- package/lib/shared/configuration.js +3 -25
- package/lib/shared/constants.d.ts +1 -2
- package/lib/shared/constants.js +5 -5
- package/lib/shared/stepzen-sdk.d.ts +25 -0
- package/lib/shared/stepzen-sdk.js +7 -0
- package/lib/shared/utils.d.ts +16 -0
- package/lib/shared/utils.js +54 -12
- package/lib/start/deploy.js +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ $ npm install -g stepzen
|
|
|
29
29
|
$ stepzen COMMAND
|
|
30
30
|
running command...
|
|
31
31
|
$ stepzen (-v|--version|version)
|
|
32
|
-
stepzen/0.9.
|
|
32
|
+
stepzen/0.9.39-beta.2 darwin-x64 node-v14.18.3
|
|
33
33
|
$ stepzen --help [COMMAND]
|
|
34
34
|
USAGE
|
|
35
35
|
$ stepzen COMMAND
|
|
@@ -80,7 +80,7 @@ OPTIONS
|
|
|
80
80
|
-n, --nested-commands Include all nested commands in the output.
|
|
81
81
|
```
|
|
82
82
|
|
|
83
|
-
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.1.
|
|
83
|
+
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.1.11/src/commands/help.ts)_
|
|
84
84
|
|
|
85
85
|
## `stepzen import SCHEMAS`
|
|
86
86
|
|
|
@@ -91,8 +91,15 @@ USAGE
|
|
|
91
91
|
$ stepzen import SCHEMAS
|
|
92
92
|
|
|
93
93
|
OPTIONS
|
|
94
|
-
-h, --help
|
|
95
|
-
--dir=dir
|
|
94
|
+
-h, --help show CLI help
|
|
95
|
+
--dir=dir working directory
|
|
96
|
+
|
|
97
|
+
--name=name subfolder inside the workspace folder to save the imported schema files, defaults to the
|
|
98
|
+
imported schema name
|
|
99
|
+
|
|
100
|
+
--query-name=query-name [curl] property name to add to the Query type as a way to access the imported cURL endpoint.
|
|
101
|
+
|
|
102
|
+
--root-type=root-type [curl] type name for the root type returned by the cURL endpoint in the generated schema.
|
|
96
103
|
```
|
|
97
104
|
|
|
98
105
|
## `stepzen list TYPE`
|
package/lib/commands/import.d.ts
CHANGED
package/lib/commands/import.js
CHANGED
|
@@ -4,38 +4,89 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
const chalk = require("chalk");
|
|
5
5
|
const fs = require("fs-extra");
|
|
6
6
|
const command_1 = require("@oclif/command");
|
|
7
|
+
const errors_1 = require("@oclif/errors");
|
|
8
|
+
const transpiler_1 = require("@stepzen/transpiler");
|
|
9
|
+
const cli_ux_1 = require("cli-ux");
|
|
7
10
|
const deploy_1 = require("./deploy");
|
|
8
11
|
const generate_1 = require("../generate");
|
|
9
12
|
const utils_1 = require("../shared/utils");
|
|
10
13
|
const helpers_1 = require("../generate/helpers");
|
|
14
|
+
const curl2sdl_1 = require("../generate/curl2sdl");
|
|
11
15
|
const workspace_1 = require("../shared/workspace");
|
|
12
16
|
const init_1 = require("./init");
|
|
13
17
|
const constants_1 = require("../shared/constants");
|
|
14
|
-
const { validate } = require('@stepzen/transpiler');
|
|
15
18
|
class Import extends command_1.Command {
|
|
16
19
|
async run() {
|
|
17
|
-
const { args, flags } = this.parse(Import);
|
|
20
|
+
const { args, argv, flags } = this.parse(Import);
|
|
18
21
|
// Get a list of schemas you're asking for
|
|
19
22
|
const schemas = helpers_1.getSchemaList(args.schemas);
|
|
23
|
+
if (schemas.length > 1 && flags.name) {
|
|
24
|
+
this.log('When importing several schemas the --name flag is ignored. ' +
|
|
25
|
+
'In order to use the --name flag please import each schema separately.');
|
|
26
|
+
}
|
|
20
27
|
// Get the working directory and workspace
|
|
21
28
|
const directory = utils_1.getDirectory(flags.dir);
|
|
22
29
|
let workspace = workspace_1.getWorkspace(directory);
|
|
23
30
|
if (!workspace) {
|
|
24
31
|
workspace = await init_1.default.run([directory]);
|
|
25
32
|
}
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
// Select an import execution flow:
|
|
34
|
+
// - v1 with `stepzen/engines` and cloud function
|
|
35
|
+
// - v2 with the graphqlize service
|
|
36
|
+
let result;
|
|
37
|
+
if (schemas.includes('curl')) {
|
|
38
|
+
// LATER: offload the check to the graphqlize service or fetch
|
|
39
|
+
// the list of supported data sources and compare agains it.
|
|
40
|
+
if (schemas.length > 1) {
|
|
41
|
+
throw new errors_1.CLIError('Please run cURL import separately from importing other schemas');
|
|
42
|
+
}
|
|
43
|
+
if (argv.length < 2) {
|
|
44
|
+
throw new errors_1.CLIError('Please append the full cURL command, e.g. ' +
|
|
45
|
+
chalk.bold(`${this.config.name} import curl https://test.stepzen.net/version`));
|
|
46
|
+
}
|
|
47
|
+
this.log(chalk.yellow(`NOTE: ${chalk.bold('stepzen import curl')} is currently in ${chalk.bold('beta')}`));
|
|
48
|
+
this.log(chalk.yellow('If you encounter any issues with it please make sure are using the ' +
|
|
49
|
+
'latest version of stepzen CLI before reporting them to StepZen.'));
|
|
50
|
+
// LATER: introduce a generic graphqlize() API taking in schema as the first arg
|
|
51
|
+
argv.shift(); // remove 'curl' and pass everything else further
|
|
52
|
+
cli_ux_1.cli.action.start('Starting');
|
|
53
|
+
const resultOrError = await curl2sdl_1.curl2sdl({
|
|
54
|
+
argv,
|
|
55
|
+
name: flags.name,
|
|
56
|
+
source: workspace.schema,
|
|
57
|
+
queryName: flags['query-name'],
|
|
58
|
+
rootType: flags['root-type'],
|
|
59
|
+
});
|
|
60
|
+
cli_ux_1.cli.action.stop();
|
|
61
|
+
if ('error' in resultOrError) {
|
|
62
|
+
this.log('A problem occured while processing your import. ' +
|
|
63
|
+
'Please check that the given cURL command is valid.');
|
|
64
|
+
this.log(resultOrError.error);
|
|
65
|
+
this.exit();
|
|
66
|
+
}
|
|
67
|
+
result = resultOrError.outPath;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
;
|
|
71
|
+
['root-type', 'query-name'].forEach(flag => {
|
|
72
|
+
if (flag in flags) {
|
|
73
|
+
this.log(chalk.gray(`The ${chalk.bold(`--${flag}`)} flag only applies when importing ${chalk.bold('curl')}. It will be ignored now.`));
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
// Make sure the user has latest Generator Schema
|
|
77
|
+
await deploy_1.default.run([
|
|
78
|
+
constants_1.STEPZEN_GENERATOR_ENGINES_ENDPOINT,
|
|
79
|
+
'--schema',
|
|
80
|
+
constants_1.STEPZEN_GENERATOR_ENGINES_SCHEMA,
|
|
81
|
+
'--silent',
|
|
82
|
+
]);
|
|
83
|
+
// Let's go!
|
|
84
|
+
result = await generate_1.default(schemas, flags.name, workspace.schema);
|
|
85
|
+
// Validate
|
|
86
|
+
await transpiler_1.validate(result, {
|
|
87
|
+
extensions: await utils_1.getStepZenExtensions(),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
39
90
|
// Housekeeping
|
|
40
91
|
fs.copySync(result, workspace.schema);
|
|
41
92
|
fs.removeSync(result);
|
|
@@ -50,6 +101,18 @@ Import.flags = {
|
|
|
50
101
|
dir: command_1.flags.string({ description: 'working directory' }),
|
|
51
102
|
help: command_1.flags.help({ char: 'h' }),
|
|
52
103
|
silent: command_1.flags.boolean({ hidden: true }),
|
|
104
|
+
name: command_1.flags.string({
|
|
105
|
+
description: 'subfolder inside the workspace folder to save the imported' +
|
|
106
|
+
' schema files, defaults to the imported schema name',
|
|
107
|
+
}),
|
|
108
|
+
'query-name': command_1.flags.string({
|
|
109
|
+
description: '[curl] property name to add to the Query type as a way to' +
|
|
110
|
+
' access the imported cURL endpoint.',
|
|
111
|
+
}),
|
|
112
|
+
'root-type': command_1.flags.string({
|
|
113
|
+
description: '[curl] type name for the root type returned by the cURL endpoint' +
|
|
114
|
+
' in the generated schema.',
|
|
115
|
+
}),
|
|
53
116
|
};
|
|
54
117
|
Import.args = [
|
|
55
118
|
{
|
|
@@ -57,3 +120,5 @@ Import.args = [
|
|
|
57
120
|
required: true,
|
|
58
121
|
},
|
|
59
122
|
];
|
|
123
|
+
// allow any number of arguments to support `import curl [url] [curl flags and options]`
|
|
124
|
+
Import.strict = false;
|
package/lib/commands/login.js
CHANGED
|
@@ -8,6 +8,7 @@ const command_1 = require("@oclif/command");
|
|
|
8
8
|
const errors_1 = require("@oclif/errors");
|
|
9
9
|
const cli_ux_1 = require("cli-ux");
|
|
10
10
|
const configuration_1 = require("../shared/configuration");
|
|
11
|
+
const stepzen_sdk_1 = require("../shared/stepzen-sdk");
|
|
11
12
|
class Login extends command_1.Command {
|
|
12
13
|
async run() {
|
|
13
14
|
const { flags } = this.parse(Login);
|
|
@@ -37,19 +38,18 @@ class Login extends command_1.Command {
|
|
|
37
38
|
});
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
|
-
const configuration = {
|
|
41
|
-
account,
|
|
42
|
-
adminkey,
|
|
43
|
-
};
|
|
44
41
|
// Check whether the account and admin key exist and are correct by calling
|
|
45
42
|
// the stepzen admin api.
|
|
46
|
-
const isValidConfiguration = await
|
|
43
|
+
const isValidConfiguration = await stepzen_sdk_1.default.verify(account, adminkey);
|
|
47
44
|
if (!isValidConfiguration) {
|
|
48
45
|
// Exit, with error
|
|
49
46
|
throw new errors_1.CLIError('We are unable to verify your account details. Could you please check them?');
|
|
50
47
|
}
|
|
51
48
|
// Change the default account.
|
|
52
|
-
configuration_1.writeConfigurationToLoginFile(
|
|
49
|
+
configuration_1.writeConfigurationToLoginFile({
|
|
50
|
+
account,
|
|
51
|
+
adminkey,
|
|
52
|
+
});
|
|
53
53
|
this.log('You have successfully logged in.');
|
|
54
54
|
}
|
|
55
55
|
}
|
package/lib/commands/whoami.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
const chalk = require("chalk");
|
|
5
5
|
const command_1 = require("@oclif/command");
|
|
6
6
|
const configuration_1 = require("../shared/configuration");
|
|
7
|
+
const utils_1 = require("../shared/utils");
|
|
7
8
|
class WhoAmI extends command_1.Command {
|
|
8
9
|
async run() {
|
|
9
10
|
const { flags } = this.parse(WhoAmI);
|
|
@@ -17,18 +18,20 @@ class WhoAmI extends command_1.Command {
|
|
|
17
18
|
adminkey: 'not set',
|
|
18
19
|
apikey: 'not set',
|
|
19
20
|
};
|
|
21
|
+
if (flags.adminkey) {
|
|
22
|
+
this.log(configuration.adminkey || details.adminkey);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (flags.apikey) {
|
|
26
|
+
this.log(configuration.apikey || details.apikey);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
20
29
|
if (configuration.adminkey) {
|
|
21
30
|
if (flags.showkeys) {
|
|
22
31
|
details.adminkey = configuration.adminkey;
|
|
23
32
|
}
|
|
24
33
|
else {
|
|
25
|
-
|
|
26
|
-
const key = parts[2];
|
|
27
|
-
const firstTwoChars = key.substring(0, 2);
|
|
28
|
-
const lastTwoChars = key.slice(-2);
|
|
29
|
-
const stars = '*'.repeat(key.length - 4);
|
|
30
|
-
const masked = `${firstTwoChars}${stars}${lastTwoChars}`;
|
|
31
|
-
details.adminkey = `${parts[0]}::${parts[1]}::${masked} `;
|
|
34
|
+
details.adminkey = utils_1.maskStepZenKey(configuration.adminkey);
|
|
32
35
|
}
|
|
33
36
|
}
|
|
34
37
|
if (configuration.apikey) {
|
|
@@ -36,13 +39,7 @@ class WhoAmI extends command_1.Command {
|
|
|
36
39
|
details.apikey = configuration.apikey;
|
|
37
40
|
}
|
|
38
41
|
else {
|
|
39
|
-
|
|
40
|
-
const key = parts[2];
|
|
41
|
-
const firstTwoChars = key.substring(0, 2);
|
|
42
|
-
const lastTwoChars = key.slice(-2);
|
|
43
|
-
const stars = '*'.repeat(key.length - 4);
|
|
44
|
-
const masked = `${firstTwoChars}${stars}${lastTwoChars}`;
|
|
45
|
-
details.apikey = `${parts[0]}::${parts[1]}::${masked} `;
|
|
42
|
+
details.apikey = utils_1.maskStepZenKey(configuration.apikey);
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
45
|
this.log();
|
|
@@ -57,6 +54,17 @@ WhoAmI.description = 'stepzen whoami';
|
|
|
57
54
|
WhoAmI.hidden = true;
|
|
58
55
|
WhoAmI.flags = {
|
|
59
56
|
help: command_1.flags.help({ char: 'h' }),
|
|
60
|
-
showkeys: command_1.flags.boolean({
|
|
57
|
+
showkeys: command_1.flags.boolean({
|
|
58
|
+
default: false,
|
|
59
|
+
exclusive: ['adminkey', 'apikey'],
|
|
60
|
+
}),
|
|
61
|
+
apikey: command_1.flags.boolean({
|
|
62
|
+
default: false,
|
|
63
|
+
exclusive: ['showkeys', 'adminkey'],
|
|
64
|
+
}),
|
|
65
|
+
adminkey: command_1.flags.boolean({
|
|
66
|
+
default: false,
|
|
67
|
+
exclusive: ['showkeys', 'apikey'],
|
|
68
|
+
}),
|
|
61
69
|
};
|
|
62
70
|
WhoAmI.args = [];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare type Curl2SdlOptions = {
|
|
2
|
+
argv: readonly string[];
|
|
3
|
+
name: string;
|
|
4
|
+
source: string;
|
|
5
|
+
queryName?: string;
|
|
6
|
+
rootType?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare type HeaderInput = {
|
|
9
|
+
name: string;
|
|
10
|
+
value: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const curl2sdl: ({ argv, name, source, queryName, rootType, }: Curl2SdlOptions) => Promise<{
|
|
13
|
+
error: string;
|
|
14
|
+
} | {
|
|
15
|
+
outPath: string;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.curl2sdl = void 0;
|
|
5
|
+
const parser_1 = require("@oclif/parser");
|
|
6
|
+
const errors_1 = require("@oclif/errors");
|
|
7
|
+
const fs = require("fs-extra");
|
|
8
|
+
const os = require("os");
|
|
9
|
+
const path = require("path");
|
|
10
|
+
const node_fetch_1 = require("node-fetch");
|
|
11
|
+
const debug = require("debug");
|
|
12
|
+
const prettier = require("prettier");
|
|
13
|
+
const constants_1 = require("../shared/constants");
|
|
14
|
+
const errors_2 = require("../shared/errors");
|
|
15
|
+
const transpiler_1 = require("@stepzen/transpiler");
|
|
16
|
+
const utils_1 = require("../shared/utils");
|
|
17
|
+
const curlArgs = [
|
|
18
|
+
{
|
|
19
|
+
name: 'url',
|
|
20
|
+
required: true,
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
const curlFlags = {
|
|
24
|
+
header: parser_1.flags.string({
|
|
25
|
+
char: 'H',
|
|
26
|
+
description: 'Extra header to include in the request when sending ' +
|
|
27
|
+
'HTTP to a server, https://curl.se/docs/manpage.html#-H',
|
|
28
|
+
multiple: true,
|
|
29
|
+
}),
|
|
30
|
+
};
|
|
31
|
+
exports.curl2sdl = async ({ argv, name, source, queryName, rootType, }) => {
|
|
32
|
+
let json;
|
|
33
|
+
const { args, flags } = parser_1.parse([...argv], {
|
|
34
|
+
args: curlArgs,
|
|
35
|
+
flags: curlFlags,
|
|
36
|
+
});
|
|
37
|
+
const curlHeaders = (flags.header &&
|
|
38
|
+
flags.header
|
|
39
|
+
.map(utils_1.parseCurlHeaderString)
|
|
40
|
+
// a `null` from parseHeaderString() means a header should NOT be sent
|
|
41
|
+
// This is not supported by zenserv / the introspection service so the
|
|
42
|
+
// CLI simply omits such headers
|
|
43
|
+
.filter(h => h !== null)) ||
|
|
44
|
+
[];
|
|
45
|
+
try {
|
|
46
|
+
const url = `${constants_1.STEPZEN_JSON2SDL_SERVER_URL}/api/graphql`;
|
|
47
|
+
const headers = {
|
|
48
|
+
'Content-Type': 'application/json',
|
|
49
|
+
};
|
|
50
|
+
const query = `query (
|
|
51
|
+
$command: String!
|
|
52
|
+
$queryName: String
|
|
53
|
+
$rootType: String
|
|
54
|
+
$headers: [HeaderInput!]
|
|
55
|
+
) {
|
|
56
|
+
getSDLFromCurl(
|
|
57
|
+
command: $command
|
|
58
|
+
queryName: $queryName
|
|
59
|
+
rootType: $rootType
|
|
60
|
+
headers: $headers
|
|
61
|
+
) {
|
|
62
|
+
sdl
|
|
63
|
+
config
|
|
64
|
+
}
|
|
65
|
+
}`;
|
|
66
|
+
const variables = {
|
|
67
|
+
command: args.url,
|
|
68
|
+
queryName: queryName || null,
|
|
69
|
+
rootType: rootType || null,
|
|
70
|
+
headers: curlHeaders.length > 0 ? curlHeaders : null,
|
|
71
|
+
};
|
|
72
|
+
debug('stepzen:curl2sdl')(url);
|
|
73
|
+
debug('stepzen:curl2sdl')(query);
|
|
74
|
+
debug('stepzen:curl2sdl')(variables);
|
|
75
|
+
const payload = JSON.stringify({
|
|
76
|
+
query,
|
|
77
|
+
variables,
|
|
78
|
+
});
|
|
79
|
+
debug('stepzen:curl2sdl')(payload);
|
|
80
|
+
const response = await node_fetch_1.default(url, {
|
|
81
|
+
method: 'POST',
|
|
82
|
+
headers,
|
|
83
|
+
body: JSON.stringify({
|
|
84
|
+
query,
|
|
85
|
+
variables,
|
|
86
|
+
}),
|
|
87
|
+
});
|
|
88
|
+
const text = await response.text();
|
|
89
|
+
debug('stepzen:curl2sdl')(text);
|
|
90
|
+
json = JSON.parse(text);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
debug('stepzen:curl2sdl')(error);
|
|
94
|
+
throw new errors_1.CLIError(errors_2.PERMANENT_STEPZEN_ERROR);
|
|
95
|
+
}
|
|
96
|
+
if (!json.data && !json.errors) {
|
|
97
|
+
debug('stepzen:curl2sdl')('expected the response from the JSON introspection service ' +
|
|
98
|
+
'to contain either `data` or `errors`');
|
|
99
|
+
throw new errors_1.CLIError(errors_2.PERMANENT_STEPZEN_ERROR);
|
|
100
|
+
}
|
|
101
|
+
if (json.errors) {
|
|
102
|
+
return { error: json.errors.map((error) => error.message).join('\n') };
|
|
103
|
+
}
|
|
104
|
+
const { getSDLFromCurl } = json.data;
|
|
105
|
+
if (!getSDLFromCurl) {
|
|
106
|
+
debug('stepzen:curl2sdl')('expected the response from the JSON introspection service ' +
|
|
107
|
+
'to contain a `getSDLFromCurl` object');
|
|
108
|
+
throw new errors_1.CLIError(errors_2.PERMANENT_STEPZEN_ERROR);
|
|
109
|
+
}
|
|
110
|
+
const { config, sdl } = getSDLFromCurl;
|
|
111
|
+
if (!config && !sdl) {
|
|
112
|
+
debug('stepzen:curl2sdl')('expected the response from the JSON introspection service ' +
|
|
113
|
+
'to contain at least one of `getSDLFromCurl.config` or ' +
|
|
114
|
+
'`getSDLFromCurl.sdl` properties');
|
|
115
|
+
throw new errors_1.CLIError(errors_2.PERMANENT_STEPZEN_ERROR);
|
|
116
|
+
}
|
|
117
|
+
// write out the generated config and schema files
|
|
118
|
+
const tmp = path.join(os.tmpdir(), `stepzen-curl2sdl-${Date.now()}`);
|
|
119
|
+
fs.ensureDirSync(tmp);
|
|
120
|
+
// fs.ensureDirSync(path.join(tmp, subfolder))
|
|
121
|
+
if (config) {
|
|
122
|
+
fs.writeFileSync(path.join(tmp, 'config.yaml'), prettier.format(config, { parser: 'yaml' }));
|
|
123
|
+
}
|
|
124
|
+
if (sdl) {
|
|
125
|
+
fs.writeFileSync(path.join(tmp, 'index.graphql'), prettier.format(sdl, { parser: 'graphql' }));
|
|
126
|
+
}
|
|
127
|
+
const result = await transpiler_1.merge(source, {
|
|
128
|
+
name: name || 'curl',
|
|
129
|
+
source: tmp,
|
|
130
|
+
}, {
|
|
131
|
+
answers: {},
|
|
132
|
+
output: null,
|
|
133
|
+
silent: true,
|
|
134
|
+
mergeTypes: false,
|
|
135
|
+
});
|
|
136
|
+
return { outPath: result };
|
|
137
|
+
};
|
package/lib/generate/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: (schemas: any, source: string) => Promise<string>;
|
|
1
|
+
declare const _default: (schemas: any, name: string, source: string) => Promise<string>;
|
|
2
2
|
export default _default;
|
package/lib/generate/index.js
CHANGED
|
@@ -8,9 +8,9 @@ const fs = require("fs-extra");
|
|
|
8
8
|
const lodash = require("lodash");
|
|
9
9
|
const os = require("os");
|
|
10
10
|
const path = require("path");
|
|
11
|
+
const transpiler_1 = require("@stepzen/transpiler");
|
|
11
12
|
const helpers_1 = require("./helpers");
|
|
12
|
-
|
|
13
|
-
exports.default = async (schemas, source) => {
|
|
13
|
+
exports.default = async (schemas, name, source) => {
|
|
14
14
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
15
15
|
var _e;
|
|
16
16
|
// Store the generators
|
|
@@ -115,24 +115,26 @@ exports.default = async (schemas, source) => {
|
|
|
115
115
|
const [id, generator] = _o.value;
|
|
116
116
|
if (generator.type === 'generator') {
|
|
117
117
|
const files = await helpers_1.createGeneratorFiles(id, generator);
|
|
118
|
-
const tmp = await merge(output, {
|
|
118
|
+
const tmp = await transpiler_1.merge(output, {
|
|
119
119
|
name: id,
|
|
120
120
|
source: files,
|
|
121
121
|
}, {
|
|
122
122
|
answers,
|
|
123
123
|
silent: true,
|
|
124
|
+
output: null,
|
|
124
125
|
});
|
|
125
126
|
fs.copySync(tmp, output);
|
|
126
127
|
fs.removeSync(files);
|
|
127
128
|
fs.removeSync(tmp);
|
|
128
129
|
}
|
|
129
130
|
if (generator.type === 'template') {
|
|
130
|
-
const tmp = await merge(output, {
|
|
131
|
-
name: id,
|
|
131
|
+
const tmp = await transpiler_1.merge(output, {
|
|
132
|
+
name: name || id,
|
|
132
133
|
source: path.join(templates, id),
|
|
133
134
|
}, {
|
|
134
135
|
answers,
|
|
135
136
|
silent: true,
|
|
137
|
+
output: null,
|
|
136
138
|
});
|
|
137
139
|
fs.copySync(tmp, output);
|
|
138
140
|
fs.removeSync(tmp);
|
package/lib/shared/actions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ZenCtlResponse } from './types';
|
|
2
2
|
export declare const deploy: (destination: string, configurationsets: string | undefined, schema: string) => Promise<ZenCtlResponse>;
|
|
3
|
-
export declare const list: (type:
|
|
3
|
+
export declare const list: (type: 'configurationsets' | 'schemas') => Promise<ZenCtlResponse>;
|
|
4
4
|
export declare const upload: (type: string, destination: string, file: string | undefined, directory: string | undefined) => Promise<any>;
|
package/lib/shared/actions.js
CHANGED
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.upload = exports.list = exports.deploy = void 0;
|
|
5
|
+
// This file contains 'actions' - calls to zenctl
|
|
6
|
+
const errors_1 = require("@oclif/errors");
|
|
5
7
|
const configuration_1 = require("./configuration");
|
|
6
8
|
const constants_1 = require("./constants");
|
|
7
|
-
const
|
|
9
|
+
const stepzen_sdk_1 = require("./stepzen-sdk");
|
|
8
10
|
exports.deploy = async (destination, configurationsets, schema) => {
|
|
9
11
|
const config = configuration_1.readConfiguration();
|
|
10
12
|
const server = constants_1.STEPZEN_SERVER_URL.replace('{account}', config.account);
|
|
11
|
-
const client = await
|
|
13
|
+
const client = await stepzen_sdk_1.default.client({
|
|
12
14
|
account: config.account,
|
|
13
15
|
adminkey: config.adminkey,
|
|
14
16
|
domain: constants_1.STEPZEN_DOMAIN,
|
|
@@ -23,7 +25,7 @@ exports.deploy = async (destination, configurationsets, schema) => {
|
|
|
23
25
|
exports.list = async (type) => {
|
|
24
26
|
const config = configuration_1.readConfiguration();
|
|
25
27
|
const server = constants_1.STEPZEN_SERVER_URL.replace('{account}', config.account);
|
|
26
|
-
const client = await
|
|
28
|
+
const client = await stepzen_sdk_1.default.client({
|
|
27
29
|
account: config.account,
|
|
28
30
|
adminkey: config.adminkey,
|
|
29
31
|
domain: constants_1.STEPZEN_DOMAIN,
|
|
@@ -34,16 +36,22 @@ exports.list = async (type) => {
|
|
|
34
36
|
exports.upload = async (type, destination, file, directory) => {
|
|
35
37
|
const config = configuration_1.readConfiguration();
|
|
36
38
|
const server = constants_1.STEPZEN_SERVER_URL.replace('{account}', config.account);
|
|
37
|
-
const client = await
|
|
39
|
+
const client = await stepzen_sdk_1.default.client({
|
|
38
40
|
account: config.account,
|
|
39
41
|
adminkey: config.adminkey,
|
|
40
42
|
domain: constants_1.STEPZEN_DOMAIN,
|
|
41
43
|
server,
|
|
42
44
|
});
|
|
43
45
|
if (type === 'configurationset') {
|
|
46
|
+
if (!file) {
|
|
47
|
+
throw new errors_1.CLIError('Please specify a source file with the --file flag');
|
|
48
|
+
}
|
|
44
49
|
return client.upload.configurationset(destination, file);
|
|
45
50
|
}
|
|
46
51
|
if (type === 'schema') {
|
|
52
|
+
if (!directory) {
|
|
53
|
+
throw new errors_1.CLIError('Please specify a source directory with the --dir flag');
|
|
54
|
+
}
|
|
47
55
|
return client.upload.schema(destination, directory);
|
|
48
56
|
}
|
|
49
57
|
};
|
|
@@ -2,5 +2,4 @@ import { MachineConfiguration } from './types';
|
|
|
2
2
|
export declare const readConfiguration: () => MachineConfiguration | boolean;
|
|
3
3
|
export declare const importConfiguration: (filepath: string) => MachineConfiguration;
|
|
4
4
|
export declare const removeConfigurationFromLoginFile: () => boolean;
|
|
5
|
-
export declare const verifyConfiguration: (configuration: MachineConfiguration) => Promise<boolean>;
|
|
6
5
|
export declare const writeConfigurationToLoginFile: (configuration: MachineConfiguration) => MachineConfiguration;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.writeConfigurationToLoginFile = exports.
|
|
4
|
+
exports.writeConfigurationToLoginFile = exports.removeConfigurationFromLoginFile = exports.importConfiguration = exports.readConfiguration = void 0;
|
|
5
5
|
// This file contains methods for managing configuration
|
|
6
6
|
const errors_1 = require("@oclif/errors");
|
|
7
7
|
const debug = require("debug");
|
|
8
|
-
const node_fetch_1 = require("node-fetch");
|
|
9
8
|
const fs = require("fs");
|
|
10
9
|
const path = require("path");
|
|
11
10
|
const yaml = require("yaml");
|
|
@@ -14,8 +13,8 @@ exports.readConfiguration = () => {
|
|
|
14
13
|
try {
|
|
15
14
|
let configuration;
|
|
16
15
|
// If the configuration comes from an env var, use it
|
|
17
|
-
if (
|
|
18
|
-
configuration =
|
|
16
|
+
if (process.env.STEPZEN_CONFIG_CONTENT) {
|
|
17
|
+
configuration = process.env.STEPZEN_CONFIG_CONTENT;
|
|
19
18
|
}
|
|
20
19
|
else {
|
|
21
20
|
// Read the stored configuration, if it exists.
|
|
@@ -56,27 +55,6 @@ exports.removeConfigurationFromLoginFile = () => {
|
|
|
56
55
|
return false;
|
|
57
56
|
}
|
|
58
57
|
};
|
|
59
|
-
exports.verifyConfiguration = async (configuration) => {
|
|
60
|
-
const headers = {
|
|
61
|
-
Authorization: `Apikey ${configuration.adminkey}`,
|
|
62
|
-
Host: `${configuration.account}.${constants_1.STEPZEN_DOMAIN}`,
|
|
63
|
-
};
|
|
64
|
-
const url = `${constants_1.STEPZEN_SERVER_URL}${constants_1.ADMIN_VERIFY_URL}`.replace('{account}', configuration.account);
|
|
65
|
-
debug('stepzen:headers')(headers);
|
|
66
|
-
debug('stepzen:url')(url);
|
|
67
|
-
// Try and ping zenctl. If your details are incorrect, it will return a 404
|
|
68
|
-
try {
|
|
69
|
-
const response = await node_fetch_1.default(url, {
|
|
70
|
-
headers,
|
|
71
|
-
method: 'POST',
|
|
72
|
-
});
|
|
73
|
-
await response.json();
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
catch (_a) {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
58
|
exports.writeConfigurationToLoginFile = (configuration) => {
|
|
81
59
|
// Generate YAML from the configuration
|
|
82
60
|
const content = yaml.stringify(configuration);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export declare const STEPZEN_CONFIG_CONTENT: string | undefined;
|
|
2
1
|
export declare const STEPZEN_CONFIG_DIRECTORY: string;
|
|
3
2
|
export declare const STEPZEN_CONFIG_FILE: string;
|
|
4
3
|
export declare const STEPZEN_DOMAIN: string;
|
|
@@ -6,8 +5,8 @@ export declare const STEPZEN_SERVER_URL: string;
|
|
|
6
5
|
export declare const STEPZEN_GENERATOR_ENGINES_SCHEMA: string;
|
|
7
6
|
export declare const STEPZEN_GENERATOR_ENGINES_ENDPOINT = "stepzen-generator/engines";
|
|
8
7
|
export declare const STEPZEN_API_TEMPLATES_REPOSITORY = "https://github.com/steprz/stepzen-schemas";
|
|
9
|
-
export declare const ADMIN_ACCOUNT_URL = "/cli/admin/account";
|
|
10
8
|
export declare const ADMIN_DEPLOY_URL = "/cli/admin/deploy";
|
|
11
9
|
export declare const ADMIN_LIST_URL = "/cli/admin/list";
|
|
12
10
|
export declare const ADMIN_UPLOAD_URL = "/cli/admin/upload";
|
|
13
11
|
export declare const ADMIN_VERIFY_URL = "/cli/admin/verify";
|
|
12
|
+
export declare const STEPZEN_JSON2SDL_SERVER_URL: string;
|
package/lib/shared/constants.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.STEPZEN_JSON2SDL_SERVER_URL = exports.ADMIN_VERIFY_URL = exports.ADMIN_UPLOAD_URL = exports.ADMIN_LIST_URL = exports.ADMIN_DEPLOY_URL = exports.STEPZEN_API_TEMPLATES_REPOSITORY = exports.STEPZEN_GENERATOR_ENGINES_ENDPOINT = exports.STEPZEN_GENERATOR_ENGINES_SCHEMA = exports.STEPZEN_SERVER_URL = exports.STEPZEN_DOMAIN = exports.STEPZEN_CONFIG_FILE = exports.STEPZEN_CONFIG_DIRECTORY = void 0;
|
|
5
5
|
// This file contains constants and all magic strings
|
|
6
6
|
const dotenv = require("dotenv");
|
|
7
7
|
const os = require("os");
|
|
@@ -9,9 +9,8 @@ const path = require("path");
|
|
|
9
9
|
// This allows you to set environment variables in a `.env` file.
|
|
10
10
|
// This file needs to be in your working directory.
|
|
11
11
|
dotenv.config();
|
|
12
|
-
const {
|
|
12
|
+
const { STEPZEN_CONFIG_FILE: ENV_VAR_STEPZEN_CONFIG_FILE, STEPZEN_DOMAIN: ENV_VAR_STEPZEN_DOMAIN, STEPZEN_GENERATOR_ENGINES_SCHEMA: ENV_VAR_STEPZEN_GENERATOR_ENGINES_SCHEMA, STEPZEN_SERVER_URL: ENV_VAR_STEPZEN_SERVER_URL, STEPZEN_JSON2SDL_SERVER_URL: ENV_VAR_STEPZEN_JSON2SDL_SERVER_URL, } = process.env;
|
|
13
13
|
// Where your authentication details are stored locally
|
|
14
|
-
exports.STEPZEN_CONFIG_CONTENT = ENV_VAR_STEPZEN_CONFIG_CONTENT;
|
|
15
14
|
exports.STEPZEN_CONFIG_DIRECTORY = path.join(os.homedir(), '.stepzen');
|
|
16
15
|
exports.STEPZEN_CONFIG_FILE = ENV_VAR_STEPZEN_CONFIG_FILE || 'stepzen-config.yaml';
|
|
17
16
|
// The zenctl domain. Override with the env var `STEPZEN_DOMAIN`
|
|
@@ -25,9 +24,10 @@ exports.STEPZEN_GENERATOR_ENGINES_SCHEMA = ENV_VAR_STEPZEN_GENERATOR_ENGINES_SCH
|
|
|
25
24
|
exports.STEPZEN_GENERATOR_ENGINES_ENDPOINT = 'stepzen-generator/engines';
|
|
26
25
|
// API Templates repository
|
|
27
26
|
exports.STEPZEN_API_TEMPLATES_REPOSITORY = 'https://github.com/steprz/stepzen-schemas';
|
|
28
|
-
// Paths to the endpoints used
|
|
29
|
-
exports.ADMIN_ACCOUNT_URL = '/cli/admin/account';
|
|
27
|
+
// Paths to the endpoints used (only for tests)
|
|
30
28
|
exports.ADMIN_DEPLOY_URL = '/cli/admin/deploy';
|
|
31
29
|
exports.ADMIN_LIST_URL = '/cli/admin/list';
|
|
32
30
|
exports.ADMIN_UPLOAD_URL = '/cli/admin/upload';
|
|
33
31
|
exports.ADMIN_VERIFY_URL = '/cli/admin/verify';
|
|
32
|
+
exports.STEPZEN_JSON2SDL_SERVER_URL = ENV_VAR_STEPZEN_JSON2SDL_SERVER_URL ||
|
|
33
|
+
'https://jsonintrospection-ng-prod-xynkgeaaaa-uc.a.run.app';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
declare const stepzen: {
|
|
2
|
+
verify: (account: string, adminkey: string) => Promise<boolean>;
|
|
3
|
+
client: (options: Pick<import("@stepzen/sdk").StepZenAccount, "account" | "adminkey"> & Partial<import("@stepzen/sdk").StepZenAccount>) => Promise<{
|
|
4
|
+
account: () => Promise<{
|
|
5
|
+
account: string;
|
|
6
|
+
apikey: string;
|
|
7
|
+
} | {
|
|
8
|
+
success: false;
|
|
9
|
+
errors: string[];
|
|
10
|
+
}>;
|
|
11
|
+
deploy: (destination: string, properties: {
|
|
12
|
+
configurationsets?: string[] | undefined;
|
|
13
|
+
schema: string;
|
|
14
|
+
}) => Promise<import("@stepzen/sdk").ZenCtlResponse>;
|
|
15
|
+
list: {
|
|
16
|
+
configurationsets: () => Promise<import("@stepzen/sdk").ZenCtlResponse>;
|
|
17
|
+
schemas: () => Promise<import("@stepzen/sdk").ZenCtlResponse>;
|
|
18
|
+
};
|
|
19
|
+
upload: {
|
|
20
|
+
configurationset: (destination: string, file: string) => Promise<import("@stepzen/sdk").ZenCtlResponse>;
|
|
21
|
+
schema: (destination: string, directory: string) => Promise<import("@stepzen/sdk").ZenCtlResponse>;
|
|
22
|
+
};
|
|
23
|
+
}>;
|
|
24
|
+
};
|
|
25
|
+
export default stepzen;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const sdk_1 = require("@stepzen/sdk");
|
|
5
|
+
const { version } = require('../../package.json');
|
|
6
|
+
const stepzen = sdk_1.init({ appName: `stepzen-cli/${version}` });
|
|
7
|
+
exports.default = stepzen;
|
package/lib/shared/utils.d.ts
CHANGED
|
@@ -4,3 +4,19 @@ export declare const ensureApiKey: () => Promise<void>;
|
|
|
4
4
|
export declare const getDirectory: (d?: string | undefined) => string;
|
|
5
5
|
export declare const getStepZenExtensions: () => Promise<string>;
|
|
6
6
|
export declare const validateEndpoint: (endpoint: string) => any;
|
|
7
|
+
export declare const maskStepZenKey: (key: string) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Parse a header string according to https://curl.se/docs/manpage.html#-H
|
|
10
|
+
* and https://datatracker.ietf.org/doc/html/rfc2616#section-4.2
|
|
11
|
+
*
|
|
12
|
+
* Throws if cannot parse the string.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} header a curl header string, e.g. `"api-key: asfdasdfad"`
|
|
15
|
+
* @returns {{name: string, value: string} | null} a name/value record or
|
|
16
|
+
* `null` for the `Header:` notation that means "remove this header" in
|
|
17
|
+
* the cURL spec.
|
|
18
|
+
*/
|
|
19
|
+
export declare const parseCurlHeaderString: (header: string) => {
|
|
20
|
+
name: string;
|
|
21
|
+
value: string;
|
|
22
|
+
} | null;
|
package/lib/shared/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.validateEndpoint = exports.getStepZenExtensions = exports.getDirectory = exports.ensureApiKey = exports.clearConsole = exports.checkAuth = void 0;
|
|
4
|
+
exports.parseCurlHeaderString = exports.maskStepZenKey = exports.validateEndpoint = exports.getStepZenExtensions = exports.getDirectory = exports.ensureApiKey = exports.clearConsole = exports.checkAuth = void 0;
|
|
5
5
|
const errors_1 = require("@oclif/errors");
|
|
6
6
|
const chalk = require("chalk");
|
|
7
7
|
const debug = require("debug");
|
|
@@ -12,6 +12,7 @@ const path = require("path");
|
|
|
12
12
|
const prettier = require("prettier");
|
|
13
13
|
const constants_1 = require("./constants");
|
|
14
14
|
const configuration_1 = require("./configuration");
|
|
15
|
+
const stepzen_sdk_1 = require("./stepzen-sdk");
|
|
15
16
|
exports.checkAuth = async () => {
|
|
16
17
|
var _a;
|
|
17
18
|
const configuration = configuration_1.readConfiguration();
|
|
@@ -24,7 +25,7 @@ exports.checkAuth = async () => {
|
|
|
24
25
|
if (details.account === 'test') {
|
|
25
26
|
return;
|
|
26
27
|
}
|
|
27
|
-
const isValidAccount = await
|
|
28
|
+
const isValidAccount = await stepzen_sdk_1.default.verify(details.account, details.adminkey);
|
|
28
29
|
if (!isValidAccount) {
|
|
29
30
|
if ((_a = details.account) === null || _a === void 0 ? void 0 : _a.endsWith('Playground')) {
|
|
30
31
|
console.log(chalk.yellow(`
|
|
@@ -54,16 +55,12 @@ exports.ensureApiKey = async () => {
|
|
|
54
55
|
if (!details.apikey) {
|
|
55
56
|
debug('stepzen:account')(`Fetching API key for account ${details.account}`);
|
|
56
57
|
try {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
const { apikey } = await response.json();
|
|
65
|
-
details.apikey = apikey;
|
|
66
|
-
await configuration_1.writeConfigurationToLoginFile(details);
|
|
58
|
+
const client = await stepzen_sdk_1.default.client(details);
|
|
59
|
+
const response = await client.account();
|
|
60
|
+
if ('apikey' in response) {
|
|
61
|
+
details.apikey = response.apikey;
|
|
62
|
+
await configuration_1.writeConfigurationToLoginFile(details);
|
|
63
|
+
}
|
|
67
64
|
}
|
|
68
65
|
catch (_a) { }
|
|
69
66
|
}
|
|
@@ -105,3 +102,48 @@ exports.validateEndpoint = (endpoint) => {
|
|
|
105
102
|
return error;
|
|
106
103
|
return true;
|
|
107
104
|
};
|
|
105
|
+
exports.maskStepZenKey = (key) => {
|
|
106
|
+
const parts = key.split('::');
|
|
107
|
+
const thirdPart = parts[2];
|
|
108
|
+
const firstTwoChars = thirdPart.substring(0, 2);
|
|
109
|
+
const lastTwoChars = thirdPart.slice(-2);
|
|
110
|
+
const stars = '*'.repeat(thirdPart.length - 4);
|
|
111
|
+
const maskedThirdPart = `${firstTwoChars}${stars}${lastTwoChars}`;
|
|
112
|
+
const masked = `${parts[0]}::${parts[1]}::${maskedThirdPart} `;
|
|
113
|
+
return masked;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Parse a header string according to https://curl.se/docs/manpage.html#-H
|
|
117
|
+
* and https://datatracker.ietf.org/doc/html/rfc2616#section-4.2
|
|
118
|
+
*
|
|
119
|
+
* Throws if cannot parse the string.
|
|
120
|
+
*
|
|
121
|
+
* @param {string} header a curl header string, e.g. `"api-key: asfdasdfad"`
|
|
122
|
+
* @returns {{name: string, value: string} | null} a name/value record or
|
|
123
|
+
* `null` for the `Header:` notation that means "remove this header" in
|
|
124
|
+
* the cURL spec.
|
|
125
|
+
*/
|
|
126
|
+
exports.parseCurlHeaderString = (header) => {
|
|
127
|
+
const trimmed = header.trim();
|
|
128
|
+
// Check if it's a `Header:` case
|
|
129
|
+
if (trimmed.indexOf(':') === trimmed.length - 1) {
|
|
130
|
+
// the user intent was to _remove_ this header
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
// Check if it's a `Header;` case
|
|
134
|
+
if (trimmed.indexOf(';') === trimmed.length - 1) {
|
|
135
|
+
return {
|
|
136
|
+
name: trimmed.substring(0, trimmed.length - 1).trim(),
|
|
137
|
+
value: '',
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
// the definition of a `token` at https://datatracker.ietf.org/doc/html/rfc2616#page-17
|
|
141
|
+
const match = trimmed.match(/^(?<name>[a-zA-Z0-9!#$%&'*+,-.^_`|~]+)\s*:(?<value>.*)$/);
|
|
142
|
+
if (!match || !match.groups || !match.groups.name || !match.groups.value) {
|
|
143
|
+
throw new errors_1.CLIError(`Unexpected header syntax in "${header}". Expected "[name]: [value]", "[name];" or "[name]:"`);
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
name: match.groups.name.trim(),
|
|
147
|
+
value: match.groups.value.trim(),
|
|
148
|
+
};
|
|
149
|
+
};
|
package/lib/start/deploy.js
CHANGED
|
@@ -109,7 +109,7 @@ exports.default = async (file, workspace, flags) => {
|
|
|
109
109
|
console.log(chalk.grey(`You can test your hosted API with cURL:`));
|
|
110
110
|
console.log();
|
|
111
111
|
console.log(`curl ${endpoint} \\`);
|
|
112
|
-
console.log(` --header "Authorization: Apikey
|
|
112
|
+
console.log(` --header "Authorization: Apikey $(stepzen whoami --apikey)" \\`);
|
|
113
113
|
console.log(` --header "Content-Type: application/json" \\`);
|
|
114
114
|
console.log(` --data '{"query": "your graphql query"}'`);
|
|
115
115
|
console.log();
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.9.
|
|
1
|
+
{"version":"0.9.39-beta.2","commands":{"deploy":{"id":"deploy","description":"deploy to stepzen","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"configurationsets":{"name":"configurationsets","type":"option","description":"Configurationsets to use","default":""},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"schema":{"name":"schema","type":"option","description":"Schema to use","required":true},"silent":{"name":"silent","type":"boolean","allowNo":false}},"args":[{"name":"destination","description":"destination","required":true}]},"import":{"id":"import","description":"import schemas from stepzen","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"dir":{"name":"dir","type":"option","description":"working directory"},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"silent":{"name":"silent","type":"boolean","hidden":true,"allowNo":false},"name":{"name":"name","type":"option","description":"subfolder inside the workspace folder to save the imported schema files, defaults to the imported schema name"},"query-name":{"name":"query-name","type":"option","description":"[curl] property name to add to the Query type as a way to access the imported cURL endpoint."},"root-type":{"name":"root-type","type":"option","description":"[curl] type name for the root type returned by the cURL endpoint in the generated schema."}},"args":[{"name":"schemas","required":true}]},"init":{"id":"init","description":"stepzen init","pluginName":"stepzen","pluginType":"core","hidden":true,"aliases":[],"flags":{"endpoint":{"name":"endpoint","type":"option","hidden":true},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"yes":{"name":"yes","type":"boolean","hidden":true,"allowNo":false}},"args":[{"name":"directory","hidden":true}]},"lint":{"id":"lint","description":"stepzen lint","pluginName":"stepzen","pluginType":"core","hidden":true,"aliases":[],"flags":{"dir":{"name":"dir","type":"option","hidden":true},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"list":{"id":"list","description":"list your items","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"type","description":"type","required":true,"options":["configurationsets","schemas"]}]},"login":{"id":"login","description":"log in to stepzen","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"account":{"name":"account","type":"option","char":"a","hidden":true},"adminkey":{"name":"adminkey","type":"option","char":"k","hidden":true},"config":{"name":"config","type":"option","hidden":true},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"logout":{"id":"logout","description":"log out of stepzen","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"start":{"id":"start","description":"upload and deploy your schema","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"dir":{"name":"dir","type":"option","description":"working directory"},"endpoint":{"name":"endpoint","type":"option","description":"Override workspace endpoint"},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"no-console":{"name":"no-console","type":"boolean","hidden":true,"allowNo":false},"no-dashboard":{"name":"no-dashboard","type":"boolean","hidden":true,"allowNo":false},"no-init":{"name":"no-init","type":"boolean","hidden":true,"allowNo":false},"no-server":{"name":"no-server","type":"boolean","hidden":true,"allowNo":false},"no-validate":{"name":"no-validate","type":"boolean","hidden":true,"allowNo":false},"no-watcher":{"name":"no-watcher","type":"boolean","hidden":true,"allowNo":false},"port":{"name":"port","type":"option","default":5001}},"args":[]},"transpile":{"id":"transpile","description":"transpile a graphql schema","pluginName":"stepzen","pluginType":"core","hidden":true,"aliases":[],"flags":{"config":{"name":"config","type":"option","hidden":true},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"hide-output":{"name":"hide-output","type":"boolean","hidden":true,"allowNo":false},"inspect":{"name":"inspect","type":"boolean","char":"i","hidden":true,"allowNo":false},"inspect-after":{"name":"inspect-after","type":"boolean","hidden":true,"allowNo":false},"output-configuration":{"name":"output-configuration","type":"boolean","allowNo":false},"silent":{"name":"silent","type":"boolean","allowNo":false}},"args":[{"name":"folder","required":true}]},"upload":{"id":"upload","description":"upload to stepzen","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"dir":{"name":"dir","type":"option","description":"A directory to upload"},"file":{"name":"file","type":"option","description":"A file to upload"},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"silent":{"name":"silent","type":"boolean","allowNo":false}},"args":[{"name":"type","description":"type","required":true,"options":["configurationset","schema"]},{"name":"destination","description":"destination","required":true}]},"validate":{"id":"validate","description":"validate a graphql schema","pluginName":"stepzen","pluginType":"core","hidden":true,"aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"folder","required":true}]},"whoami":{"id":"whoami","description":"stepzen whoami","pluginName":"stepzen","pluginType":"core","hidden":true,"aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"showkeys":{"name":"showkeys","type":"boolean","allowNo":false},"apikey":{"name":"apikey","type":"boolean","allowNo":false},"adminkey":{"name":"adminkey","type":"boolean","allowNo":false}},"args":[]}}}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stepzen",
|
|
3
3
|
"description": "The StepZen CLI",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.39-beta.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Darren Waddell <darren@stepzen.com>",
|
|
7
7
|
"contributors": [
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@oclif/command": "^1.8.0",
|
|
30
|
-
"@oclif/config": "^1.
|
|
30
|
+
"@oclif/config": "^1.18.3",
|
|
31
31
|
"@oclif/errors": "1.3.5",
|
|
32
|
-
"@oclif/plugin-help": "^5.1.
|
|
33
|
-
"@stepzen/dashboard": "0.1.
|
|
34
|
-
"@stepzen/sdk": "0.9.
|
|
35
|
-
"@stepzen/transpiler": "0.0.
|
|
32
|
+
"@oclif/plugin-help": "^5.1.11",
|
|
33
|
+
"@stepzen/dashboard": "0.1.37",
|
|
34
|
+
"@stepzen/sdk": "0.9.45",
|
|
35
|
+
"@stepzen/transpiler": "0.0.37",
|
|
36
36
|
"chalk": "^4.1.1",
|
|
37
37
|
"chokidar": "^3.5.2",
|
|
38
|
-
"cli-ux": "^6.0.
|
|
38
|
+
"cli-ux": "^6.0.9",
|
|
39
39
|
"compare-versions": "^3.6.0",
|
|
40
40
|
"date-fns": "^2.26.0",
|
|
41
41
|
"debug": "^4.3.0",
|