stepzen 0.13.0-beta.2 → 0.14.0-beta.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.
Files changed (43) hide show
  1. package/README.md +1 -1
  2. package/lib/commands/deploy.d.ts +1 -0
  3. package/lib/commands/import.d.ts +1 -0
  4. package/lib/commands/import.js +4 -12
  5. package/lib/commands/init.d.ts +1 -0
  6. package/lib/commands/lint.d.ts +1 -0
  7. package/lib/commands/list.d.ts +2 -0
  8. package/lib/commands/login.d.ts +1 -0
  9. package/lib/commands/login.js +10 -9
  10. package/lib/commands/logout.d.ts +2 -0
  11. package/lib/commands/logout.js +1 -1
  12. package/lib/commands/start.d.ts +1 -0
  13. package/lib/commands/start.js +3 -4
  14. package/lib/commands/transpile.d.ts +1 -0
  15. package/lib/commands/upload.d.ts +1 -0
  16. package/lib/commands/upload.js +13 -4
  17. package/lib/commands/validate.d.ts +2 -0
  18. package/lib/commands/whoami.d.ts +2 -0
  19. package/lib/commands/whoami.js +2 -2
  20. package/lib/generate/helpers.d.ts +0 -4
  21. package/lib/generate/helpers.js +27 -110
  22. package/lib/generate/index.js +5 -5
  23. package/lib/hooks/prerun/{ensure-api-key.d.ts → ensure-config-file.d.ts} +0 -0
  24. package/lib/hooks/prerun/ensure-config-file.js +28 -0
  25. package/lib/shared/actions.d.ts +1 -1
  26. package/lib/shared/actions.js +5 -18
  27. package/lib/shared/configuration.d.ts +24 -5
  28. package/lib/shared/configuration.js +92 -34
  29. package/lib/shared/constants.d.ts +2 -2
  30. package/lib/shared/constants.js +4 -3
  31. package/lib/shared/curl-parser.js +22 -8
  32. package/lib/shared/path-params-parser.js +17 -9
  33. package/lib/shared/stepzen-sdk.d.ts +14 -14
  34. package/lib/shared/stepzen-sdk.js +25 -17
  35. package/lib/shared/types.d.ts +14 -2
  36. package/lib/shared/utils.d.ts +0 -2
  37. package/lib/shared/utils.js +1 -50
  38. package/lib/shared/zen-command.d.ts +6 -5
  39. package/lib/shared/zen-command.js +28 -8
  40. package/lib/start/deploy.js +4 -4
  41. package/oclif.manifest.json +1 -1
  42. package/package.json +6 -6
  43. package/lib/hooks/prerun/ensure-api-key.js +0 -8
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.2 darwin-x64 node-v14.19.1
32
+ stepzen/0.14.0-beta.0 darwin-x64 node-v14.19.1
33
33
  $ stepzen --help [COMMAND]
34
34
  USAGE
35
35
  $ stepzen COMMAND
@@ -8,6 +8,7 @@ export default class Deploy extends ZenCommand {
8
8
  schema: flags.IOptionFlag<string>;
9
9
  silent: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
10
10
  'non-interactive': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
11
+ 'enable-login-prompt': flags.IOptionFlag<boolean | undefined>;
11
12
  };
12
13
  static args: {
13
14
  name: string;
@@ -12,6 +12,7 @@ export default class Import extends ZenCommand {
12
12
  'query-type': flags.IOptionFlag<string | undefined>;
13
13
  'path-params': flags.IOptionFlag<string | undefined>;
14
14
  'non-interactive': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
15
+ 'enable-login-prompt': flags.IOptionFlag<boolean | undefined>;
15
16
  };
16
17
  static args: {
17
18
  name: string;
@@ -6,8 +6,7 @@ const fs = require("fs-extra");
6
6
  const command_1 = require("@oclif/command");
7
7
  const errors_1 = require("@oclif/errors");
8
8
  const transpiler_1 = require("@stepzen/transpiler");
9
- const cli_ux_1 = require("cli-ux");
10
- const deploy_1 = require("./deploy");
9
+ const core_1 = require("@oclif/core");
11
10
  const generate_1 = require("../generate");
12
11
  const utils_1 = require("../shared/utils");
13
12
  const helpers_1 = require("../generate/helpers");
@@ -89,9 +88,9 @@ class Import extends zen_command_1.default {
89
88
  }
90
89
  curl2sdlOptions = Object.assign(Object.assign(Object.assign({}, fixedOptions), editableOptions), { pathParams: parsedPathParamsOrError, curlArgs: argsOrError });
91
90
  }
92
- cli_ux_1.cli.action.start('Starting');
91
+ core_1.CliUx.ux.action.start('Starting');
93
92
  const resultOrError = await curl2sdl_1.curl2sdl(curl2sdlOptions);
94
- cli_ux_1.cli.action.stop();
93
+ core_1.CliUx.ux.action.stop();
95
94
  if ('error' in resultOrError) {
96
95
  this.log('A problem occured while processing your import. ' +
97
96
  'Please check that the given cURL command is valid.');
@@ -101,19 +100,12 @@ class Import extends zen_command_1.default {
101
100
  result = resultOrError.outPath;
102
101
  }
103
102
  else {
104
- await this.ensureStepZenAccount();
103
+ ;
105
104
  ['prefix', 'query-type', 'query-name', 'path-params'].forEach(flag => {
106
105
  if (flag in flags) {
107
106
  this.log(chalk.gray(`The ${chalk.bold(`--${flag}`)} flag only applies when importing ${chalk.bold('curl')}. It will be ignored now.`));
108
107
  }
109
108
  });
110
- // Make sure the user has latest Generator Schema
111
- await deploy_1.default.run([
112
- constants_1.STEPZEN_GENERATOR_ENGINES_ENDPOINT,
113
- '--schema',
114
- constants_1.STEPZEN_GENERATOR_ENGINES_SCHEMA,
115
- '--silent',
116
- ]);
117
109
  // Let's go!
118
110
  result = await generate_1.default(schemas, flags.name, workspace.schema);
119
111
  // Validate
@@ -11,6 +11,7 @@ export default class Init extends ZenCommand {
11
11
  help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
12
12
  yes: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
13
13
  'non-interactive': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
14
+ 'enable-login-prompt': flags.IOptionFlag<boolean | undefined>;
14
15
  };
15
16
  static args: {
16
17
  hidden: boolean;
@@ -7,6 +7,7 @@ export default class Init extends ZenCommand {
7
7
  dir: flags.IOptionFlag<string | undefined>;
8
8
  help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
9
9
  'non-interactive': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
10
+ 'enable-login-prompt': flags.IOptionFlag<boolean | undefined>;
10
11
  };
11
12
  run(): Promise<void>;
12
13
  }
@@ -1,9 +1,11 @@
1
+ import { flags } from '@oclif/command';
1
2
  import ZenCommand from '../shared/zen-command';
2
3
  export default class List extends ZenCommand {
3
4
  static description: string;
4
5
  static flags: {
5
6
  help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
6
7
  'non-interactive': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
8
+ 'enable-login-prompt': flags.IOptionFlag<boolean | undefined>;
7
9
  };
8
10
  static args: {
9
11
  name: string;
@@ -8,6 +8,7 @@ export default class Login extends ZenCommand {
8
8
  config: flags.IOptionFlag<string | undefined>;
9
9
  help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
10
10
  'non-interactive': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
11
+ 'enable-login-prompt': flags.IOptionFlag<boolean | undefined>;
11
12
  };
12
13
  run(): Promise<void>;
13
14
  }
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
5
5
  // Stepzen login checks that credentials presented are good and
6
6
  // subsequently changes the identity of the logged in account.
7
7
  const command_1 = require("@oclif/command");
8
- const cli_ux_1 = require("cli-ux");
8
+ const core_1 = require("@oclif/core");
9
9
  const configuration_1 = require("../shared/configuration");
10
10
  const stepzen_sdk_1 = require("../shared/stepzen-sdk");
11
11
  const zen_command_1 = require("../shared/zen-command");
@@ -16,7 +16,7 @@ class Login extends zen_command_1.default {
16
16
  let adminkey;
17
17
  // If the --config flag is provided, try and log in using the details in the file
18
18
  if (flags.config) {
19
- const config = configuration_1.importConfiguration(flags.config);
19
+ const config = await configuration_1.importConfiguration(flags.config);
20
20
  account = config.account;
21
21
  adminkey = config.adminkey;
22
22
  }
@@ -26,21 +26,22 @@ class Login extends zen_command_1.default {
26
26
  account = flags.account;
27
27
  }
28
28
  else {
29
- account = await cli_ux_1.default.prompt('What is your account name?');
29
+ account = await core_1.CliUx.ux.prompt('What is your account name?');
30
30
  }
31
31
  // Check if the --adminkey flag is provided, and if not prompt the user for an admin key.
32
- if (flags.adminkey) {
33
- adminkey = flags.adminkey;
34
- }
35
- else {
36
- adminkey = await cli_ux_1.default.prompt('What is your admin key?', {
32
+ if (flags.adminkey === undefined) {
33
+ adminkey = await core_1.CliUx.ux.prompt('What is your admin key?', {
34
+ required: false,
37
35
  type: 'hide',
38
36
  });
39
37
  }
38
+ else {
39
+ adminkey = flags.adminkey;
40
+ }
40
41
  }
41
42
  const configuration = await stepzen_sdk_1.default.login(adminkey, account);
42
43
  // Change the default account.
43
- configuration_1.writeConfigurationToLoginFile(configuration);
44
+ configuration_1.writeCredentialsToConfigFile(configuration);
44
45
  this.log('You have successfully logged in.');
45
46
  }
46
47
  }
@@ -1,9 +1,11 @@
1
+ import { flags } from '@oclif/command';
1
2
  import ZenCommand from '../shared/zen-command';
2
3
  export default class Logout extends ZenCommand {
3
4
  static description: string;
4
5
  static flags: {
5
6
  help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
6
7
  'non-interactive': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
8
+ 'enable-login-prompt': flags.IOptionFlag<boolean | undefined>;
7
9
  };
8
10
  run(): Promise<void>;
9
11
  }
@@ -9,7 +9,7 @@ const zen_command_1 = require("../shared/zen-command");
9
9
  class Logout extends zen_command_1.default {
10
10
  async run() {
11
11
  // Remove the configuration from the login file.
12
- configuration_1.removeConfigurationFromLoginFile();
12
+ configuration_1.removeCredentialsFromConfigFile();
13
13
  this.log('You have been logged out.');
14
14
  }
15
15
  }
@@ -14,6 +14,7 @@ export default class Start extends ZenCommand {
14
14
  'no-watcher': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
15
15
  port: import("@oclif/parser/lib/flags").IOptionFlag<number>;
16
16
  'non-interactive': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
17
+ 'enable-login-prompt': flags.IOptionFlag<boolean | undefined>;
17
18
  };
18
19
  static args: never[];
19
20
  run(): Promise<void>;
@@ -2,7 +2,7 @@
2
2
  // Copyright (c) 2020,2021,2022, StepZen, Inc.
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const chokidar = require("chokidar");
5
- const cli_ux_1 = require("cli-ux");
5
+ const core_1 = require("@oclif/core");
6
6
  const command_1 = require("@oclif/command");
7
7
  const errors_1 = require("@oclif/errors");
8
8
  const throttle_debounce_1 = require("throttle-debounce");
@@ -56,7 +56,6 @@ class Start extends zen_command_1.default {
56
56
  ignored: '**/*.js',
57
57
  })
58
58
  .on('change', throttle_debounce_1.debounce(500, async (path) => {
59
- await utils_1.checkAuth();
60
59
  utils_1.clearConsole();
61
60
  await start_1.deploy(path, workspace, flags);
62
61
  await start_1.console(workspace);
@@ -64,7 +63,7 @@ class Start extends zen_command_1.default {
64
63
  }
65
64
  // Start!
66
65
  utils_1.clearConsole();
67
- cli_ux_1.default.action.start('Starting...');
66
+ core_1.CliUx.ux.action.start('Starting...');
68
67
  // Unless explicitly disabled, auto-init
69
68
  if (!flags['no-init']) {
70
69
  await start_1.deploy(null, workspace, flags);
@@ -94,7 +93,7 @@ class Start extends zen_command_1.default {
94
93
  await ui.start();
95
94
  }
96
95
  // Done
97
- cli_ux_1.default.action.stop();
96
+ core_1.CliUx.ux.action.stop();
98
97
  }
99
98
  }
100
99
  exports.default = Start;
@@ -12,6 +12,7 @@ export default class Transpile extends ZenCommand {
12
12
  'output-configuration': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
13
13
  silent: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
14
14
  'non-interactive': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
15
+ 'enable-login-prompt': flags.IOptionFlag<boolean | undefined>;
15
16
  };
16
17
  static args: {
17
18
  name: string;
@@ -8,6 +8,7 @@ export default class Upload extends ZenCommand {
8
8
  help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
9
9
  silent: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
10
10
  'non-interactive': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
11
+ 'enable-login-prompt': flags.IOptionFlag<boolean | undefined>;
11
12
  };
12
13
  static args: ({
13
14
  name: string;
@@ -21,14 +21,23 @@ class Upload extends zen_command_1.default {
21
21
  throw new errors_1.CLIError('You must specify the folder/name you want to use');
22
22
  }
23
23
  await this.ensureStepZenAccount();
24
- if (!flags.file && !flags.dir) {
25
- // You need to specify a file or directory. Exit with error.
26
- throw new errors_1.CLIError('You must specify a file or directory.');
24
+ let source;
25
+ if (args.type === 'configurationset') {
26
+ if (!flags.file) {
27
+ throw new errors_1.CLIError('Please specify a source file with the --file flag');
28
+ }
29
+ source = flags.file;
30
+ }
31
+ else {
32
+ if (!flags.dir) {
33
+ throw new errors_1.CLIError('Please specify a source directory with the --dir flag');
34
+ }
35
+ source = flags.dir;
27
36
  }
28
37
  if (!flags.silent) {
29
38
  this.log('Uploading...');
30
39
  }
31
- const response = await actions_1.upload(args.type, args.destination, flags.file, flags.dir);
40
+ const response = await actions_1.upload(args.type, args.destination, source);
32
41
  if (response.success) {
33
42
  if (!flags.silent) {
34
43
  this.log(response.message);
@@ -1,3 +1,4 @@
1
+ import { flags } from '@oclif/command';
1
2
  import ZenCommand from '../shared/zen-command';
2
3
  export default class Validate extends ZenCommand {
3
4
  static description: string;
@@ -5,6 +6,7 @@ export default class Validate extends ZenCommand {
5
6
  static flags: {
6
7
  help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
7
8
  'non-interactive': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
9
+ 'enable-login-prompt': flags.IOptionFlag<boolean | undefined>;
8
10
  };
9
11
  static args: {
10
12
  name: string;
@@ -1,3 +1,4 @@
1
+ import { flags } from '@oclif/command';
1
2
  import ZenCommand from '../shared/zen-command';
2
3
  export default class WhoAmI extends ZenCommand {
3
4
  static description: string;
@@ -8,6 +9,7 @@ export default class WhoAmI extends ZenCommand {
8
9
  apikey: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
9
10
  adminkey: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
10
11
  'non-interactive': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
12
+ 'enable-login-prompt': flags.IOptionFlag<boolean | undefined>;
11
13
  };
12
14
  static args: never[];
13
15
  run(): Promise<void>;
@@ -9,8 +9,8 @@ const zen_command_1 = require("../shared/zen-command");
9
9
  class WhoAmI extends zen_command_1.default {
10
10
  async run() {
11
11
  const { flags } = this.parse(WhoAmI);
12
- const configuration = configuration_1.readConfiguration();
13
- if (!configuration) {
12
+ const configuration = await configuration_1.readConfiguration();
13
+ if (!('account' in configuration)) {
14
14
  this.log('You are not logged in.');
15
15
  this.exit();
16
16
  }
@@ -1,6 +1,4 @@
1
1
  import type { Answers, DistinctQuestion } from 'inquirer';
2
- export declare const createGeneratorFilesDirectly: (id: string, details: any) => Promise<string>;
3
- export declare const createGeneratorFilesViaStepZen: (id: string, details: any) => Promise<string>;
4
2
  export declare const createGeneratorFiles: (id: string, details: any) => Promise<string>;
5
3
  export declare type GeneratorConfiguration = {
6
4
  questions: DistinctQuestion<Answers>[];
@@ -8,8 +6,6 @@ export declare type GeneratorConfiguration = {
8
6
  errors: Record<string, any>;
9
7
  status: number;
10
8
  };
11
- export declare const getConfigurationDirectly: (id: string, details?: any) => Promise<GeneratorConfiguration | null>;
12
- export declare const getConfigurationViaStepZen: (id: string, details?: any) => Promise<GeneratorConfiguration | null>;
13
9
  export declare const getConfiguration: (id: string, details?: any) => Promise<GeneratorConfiguration | null>;
14
10
  export declare const getSchemaList: (arg: string) => string[];
15
11
  export declare const getTemplates: () => Promise<string>;
@@ -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.askTemplateQuestions = exports.askGeneratorQuestions = exports.getTemplates = exports.getSchemaList = exports.getConfiguration = exports.getConfigurationViaStepZen = exports.getConfigurationDirectly = exports.createGeneratorFiles = exports.createGeneratorFilesViaStepZen = exports.createGeneratorFilesDirectly = void 0;
4
+ exports.askTemplateQuestions = exports.askGeneratorQuestions = exports.getTemplates = exports.getSchemaList = exports.getConfiguration = exports.createGeneratorFiles = void 0;
5
5
  const errors_1 = require("@oclif/errors");
6
6
  const chalk = require("chalk");
7
7
  const debug = require("debug");
@@ -12,13 +12,13 @@ const lodash_1 = require("lodash");
12
12
  const os = require("os");
13
13
  const path = require("path");
14
14
  const shell = require("shelljs");
15
- const configuration_1 = require("../shared/configuration");
16
15
  const constants_1 = require("../shared/constants");
17
16
  const errors_2 = require("../shared/errors");
18
17
  const { version } = require('../../package.json');
19
- exports.createGeneratorFilesDirectly = async (id, details) => {
18
+ exports.createGeneratorFiles = async (id, details) => {
20
19
  const url = `${constants_1.STEPZEN_DIRECT_GENERATOR_ENGINES_URL}/create`;
21
20
  debug('stepzen:generate')(`calling the generator engine ${id} via ${url}`);
21
+ const engineErrorMessageWrap = (msg) => `An error has occurred when creating the schema: ${msg}. Please check your parameters and try again.`;
22
22
  try {
23
23
  const response = await node_fetch_1.default(url, {
24
24
  body: JSON.stringify({
@@ -31,63 +31,36 @@ exports.createGeneratorFilesDirectly = async (id, details) => {
31
31
  },
32
32
  method: 'POST',
33
33
  });
34
- const files = await response.json();
35
- const tmp = path.join(os.tmpdir(), `stepzen-generated-schema-${Date.now()}`);
36
- fs.ensureDirSync(tmp);
37
- for (const file of files) {
38
- const dir = path.join(tmp, file.name);
39
- fs.writeFileSync(dir, file.content);
34
+ const responseJson = await response.json();
35
+ if (responseJson.errors) {
36
+ // assuming a response of type { status: Int, errors: String }
37
+ throw new errors_1.CLIError(engineErrorMessageWrap(responseJson.errors));
38
+ }
39
+ else {
40
+ // where errors is an error message if name === null.
41
+ const files = responseJson;
42
+ const tmp = path.join(os.tmpdir(), `stepzen-generated-schema-${Date.now()}`);
43
+ fs.ensureDirSync(tmp);
44
+ for (const file of files) {
45
+ if (file.errors) {
46
+ throw new errors_1.CLIError(engineErrorMessageWrap(file.errors));
47
+ }
48
+ else {
49
+ const dir = path.join(tmp, file.name);
50
+ fs.writeFileSync(dir, file.content);
51
+ }
52
+ }
53
+ return tmp;
40
54
  }
41
- return tmp;
42
55
  }
43
56
  catch (error) {
44
57
  debug('stepzen:generate')(error);
45
- throw new errors_1.CLIError(errors_2.PERMANENT_STEPZEN_ERROR);
46
- }
47
- };
48
- exports.createGeneratorFilesViaStepZen = async (id, details) => {
49
- const config = configuration_1.readConfiguration();
50
- const domain = constants_1.STEPZEN_DOMAIN.replace('.io', '.net');
51
- const url = `https://${config.account}.${domain}/${constants_1.STEPZEN_GENERATOR_ENGINES_ENDPOINT}/__graphql`;
52
- debug('stepzen:generate')(`calling the generator engine ${id} via ${url}`);
53
- const response = await node_fetch_1.default(url, {
54
- body: JSON.stringify({
55
- query: `
56
- query {
57
- create(id: "${id}" details: "${JSON.stringify(details.answers).replace(/"/g, '\\"')}") {
58
- content
59
- name
60
- }
61
- }
62
- `,
63
- }),
64
- headers: {
65
- Authorization: `Apikey ${config.adminkey}`,
66
- 'Content-Type': 'application/json',
67
- 'stepzen-cli-version': version,
68
- 'user-agent': `stepzen-cli/${version}`,
69
- },
70
- method: 'POST',
71
- });
72
- const { data, errors } = await response.json();
73
- if (errors) {
74
- throw new errors_1.CLIError(errors_2.formatTemporaryErrorMessage(errors));
75
- }
76
- const tmp = path.join(os.tmpdir(), `stepzen-generated-schema-${Date.now()}`);
77
- fs.ensureDirSync(tmp);
78
- for (const file of data.create) {
79
- const dir = path.join(tmp, file.name);
80
- fs.writeFileSync(dir, file.content);
58
+ throw error instanceof errors_1.CLIError
59
+ ? error
60
+ : new errors_1.CLIError(errors_2.PERMANENT_STEPZEN_ERROR);
81
61
  }
82
- return tmp;
83
62
  };
84
- exports.createGeneratorFiles = async (id, details) => {
85
- const fn = constants_1.STEPZEN_DIRECT_GENERATOR_ENGINES_URL
86
- ? exports.createGeneratorFilesDirectly
87
- : exports.createGeneratorFilesViaStepZen;
88
- return fn(id, details);
89
- };
90
- exports.getConfigurationDirectly = async (id, details = {}) => {
63
+ exports.getConfiguration = async (id, details = {}) => {
91
64
  const url = `${constants_1.STEPZEN_DIRECT_GENERATOR_ENGINES_URL}/configure`;
92
65
  debug('stepzen:generate')(`calling the generator engine ${id} via ${url}`);
93
66
  try {
@@ -115,62 +88,6 @@ exports.getConfigurationDirectly = async (id, details = {}) => {
115
88
  throw new errors_1.CLIError(errors_2.PERMANENT_STEPZEN_ERROR);
116
89
  }
117
90
  };
118
- exports.getConfigurationViaStepZen = async (id, details = {}) => {
119
- const config = configuration_1.readConfiguration();
120
- const domain = constants_1.STEPZEN_DOMAIN.replace('.io', '.net');
121
- const url = `https://${config.account}.${domain}/${constants_1.STEPZEN_GENERATOR_ENGINES_ENDPOINT}/__graphql`;
122
- debug('stepzen:generate')(`calling the generator engine ${id} via ${url}`);
123
- const response = await node_fetch_1.default(url, {
124
- body: JSON.stringify({
125
- query: `
126
- query {
127
- configure(id: "${id}" details: "${JSON.stringify(details).replace(/"/g, '\\"')}") {
128
- answers
129
- errors
130
- questions
131
- status
132
- }
133
- }
134
- `,
135
- }),
136
- headers: {
137
- Authorization: `Apikey ${config.adminkey}`,
138
- 'Content-Type': 'application/json',
139
- 'stepzen-cli-version': version,
140
- 'user-agent': `stepzen-cli/${version}`,
141
- },
142
- method: 'POST',
143
- });
144
- const { data, errors } = await response.json();
145
- if (errors) {
146
- return {
147
- questions: [],
148
- answers: {},
149
- status: -1,
150
- errors: {
151
- error: errors[0].message,
152
- },
153
- };
154
- }
155
- try {
156
- if (data.configure) {
157
- data.configure.answers = JSON.parse(data.configure.answers);
158
- data.configure.errors = JSON.parse(data.configure.errors);
159
- data.configure.questions = JSON.parse(data.configure.questions);
160
- }
161
- }
162
- catch (error) {
163
- debug('stepzen:response')(error);
164
- throw new errors_1.CLIError(errors_2.PERMANENT_STEPZEN_ERROR);
165
- }
166
- return data.configure;
167
- };
168
- exports.getConfiguration = async (id, details = {}) => {
169
- const fn = constants_1.STEPZEN_DIRECT_GENERATOR_ENGINES_URL
170
- ? exports.getConfigurationDirectly
171
- : exports.getConfigurationViaStepZen;
172
- return fn(id, details);
173
- };
174
91
  exports.getSchemaList = (arg) => {
175
92
  const schemas = arg.split(',').map((schema) => schema.trim());
176
93
  // Make sure they're unique, otherwise, complain
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const tslib_1 = require("tslib");
5
5
  const errors_1 = require("@oclif/errors");
6
- const cli_ux_1 = require("cli-ux");
6
+ const core_1 = require("@oclif/core");
7
7
  const fs = require("fs-extra");
8
8
  const lodash = require("lodash");
9
9
  const os = require("os");
@@ -21,7 +21,7 @@ exports.default = async (schemas, name, source) => {
21
21
  // Store the answers
22
22
  let answers = {};
23
23
  // Start downloading
24
- cli_ux_1.default.action.start('Downloading from StepZen...');
24
+ core_1.CliUx.ux.action.start('Downloading from StepZen...');
25
25
  try {
26
26
  // Get all generators from...Generators
27
27
  for (var _f = tslib_1.__asyncValues(Object.keys(generators)), _g; _g = await _f.next(), !_g.done;) {
@@ -68,7 +68,7 @@ exports.default = async (schemas, name, source) => {
68
68
  finally { if (e_2) throw e_2.error; }
69
69
  }
70
70
  // Finished downloading
71
- cli_ux_1.default.action.stop();
71
+ core_1.CliUx.ux.action.stop();
72
72
  console.log();
73
73
  // If you've tried to import non-existent templates, complain and exit
74
74
  const notFound = Object.entries(generators)
@@ -109,7 +109,7 @@ exports.default = async (schemas, name, source) => {
109
109
  fs.ensureDirSync(output);
110
110
  fs.copySync(source, output);
111
111
  console.log();
112
- cli_ux_1.default.action.start('Generating schemas...');
112
+ core_1.CliUx.ux.action.start('Generating schemas...');
113
113
  try {
114
114
  for (var _m = tslib_1.__asyncValues(Object.entries(generators)), _o; _o = await _m.next(), !_o.done;) {
115
115
  const [id, generator] = _o.value;
@@ -149,7 +149,7 @@ exports.default = async (schemas, name, source) => {
149
149
  finally { if (e_4) throw e_4.error; }
150
150
  }
151
151
  // Housekeeping
152
- cli_ux_1.default.action.stop();
152
+ core_1.CliUx.ux.action.stop();
153
153
  fs.removeSync(templates);
154
154
  return output;
155
155
  };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ // Copyright (c) 2020,2021,2022, StepZen, Inc.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const path = require("path");
5
+ const debug = require("debug");
6
+ const configuration_1 = require("../../shared/configuration");
7
+ const constants_1 = require("../../shared/constants");
8
+ const hook = async function () {
9
+ // If the configuration is set through an env variable,
10
+ // skip all the config file checks.
11
+ if (process.env.STEPZEN_CONFIG_CONTENT) {
12
+ return;
13
+ }
14
+ const configFilePath = path.join(constants_1.STEPZEN_CONFIG_DIRECTORY, constants_1.STEPZEN_CONFIG_FILE);
15
+ let rawConfiguration;
16
+ try {
17
+ rawConfiguration = await configuration_1.importConfiguration(configFilePath);
18
+ }
19
+ catch (_a) {
20
+ rawConfiguration = null;
21
+ }
22
+ const { configuration, modified } = await configuration_1.ensureValidConfiguration(rawConfiguration);
23
+ if (modified) {
24
+ configuration_1.writeConfiguration(configuration);
25
+ debug('stepzen:configuration')(`Automatically updated the ${configFilePath} config file.`);
26
+ }
27
+ };
28
+ exports.default = hook;
@@ -1,4 +1,4 @@
1
1
  import { ZenCtlResponse } from './types';
2
2
  export declare const deploy: (destination: string, configurationsets: string | undefined, schema: string) => Promise<ZenCtlResponse>;
3
3
  export declare const list: (type: 'configurationsets' | 'schemas') => Promise<ZenCtlResponse>;
4
- export declare const upload: (type: string, destination: string, file: string | undefined, directory: string | undefined) => Promise<any>;
4
+ export declare const upload: (type: 'configurationset' | 'schema', destination: string, source: string) => Promise<any>;
@@ -2,13 +2,11 @@
2
2
  // Copyright (c) 2020,2021,2022, StepZen, Inc.
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.upload = exports.list = exports.deploy = void 0;
5
- // This file contains 'actions' - calls to zenctl
6
- const errors_1 = require("@oclif/errors");
7
5
  const configuration_1 = require("./configuration");
8
6
  const constants_1 = require("./constants");
9
7
  const stepzen_sdk_1 = require("./stepzen-sdk");
10
8
  exports.deploy = async (destination, configurationsets, schema) => {
11
- const config = configuration_1.readConfiguration();
9
+ const config = (await configuration_1.readConfiguration());
12
10
  const server = constants_1.STEPZEN_SERVER_URL.replace('{account}', config.account);
13
11
  const client = await stepzen_sdk_1.default.client({
14
12
  account: config.account,
@@ -23,7 +21,7 @@ exports.deploy = async (destination, configurationsets, schema) => {
23
21
  return client.deploy(destination, payload);
24
22
  };
25
23
  exports.list = async (type) => {
26
- const config = configuration_1.readConfiguration();
24
+ const config = (await configuration_1.readConfiguration());
27
25
  const server = constants_1.STEPZEN_SERVER_URL.replace('{account}', config.account);
28
26
  const client = await stepzen_sdk_1.default.client({
29
27
  account: config.account,
@@ -33,8 +31,8 @@ exports.list = async (type) => {
33
31
  });
34
32
  return client.list[type]();
35
33
  };
36
- exports.upload = async (type, destination, file, directory) => {
37
- const config = configuration_1.readConfiguration();
34
+ exports.upload = async (type, destination, source) => {
35
+ const config = (await configuration_1.readConfiguration());
38
36
  const server = constants_1.STEPZEN_SERVER_URL.replace('{account}', config.account);
39
37
  const client = await stepzen_sdk_1.default.client({
40
38
  account: config.account,
@@ -42,16 +40,5 @@ exports.upload = async (type, destination, file, directory) => {
42
40
  domain: constants_1.STEPZEN_DOMAIN,
43
41
  server,
44
42
  });
45
- if (type === 'configurationset') {
46
- if (!file) {
47
- throw new errors_1.CLIError('Please specify a source file with the --file flag');
48
- }
49
- return client.upload.configurationset(destination, file);
50
- }
51
- if (type === 'schema') {
52
- if (!directory) {
53
- throw new errors_1.CLIError('Please specify a source directory with the --dir flag');
54
- }
55
- return client.upload.schema(destination, directory);
56
- }
43
+ return client.upload[type](destination, source);
57
44
  };