stepzen 0.11.0-beta.1 → 0.11.0
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 +25 -12
- package/lib/commands/import.js +20 -4
- package/lib/generate/curl2sdl.d.ts +5 -2
- package/lib/generate/curl2sdl.js +26 -2
- package/lib/shared/constants.d.ts +1 -0
- package/lib/shared/constants.js +2 -1
- package/lib/shared/curl-parser.js +12 -7
- package/lib/shared/errors.js +4 -3
- package/lib/shared/path-params-parser.d.ts +7 -0
- package/lib/shared/path-params-parser.js +73 -0
- package/oclif.manifest.json +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The StepZen Command Line Interface (CLI) tool enables you to set up and manage StepZen using commands in your command-line shell.
|
|
4
4
|
|
|
5
|
-
After you have written your GraphQL schema in the form of a Schema Definition Language (SDL) file, and defined your "configuration" in a YAML files, you can upload and deploy them to StepZen using the StepZen CLI - resulting in a live GraphQL endpoint.
|
|
5
|
+
After you have written or imported your GraphQL schema in the form of a Schema Definition Language (SDL) file, and defined your "configuration" in a YAML files, you can upload and deploy them to StepZen using the StepZen CLI - resulting in a live GraphQL endpoint.
|
|
6
6
|
|
|
7
7
|
# Installing
|
|
8
8
|
|
|
@@ -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.11.0
|
|
32
|
+
stepzen/0.11.0 darwin-x64 node-v14.19.1
|
|
33
33
|
$ stepzen --help [COMMAND]
|
|
34
34
|
USAGE
|
|
35
35
|
$ stepzen COMMAND
|
|
@@ -80,29 +80,42 @@ 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.12/src/commands/help.ts)_
|
|
84
84
|
|
|
85
85
|
## `stepzen import SCHEMAS`
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
Import a schema for an external data source or a API endpoint to your GraphQL API.
|
|
88
88
|
|
|
89
89
|
```
|
|
90
90
|
USAGE
|
|
91
91
|
$ stepzen import SCHEMAS
|
|
92
92
|
|
|
93
93
|
OPTIONS
|
|
94
|
-
-h, --help
|
|
95
|
-
|
|
94
|
+
-h, --help
|
|
95
|
+
show CLI help
|
|
96
96
|
|
|
97
|
-
--
|
|
98
|
-
|
|
97
|
+
--dir=dir
|
|
98
|
+
working directory
|
|
99
99
|
|
|
100
|
-
--
|
|
100
|
+
--name=name
|
|
101
|
+
subfolder inside the workspace folder to save the imported schema files, defaults to the imported schema name
|
|
101
102
|
|
|
102
|
-
--
|
|
103
|
+
--path-params=path-params
|
|
104
|
+
[curl] specifies path parameters in the URL path. Can be formed by taking the original path and replacing the
|
|
105
|
+
variable segments with $paramName placeholders.
|
|
103
106
|
|
|
104
|
-
|
|
105
|
-
|
|
107
|
+
Example:
|
|
108
|
+
stepzen import curl https://example.com/users/jane/posts/12 --path-params '/users/$userId/posts/$postId'
|
|
109
|
+
|
|
110
|
+
--prefix=prefix
|
|
111
|
+
[curl] prefix to add every type in the generated schema.
|
|
112
|
+
|
|
113
|
+
--query-name=query-name
|
|
114
|
+
[curl] property name to add to the Query type as a way to access the imported cURL endpoint.
|
|
115
|
+
|
|
116
|
+
--query-type=query-type
|
|
117
|
+
[curl] name for the type returned by the cURL endpoint in the generated schema. The name specified by --query-type
|
|
118
|
+
is not prefixed by --prefix if both flags are present.
|
|
106
119
|
```
|
|
107
120
|
|
|
108
121
|
## `stepzen list TYPE`
|
package/lib/commands/import.js
CHANGED
|
@@ -16,6 +16,7 @@ const curl_parser_1 = require("../shared/curl-parser");
|
|
|
16
16
|
const workspace_1 = require("../shared/workspace");
|
|
17
17
|
const init_1 = require("./init");
|
|
18
18
|
const constants_1 = require("../shared/constants");
|
|
19
|
+
const path_params_parser_1 = require("../shared/path-params-parser");
|
|
19
20
|
class Import extends command_1.Command {
|
|
20
21
|
async run() {
|
|
21
22
|
const { args, argv, flags } = this.parse(Import);
|
|
@@ -44,7 +45,7 @@ class Import extends command_1.Command {
|
|
|
44
45
|
this.log(chalk.yellow(`NOTE: ${chalk.bold('stepzen import curl')} is a ${chalk.bold('new')} feature.`));
|
|
45
46
|
this.log(chalk.yellow('If you have any issues, please check if they have been addressed ' +
|
|
46
47
|
'in the latest version, or reach out to StepZen on Discord: ' +
|
|
47
|
-
|
|
48
|
+
constants_1.STEPZEN_DISCORD_URL));
|
|
48
49
|
let curl2sdlOptions;
|
|
49
50
|
const fixedOptions = {
|
|
50
51
|
name: flags.name,
|
|
@@ -54,6 +55,7 @@ class Import extends command_1.Command {
|
|
|
54
55
|
queryName: flags['query-name'],
|
|
55
56
|
rootType: flags['query-type'],
|
|
56
57
|
typePrefix: flags.prefix,
|
|
58
|
+
pathParams: flags['path-params'],
|
|
57
59
|
};
|
|
58
60
|
if (argv.length === 1) {
|
|
59
61
|
// no parameters given: start an interactive prompt
|
|
@@ -71,7 +73,11 @@ class Import extends command_1.Command {
|
|
|
71
73
|
if ('error' in argsOrError) {
|
|
72
74
|
throw new errors_1.CLIError(argsOrError.error);
|
|
73
75
|
}
|
|
74
|
-
|
|
76
|
+
const parsedPathParamsOrError = 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
|
+
curl2sdlOptions = Object.assign(Object.assign(Object.assign({}, fixedOptions), editableOptions), { pathParams: parsedPathParamsOrError, curlArgs: argsOrError });
|
|
75
81
|
}
|
|
76
82
|
cli_ux_1.cli.action.start('Starting');
|
|
77
83
|
const resultOrError = await curl2sdl_1.curl2sdl(curl2sdlOptions);
|
|
@@ -86,7 +92,7 @@ class Import extends command_1.Command {
|
|
|
86
92
|
}
|
|
87
93
|
else {
|
|
88
94
|
;
|
|
89
|
-
['prefix', 'query-type', 'query-name'].forEach(flag => {
|
|
95
|
+
['prefix', 'query-type', 'query-name', 'path-params'].forEach(flag => {
|
|
90
96
|
if (flag in flags) {
|
|
91
97
|
this.log(chalk.gray(`The ${chalk.bold(`--${flag}`)} flag only applies when importing ${chalk.bold('curl')}. It will be ignored now.`));
|
|
92
98
|
}
|
|
@@ -114,7 +120,7 @@ class Import extends command_1.Command {
|
|
|
114
120
|
}
|
|
115
121
|
}
|
|
116
122
|
exports.default = Import;
|
|
117
|
-
Import.description = '
|
|
123
|
+
Import.description = 'Import a schema for an external data source or a API endpoint to your GraphQL API.';
|
|
118
124
|
Import.flags = {
|
|
119
125
|
dir: command_1.flags.string({ description: 'working directory' }),
|
|
120
126
|
help: command_1.flags.help({ char: 'h' }),
|
|
@@ -134,6 +140,16 @@ Import.flags = {
|
|
|
134
140
|
description: '[curl] name for the type returned by the cURL endpoint in the ' +
|
|
135
141
|
`generated schema. The name specified by ${chalk.bold('--query-type')} is not prefixed by ${chalk.bold('--prefix')} if both flags are present.`,
|
|
136
142
|
}),
|
|
143
|
+
'path-params': command_1.flags.string({
|
|
144
|
+
description: `[curl] specifies path parameters in the URL path.` +
|
|
145
|
+
` Can be formed by taking the original path and replacing the` +
|
|
146
|
+
` variable segments with ${chalk.bold('$paramName')} placeholders.` +
|
|
147
|
+
`\n` +
|
|
148
|
+
`\nExample:` +
|
|
149
|
+
`\nstepzen import curl https://example.com/users/jane/posts/12` +
|
|
150
|
+
` --path-params` +
|
|
151
|
+
` '/users/${chalk.bold('$userId')}/posts/${chalk.bold('$postId')}'`,
|
|
152
|
+
}),
|
|
137
153
|
};
|
|
138
154
|
Import.args = [
|
|
139
155
|
{
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CurlArguments } from '../shared/curl-parser';
|
|
2
|
+
import { PathParam } from '../shared/path-params-parser';
|
|
2
3
|
export declare type Curl2SdlOptions = {
|
|
3
4
|
curlArgs: CurlArguments;
|
|
4
5
|
name: string;
|
|
@@ -6,16 +7,18 @@ export declare type Curl2SdlOptions = {
|
|
|
6
7
|
queryName?: string;
|
|
7
8
|
rootType?: string;
|
|
8
9
|
typePrefix?: string;
|
|
10
|
+
pathParams: readonly PathParam[];
|
|
9
11
|
};
|
|
10
|
-
export declare type EditableCurl2SdlOptions = Pick<Curl2SdlOptions, 'curlArgs' | 'queryName' | 'rootType' | 'typePrefix'>;
|
|
12
|
+
export declare type EditableCurl2SdlOptions = Pick<Curl2SdlOptions, 'curlArgs' | 'queryName' | 'rootType' | 'typePrefix' | 'pathParams'>;
|
|
11
13
|
export declare type CurlAnswers = {
|
|
12
14
|
url: string;
|
|
13
15
|
queryName: string;
|
|
14
16
|
rootType: string;
|
|
15
17
|
typePrefix: string;
|
|
18
|
+
pathParams: string;
|
|
16
19
|
};
|
|
17
20
|
export declare const askCurlQuestions: (defaultAnswers?: Partial<CurlAnswers>) => Promise<EditableCurl2SdlOptions>;
|
|
18
|
-
export declare const curl2sdl: ({ curlArgs, name, source, queryName, rootType, typePrefix, }: Curl2SdlOptions) => Promise<{
|
|
21
|
+
export declare const curl2sdl: ({ curlArgs, name, source, queryName, rootType, typePrefix, pathParams, }: Curl2SdlOptions) => Promise<{
|
|
19
22
|
error: string;
|
|
20
23
|
} | {
|
|
21
24
|
outPath: string;
|
package/lib/generate/curl2sdl.js
CHANGED
|
@@ -15,6 +15,7 @@ const debug = require("debug");
|
|
|
15
15
|
const prettier = require("prettier");
|
|
16
16
|
const transpiler_1 = require("@stepzen/transpiler");
|
|
17
17
|
const curl_parser_1 = require("../shared/curl-parser");
|
|
18
|
+
const path_params_parser_1 = require("../shared/path-params-parser");
|
|
18
19
|
const constants_1 = require("../shared/constants");
|
|
19
20
|
const errors_2 = require("../shared/errors");
|
|
20
21
|
exports.askCurlQuestions = async (defaultAnswers = {}) => {
|
|
@@ -23,6 +24,10 @@ exports.askCurlQuestions = async (defaultAnswers = {}) => {
|
|
|
23
24
|
name: 'url',
|
|
24
25
|
message: 'Endpoint URL or a full curl command',
|
|
25
26
|
},
|
|
27
|
+
{
|
|
28
|
+
name: 'pathParams',
|
|
29
|
+
message: 'Parameters for endpoint URL path',
|
|
30
|
+
},
|
|
26
31
|
{
|
|
27
32
|
name: 'queryName',
|
|
28
33
|
message: 'Query name to use when generating schema (leave blank to use defaults)',
|
|
@@ -41,7 +46,22 @@ exports.askCurlQuestions = async (defaultAnswers = {}) => {
|
|
|
41
46
|
const curlArgs = curl_parser_1.parseCurlArgv(string_argv_1.default(answers.url));
|
|
42
47
|
if ('error' in curlArgs) {
|
|
43
48
|
console.log();
|
|
44
|
-
console.log(chalk.red('A problem occurred while parsing the curl command:\n', curlArgs.error), '\nPlease
|
|
49
|
+
console.log(chalk.red('A problem occurred while parsing the curl command:\n', curlArgs.error), '\nPlease enter a URL or a supported curl command.');
|
|
50
|
+
console.log();
|
|
51
|
+
return exports.askCurlQuestions(answers);
|
|
52
|
+
}
|
|
53
|
+
const parsedPathParamsOrError = path_params_parser_1.parsePathParamsPattern(curlArgs.url, answers.pathParams);
|
|
54
|
+
if ('error' in parsedPathParamsOrError) {
|
|
55
|
+
console.log();
|
|
56
|
+
console.log(chalk.red('A problem occurred while parsing path parameters pattern:\n', parsedPathParamsOrError.error));
|
|
57
|
+
console.log();
|
|
58
|
+
console.log(`Please enter a path parameter specification that` +
|
|
59
|
+
` can be formed by taking the original path and replacing the variable` +
|
|
60
|
+
` segments with ${chalk.bold('$paramName')} placeholders.`);
|
|
61
|
+
console.log();
|
|
62
|
+
console.log('Example:\n' +
|
|
63
|
+
`\tendpoint URL: https://example.com/users/jane/posts/12\n ` +
|
|
64
|
+
`\tpath parameters: /users/${chalk.bold('$userId')}/posts/${chalk.bold('$postId')}`);
|
|
45
65
|
console.log();
|
|
46
66
|
return exports.askCurlQuestions(answers);
|
|
47
67
|
}
|
|
@@ -50,9 +70,10 @@ exports.askCurlQuestions = async (defaultAnswers = {}) => {
|
|
|
50
70
|
queryName: answers.queryName,
|
|
51
71
|
rootType: answers.rootType,
|
|
52
72
|
typePrefix: answers.typePrefix,
|
|
73
|
+
pathParams: parsedPathParamsOrError,
|
|
53
74
|
};
|
|
54
75
|
};
|
|
55
|
-
exports.curl2sdl = async ({ curlArgs, name, source, queryName, rootType, typePrefix, }) => {
|
|
76
|
+
exports.curl2sdl = async ({ curlArgs, name, source, queryName, rootType, typePrefix, pathParams, }) => {
|
|
56
77
|
let json;
|
|
57
78
|
try {
|
|
58
79
|
const url = `${constants_1.STEPZEN_JSON2SDL_SERVER_URL}/api/graphql`;
|
|
@@ -64,6 +85,7 @@ exports.curl2sdl = async ({ curlArgs, name, source, queryName, rootType, typePre
|
|
|
64
85
|
$headers: [HeaderInput!]
|
|
65
86
|
$data: String
|
|
66
87
|
$method: HTTPMethod
|
|
88
|
+
$pathParams: [PathParamInput!]
|
|
67
89
|
) {
|
|
68
90
|
getSDLFromCurl(
|
|
69
91
|
command: $command
|
|
@@ -73,6 +95,7 @@ exports.curl2sdl = async ({ curlArgs, name, source, queryName, rootType, typePre
|
|
|
73
95
|
headers: $headers
|
|
74
96
|
data: $data
|
|
75
97
|
method: $method
|
|
98
|
+
pathParams: $pathParams
|
|
76
99
|
) {
|
|
77
100
|
sdl
|
|
78
101
|
config
|
|
@@ -86,6 +109,7 @@ exports.curl2sdl = async ({ curlArgs, name, source, queryName, rootType, typePre
|
|
|
86
109
|
headers: curlArgs.headers.length > 0 ? curlArgs.headers : null,
|
|
87
110
|
data: curlArgs.data || null,
|
|
88
111
|
method: curlArgs.method,
|
|
112
|
+
pathParams: pathParams.length > 0 ? pathParams : null,
|
|
89
113
|
};
|
|
90
114
|
debug('stepzen:curl2sdl')(url);
|
|
91
115
|
debug('stepzen:curl2sdl')(query);
|
|
@@ -11,3 +11,4 @@ export declare const ADMIN_LIST_URL = "/cli/admin/list";
|
|
|
11
11
|
export declare const ADMIN_UPLOAD_URL = "/cli/admin/upload";
|
|
12
12
|
export declare const ADMIN_VERIFY_URL = "/cli/admin/verify";
|
|
13
13
|
export declare const STEPZEN_JSON2SDL_SERVER_URL: string;
|
|
14
|
+
export declare const STEPZEN_DISCORD_URL = "https://discord.gg/9k2VdPn2FR";
|
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.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_LAST_UPDATE_CHECK_TIMESTAMP = exports.STEPZEN_CONFIG_DIRECTORY = void 0;
|
|
4
|
+
exports.STEPZEN_DISCORD_URL = 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_LAST_UPDATE_CHECK_TIMESTAMP = 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");
|
|
@@ -32,3 +32,4 @@ exports.ADMIN_UPLOAD_URL = '/cli/admin/upload';
|
|
|
32
32
|
exports.ADMIN_VERIFY_URL = '/cli/admin/verify';
|
|
33
33
|
exports.STEPZEN_JSON2SDL_SERVER_URL = ENV_VAR_STEPZEN_JSON2SDL_SERVER_URL ||
|
|
34
34
|
'https://jsonintrospection-ng-prod-xynkgeaaaa-uc.a.run.app';
|
|
35
|
+
exports.STEPZEN_DISCORD_URL = 'https://discord.gg/9k2VdPn2FR';
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.parseCurlArgv = exports.parseCurlHeaderString = void 0;
|
|
5
|
+
const constants_1 = require("./constants");
|
|
5
6
|
// Based on the existing curl flags at https://curl.se/docs/manpage.html
|
|
6
7
|
const curlFlagRegex = /^(-[a-zA-Z0-9.:#])|(--[a-zA-Z0-9.-]+)$/;
|
|
7
8
|
// Based on the definition of a `token` at
|
|
@@ -46,7 +47,7 @@ exports.parseCurlHeaderString = (header) => {
|
|
|
46
47
|
const isAFlagArg = (arg) => curlFlagRegex.test(arg);
|
|
47
48
|
const isAURL = (arg) => httpURLRegex.test(arg);
|
|
48
49
|
const parseHeaderFlag = (argv, i, partialCurlArgs) => {
|
|
49
|
-
if (i + 1
|
|
50
|
+
if (i + 1 >= argv.length) {
|
|
50
51
|
return {
|
|
51
52
|
error: `The '${argv[i]}' curl flag requires a value`,
|
|
52
53
|
};
|
|
@@ -68,7 +69,7 @@ const parseHeaderFlag = (argv, i, partialCurlArgs) => {
|
|
|
68
69
|
};
|
|
69
70
|
};
|
|
70
71
|
const parseDataFlag = (argv, i, partialCurlArgs) => {
|
|
71
|
-
if (i + 1
|
|
72
|
+
if (i + 1 >= argv.length) {
|
|
72
73
|
return {
|
|
73
74
|
error: `The '${argv[i]}' curl flag requires a value`,
|
|
74
75
|
};
|
|
@@ -76,7 +77,8 @@ const parseDataFlag = (argv, i, partialCurlArgs) => {
|
|
|
76
77
|
if (argv[i] !== '--data-raw' && argv[i + 1].charAt(0) === '@') {
|
|
77
78
|
return {
|
|
78
79
|
error: `Reading request data from local files in not currently supported ` +
|
|
79
|
-
`by StepZen CLI (${argv[i]} ${argv[i + 1]})
|
|
80
|
+
`by StepZen CLI (${argv[i]} ${argv[i + 1]}). If this is a blocker ` +
|
|
81
|
+
`for you, please let us know on Discord (${constants_1.STEPZEN_DISCORD_URL})`,
|
|
80
82
|
};
|
|
81
83
|
}
|
|
82
84
|
const data = (partialCurlArgs.data ? partialCurlArgs.data + '&' : '') + argv[i + 1];
|
|
@@ -129,13 +131,15 @@ exports.parseCurlArgv = (argv) => {
|
|
|
129
131
|
}
|
|
130
132
|
else {
|
|
131
133
|
return {
|
|
132
|
-
error: `The '${argv[i]}' curl flag is not currently supported by StepZen CLI
|
|
134
|
+
error: `The '${argv[i]}' curl flag is not currently supported by StepZen CLI.` +
|
|
135
|
+
` If this is a blocker for you, please let us know on Discord (${constants_1.STEPZEN_DISCORD_URL})`,
|
|
133
136
|
};
|
|
134
137
|
}
|
|
135
138
|
}
|
|
136
139
|
else if (result.url) {
|
|
137
140
|
return {
|
|
138
|
-
error: `Multiple URLs are not currently supported by StepZen CLI (${argv[i]})
|
|
141
|
+
error: `Multiple URLs are not currently supported by StepZen CLI (${argv[i]}).` +
|
|
142
|
+
` If this is a blocker for you, please let us know on Discord (${constants_1.STEPZEN_DISCORD_URL})`,
|
|
139
143
|
};
|
|
140
144
|
}
|
|
141
145
|
else {
|
|
@@ -149,8 +153,9 @@ exports.parseCurlArgv = (argv) => {
|
|
|
149
153
|
}
|
|
150
154
|
if (!isAURL(result.url)) {
|
|
151
155
|
return {
|
|
152
|
-
error: `Unsupported URL schema in '${result.url}'
|
|
153
|
-
`StepZen CLI currently supports 'https' and 'http'
|
|
156
|
+
error: `Unsupported URL schema in '${result.url}'.` +
|
|
157
|
+
` StepZen CLI currently supports 'https' and 'http'.` +
|
|
158
|
+
` If this is a blocker for you, please let us know on Discord (${constants_1.STEPZEN_DISCORD_URL})`,
|
|
154
159
|
};
|
|
155
160
|
}
|
|
156
161
|
result.headers = result.headers || [];
|
package/lib/shared/errors.js
CHANGED
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.UPGRADE_CHECK_ERROR = exports.PERMANENT_STEPZEN_ERROR = exports.formatTemporaryErrorMessage = void 0;
|
|
5
|
+
const constants_1 = require("./constants");
|
|
5
6
|
exports.formatTemporaryErrorMessage = (errors) => `A problem occurred while processing your import${errors.length > 0 && errors[0].message ? `: "${errors[0].message}"` : ''}. Please try again.` +
|
|
6
7
|
` If the issue persists, make sure you are on the latest version of StepZen ` +
|
|
7
8
|
`CLI. And if the issue still persists contact support via the StepZen discord ` +
|
|
8
|
-
`channel (
|
|
9
|
+
`channel (${constants_1.STEPZEN_DISCORD_URL}).`;
|
|
9
10
|
exports.PERMANENT_STEPZEN_ERROR = 'An unexpected problem occurred while processing your import.' +
|
|
10
11
|
` If the issue persists, make sure you are on the latest version of StepZen ` +
|
|
11
12
|
`CLI. And if the issue still persists contact support via the StepZen discord ` +
|
|
12
|
-
`channel (
|
|
13
|
+
`channel (${constants_1.STEPZEN_DISCORD_URL}).`;
|
|
13
14
|
exports.UPGRADE_CHECK_ERROR = 'An unexpected problem occurred while checking for new CLI versions.' +
|
|
14
15
|
` If the issue persists, make sure you are on the latest version of StepZen ` +
|
|
15
16
|
`CLI. And if the issue still persists contact support via the StepZen discord ` +
|
|
16
|
-
`channel (
|
|
17
|
+
`channel (${constants_1.STEPZEN_DISCORD_URL}).`;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ParseError } from './curl-parser';
|
|
2
|
+
export declare type PathParam = {
|
|
3
|
+
index: number;
|
|
4
|
+
name: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const formatPatternDiffWithPath: (patternSegments: readonly string[], pathSegments: readonly string[]) => string | null;
|
|
7
|
+
export declare const parsePathParamsPattern: (url: string, pathParamsPattern?: string | undefined) => PathParam[] | ParseError;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.parsePathParamsPattern = exports.formatPatternDiffWithPath = void 0;
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const pathParamRegex = /^\$[_A-Za-z]\w*$/;
|
|
7
|
+
exports.formatPatternDiffWithPath = (patternSegments, pathSegments) => {
|
|
8
|
+
let hasErrors = false;
|
|
9
|
+
const diff = [];
|
|
10
|
+
for (let i = 0; i < patternSegments.length; i++) {
|
|
11
|
+
const patternSegment = patternSegments[i];
|
|
12
|
+
if (i >= pathSegments.length) {
|
|
13
|
+
diff.push(chalk.red(`< ${patternSegment} >`));
|
|
14
|
+
hasErrors = true;
|
|
15
|
+
}
|
|
16
|
+
else if (patternSegment.charAt(0) === '$') {
|
|
17
|
+
diff.push(patternSegment);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
const pathSegment = pathSegments[i];
|
|
21
|
+
if (pathSegment === patternSegment) {
|
|
22
|
+
diff.push(pathSegment);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
diff.push(chalk.red(`< ${patternSegment} >`));
|
|
26
|
+
hasErrors = true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
for (let i = patternSegments.length; i < pathSegments.length; i++) {
|
|
31
|
+
diff.push(chalk.magenta(`< ${pathSegments[i]} >`));
|
|
32
|
+
hasErrors = true;
|
|
33
|
+
}
|
|
34
|
+
return hasErrors ? diff.join('/') : null;
|
|
35
|
+
};
|
|
36
|
+
exports.parsePathParamsPattern = (url, pathParamsPattern) => {
|
|
37
|
+
if (!pathParamsPattern) {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
if (pathParamsPattern.charAt(0) === '/') {
|
|
41
|
+
pathParamsPattern = pathParamsPattern.slice(1);
|
|
42
|
+
}
|
|
43
|
+
let pathname = new URL(url).pathname;
|
|
44
|
+
if (pathname.charAt(0) === '/') {
|
|
45
|
+
pathname = pathname.slice(1);
|
|
46
|
+
}
|
|
47
|
+
const pathSegments = pathname.split('/');
|
|
48
|
+
const patternSegments = pathParamsPattern.split('/');
|
|
49
|
+
const maybeDiff = exports.formatPatternDiffWithPath(patternSegments, pathSegments);
|
|
50
|
+
if (maybeDiff) {
|
|
51
|
+
return {
|
|
52
|
+
error: `Path parameters do not align with the URL path: /${maybeDiff}`,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const invalidParameterSegments = patternSegments.filter(segment => segment.charAt(0) === '$' && !pathParamRegex.test(segment));
|
|
56
|
+
if (invalidParameterSegments.length > 0) {
|
|
57
|
+
return {
|
|
58
|
+
error: `The path parameter name '${invalidParameterSegments[0]}' is not` +
|
|
59
|
+
` allowed. Path parameter names should be valid GraphQL identifiers` +
|
|
60
|
+
` prefixed with $ (dollar sign).`,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return patternSegments
|
|
64
|
+
.map((segment, index) => ({
|
|
65
|
+
index,
|
|
66
|
+
name: segment,
|
|
67
|
+
}))
|
|
68
|
+
.filter(({ name }) => name.charAt(0) === '$')
|
|
69
|
+
.map(({ index, name }) => ({
|
|
70
|
+
index,
|
|
71
|
+
name: name.slice(1),
|
|
72
|
+
}));
|
|
73
|
+
};
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.11.0
|
|
1
|
+
{"version":"0.11.0","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 a schema for an external data source or a API endpoint to your GraphQL API.","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"},"prefix":{"name":"prefix","type":"option","description":"[curl] prefix to add every type in the generated schema."},"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."},"query-type":{"name":"query-type","type":"option","description":"[curl] name for the type returned by the cURL endpoint in the generated schema. The name specified by --query-type is not prefixed by --prefix if both flags are present."},"path-params":{"name":"path-params","type":"option","description":"[curl] specifies path parameters in the URL path. Can be formed by taking the original path and replacing the variable segments with $paramName placeholders.\n\nExample:\nstepzen import curl https://example.com/users/jane/posts/12 --path-params '/users/$userId/posts/$postId'"}},"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.11.0
|
|
4
|
+
"version": "0.11.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Darren Waddell <darren@stepzen.com>",
|
|
7
7
|
"contributors": [
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@oclif/command": "^1.8.0",
|
|
30
30
|
"@oclif/config": "^1.18.3",
|
|
31
31
|
"@oclif/errors": "1.3.5",
|
|
32
|
-
"@oclif/plugin-help": "^5.1.
|
|
32
|
+
"@oclif/plugin-help": "^5.1.12",
|
|
33
33
|
"@stepzen/dashboard": "0.1.37",
|
|
34
34
|
"@stepzen/sdk": "0.9.46",
|
|
35
35
|
"@stepzen/transpiler": "0.0.38",
|