stepzen 0.19.0-beta.0 → 0.19.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 +13 -3
- package/lib/commands/deploy.js +1 -1
- package/lib/commands/import.d.ts +19 -6
- package/lib/commands/import.js +124 -74
- package/lib/commands/init.js +2 -2
- package/lib/commands/lint.js +2 -2
- package/lib/commands/list.js +1 -1
- package/lib/commands/login.js +3 -3
- package/lib/commands/logout.js +1 -1
- package/lib/commands/start.js +14 -12
- package/lib/commands/transpile.js +5 -5
- package/lib/commands/upload.js +1 -1
- package/lib/commands/validate.js +6 -4
- package/lib/commands/whoami.js +3 -3
- package/lib/generate/curl2sdl.d.ts +2 -2
- package/lib/generate/curl2sdl.js +24 -15
- package/lib/generate/graphql2sdl.d.ts +3 -3
- package/lib/generate/graphql2sdl.js +19 -5
- package/lib/generate/helpers.d.ts +7 -1
- package/lib/generate/helpers.js +39 -21
- package/lib/generate/index.js +6 -6
- package/lib/generate/sql2sdl.d.ts +6 -5
- package/lib/generate/sql2sdl.js +37 -10
- package/lib/hooks/prerun/check-upgrade.js +13 -10
- package/lib/hooks/prerun/ensure-config-file.js +3 -3
- package/lib/index.js +1 -0
- package/lib/shared/actions.js +9 -6
- package/lib/shared/configuration.js +20 -14
- package/lib/shared/constants.d.ts +3 -0
- package/lib/shared/constants.js +17 -5
- package/lib/shared/curl-parser.js +3 -2
- package/lib/shared/errors.js +2 -1
- package/lib/shared/header-params-parser.js +6 -4
- package/lib/shared/header.js +2 -1
- package/lib/shared/moniker.js +5 -3
- package/lib/shared/path-params-parser.d.ts +1 -1
- package/lib/shared/path-params-parser.js +5 -3
- package/lib/shared/stepzen-sdk.d.ts +1 -1
- package/lib/shared/stepzen-sdk.js +1 -1
- package/lib/shared/utils.d.ts +1 -0
- package/lib/shared/utils.js +22 -8
- package/lib/shared/validation.js +4 -2
- package/lib/shared/workspace.js +21 -16
- package/lib/shared/zen-command.js +7 -7
- package/lib/start/console.d.ts +1 -1
- package/lib/start/console.js +16 -9
- package/lib/start/index.js +1 -0
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
|
@@ -13,7 +13,7 @@ const errors_1 = require("../../shared/errors");
|
|
|
13
13
|
const majorRegexp = /\d+\./;
|
|
14
14
|
const timeoutBeta = 1000 * 60 * 60 * 24; // one day
|
|
15
15
|
const timeoutStable = 7 * timeoutBeta; // one week
|
|
16
|
-
|
|
16
|
+
const compareMajorVersions = (v1, v2) => {
|
|
17
17
|
const v1Major = v1.match(majorRegexp);
|
|
18
18
|
const v2Major = v2.match(majorRegexp);
|
|
19
19
|
if (!v1Major || !v2Major) {
|
|
@@ -22,7 +22,8 @@ exports.compareMajorVersions = (v1, v2) => {
|
|
|
22
22
|
}
|
|
23
23
|
return parseInt(v1Major[0], 10) - parseInt(v2Major[0], 10);
|
|
24
24
|
};
|
|
25
|
-
exports.
|
|
25
|
+
exports.compareMajorVersions = compareMajorVersions;
|
|
26
|
+
const shouldCheckVersion = (version) => {
|
|
26
27
|
if (!fs.existsSync(constants_1.STEPZEN_LAST_UPDATE_CHECK_TIMESTAMP)) {
|
|
27
28
|
// always check for a new version if the file does not exist
|
|
28
29
|
return true;
|
|
@@ -31,18 +32,19 @@ exports.shouldCheckVersion = (version) => {
|
|
|
31
32
|
const threshold = version.includes('beta') ? timeoutBeta : timeoutStable;
|
|
32
33
|
return new Date().getTime() - mtime.getTime() > threshold;
|
|
33
34
|
};
|
|
34
|
-
exports.
|
|
35
|
-
|
|
35
|
+
exports.shouldCheckVersion = shouldCheckVersion;
|
|
36
|
+
const checkUpgrade = async (version) => {
|
|
37
|
+
if (!(0, exports.shouldCheckVersion)(version)) {
|
|
36
38
|
return { message: undefined, isBlocking: false };
|
|
37
39
|
}
|
|
38
40
|
let versions;
|
|
39
41
|
try {
|
|
40
|
-
const pkgmeta = await node_fetch_1.default('https://registry.npmjs.org/stepzen').then(r => r.json());
|
|
42
|
+
const pkgmeta = await (0, node_fetch_1.default)('https://registry.npmjs.org/stepzen').then(r => r.json());
|
|
41
43
|
versions = pkgmeta['dist-tags'];
|
|
42
44
|
}
|
|
43
45
|
catch (error) {
|
|
44
46
|
// cannot connect to npm -> proceed
|
|
45
|
-
debug_1.default('stepzen:check-upgrade')('failed to get the stepzen version info from npm', error);
|
|
47
|
+
(0, debug_1.default)('stepzen:check-upgrade')('failed to get the stepzen version info from npm', error);
|
|
46
48
|
return { message: undefined, isBlocking: false };
|
|
47
49
|
}
|
|
48
50
|
let beta = false;
|
|
@@ -70,9 +72,9 @@ ${diff}
|
|
|
70
72
|
${chalk.green('npm install -g stepzen')}
|
|
71
73
|
`;
|
|
72
74
|
}
|
|
73
|
-
const versionCmpLatest = exports.compareMajorVersions(version, latest);
|
|
75
|
+
const versionCmpLatest = (0, exports.compareMajorVersions)(version, latest);
|
|
74
76
|
if (typeof versionCmpLatest === 'string') {
|
|
75
|
-
debug_1.default('stepzen:check-upgrade')(versionCmpLatest);
|
|
77
|
+
(0, debug_1.default)('stepzen:check-upgrade')(versionCmpLatest);
|
|
76
78
|
result.message = errors_1.UPGRADE_CHECK_ERROR;
|
|
77
79
|
result.isBlocking = true;
|
|
78
80
|
}
|
|
@@ -89,11 +91,12 @@ ${chalk.green('npm install -g stepzen')}
|
|
|
89
91
|
}
|
|
90
92
|
return result;
|
|
91
93
|
};
|
|
94
|
+
exports.checkUpgrade = checkUpgrade;
|
|
92
95
|
const hook = async function (options) {
|
|
93
|
-
const { message, isBlocking } = await exports.checkUpgrade(this.config.version);
|
|
96
|
+
const { message, isBlocking } = await (0, exports.checkUpgrade)(this.config.version);
|
|
94
97
|
// parse the command line to get `flags['non-interactive']`
|
|
95
98
|
const TheCommand = options.Command;
|
|
96
|
-
const { flags } = parser_1.parse(options.argv, Object.assign({ context: Object.assign(Object.assign({}, this), { _help: () => {
|
|
99
|
+
const { flags } = (0, parser_1.parse)(options.argv, Object.assign({ context: Object.assign(Object.assign({}, this), { _help: () => {
|
|
97
100
|
// workaround for https://github.com/steprz/stepzen-cli/issues/637
|
|
98
101
|
} }) }, TheCommand));
|
|
99
102
|
// In a non-interactive shell only print the upgrade nudge if the upgrade
|
|
@@ -14,14 +14,14 @@ const hook = async function () {
|
|
|
14
14
|
const configFilePath = path.join(constants_1.STEPZEN_CONFIG_DIRECTORY, constants_1.STEPZEN_CONFIG_FILE);
|
|
15
15
|
let rawConfiguration;
|
|
16
16
|
try {
|
|
17
|
-
rawConfiguration = await configuration_1.importConfiguration(configFilePath);
|
|
17
|
+
rawConfiguration = await (0, configuration_1.importConfiguration)(configFilePath);
|
|
18
18
|
}
|
|
19
19
|
catch (_a) {
|
|
20
20
|
rawConfiguration = null;
|
|
21
21
|
}
|
|
22
|
-
const { configuration, modified } = await configuration_1.ensureValidConfiguration(rawConfiguration);
|
|
22
|
+
const { configuration, modified } = await (0, configuration_1.ensureValidConfiguration)(rawConfiguration);
|
|
23
23
|
if (modified) {
|
|
24
|
-
configuration_1.writeConfiguration(configuration);
|
|
24
|
+
(0, configuration_1.writeConfiguration)(configuration);
|
|
25
25
|
debug('stepzen:configuration')(`Automatically updated the ${configFilePath} config file.`);
|
|
26
26
|
}
|
|
27
27
|
};
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.run = void 0;
|
|
4
5
|
var command_1 = require("@oclif/command");
|
|
5
6
|
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return command_1.run; } });
|
package/lib/shared/actions.js
CHANGED
|
@@ -5,8 +5,8 @@ exports.upload = exports.list = exports.deploy = void 0;
|
|
|
5
5
|
const configuration_1 = require("./configuration");
|
|
6
6
|
const constants_1 = require("./constants");
|
|
7
7
|
const stepzen_sdk_1 = require("./stepzen-sdk");
|
|
8
|
-
|
|
9
|
-
const config = (await configuration_1.readConfiguration());
|
|
8
|
+
const deploy = async (destination, configurationsets, schema) => {
|
|
9
|
+
const config = (await (0, configuration_1.readConfiguration)());
|
|
10
10
|
const server = constants_1.STEPZEN_SERVER_URL.replace('{account}', config.account);
|
|
11
11
|
const client = await stepzen_sdk_1.default.client({
|
|
12
12
|
account: config.account,
|
|
@@ -20,8 +20,9 @@ exports.deploy = async (destination, configurationsets, schema) => {
|
|
|
20
20
|
}
|
|
21
21
|
return client.deploy(destination, payload);
|
|
22
22
|
};
|
|
23
|
-
exports.
|
|
24
|
-
|
|
23
|
+
exports.deploy = deploy;
|
|
24
|
+
const list = async (type) => {
|
|
25
|
+
const config = (await (0, configuration_1.readConfiguration)());
|
|
25
26
|
const server = constants_1.STEPZEN_SERVER_URL.replace('{account}', config.account);
|
|
26
27
|
const client = await stepzen_sdk_1.default.client({
|
|
27
28
|
account: config.account,
|
|
@@ -31,8 +32,9 @@ exports.list = async (type) => {
|
|
|
31
32
|
});
|
|
32
33
|
return client.list[type]();
|
|
33
34
|
};
|
|
34
|
-
exports.
|
|
35
|
-
|
|
35
|
+
exports.list = list;
|
|
36
|
+
const upload = async (type, destination, source) => {
|
|
37
|
+
const config = (await (0, configuration_1.readConfiguration)());
|
|
36
38
|
const server = constants_1.STEPZEN_SERVER_URL.replace('{account}', config.account);
|
|
37
39
|
const client = await stepzen_sdk_1.default.client({
|
|
38
40
|
account: config.account,
|
|
@@ -42,3 +44,4 @@ exports.upload = async (type, destination, source) => {
|
|
|
42
44
|
});
|
|
43
45
|
return client.upload[type](destination, source);
|
|
44
46
|
};
|
|
47
|
+
exports.upload = upload;
|
|
@@ -26,7 +26,7 @@ const configFilePath = path.join(constants_1.STEPZEN_CONFIG_DIRECTORY, constants
|
|
|
26
26
|
*
|
|
27
27
|
* @param {*} maybeConfiguration raw contents of the configuration file
|
|
28
28
|
*/
|
|
29
|
-
|
|
29
|
+
const ensureValidConfiguration = async (maybeConfiguration) => {
|
|
30
30
|
let modified = false;
|
|
31
31
|
const configuration = Object.assign({}, maybeConfiguration);
|
|
32
32
|
// ensure configuration exists
|
|
@@ -35,7 +35,7 @@ exports.ensureValidConfiguration = async (maybeConfiguration) => {
|
|
|
35
35
|
}
|
|
36
36
|
// ensure configuration has a UUID
|
|
37
37
|
if (!configuration.uuid) {
|
|
38
|
-
configuration.uuid = uuid_1.v4();
|
|
38
|
+
configuration.uuid = (0, uuid_1.v4)();
|
|
39
39
|
debug('stepzen:configuration')(`Generated a new machine UUID: ${configuration.uuid}`);
|
|
40
40
|
modified = true;
|
|
41
41
|
}
|
|
@@ -65,7 +65,8 @@ exports.ensureValidConfiguration = async (maybeConfiguration) => {
|
|
|
65
65
|
modified,
|
|
66
66
|
};
|
|
67
67
|
};
|
|
68
|
-
exports.
|
|
68
|
+
exports.ensureValidConfiguration = ensureValidConfiguration;
|
|
69
|
+
const importConfiguration = async (filepath) => {
|
|
69
70
|
if (!fs.existsSync(filepath)) {
|
|
70
71
|
throw new errors_1.CLIError('Configuration file does not exist');
|
|
71
72
|
}
|
|
@@ -77,7 +78,8 @@ exports.importConfiguration = async (filepath) => {
|
|
|
77
78
|
throw new errors_1.CLIError('Configuration file is not valid yaml');
|
|
78
79
|
}
|
|
79
80
|
};
|
|
80
|
-
exports.
|
|
81
|
+
exports.importConfiguration = importConfiguration;
|
|
82
|
+
const readConfiguration = async () => {
|
|
81
83
|
let maybeConfiguration = null;
|
|
82
84
|
// If the configuration comes from an env var, use it
|
|
83
85
|
if (process.env.STEPZEN_CONFIG_CONTENT) {
|
|
@@ -90,17 +92,18 @@ exports.readConfiguration = async () => {
|
|
|
90
92
|
}
|
|
91
93
|
else {
|
|
92
94
|
try {
|
|
93
|
-
maybeConfiguration = await exports.importConfiguration(configFilePath);
|
|
95
|
+
maybeConfiguration = await (0, exports.importConfiguration)(configFilePath);
|
|
94
96
|
}
|
|
95
97
|
catch (error) {
|
|
96
98
|
debug('stepzen:configuration')(`Could not read the config file at ${configFilePath}: ${error}`);
|
|
97
99
|
}
|
|
98
100
|
}
|
|
99
|
-
const { configuration } = await exports.ensureValidConfiguration(maybeConfiguration);
|
|
101
|
+
const { configuration } = await (0, exports.ensureValidConfiguration)(maybeConfiguration);
|
|
100
102
|
debug('stepzen:configuration')(configuration);
|
|
101
103
|
return configuration;
|
|
102
104
|
};
|
|
103
|
-
exports.
|
|
105
|
+
exports.readConfiguration = readConfiguration;
|
|
106
|
+
const writeConfiguration = async (configuration) => {
|
|
104
107
|
// Generate YAML from the configuration
|
|
105
108
|
const content = yaml.stringify(configuration);
|
|
106
109
|
// Check that the configuration directory exists. If not, create it.
|
|
@@ -109,19 +112,22 @@ exports.writeConfiguration = async (configuration) => {
|
|
|
109
112
|
}
|
|
110
113
|
// Write the configuration file. Overwrites if it already exists.
|
|
111
114
|
fs.writeFileSync(configFilePath, content, { mode: '600' });
|
|
112
|
-
return exports.readConfiguration();
|
|
115
|
+
return (0, exports.readConfiguration)();
|
|
113
116
|
};
|
|
114
|
-
exports.
|
|
115
|
-
|
|
117
|
+
exports.writeConfiguration = writeConfiguration;
|
|
118
|
+
const writeCredentialsToConfigFile = async (credentials) => {
|
|
119
|
+
const oldConfig = await (0, exports.readConfiguration)();
|
|
116
120
|
const newConfig = Object.assign(Object.assign({}, oldConfig), credentials);
|
|
117
|
-
const writtenConfig = await exports.writeConfiguration(newConfig);
|
|
121
|
+
const writtenConfig = await (0, exports.writeConfiguration)(newConfig);
|
|
118
122
|
return Object.assign(Object.assign({}, newConfig), writtenConfig);
|
|
119
123
|
};
|
|
120
|
-
exports.
|
|
121
|
-
|
|
124
|
+
exports.writeCredentialsToConfigFile = writeCredentialsToConfigFile;
|
|
125
|
+
const removeCredentialsFromConfigFile = async () => {
|
|
126
|
+
const configuration = await (0, exports.readConfiguration)();
|
|
122
127
|
delete configuration.account;
|
|
123
128
|
delete configuration.apikey;
|
|
124
129
|
delete configuration.adminkey;
|
|
125
|
-
await exports.writeConfiguration(configuration);
|
|
130
|
+
await (0, exports.writeConfiguration)(configuration);
|
|
126
131
|
return configuration;
|
|
127
132
|
};
|
|
133
|
+
exports.removeCredentialsFromConfigFile = removeCredentialsFromConfigFile;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare const appendPathnameIfEmpty: (url: string, path: string) => string;
|
|
1
2
|
export declare const STEPZEN_CONFIG_DIRECTORY: string;
|
|
2
3
|
export declare const STEPZEN_LAST_UPDATE_CHECK_TIMESTAMP: string;
|
|
3
4
|
export declare const STEPZEN_CONFIG_FILE: string;
|
|
@@ -12,3 +13,5 @@ export declare const ADMIN_ACCOUNT_URL = "/cli/admin/account";
|
|
|
12
13
|
export declare const STEPZEN_JSON2SDL_SERVER_URL: string;
|
|
13
14
|
export declare const STEPZEN_DBINTROSPECTION_SERVER_URL: string;
|
|
14
15
|
export declare const STEPZEN_DISCORD_URL = "https://discord.gg/9k2VdPn2FR";
|
|
16
|
+
export declare const DETECT_NAME_CONFLICTS = "STEPZEN_DETECT_NAME_CONFLICTS";
|
|
17
|
+
export declare const USE_GENERATOR_ENGINES = "STEPZEN_USE_GENERATOR_ENGINES";
|
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_DISCORD_URL = exports.STEPZEN_DBINTROSPECTION_SERVER_URL = exports.STEPZEN_JSON2SDL_SERVER_URL = exports.ADMIN_ACCOUNT_URL = exports.ADMIN_UPLOAD_URL = exports.ADMIN_LIST_URL = exports.ADMIN_DEPLOY_URL = exports.STEPZEN_API_TEMPLATES_REPOSITORY = exports.STEPZEN_DIRECT_GENERATOR_ENGINES_URL = 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.USE_GENERATOR_ENGINES = exports.DETECT_NAME_CONFLICTS = exports.STEPZEN_DISCORD_URL = exports.STEPZEN_DBINTROSPECTION_SERVER_URL = exports.STEPZEN_JSON2SDL_SERVER_URL = exports.ADMIN_ACCOUNT_URL = exports.ADMIN_UPLOAD_URL = exports.ADMIN_LIST_URL = exports.ADMIN_DEPLOY_URL = exports.STEPZEN_API_TEMPLATES_REPOSITORY = exports.STEPZEN_DIRECT_GENERATOR_ENGINES_URL = exports.STEPZEN_SERVER_URL = exports.STEPZEN_DOMAIN = exports.STEPZEN_CONFIG_FILE = exports.STEPZEN_LAST_UPDATE_CHECK_TIMESTAMP = exports.STEPZEN_CONFIG_DIRECTORY = exports.appendPathnameIfEmpty = void 0;
|
|
5
5
|
// This file contains constants and all magic strings
|
|
6
6
|
const dotenv = require("dotenv");
|
|
7
7
|
const os = require("os");
|
|
@@ -10,6 +10,16 @@ const path = require("path");
|
|
|
10
10
|
// This file needs to be in your working directory.
|
|
11
11
|
dotenv.config();
|
|
12
12
|
const { STEPZEN_CONFIG_FILE: ENV_VAR_STEPZEN_CONFIG_FILE, STEPZEN_DOMAIN: ENV_VAR_STEPZEN_DOMAIN, STEPZEN_SERVER_URL: ENV_VAR_STEPZEN_SERVER_URL, STEPZEN_JSON2SDL_SERVER_URL: ENV_VAR_STEPZEN_JSON2SDL_SERVER_URL, STEPZEN_DBINTROSPECTION_SERVER_URL: ENV_VAR_DBINTROSPECTION_SERVER_URL, STEPZEN_DIRECT_GENERATOR_ENGINES_URL: ENV_VAR_STEPZEN_DIRECT_GENERATOR_ENGINES_URL, } = process.env;
|
|
13
|
+
// moved out of utils.ts to avoid circular dependency between utils.ts and constants.ts
|
|
14
|
+
const appendPathnameIfEmpty = (url, path) => {
|
|
15
|
+
const parsedUrl = new URL(url);
|
|
16
|
+
if (parsedUrl.pathname === '/') {
|
|
17
|
+
parsedUrl.pathname = path;
|
|
18
|
+
return parsedUrl.toString();
|
|
19
|
+
}
|
|
20
|
+
return url;
|
|
21
|
+
};
|
|
22
|
+
exports.appendPathnameIfEmpty = appendPathnameIfEmpty;
|
|
13
23
|
// Where your authentication details are stored locally
|
|
14
24
|
exports.STEPZEN_CONFIG_DIRECTORY = path.join(os.homedir(), '.stepzen');
|
|
15
25
|
exports.STEPZEN_LAST_UPDATE_CHECK_TIMESTAMP = path.join(exports.STEPZEN_CONFIG_DIRECTORY, 'last_update_check.timestamp');
|
|
@@ -28,8 +38,10 @@ exports.ADMIN_DEPLOY_URL = '/cli/admin/deploy';
|
|
|
28
38
|
exports.ADMIN_LIST_URL = '/cli/admin/list';
|
|
29
39
|
exports.ADMIN_UPLOAD_URL = '/cli/admin/upload';
|
|
30
40
|
exports.ADMIN_ACCOUNT_URL = '/cli/admin/account';
|
|
31
|
-
exports.STEPZEN_JSON2SDL_SERVER_URL = ENV_VAR_STEPZEN_JSON2SDL_SERVER_URL ||
|
|
32
|
-
'https://jsonintrospection-ng-prod-xynkgeaaaa-uc.a.run.app/api/graphql';
|
|
33
|
-
exports.STEPZEN_DBINTROSPECTION_SERVER_URL = ENV_VAR_DBINTROSPECTION_SERVER_URL ||
|
|
34
|
-
'https://dbintrospection-prod-xynkgeaaaa-uc.a.run.app/graphql';
|
|
41
|
+
exports.STEPZEN_JSON2SDL_SERVER_URL = (0, exports.appendPathnameIfEmpty)(ENV_VAR_STEPZEN_JSON2SDL_SERVER_URL ||
|
|
42
|
+
'https://jsonintrospection-ng-prod-xynkgeaaaa-uc.a.run.app', '/api/graphql');
|
|
43
|
+
exports.STEPZEN_DBINTROSPECTION_SERVER_URL = (0, exports.appendPathnameIfEmpty)(ENV_VAR_DBINTROSPECTION_SERVER_URL ||
|
|
44
|
+
'https://dbintrospection-prod-xynkgeaaaa-uc.a.run.app', '/graphql');
|
|
35
45
|
exports.STEPZEN_DISCORD_URL = 'https://discord.gg/9k2VdPn2FR';
|
|
46
|
+
exports.DETECT_NAME_CONFLICTS = 'STEPZEN_DETECT_NAME_CONFLICTS';
|
|
47
|
+
exports.USE_GENERATOR_ENGINES = 'STEPZEN_USE_GENERATOR_ENGINES';
|
|
@@ -10,7 +10,7 @@ const httpURLRegex = /^https?:\/\//i;
|
|
|
10
10
|
const isAFlagArg = (arg) => curlFlagRegex.test(arg);
|
|
11
11
|
const isAURL = (arg) => httpURLRegex.test(arg);
|
|
12
12
|
const parseHeaderFlag = (value, partialCurlArgs) => {
|
|
13
|
-
const headerOrError = header_1.parseHeader(value);
|
|
13
|
+
const headerOrError = (0, header_1.parseHeader)(value);
|
|
14
14
|
if (headerOrError && 'error' in headerOrError) {
|
|
15
15
|
return headerOrError; // error
|
|
16
16
|
}
|
|
@@ -117,7 +117,7 @@ const tryMatchCurlFlag = (matches, argv, i) => {
|
|
|
117
117
|
* ]`
|
|
118
118
|
* @returns {*} a structured object with the curl arguments
|
|
119
119
|
*/
|
|
120
|
-
|
|
120
|
+
const parseCurlArgv = (argv) => {
|
|
121
121
|
var _a;
|
|
122
122
|
if (((_a = argv[0]) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'curl') {
|
|
123
123
|
argv = argv.slice(1);
|
|
@@ -186,3 +186,4 @@ exports.parseCurlArgv = (argv) => {
|
|
|
186
186
|
}
|
|
187
187
|
return result;
|
|
188
188
|
};
|
|
189
|
+
exports.parseCurlArgv = parseCurlArgv;
|
package/lib/shared/errors.js
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.UPGRADE_CHECK_ERROR = exports.PERMANENT_STEPZEN_ERROR = exports.formatTemporaryErrorMessage = void 0;
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
|
-
|
|
6
|
+
const formatTemporaryErrorMessage = (errors) => `A problem occurred while processing your import${errors.length > 0 && errors[0].message ? `: "${errors[0].message}"` : ''}. Please try again.` +
|
|
7
7
|
` If the issue persists, make sure you are on the latest version of StepZen ` +
|
|
8
8
|
`CLI. And if the issue still persists contact support via the StepZen discord ` +
|
|
9
9
|
`channel (${constants_1.STEPZEN_DISCORD_URL}).`;
|
|
10
|
+
exports.formatTemporaryErrorMessage = formatTemporaryErrorMessage;
|
|
10
11
|
exports.PERMANENT_STEPZEN_ERROR = 'An unexpected problem occurred while processing your import.' +
|
|
11
12
|
` If the issue persists, make sure you are on the latest version of StepZen ` +
|
|
12
13
|
`CLI. And if the issue still persists contact support via the StepZen discord ` +
|
|
@@ -6,8 +6,8 @@ const chalk = require("chalk");
|
|
|
6
6
|
const debug = require("debug");
|
|
7
7
|
const header_1 = require("./header");
|
|
8
8
|
const headerParamRegex = /^(?<prefix>([^$]|\$\$)*)(?<param>\$[_A-Za-z]\w*);?(?<suffix>.*)$/;
|
|
9
|
-
|
|
10
|
-
const headerOrError = header_1.parseHeader(headerParam);
|
|
9
|
+
const parseHeaderParam = (headers, headerParam) => {
|
|
10
|
+
const headerOrError = (0, header_1.parseHeader)(headerParam);
|
|
11
11
|
if (!headerOrError || 'error' in headerOrError) {
|
|
12
12
|
if (headerOrError) {
|
|
13
13
|
debug('stepzen:curl2sdl')(`Failed to parse a header param ${headerParam}.` +
|
|
@@ -92,11 +92,12 @@ exports.parseHeaderParam = (headers, headerParam) => {
|
|
|
92
92
|
remainingHeaders: headers.filter(h => h !== matches[0]),
|
|
93
93
|
};
|
|
94
94
|
};
|
|
95
|
-
exports.
|
|
95
|
+
exports.parseHeaderParam = parseHeaderParam;
|
|
96
|
+
const makeHeaders = (curlHeaders, headerParams = []) => {
|
|
96
97
|
const headers = [];
|
|
97
98
|
let remainingCurlHeaders = curlHeaders;
|
|
98
99
|
for (const headerParam of headerParams) {
|
|
99
|
-
const resultOrError = exports.parseHeaderParam(remainingCurlHeaders, headerParam);
|
|
100
|
+
const resultOrError = (0, exports.parseHeaderParam)(remainingCurlHeaders, headerParam);
|
|
100
101
|
if ('error' in resultOrError) {
|
|
101
102
|
return resultOrError;
|
|
102
103
|
}
|
|
@@ -106,3 +107,4 @@ exports.makeHeaders = (curlHeaders, headerParams = []) => {
|
|
|
106
107
|
headers.push(...remainingCurlHeaders);
|
|
107
108
|
return headers;
|
|
108
109
|
};
|
|
110
|
+
exports.makeHeaders = makeHeaders;
|
package/lib/shared/header.js
CHANGED
|
@@ -14,7 +14,7 @@ exports.HEADER_REGEX = /^(?<name>[a-zA-Z0-9!#$%&'*+,-.^_`|~]+)\s*:(?<value>.*)$/
|
|
|
14
14
|
* `null` for the `Header:` notation that means "remove this header" in
|
|
15
15
|
* the cURL spec or a error object if cannot parse the string.
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
const parseHeader = (header) => {
|
|
18
18
|
const trimmed = header.trim();
|
|
19
19
|
// Check if it's a `Header:` case
|
|
20
20
|
if (trimmed.indexOf(':') === trimmed.length - 1) {
|
|
@@ -41,3 +41,4 @@ exports.parseHeader = (header) => {
|
|
|
41
41
|
value: match.groups.value.trim(),
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
|
+
exports.parseHeader = parseHeader;
|
package/lib/shared/moniker.js
CHANGED
|
@@ -638,6 +638,8 @@ const descriptors = [
|
|
|
638
638
|
'zinc',
|
|
639
639
|
'zooming',
|
|
640
640
|
];
|
|
641
|
-
|
|
642
|
-
exports.
|
|
643
|
-
|
|
641
|
+
const getRandomAnimal = () => animals[(0, lodash_1.random)(0, animals.length - 1)];
|
|
642
|
+
exports.getRandomAnimal = getRandomAnimal;
|
|
643
|
+
const getRandomDescriptor = () => descriptors[(0, lodash_1.random)(0, descriptors.length - 1)];
|
|
644
|
+
exports.getRandomDescriptor = getRandomDescriptor;
|
|
645
|
+
exports.default = () => `${(0, exports.getRandomDescriptor)()}-${(0, exports.getRandomAnimal)()}`;
|
|
@@ -4,4 +4,4 @@ export declare type PathParam = {
|
|
|
4
4
|
name: string;
|
|
5
5
|
};
|
|
6
6
|
export declare const formatPatternDiffWithPath: (patternSegments: readonly string[], pathSegments: readonly string[]) => string | null;
|
|
7
|
-
export declare const parsePathParamsPattern: (url: string, pathParamsPattern?: string
|
|
7
|
+
export declare const parsePathParamsPattern: (url: string, pathParamsPattern?: string) => PathParam[] | ParseError;
|
|
@@ -6,7 +6,7 @@ const chalk = require("chalk");
|
|
|
6
6
|
const pathParamRegex = /^\$[_A-Za-z]\w*$/;
|
|
7
7
|
// in a literal segment, $ should be escaped as $$
|
|
8
8
|
const pathSegmentRegex = /^([^$]|\$\$)+$/;
|
|
9
|
-
|
|
9
|
+
const formatPatternDiffWithPath = (patternSegments, pathSegments) => {
|
|
10
10
|
let hasErrors = false;
|
|
11
11
|
const diff = [];
|
|
12
12
|
for (let i = 0; i < patternSegments.length; i++) {
|
|
@@ -39,7 +39,8 @@ exports.formatPatternDiffWithPath = (patternSegments, pathSegments) => {
|
|
|
39
39
|
}
|
|
40
40
|
return hasErrors ? diff.join('/') : null;
|
|
41
41
|
};
|
|
42
|
-
exports.
|
|
42
|
+
exports.formatPatternDiffWithPath = formatPatternDiffWithPath;
|
|
43
|
+
const parsePathParamsPattern = (url, pathParamsPattern) => {
|
|
43
44
|
if (!pathParamsPattern) {
|
|
44
45
|
return [];
|
|
45
46
|
}
|
|
@@ -52,7 +53,7 @@ exports.parsePathParamsPattern = (url, pathParamsPattern) => {
|
|
|
52
53
|
}
|
|
53
54
|
const pathSegments = pathname.split('/');
|
|
54
55
|
const patternSegments = pathParamsPattern.split('/');
|
|
55
|
-
const maybeDiff = exports.formatPatternDiffWithPath(patternSegments, pathSegments);
|
|
56
|
+
const maybeDiff = (0, exports.formatPatternDiffWithPath)(patternSegments, pathSegments);
|
|
56
57
|
if (maybeDiff) {
|
|
57
58
|
return {
|
|
58
59
|
error: `Path parameters do not align with the URL path: /${maybeDiff}`,
|
|
@@ -79,3 +80,4 @@ exports.parsePathParamsPattern = (url, pathParamsPattern) => {
|
|
|
79
80
|
}));
|
|
80
81
|
return retval;
|
|
81
82
|
};
|
|
83
|
+
exports.parsePathParamsPattern = parsePathParamsPattern;
|
|
@@ -3,7 +3,7 @@ declare const stepzen: {
|
|
|
3
3
|
login: (adminkey: string, account?: string) => Promise<StepZenCredentials>;
|
|
4
4
|
createAnonymousAccount: (uuid: string) => Promise<StepZenCredentials>;
|
|
5
5
|
verify: (account: string, adminkey: string) => Promise<boolean>;
|
|
6
|
-
client: (options: import("@stepzen/sdk/lib/client").
|
|
6
|
+
client: (options: import("@stepzen/sdk/lib/client").UserCredentialsClientOptions | import("@stepzen/sdk/lib/client").AnonymousClientOptions) => Promise<{
|
|
7
7
|
readonly credentials: {
|
|
8
8
|
account: string;
|
|
9
9
|
adminkey: string;
|
|
@@ -5,7 +5,7 @@ const errors_1 = require("@oclif/errors");
|
|
|
5
5
|
const sdk_1 = require("@stepzen/sdk");
|
|
6
6
|
const constants_1 = require("./constants");
|
|
7
7
|
const { version } = require('../../package.json');
|
|
8
|
-
const stepzen = Object.assign(Object.assign({}, sdk_1.init({ appName: `stepzen-cli/${version}` })), { login: async (adminkey, account = adminkey.split(':')[0]) => {
|
|
8
|
+
const stepzen = Object.assign(Object.assign({}, (0, sdk_1.init)({ appName: `stepzen-cli/${version}` })), { login: async (adminkey, account = adminkey.split(':')[0]) => {
|
|
9
9
|
try {
|
|
10
10
|
const client = await stepzen.client({
|
|
11
11
|
account,
|
package/lib/shared/utils.d.ts
CHANGED
|
@@ -17,3 +17,4 @@ export declare const workspaceRelative: (absPath: string, workspace: string) =>
|
|
|
17
17
|
export declare const getStepZenExtensions: () => Promise<string>;
|
|
18
18
|
export declare const validateEndpoint: (endpoint: string) => any;
|
|
19
19
|
export declare const maskStepZenKey: (key: string) => string;
|
|
20
|
+
export declare const getFeatureFlag: (flag: string) => boolean;
|
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.workspaceRelative = exports.homeRelative = exports.getDirectory = void 0;
|
|
4
|
+
exports.getFeatureFlag = exports.maskStepZenKey = exports.validateEndpoint = exports.getStepZenExtensions = exports.workspaceRelative = exports.homeRelative = exports.getDirectory = void 0;
|
|
5
5
|
const errors_1 = require("@oclif/errors");
|
|
6
6
|
const debug = require("debug");
|
|
7
7
|
const node_fetch_1 = require("node-fetch");
|
|
@@ -10,7 +10,7 @@ const os = require("os");
|
|
|
10
10
|
const path = require("path");
|
|
11
11
|
const prettier = require("prettier");
|
|
12
12
|
const constants_1 = require("./constants");
|
|
13
|
-
|
|
13
|
+
const getDirectory = (d = process.cwd()) => {
|
|
14
14
|
let directory = d;
|
|
15
15
|
// If it starts with `~`, expand this
|
|
16
16
|
if (directory.startsWith('~')) {
|
|
@@ -25,19 +25,21 @@ exports.getDirectory = (d = process.cwd()) => {
|
|
|
25
25
|
}
|
|
26
26
|
return directory;
|
|
27
27
|
};
|
|
28
|
+
exports.getDirectory = getDirectory;
|
|
28
29
|
/**
|
|
29
30
|
* Replace the path prefix with `~` if it is inside the user's home directory.
|
|
30
31
|
*
|
|
31
32
|
* @param {*} absPath an absolute file or directory path
|
|
32
33
|
* @returns {*} the same path that possibly looks more friendly to users
|
|
33
34
|
*/
|
|
34
|
-
|
|
35
|
+
const homeRelative = (absPath) => {
|
|
35
36
|
let pretty = absPath;
|
|
36
37
|
if (absPath.startsWith(os.homedir())) {
|
|
37
38
|
pretty = '~' + absPath.substring(os.homedir().length);
|
|
38
39
|
}
|
|
39
40
|
return pretty;
|
|
40
41
|
};
|
|
42
|
+
exports.homeRelative = homeRelative;
|
|
41
43
|
/**
|
|
42
44
|
* Replace the path prefix with `~` if it is inside the user's home directory.
|
|
43
45
|
*
|
|
@@ -45,24 +47,26 @@ exports.homeRelative = (absPath) => {
|
|
|
45
47
|
* @param {*} workspace an absolute file or the workspace root
|
|
46
48
|
* @returns {*} the same path that possibly looks more friendly to users
|
|
47
49
|
*/
|
|
48
|
-
|
|
50
|
+
const workspaceRelative = (absPath, workspace) => {
|
|
49
51
|
let pretty = absPath;
|
|
50
52
|
if (absPath.startsWith(workspace)) {
|
|
51
53
|
pretty = '.' + absPath.substring(workspace.length);
|
|
52
54
|
}
|
|
53
55
|
return pretty;
|
|
54
56
|
};
|
|
55
|
-
exports.
|
|
57
|
+
exports.workspaceRelative = workspaceRelative;
|
|
58
|
+
const getStepZenExtensions = async () => {
|
|
56
59
|
const domain = constants_1.STEPZEN_DOMAIN.replace('.io', '.net');
|
|
57
60
|
const url = `https://www.${domain}/directives.graphql`;
|
|
58
|
-
const response = await node_fetch_1.default(url);
|
|
61
|
+
const response = await (0, node_fetch_1.default)(url);
|
|
59
62
|
const schema = await response.text();
|
|
60
63
|
const formatted = prettier.format(schema, { parser: 'graphql' });
|
|
61
64
|
debug('stepzen:extensions')(`Fetching StepZen extensions from ${url}`);
|
|
62
65
|
debug('stepzen:extensions')(`Extensions: ${formatted}`);
|
|
63
66
|
return formatted;
|
|
64
67
|
};
|
|
65
|
-
exports.
|
|
68
|
+
exports.getStepZenExtensions = getStepZenExtensions;
|
|
69
|
+
const validateEndpoint = (endpoint) => {
|
|
66
70
|
const error = 'The endpoint must be of the format [folder]/[name], matching the pattern ^[\\w-]+$';
|
|
67
71
|
if (endpoint.includes('/') === false)
|
|
68
72
|
return error;
|
|
@@ -75,7 +79,8 @@ exports.validateEndpoint = (endpoint) => {
|
|
|
75
79
|
return error;
|
|
76
80
|
return true;
|
|
77
81
|
};
|
|
78
|
-
exports.
|
|
82
|
+
exports.validateEndpoint = validateEndpoint;
|
|
83
|
+
const maskStepZenKey = (key) => {
|
|
79
84
|
const parts = key.split('::');
|
|
80
85
|
const thirdPart = parts[2];
|
|
81
86
|
const firstTwoChars = thirdPart.substring(0, 2);
|
|
@@ -85,3 +90,12 @@ exports.maskStepZenKey = (key) => {
|
|
|
85
90
|
const masked = `${parts[0]}::${parts[1]}::${maskedThirdPart} `;
|
|
86
91
|
return masked;
|
|
87
92
|
};
|
|
93
|
+
exports.maskStepZenKey = maskStepZenKey;
|
|
94
|
+
const getFeatureFlag = (flag) => {
|
|
95
|
+
const value = process.env[flag];
|
|
96
|
+
if (value === undefined) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
return value.toLowerCase() !== 'false';
|
|
100
|
+
};
|
|
101
|
+
exports.getFeatureFlag = getFeatureFlag;
|
package/lib/shared/validation.js
CHANGED
|
@@ -7,7 +7,7 @@ const fs = require("fs");
|
|
|
7
7
|
const glob = require("glob");
|
|
8
8
|
const yaml = require("yaml");
|
|
9
9
|
// Validate the Configurationset file
|
|
10
|
-
|
|
10
|
+
const validateConfigurationset = async (file) => {
|
|
11
11
|
if (!file) {
|
|
12
12
|
throw new errors_1.CLIError('You must provide a file path');
|
|
13
13
|
}
|
|
@@ -23,8 +23,9 @@ exports.validateConfigurationset = async (file) => {
|
|
|
23
23
|
throw new errors_1.CLIError('The file is not valid YAML');
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
|
+
exports.validateConfigurationset = validateConfigurationset;
|
|
26
27
|
// Validate the Schema directory
|
|
27
|
-
|
|
28
|
+
const validateSchema = async (directory) => {
|
|
28
29
|
if (!directory) {
|
|
29
30
|
throw new errors_1.CLIError('You must provide a directory path');
|
|
30
31
|
}
|
|
@@ -37,3 +38,4 @@ exports.validateSchema = async (directory) => {
|
|
|
37
38
|
throw new errors_1.CLIError('Schemas must include an `index.graphql` file');
|
|
38
39
|
}
|
|
39
40
|
};
|
|
41
|
+
exports.validateSchema = validateSchema;
|