stepzen 0.9.39-beta.1 → 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 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.1 darwin-x64 node-v14.18.3
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
@@ -91,11 +91,15 @@ USAGE
91
91
  $ stepzen import SCHEMAS
92
92
 
93
93
  OPTIONS
94
- -h, --help show CLI help
95
- --dir=dir working directory
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.
96
101
 
97
- --name=name subfolder inside the schema folder to save the imported schema files, defaults to the imported schema
98
- name
102
+ --root-type=root-type [curl] type name for the root type returned by the cURL endpoint in the generated schema.
99
103
  ```
100
104
 
101
105
  ## `stepzen list TYPE`
@@ -54,6 +54,8 @@ class Import extends command_1.Command {
54
54
  argv,
55
55
  name: flags.name,
56
56
  source: workspace.schema,
57
+ queryName: flags['query-name'],
58
+ rootType: flags['root-type'],
57
59
  });
58
60
  cli_ux_1.cli.action.stop();
59
61
  if ('error' in resultOrError) {
@@ -65,6 +67,12 @@ class Import extends command_1.Command {
65
67
  result = resultOrError.outPath;
66
68
  }
67
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
+ });
68
76
  // Make sure the user has latest Generator Schema
69
77
  await deploy_1.default.run([
70
78
  constants_1.STEPZEN_GENERATOR_ENGINES_ENDPOINT,
@@ -94,9 +102,17 @@ Import.flags = {
94
102
  help: command_1.flags.help({ char: 'h' }),
95
103
  silent: command_1.flags.boolean({ hidden: true }),
96
104
  name: command_1.flags.string({
97
- description: 'subfolder inside the schema folder to save the imported' +
105
+ description: 'subfolder inside the workspace folder to save the imported' +
98
106
  ' schema files, defaults to the imported schema name',
99
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
+ }),
100
116
  };
101
117
  Import.args = [
102
118
  {
@@ -1,8 +1,15 @@
1
- export declare const curl2sdl: ({ argv, name, source, }: {
1
+ export declare type Curl2SdlOptions = {
2
2
  argv: readonly string[];
3
3
  name: string;
4
4
  source: string;
5
- }) => Promise<{
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<{
6
13
  error: string;
7
14
  } | {
8
15
  outPath: string;
@@ -2,31 +2,72 @@
2
2
  // Copyright (c) 2020,2021,2022, StepZen, Inc.
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.curl2sdl = void 0;
5
+ const parser_1 = require("@oclif/parser");
6
+ const errors_1 = require("@oclif/errors");
5
7
  const fs = require("fs-extra");
6
8
  const os = require("os");
7
9
  const path = require("path");
8
10
  const node_fetch_1 = require("node-fetch");
9
11
  const debug = require("debug");
10
12
  const prettier = require("prettier");
11
- const errors_1 = require("@oclif/errors");
12
13
  const constants_1 = require("../shared/constants");
13
14
  const errors_2 = require("../shared/errors");
14
15
  const transpiler_1 = require("@stepzen/transpiler");
15
- exports.curl2sdl = async ({ argv, name, source, }) => {
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, }) => {
16
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
+ [];
17
45
  try {
18
46
  const url = `${constants_1.STEPZEN_JSON2SDL_SERVER_URL}/api/graphql`;
19
47
  const headers = {
20
48
  'Content-Type': 'application/json',
21
49
  };
22
- const query = `query ($command: String!) {
23
- getSDLFromCurl(command: $command, rootType: "Root") {
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
+ ) {
24
62
  sdl
25
63
  config
26
64
  }
27
65
  }`;
28
66
  const variables = {
29
- command: argv.join(' '),
67
+ command: args.url,
68
+ queryName: queryName || null,
69
+ rootType: rootType || null,
70
+ headers: curlHeaders.length > 0 ? curlHeaders : null,
30
71
  };
31
72
  debug('stepzen:curl2sdl')(url);
32
73
  debug('stepzen:curl2sdl')(query);
@@ -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;
@@ -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
+ };
@@ -1 +1 @@
1
- {"version":"0.9.39-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 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 schema folder to save the imported schema files, defaults to the imported schema name"}},"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.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.39-beta.1",
4
+ "version": "0.9.39-beta.2",
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.36",
34
- "@stepzen/sdk": "0.9.44",
35
- "@stepzen/transpiler": "0.0.36",
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
38
  "cli-ux": "^6.0.9",