stepzen 0.9.39-beta.0 → 0.9.39-beta.3
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 +10 -3
- package/lib/commands/import.d.ts +1 -0
- package/lib/commands/import.js +80 -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/constants.d.ts +1 -0
- package/lib/shared/constants.js +4 -2
- package/lib/shared/utils.d.ts +15 -0
- package/lib/shared/utils.js +36 -1
- package/oclif.manifest.json +1 -1
- package/package.json +4 -4
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.39-beta.
|
|
32
|
+
stepzen/0.9.39-beta.3 darwin-x64 node-v14.18.3
|
|
33
33
|
$ stepzen --help [COMMAND]
|
|
34
34
|
USAGE
|
|
35
35
|
$ stepzen COMMAND
|
|
@@ -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;
|
|
@@ -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);
|
|
@@ -9,3 +9,4 @@ export declare const ADMIN_DEPLOY_URL = "/cli/admin/deploy";
|
|
|
9
9
|
export declare const ADMIN_LIST_URL = "/cli/admin/list";
|
|
10
10
|
export declare const ADMIN_UPLOAD_URL = "/cli/admin/upload";
|
|
11
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.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;
|
|
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,7 +9,7 @@ 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 { 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, } = process.env;
|
|
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
14
|
exports.STEPZEN_CONFIG_DIRECTORY = path.join(os.homedir(), '.stepzen');
|
|
15
15
|
exports.STEPZEN_CONFIG_FILE = ENV_VAR_STEPZEN_CONFIG_FILE || 'stepzen-config.yaml';
|
|
@@ -29,3 +29,5 @@ exports.ADMIN_DEPLOY_URL = '/cli/admin/deploy';
|
|
|
29
29
|
exports.ADMIN_LIST_URL = '/cli/admin/list';
|
|
30
30
|
exports.ADMIN_UPLOAD_URL = '/cli/admin/upload';
|
|
31
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';
|
package/lib/shared/utils.d.ts
CHANGED
|
@@ -5,3 +5,18 @@ 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
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.maskStepZenKey = 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");
|
|
@@ -112,3 +112,38 @@ exports.maskStepZenKey = (key) => {
|
|
|
112
112
|
const masked = `${parts[0]}::${parts[1]}::${maskedThirdPart} `;
|
|
113
113
|
return masked;
|
|
114
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/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.9.39-beta.
|
|
1
|
+
{"version":"0.9.39-beta.3","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.39-beta.
|
|
4
|
+
"version": "0.9.39-beta.3",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Darren Waddell <darren@stepzen.com>",
|
|
7
7
|
"contributors": [
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"@oclif/config": "^1.18.3",
|
|
31
31
|
"@oclif/errors": "1.3.5",
|
|
32
32
|
"@oclif/plugin-help": "^5.1.11",
|
|
33
|
-
"@stepzen/dashboard": "0.1.
|
|
34
|
-
"@stepzen/sdk": "0.9.
|
|
35
|
-
"@stepzen/transpiler": "0.0.
|
|
33
|
+
"@stepzen/dashboard": "0.1.37",
|
|
34
|
+
"@stepzen/sdk": "0.9.46",
|
|
35
|
+
"@stepzen/transpiler": "0.0.38",
|
|
36
36
|
"chalk": "^4.1.1",
|
|
37
37
|
"chokidar": "^3.5.2",
|
|
38
38
|
"cli-ux": "^6.0.9",
|