stepzen 0.18.0 → 0.19.0-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.
Files changed (50) hide show
  1. package/README.md +13 -3
  2. package/lib/commands/deploy.js +1 -1
  3. package/lib/commands/import.d.ts +21 -0
  4. package/lib/commands/import.js +208 -120
  5. package/lib/commands/init.js +2 -2
  6. package/lib/commands/lint.js +2 -2
  7. package/lib/commands/list.js +1 -1
  8. package/lib/commands/login.js +3 -3
  9. package/lib/commands/logout.js +1 -1
  10. package/lib/commands/start.js +14 -12
  11. package/lib/commands/transpile.js +5 -5
  12. package/lib/commands/upload.js +1 -1
  13. package/lib/commands/validate.js +6 -4
  14. package/lib/commands/whoami.js +3 -3
  15. package/lib/generate/curl2sdl.d.ts +4 -6
  16. package/lib/generate/curl2sdl.js +26 -17
  17. package/lib/generate/graphql2sdl.d.ts +5 -7
  18. package/lib/generate/graphql2sdl.js +21 -8
  19. package/lib/generate/helpers.d.ts +10 -2
  20. package/lib/generate/helpers.js +45 -22
  21. package/lib/generate/index.d.ts +5 -3
  22. package/lib/generate/index.js +6 -6
  23. package/lib/generate/sql2sdl.d.ts +23 -0
  24. package/lib/generate/sql2sdl.js +155 -0
  25. package/lib/hooks/prerun/check-upgrade.js +13 -10
  26. package/lib/hooks/prerun/ensure-config-file.js +3 -3
  27. package/lib/index.js +1 -0
  28. package/lib/shared/actions.js +9 -6
  29. package/lib/shared/configuration.js +20 -14
  30. package/lib/shared/constants.d.ts +4 -0
  31. package/lib/shared/constants.js +18 -4
  32. package/lib/shared/curl-parser.js +3 -2
  33. package/lib/shared/errors.js +2 -1
  34. package/lib/shared/header-params-parser.js +6 -4
  35. package/lib/shared/header.js +2 -1
  36. package/lib/shared/moniker.js +5 -3
  37. package/lib/shared/path-params-parser.d.ts +1 -1
  38. package/lib/shared/path-params-parser.js +5 -3
  39. package/lib/shared/stepzen-sdk.d.ts +1 -1
  40. package/lib/shared/stepzen-sdk.js +1 -1
  41. package/lib/shared/utils.d.ts +1 -0
  42. package/lib/shared/utils.js +22 -8
  43. package/lib/shared/validation.js +4 -2
  44. package/lib/shared/workspace.js +21 -16
  45. package/lib/shared/zen-command.js +7 -7
  46. package/lib/start/console.d.ts +1 -1
  47. package/lib/start/console.js +16 -9
  48. package/lib/start/index.js +1 -0
  49. package/oclif.manifest.json +1 -1
  50. package/package.json +3 -3
@@ -0,0 +1,23 @@
1
+ import type { CommonImportOptions } from '.';
2
+ export declare type DBType = 'mysql' | 'postgresql';
3
+ export declare type Sql2SdlOptions = CommonImportOptions & {
4
+ host: string;
5
+ database: string;
6
+ user: string;
7
+ password: string;
8
+ linkTypes?: boolean;
9
+ schema?: string;
10
+ include?: 'tables-only' | 'views-only' | 'tables-and-views';
11
+ };
12
+ export declare type InteractiveSql2SdlOptions = Pick<Sql2SdlOptions, 'host' | 'database' | 'user' | 'password' | 'linkTypes' | 'schema'>;
13
+ export declare const parseHost: (host?: string) => {
14
+ host?: string | undefined;
15
+ port?: string | undefined;
16
+ isValid: boolean;
17
+ };
18
+ export declare const askSqlQuestions: (dbType: DBType, defaultAnswers?: Partial<Sql2SdlOptions>) => Promise<InteractiveSql2SdlOptions>;
19
+ export declare const sql2sdl: (dbType: DBType, { name, source, host, database, user, password, linkTypes, include, schema, onConflict, }: Sql2SdlOptions) => Promise<{
20
+ error: string;
21
+ } | {
22
+ outPath: string;
23
+ }>;
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ // Copyright (c) 2020,2021,2022, StepZen, Inc.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.sql2sdl = exports.askSqlQuestions = exports.parseHost = void 0;
5
+ const chalk = require("chalk");
6
+ const inquirer = require("inquirer");
7
+ const helpers_1 = require("./helpers");
8
+ const constants_1 = require("../shared/constants");
9
+ const parseHost = (host) => {
10
+ if (!host) {
11
+ return { host: undefined, port: undefined, isValid: false };
12
+ }
13
+ let url;
14
+ // Try parsing as a DNS name or an IPv4 address (possibly with a port)
15
+ // e.g. "example.com:5432" or "[fedc:ba98:7654:3210:fedc:ba98:7654:3210]:5432"
16
+ try {
17
+ url = new URL(`http://${host}`);
18
+ }
19
+ catch (_a) {
20
+ // Try parsing as an IPv6 address (without a port)
21
+ // e.g. fedc:ba98:7654:3210:fedc:ba98:7654:3210
22
+ try {
23
+ url = new URL(`http://[${host}]`);
24
+ }
25
+ catch (_b) {
26
+ // ignore
27
+ }
28
+ }
29
+ if (!url) {
30
+ return { host, port: undefined, isValid: false };
31
+ }
32
+ return {
33
+ host: url.hostname,
34
+ port: url.port || undefined,
35
+ isValid: true,
36
+ };
37
+ };
38
+ exports.parseHost = parseHost;
39
+ const askSqlQuestions = async (dbType, defaultAnswers = {}) => {
40
+ let questions = [
41
+ {
42
+ name: 'host',
43
+ message: 'What is your host?',
44
+ validate: input => (0, exports.parseHost)(input).isValid || `Could not parse "${input}" as a hostname.`,
45
+ },
46
+ {
47
+ name: 'database',
48
+ message: 'What is your database name?',
49
+ validate: input => input.trim() !== '' || 'Database name must not be empty',
50
+ },
51
+ {
52
+ name: 'user',
53
+ message: 'What is the username?',
54
+ validate: input => input.trim() !== '' || 'Username must not be empty',
55
+ },
56
+ {
57
+ name: 'password',
58
+ message: 'What is the password?',
59
+ type: 'password',
60
+ },
61
+ {
62
+ name: 'linkTypes',
63
+ message: `Automatically link types based on foreign key relationships using @materializer` +
64
+ `\n ${chalk.dim('(https://stepzen.com/docs/features/linking-types)')}`,
65
+ type: 'confirm',
66
+ default: false,
67
+ },
68
+ ];
69
+ if (dbType === 'postgresql') {
70
+ questions = questions.concat([
71
+ {
72
+ name: 'schema',
73
+ message: 'What is your database schema (leave blank to use defaults)?',
74
+ },
75
+ ]);
76
+ }
77
+ return inquirer.prompt((0, helpers_1.overrideDefaults)(questions, defaultAnswers));
78
+ };
79
+ exports.askSqlQuestions = askSqlQuestions;
80
+ const sql2sdl = async (dbType, { name, source, host, database, user, password, linkTypes, include, schema, onConflict, }) => {
81
+ let inludeAsTableOptions;
82
+ switch (include) {
83
+ case 'tables-only':
84
+ inludeAsTableOptions = 'ONLYTABLES';
85
+ break;
86
+ case 'views-only':
87
+ inludeAsTableOptions = 'ONLYVIEWS';
88
+ break;
89
+ case 'tables-and-views':
90
+ inludeAsTableOptions = 'TABLESANDVIEWS';
91
+ break;
92
+ default:
93
+ inludeAsTableOptions = null;
94
+ }
95
+ const effectiveName = name || dbType;
96
+ const hostDetails = (0, exports.parseHost)(host);
97
+ const response = await (0, helpers_1.queryIntrospectionService)(constants_1.STEPZEN_DBINTROSPECTION_SERVER_URL, {
98
+ operation: 'generateSDL',
99
+ variables: {
100
+ driver: {
101
+ type: 'DBDriver!',
102
+ value: dbType === 'mysql' ? 'MYSQL' : 'POSTGRESQL',
103
+ },
104
+ host: {
105
+ type: 'String!',
106
+ value: hostDetails.host,
107
+ },
108
+ port: {
109
+ type: 'Int',
110
+ value: hostDetails.port === undefined
111
+ ? null
112
+ : parseInt(hostDetails.port, 10),
113
+ },
114
+ database: {
115
+ type: 'String!',
116
+ value: database,
117
+ },
118
+ user: {
119
+ type: 'String!',
120
+ value: user,
121
+ },
122
+ password: {
123
+ type: 'String!',
124
+ value: password,
125
+ },
126
+ onlyTypes: {
127
+ type: 'Boolean',
128
+ value: !linkTypes,
129
+ },
130
+ include: {
131
+ type: 'TableOptions',
132
+ value: inludeAsTableOptions,
133
+ },
134
+ schema: {
135
+ type: 'String',
136
+ value: schema,
137
+ },
138
+ configName: {
139
+ type: 'String!',
140
+ value: `${effectiveName}_config`,
141
+ },
142
+ },
143
+ });
144
+ if (response.error) {
145
+ return { error: response.error };
146
+ }
147
+ return (0, helpers_1.writeSdlAndConfig)({
148
+ name: effectiveName,
149
+ source,
150
+ mergeTypes: true,
151
+ onConflict,
152
+ response,
153
+ });
154
+ };
155
+ exports.sql2sdl = sql2sdl;
@@ -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
- exports.compareMajorVersions = (v1, v2) => {
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.shouldCheckVersion = (version) => {
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.checkUpgrade = async (version) => {
35
- if (!exports.shouldCheckVersion(version)) {
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; } });
@@ -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
- exports.deploy = async (destination, configurationsets, schema) => {
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.list = async (type) => {
24
- const config = (await configuration_1.readConfiguration());
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.upload = async (type, destination, source) => {
35
- const config = (await configuration_1.readConfiguration());
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
- exports.ensureValidConfiguration = async (maybeConfiguration) => {
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.importConfiguration = async (filepath) => {
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.readConfiguration = async () => {
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.writeConfiguration = async (configuration) => {
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.writeCredentialsToConfigFile = async (credentials) => {
115
- const oldConfig = await exports.readConfiguration();
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.removeCredentialsFromConfigFile = async () => {
121
- const configuration = await exports.readConfiguration();
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;
@@ -10,4 +11,7 @@ export declare const ADMIN_LIST_URL = "/cli/admin/list";
10
11
  export declare const ADMIN_UPLOAD_URL = "/cli/admin/upload";
11
12
  export declare const ADMIN_ACCOUNT_URL = "/cli/admin/account";
12
13
  export declare const STEPZEN_JSON2SDL_SERVER_URL: string;
14
+ export declare const STEPZEN_DBINTROSPECTION_SERVER_URL: string;
13
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";
@@ -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_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");
@@ -9,7 +9,17 @@ const path = require("path");
9
9
  // This allows you to set environment variables in a `.env` file.
10
10
  // This file needs to be in your working directory.
11
11
  dotenv.config();
12
- const { STEPZEN_CONFIG_FILE: ENV_VAR_STEPZEN_CONFIG_FILE, STEPZEN_DOMAIN: ENV_VAR_STEPZEN_DOMAIN, STEPZEN_SERVER_URL: ENV_VAR_STEPZEN_SERVER_URL, STEPZEN_JSON2SDL_SERVER_URL: ENV_VAR_STEPZEN_JSON2SDL_SERVER_URL, STEPZEN_DIRECT_GENERATOR_ENGINES_URL: ENV_VAR_STEPZEN_DIRECT_GENERATOR_ENGINES_URL, } = process.env;
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,6 +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';
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');
33
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
- exports.parseCurlArgv = (argv) => {
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;
@@ -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
- exports.formatTemporaryErrorMessage = (errors) => `A problem occurred while processing your import${errors.length > 0 && errors[0].message ? `: "${errors[0].message}"` : ''}. Please try again.` +
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
- exports.parseHeaderParam = (headers, headerParam) => {
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.makeHeaders = (curlHeaders, headerParams = []) => {
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;
@@ -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
- exports.parseHeader = (header) => {
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;
@@ -638,6 +638,8 @@ const descriptors = [
638
638
  'zinc',
639
639
  'zooming',
640
640
  ];
641
- exports.getRandomAnimal = () => animals[lodash_1.random(0, animals.length - 1)];
642
- exports.getRandomDescriptor = () => descriptors[lodash_1.random(0, descriptors.length - 1)];
643
- exports.default = () => `${exports.getRandomDescriptor()}-${exports.getRandomAnimal()}`;
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 | undefined) => PathParam[] | ParseError;
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
- exports.formatPatternDiffWithPath = (patternSegments, pathSegments) => {
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.parsePathParamsPattern = (url, pathParamsPattern) => {
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").AnonymousClientOptions | import("@stepzen/sdk/lib/client").UserCredentialsClientOptions) => Promise<{
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,
@@ -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;