stepzen 0.13.0-beta.0 → 0.13.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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.13.0-beta.0 darwin-x64 node-v14.19.1
32
+ stepzen/0.13.0-beta.1 darwin-x64 node-v14.19.1
33
33
  $ stepzen --help [COMMAND]
34
34
  USAGE
35
35
  $ stepzen COMMAND
@@ -46,13 +46,8 @@ exports.parseCurlHeaderString = (header) => {
46
46
  };
47
47
  const isAFlagArg = (arg) => curlFlagRegex.test(arg);
48
48
  const isAURL = (arg) => httpURLRegex.test(arg);
49
- const parseHeaderFlag = (argv, i, partialCurlArgs) => {
50
- if (i + 1 >= argv.length) {
51
- return {
52
- error: `The '${argv[i]}' curl flag requires a value`,
53
- };
54
- }
55
- const headerOrError = exports.parseCurlHeaderString(argv[i + 1]);
49
+ const parseHeaderFlag = (value, partialCurlArgs) => {
50
+ const headerOrError = exports.parseCurlHeaderString(value);
56
51
  if (headerOrError && 'error' in headerOrError) {
57
52
  return headerOrError; // error
58
53
  }
@@ -65,26 +60,31 @@ const parseHeaderFlag = (argv, i, partialCurlArgs) => {
65
60
  }
66
61
  return {
67
62
  result: Object.assign(Object.assign({}, partialCurlArgs), { headers }),
68
- skip: 1,
69
63
  };
70
64
  };
71
- const parseDataFlag = (argv, i, partialCurlArgs) => {
72
- if (i + 1 >= argv.length) {
73
- return {
74
- error: `The '${argv[i]}' curl flag requires a value`,
75
- };
76
- }
77
- if (argv[i] !== '--data-raw' && argv[i + 1].charAt(0) === '@') {
65
+ const parseDataFlag = (value, partialCurlArgs, match) => {
66
+ if (match !== '--data-raw' && value.charAt(0) === '@') {
78
67
  return {
79
68
  error: `Reading request data from local files in not currently supported ` +
80
- `by StepZen CLI (${argv[i]} ${argv[i + 1]}). If this is a blocker ` +
69
+ `by StepZen CLI (${match} ${value}). If this is a blocker ` +
81
70
  `for you, please let us know on Discord (${constants_1.STEPZEN_DISCORD_URL})`,
82
71
  };
83
72
  }
84
- const data = (partialCurlArgs.data ? partialCurlArgs.data + '&' : '') + argv[i + 1];
73
+ const data = (partialCurlArgs.data ? partialCurlArgs.data + '&' : '') + value;
85
74
  return {
86
75
  result: Object.assign(Object.assign({}, partialCurlArgs), { data }),
87
- skip: 1,
76
+ };
77
+ };
78
+ const parseMethodFlag = (value, partialCurlArgs) => {
79
+ const lowercaseMethod = value.toLowerCase();
80
+ if (lowercaseMethod !== 'post' && lowercaseMethod !== 'get') {
81
+ return {
82
+ error: `The method ${value} is currently not supported.`,
83
+ };
84
+ }
85
+ const method = lowercaseMethod === 'post' ? 'Post' : 'Get';
86
+ return {
87
+ result: Object.assign(Object.assign({}, partialCurlArgs), { method }),
88
88
  };
89
89
  };
90
90
  const flags = [
@@ -96,7 +96,34 @@ const flags = [
96
96
  matches: ['-d', '--data', '--data-ascii', '--data-raw', '--data-binary'],
97
97
  parse: parseDataFlag,
98
98
  },
99
+ {
100
+ matches: ['-X', '--request'],
101
+ parse: parseMethodFlag,
102
+ },
99
103
  ];
104
+ const tryMatchCurlFlag = (matches, argv, i) => {
105
+ for (const match of matches) {
106
+ const isShortFlag = match.length === 2;
107
+ if (isShortFlag && argv[i].startsWith(match) && argv[i].length > 2) {
108
+ return {
109
+ value: argv[i].substring(2),
110
+ match,
111
+ };
112
+ }
113
+ if (argv[i] === match) {
114
+ if (i + 1 >= argv.length) {
115
+ return {
116
+ error: `The '${argv[i]}' curl flag requires a value`,
117
+ };
118
+ }
119
+ return {
120
+ value: argv[i + 1],
121
+ match,
122
+ skip: 1,
123
+ };
124
+ }
125
+ }
126
+ };
100
127
  /**
101
128
  * Parse a curl command line arguments array to a JSON structure consumable by
102
129
  * the StepZen introspection service backend.
@@ -120,16 +147,27 @@ exports.parseCurlArgv = (argv) => {
120
147
  let result = {};
121
148
  for (let i = 0; i < argv.length; i++) {
122
149
  if (isAFlagArg(argv[i])) {
123
- const knownFlag = flags.find(flag => flag.matches.includes(argv[i]));
124
- if (knownFlag) {
125
- const resultOrError = knownFlag.parse(argv, i, result);
126
- if ('error' in resultOrError) {
127
- return resultOrError; // error
150
+ let isKnownFlag = false;
151
+ for (const flag of flags) {
152
+ const matcherResult = tryMatchCurlFlag(flag.matches, argv, i);
153
+ if (!matcherResult) {
154
+ // no match => try matching the next flag
155
+ continue;
156
+ }
157
+ if ('error' in matcherResult) {
158
+ // flag matched but it requies a value which is missing
159
+ return matcherResult;
160
+ }
161
+ const parserResult = flag.parse(matcherResult.value, result, matcherResult.match);
162
+ if ('error' in parserResult) {
163
+ return parserResult;
128
164
  }
129
- result = resultOrError.result; // result
130
- i += resultOrError.skip || 0;
165
+ result = parserResult.result;
166
+ i += matcherResult.skip || 0;
167
+ isKnownFlag = true;
168
+ break;
131
169
  }
132
- else {
170
+ if (!isKnownFlag) {
133
171
  return {
134
172
  error: `The '${argv[i]}' curl flag is not currently supported by StepZen CLI.` +
135
173
  ` If this is a blocker for you, please let us know on Discord (${constants_1.STEPZEN_DISCORD_URL})`,
@@ -159,7 +197,7 @@ exports.parseCurlArgv = (argv) => {
159
197
  };
160
198
  }
161
199
  result.headers = result.headers || [];
162
- result.method = result.method || result.data ? 'Post' : 'Get';
200
+ result.method = result.method || (result.data ? 'Post' : 'Get');
163
201
  // Add the default content-type header if the request has any data
164
202
  // in it, and no content-type header is explicitly provided.
165
203
  if (result.headers.findIndex(header => header.name.toLowerCase() === 'content-type') === -1 &&
@@ -1 +1 @@
1
- {"version":"0.13.0-beta.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":[]}}}
1
+ {"version":"0.13.0-beta.1","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.13.0-beta.0",
4
+ "version": "0.13.0-beta.1",
5
5
  "license": "MIT",
6
6
  "author": "Darren Waddell <darren@stepzen.com>",
7
7
  "contributors": [