zcatalyst-cli 1.26.2 → 1.27.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 (151) hide show
  1. package/README.md +1 -0
  2. package/lib/authentication/credential.d.ts +2 -1
  3. package/lib/authentication/credential.js +20 -3
  4. package/lib/authentication/crypt.d.ts +7 -3
  5. package/lib/authentication/crypt.js +87 -16
  6. package/lib/authentication/index.js +1 -0
  7. package/lib/authentication/key-manager.d.ts +7 -0
  8. package/lib/authentication/key-manager.js +62 -0
  9. package/lib/authentication/login.js +20 -20
  10. package/lib/bin/catalyst.js +1 -15
  11. package/lib/client.d.ts +3 -1
  12. package/lib/client.js +16 -5
  13. package/lib/command_needs/rc.js +13 -3
  14. package/lib/commands/appsail/add.js +10 -0
  15. package/lib/commands/client/delete.js +18 -6
  16. package/lib/commands/client/setup.js +7 -0
  17. package/lib/commands/deploy/index.js +3 -3
  18. package/lib/commands/deploy/slate.js +65 -4
  19. package/lib/commands/functions/add.js +7 -0
  20. package/lib/commands/functions/delete.js +22 -4
  21. package/lib/commands/functions/execute.js +39 -71
  22. package/lib/commands/functions/setup.js +13 -0
  23. package/lib/commands/functions/shell.js +15 -1
  24. package/lib/commands/iac/import.js +2 -2
  25. package/lib/commands/init.js +34 -20
  26. package/lib/commands/login.js +1 -0
  27. package/lib/commands/pull.js +22 -1
  28. package/lib/commands/serve.js +2 -1
  29. package/lib/commands/slate/create.js +7 -4
  30. package/lib/commands/slate/link.js +11 -5
  31. package/lib/commands/slate/unlink.js +7 -0
  32. package/lib/commands/zest/generate/index.js +28 -35
  33. package/lib/deploy/features/slate.d.ts +3 -1
  34. package/lib/deploy/features/slate.js +204 -5
  35. package/lib/docs/client-utils.toml +0 -5
  36. package/lib/docs/command_needs/rc.toml +9 -1
  37. package/lib/docs/commands/client/delete.toml +4 -0
  38. package/lib/docs/commands/deploy/slate.toml +3 -0
  39. package/lib/docs/commands/functions/delete.toml +10 -0
  40. package/lib/docs/commands/functions/execute.toml +1 -16
  41. package/lib/docs/commands/functions/setup.toml +3 -0
  42. package/lib/docs/commands/functions/shell.toml +8 -0
  43. package/lib/docs/commands/init.toml +3 -0
  44. package/lib/docs/commands/pull.toml +6 -0
  45. package/lib/docs/commands/slate/unlink.toml +6 -0
  46. package/lib/docs/execute/command-utils.toml +14 -0
  47. package/lib/docs/execute/execute-input-resolver.toml +37 -0
  48. package/lib/docs/init/features/project.toml +20 -0
  49. package/lib/docs/init/util/client.toml +4 -0
  50. package/lib/docs/prompt/index.toml +15 -0
  51. package/lib/docs/pull/features/apig.toml +6 -0
  52. package/lib/docs/pull/features/client.toml +20 -0
  53. package/lib/docs/pull/features/functions/index.toml +24 -0
  54. package/lib/endpoints/lib/slate.d.ts +14 -1
  55. package/lib/endpoints/lib/slate.js +35 -0
  56. package/lib/error/context-help.js +1 -1
  57. package/lib/error/index.js +9 -13
  58. package/lib/execute/command-utils.d.ts +5 -0
  59. package/lib/execute/command-utils.js +86 -0
  60. package/lib/execute/execute-input-resolver.d.ts +29 -0
  61. package/lib/execute/execute-input-resolver.js +207 -0
  62. package/lib/execute/index.d.ts +4 -1
  63. package/lib/execute/index.js +3 -2
  64. package/lib/fn-utils/lib/integ.js +22 -17
  65. package/lib/index.js +1 -0
  66. package/lib/init/dependencies/package-json.js +11 -7
  67. package/lib/init/features/appsail/index.js +75 -26
  68. package/lib/init/features/appsail/prompt-fields.d.ts +43 -0
  69. package/lib/init/features/appsail/prompt-fields.js +55 -0
  70. package/lib/init/features/appsail/utils/custom-runtime.d.ts +3 -0
  71. package/lib/init/features/appsail/utils/custom-runtime.js +161 -0
  72. package/lib/init/features/appsail/{utils.d.ts → utils/index.d.ts} +2 -2
  73. package/lib/init/features/appsail/utils/index.js +170 -0
  74. package/lib/init/features/client/index.js +4 -3
  75. package/lib/init/features/client/initializers/angular.js +3 -2
  76. package/lib/init/features/client/initializers/react.js +4 -3
  77. package/lib/init/features/client/prompt-fields.d.ts +37 -0
  78. package/lib/init/features/client/prompt-fields.js +48 -0
  79. package/lib/init/features/functions/index.js +37 -8
  80. package/lib/init/features/functions/languages/java.js +42 -7
  81. package/lib/init/features/functions/languages/node.js +42 -10
  82. package/lib/init/features/functions/languages/python.js +42 -7
  83. package/lib/init/features/functions/prompt-fields.d.ts +25 -0
  84. package/lib/init/features/functions/prompt-fields.js +34 -0
  85. package/lib/init/features/project.js +41 -6
  86. package/lib/init/features/slate/index.js +2 -0
  87. package/lib/init/features/slate/prompt-fields.d.ts +31 -0
  88. package/lib/init/features/slate/prompt-fields.js +41 -0
  89. package/lib/init/index.js +2 -1
  90. package/lib/init/util/client.js +11 -8
  91. package/lib/init/util/common.d.ts +2 -0
  92. package/lib/init/util/common.js +33 -3
  93. package/lib/init/util/prompt-fields.d.ts +7 -0
  94. package/lib/init/util/prompt-fields.js +13 -0
  95. package/lib/internal/command.d.ts +3 -0
  96. package/lib/internal/command.js +26 -3
  97. package/lib/migration/global/1.27.0.d.ts +2 -0
  98. package/lib/migration/global/1.27.0.js +39 -0
  99. package/lib/prompt/choice.d.ts +2 -0
  100. package/lib/prompt/choice.js +24 -0
  101. package/lib/prompt/cli-option-key.d.ts +1 -0
  102. package/lib/prompt/cli-option-key.js +10 -0
  103. package/lib/prompt/index.d.ts +6 -22
  104. package/lib/prompt/index.js +264 -67
  105. package/lib/prompt/overwrite-prompt.d.ts +11 -0
  106. package/lib/prompt/overwrite-prompt.js +16 -0
  107. package/lib/prompt/question-factory.d.ts +34 -0
  108. package/lib/prompt/question-factory.js +41 -0
  109. package/lib/prompt/register-fields.d.ts +24 -0
  110. package/lib/prompt/register-fields.js +37 -0
  111. package/lib/pull/features/apig.js +57 -6
  112. package/lib/pull/features/client.js +107 -24
  113. package/lib/pull/features/functions/index.js +100 -4
  114. package/lib/pull/index.js +1 -1
  115. package/lib/pull/utils.d.ts +13 -0
  116. package/lib/pull/utils.js +20 -0
  117. package/lib/repl-server.d.ts +4 -0
  118. package/lib/repl-server.js +9 -0
  119. package/lib/serve/server/lib/master/index.js +3 -3
  120. package/lib/serve/server/lib/slate/static-server.js +2 -2
  121. package/lib/serve/server/lib/web_client/server.js +2 -2
  122. package/lib/shell/format-functions.d.ts +4 -0
  123. package/lib/shell/format-functions.js +59 -0
  124. package/lib/shell/index.js +18 -0
  125. package/lib/util_modules/config/lib/appsail.d.ts +3 -2
  126. package/lib/util_modules/config/lib/appsail.js +6 -3
  127. package/lib/util_modules/config/lib/slate.d.ts +19 -0
  128. package/lib/util_modules/config-store.d.ts +1 -0
  129. package/lib/util_modules/config-store.js +29 -10
  130. package/lib/util_modules/constants/index.d.ts +0 -1
  131. package/lib/util_modules/constants/index.js +1 -3
  132. package/lib/util_modules/constants/lib/urls.d.ts +2 -0
  133. package/lib/util_modules/constants/lib/urls.js +4 -0
  134. package/lib/util_modules/dc.d.ts +6 -1
  135. package/lib/util_modules/dc.js +21 -8
  136. package/lib/util_modules/env.d.ts +3 -0
  137. package/lib/util_modules/env.js +41 -0
  138. package/lib/util_modules/fs/lib/sync.d.ts +1 -0
  139. package/lib/util_modules/fs/lib/sync.js +19 -0
  140. package/lib/util_modules/logger/utils.d.ts +1 -0
  141. package/lib/util_modules/logger/utils.js +5 -1
  142. package/lib/util_modules/option.d.ts +1 -0
  143. package/lib/util_modules/option.js +8 -0
  144. package/lib/util_modules/{server.js → server/index.js} +3 -3
  145. package/lib/util_modules/server/needed-scopes.d.ts +1 -0
  146. package/lib/util_modules/{constants/lib → server}/needed-scopes.js +7 -7
  147. package/package.json +3 -2
  148. package/lib/init/features/appsail/utils.js +0 -273
  149. package/lib/util_modules/constants/lib/needed-scopes.d.ts +0 -4
  150. /package/lib/docs/{dc.toml → util_modules/dc.toml} +0 -0
  151. /package/lib/util_modules/{server.d.ts → server/index.d.ts} +0 -0
@@ -51,8 +51,15 @@ const runtime_store_1 = __importDefault(require("../../runtime-store"));
51
51
  const constants_1 = require("../../util_modules/constants");
52
52
  const scopes_js_1 = __importDefault(require("../../authentication/constants/scopes.js"));
53
53
  const index_1 = require("../../util_modules/logger/index");
54
+ const prompt_fields_1 = require("../../init/features/client/prompt-fields");
54
55
  exports.default = new command_1.default('client:setup')
55
56
  .description('Set up and configure the client directory in your project directory')
57
+ .option(prompt_fields_1.clientPromptFields.get('clientType'))
58
+ .option(prompt_fields_1.clientPromptFields.get('name'))
59
+ .option(prompt_fields_1.clientPromptFields.get('js-ts'))
60
+ .option(prompt_fields_1.clientPromptFields.get('routing'))
61
+ .option(prompt_fields_1.clientPromptFields.get('stylesheet'))
62
+ .option(prompt_fields_1.clientPromptFields.get('overwrite'))
56
63
  .needs('auth', [scopes_js_1.default.webapp])
57
64
  .needs('config', { optional: true })
58
65
  .needs('rc')
@@ -85,7 +85,7 @@ exports.default = new command_1.default('deploy')
85
85
  return true;
86
86
  });
87
87
  (0, index_1.info)();
88
- deployTargets.forEach((deploytarget) => {
88
+ for (const deploytarget of deployTargets) {
89
89
  switch (deploytarget) {
90
90
  case 'client':
91
91
  (0, index_1.info)();
@@ -98,7 +98,7 @@ exports.default = new command_1.default('deploy')
98
98
  break;
99
99
  case 'slate':
100
100
  (0, index_1.info)((0, ansi_colors_1.bold)(' >>>>>>>>>>>>>>> Slate <<<<<<<<<<<<<<<'));
101
- (0, slate_1.slateLogger)();
101
+ yield (0, slate_1.slateLogger)({ wait: false });
102
102
  (0, index_1.info)();
103
103
  break;
104
104
  case 'apig':
@@ -121,7 +121,7 @@ exports.default = new command_1.default('deploy')
121
121
  (0, utils_1.urlLogger)();
122
122
  break;
123
123
  }
124
- });
124
+ }
125
125
  if (deployTargets.length > 0) {
126
126
  (0, index_1.success)('Catalyst deploy complete!');
127
127
  (0, index_1.info)();
@@ -50,22 +50,83 @@ const util_1 = require("../../deploy/util");
50
50
  const error_1 = __importDefault(require("../../error"));
51
51
  const command_1 = __importDefault(require("../../internal/command"));
52
52
  const logger_1 = require("../../util_modules/logger");
53
+ const option_1 = require("../../util_modules/option");
54
+ const runtime_store_1 = __importDefault(require("../../runtime-store"));
55
+ const config_1 = require("../../util_modules/config");
56
+ const prompt_1 = __importDefault(require("../../prompt"));
57
+ const env_1 = require("../../util_modules/env");
58
+ const ansi_colors_1 = require("ansi-colors");
59
+ function resolveSlateTarget(name) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ var _a, _b;
62
+ const targets = ((_a = (yield config_1.slateConfig.getAllTargetDetails(false))) !== null && _a !== void 0 ? _a : []);
63
+ const validTargets = targets.filter((t) => { var _a; return ((_a = t.validity) === null || _a === void 0 ? void 0 : _a.valid) !== false; });
64
+ if (name) {
65
+ const match = targets.find((t) => t.name === name);
66
+ if (!match) {
67
+ throw new error_1.default(`Slate service "${name}" not found in config`, {
68
+ exit: 1
69
+ });
70
+ }
71
+ if (((_b = match.validity) === null || _b === void 0 ? void 0 : _b.valid) === false) {
72
+ throw new error_1.default(`Slate service "${name}" is invalid: ${match.validity.reason}`, { exit: 1 });
73
+ }
74
+ runtime_store_1.default.set('context.opts.only', `slate:${name}`);
75
+ return;
76
+ }
77
+ if (validTargets.length === 0) {
78
+ throw new error_1.default('No valid Slate services found to deploy', {
79
+ skipHelp: true
80
+ });
81
+ }
82
+ if (validTargets.length === 1) {
83
+ runtime_store_1.default.set('context.opts.only', `slate:${validTargets[0].name}`);
84
+ return;
85
+ }
86
+ const cwd = runtime_store_1.default.get('cwd');
87
+ const cwdMatches = validTargets.filter((t) => { var _a; return (_a = t.source) === null || _a === void 0 ? void 0 : _a.includes(cwd); });
88
+ if (cwdMatches.length === 1) {
89
+ runtime_store_1.default.set('context.opts.only', `slate:${cwdMatches[0].name}`);
90
+ return;
91
+ }
92
+ const { selected } = yield prompt_1.default.ask(prompt_1.default.question('selected', 'Select a Slate service to deploy:', {
93
+ type: 'list',
94
+ choices: validTargets.map((t) => prompt_1.default.choice(t.name))
95
+ }));
96
+ runtime_store_1.default.set('context.opts.only', `slate:${selected}`);
97
+ });
98
+ }
53
99
  exports.default = new command_1.default('slate')
54
- .description('Deploy your Catalyst Slate service to Catalyst Development environment')
100
+ .description('Deploy your Catalyst Slate app to Catalyst Development environment')
101
+ .argument('[name]', 'Name of the Slate app to deploy')
55
102
  .option('-m <msg>', 'Please provide the description for your app deployment.')
56
103
  .option('--production', 'Deploy the slate app to production environment.')
104
+ .option('--no-wait', 'Deploy without waiting for build logs and status.')
57
105
  .needs('auth')
58
106
  .needs('config', { optional: true })
59
107
  .needs('rc', { optional: true })
60
- .action(() => __awaiter(void 0, void 0, void 0, function* () {
108
+ .action((name) => __awaiter(void 0, void 0, void 0, function* () {
61
109
  try {
62
110
  util_1.DeployEvents.emit('start');
111
+ if ((0, env_1.isNonInteractiveMode)() && !name) {
112
+ throw new error_1.default('Slate app name is required in non-interactive mode. Please provide the name of the Slate service to deploy.', {
113
+ exit: 1,
114
+ errorId: 'E_NON_INTERACTIVE_MODE_SLATE_NAME_REQUIRED',
115
+ arg: [(0, ansi_colors_1.italic)(`catalyst deploy slate ${(0, ansi_colors_1.green)('<slate-app-name>')}`)]
116
+ });
117
+ }
118
+ yield resolveSlateTarget(name);
63
119
  yield (yield Promise.resolve().then(() => __importStar(require('../../deploy')))).default({ feature: 'slate' });
64
120
  (0, logger_1.info)();
65
- const deployTargets = (0, slate_1.slateLogger)();
66
- if (deployTargets.length === 0) {
121
+ const wait = (0, option_1.getOptionValue)('wait', true);
122
+ const succeededTargets = yield (0, slate_1.slateLogger)({ wait });
123
+ const allTargets = runtime_store_1.default.get('context.payload.slate.targets', []);
124
+ if (succeededTargets.length === 0) {
67
125
  (0, logger_1.error)('Slate Deploy failed');
68
126
  }
127
+ else if (wait && succeededTargets.length < allTargets.length) {
128
+ (0, logger_1.success)(`Catalyst Slate Deploy is Live!)`);
129
+ }
69
130
  else {
70
131
  (0, logger_1.success)('Catalyst Slate Deploy is Live!');
71
132
  }
@@ -51,8 +51,15 @@ const runtime_store_1 = __importDefault(require("../../runtime-store"));
51
51
  const constants_1 = require("../../util_modules/constants");
52
52
  const scopes_js_1 = __importDefault(require("../../authentication/constants/scopes.js"));
53
53
  const index_1 = require("../../util_modules/logger/index");
54
+ const prompt_fields_1 = require("../../init/features/functions/prompt-fields");
55
+ const prompt_fields_2 = require("../../init/util/prompt-fields");
54
56
  exports.default = new command_1.default('functions:add')
55
57
  .description('Add a function of the required stack to the function directory')
58
+ .option(prompt_fields_1.functionsAddPromptFields.get('name'))
59
+ .option(prompt_fields_1.functionsAddPromptFields.get('type'))
60
+ .option(prompt_fields_2.initCommonPromptFields.get('stack'))
61
+ .option(prompt_fields_1.functionsAddPromptFields.get('overwrite'))
62
+ .option(prompt_fields_1.functionsAddPromptFields.get('service'))
56
63
  .needs('auth', [scopes_js_1.default.functions])
57
64
  .needs('config', { optional: true })
58
65
  .needs('rc')
@@ -25,8 +25,10 @@ const scopes_js_1 = __importDefault(require("../../authentication/constants/scop
25
25
  const js_1 = require("../../util_modules/js");
26
26
  const index_1 = require("../../util_modules/logger/index");
27
27
  const option_1 = require("../../util_modules/option");
28
- exports.default = new command_1.default('functions:delete [function_name_or_id]')
28
+ const env_1 = require("../../util_modules/env");
29
+ exports.default = new command_1.default('functions:delete')
29
30
  .description('Delete a function from the remote console or the local directory')
31
+ .argument('[function_name_or_id]', 'name or id of the function to delete. This is required in non-interactive mode.')
30
32
  .option('--local', 'delete the functions in local machine.')
31
33
  .option('--remote', 'delete the functions in remote console.')
32
34
  .needs('auth', [scopes_js_1.default.projects])
@@ -46,7 +48,10 @@ exports.default = new command_1.default('functions:delete [function_name_or_id]'
46
48
  arg: [(0, ansi_colors_1.bold)('--local'), (0, ansi_colors_1.bold)('--remote')]
47
49
  });
48
50
  }
49
- if (!localOpt && !remoteOpt) {
51
+ if (!localOpt && !remoteOpt && (0, env_1.isNonInteractiveMode)()) {
52
+ localOpt = true;
53
+ }
54
+ else if (!localOpt && !remoteOpt) {
50
55
  const locationAns = yield prompt_1.default.ask(prompt_1.default.question('location', 'Choose a location to get more information', {
51
56
  type: 'list',
52
57
  choices: [
@@ -93,6 +98,13 @@ exports.default = new command_1.default('functions:delete [function_name_or_id]'
93
98
  }
94
99
  target = [fnTarget];
95
100
  }
101
+ else if ((0, env_1.isNonInteractiveMode)()) {
102
+ throw new index_js_1.default('fn_name input missing in ni mode', {
103
+ exit: 1,
104
+ errorId: 'FDEL-8',
105
+ arg: [(0, ansi_colors_1.italic)(`catalyst functions:delete ${(0, ansi_colors_1.red)('<function-name>')} --local`)]
106
+ });
107
+ }
96
108
  const localTargets = target.map((fn) => (0, path_1.join)(sourceDir, fn));
97
109
  const localChoices = (yield (0, common_1.refineTargets)(localTargets, false)).map((fn) => {
98
110
  if (!fn.valid) {
@@ -122,6 +134,12 @@ exports.default = new command_1.default('functions:delete [function_name_or_id]'
122
134
  choiceArr.push(...localChoices);
123
135
  }
124
136
  if (remoteOpt) {
137
+ if ((0, env_1.isNonInteractiveMode)()) {
138
+ throw new index_js_1.default('Cannot use remote option in non-interactive mode', {
139
+ exit: 1,
140
+ errorId: 'FDEL-7'
141
+ });
142
+ }
125
143
  let remoteTargets = (yield fnApi.getAllFunctions());
126
144
  if (js_1.JS.isEmpty(remoteTargets)) {
127
145
  throw new index_js_1.default('No targets found in remote', {
@@ -182,7 +200,7 @@ exports.default = new command_1.default('functions:delete [function_name_or_id]'
182
200
  }
183
201
  return true;
184
202
  },
185
- when: () => choiceArr.length > 2,
203
+ when: choiceArr.length > 2,
186
204
  pageSize: 15
187
205
  }));
188
206
  const fnToDelete = fnAns.functions !== undefined ? fnAns.functions : [choiceArr[1].value];
@@ -190,7 +208,7 @@ exports.default = new command_1.default('functions:delete [function_name_or_id]'
190
208
  .map((fn) => `${fn.name}(${fn.location})`)
191
209
  .join(',')}`, {
192
210
  type: 'confirm',
193
- defaultAns: false
211
+ defaultAns: (0, env_1.isNonInteractiveMode)()
194
212
  }));
195
213
  if (!consentAns.consent) {
196
214
  (0, index_1.message)('Aborted by user');
@@ -57,69 +57,18 @@ const common_js_1 = require("../../fn-utils/lib/common.js");
57
57
  const index_js_3 = require("../../util_modules/constants/index.js");
58
58
  const path_1 = require("path");
59
59
  const ansi_colors_1 = require("ansi-colors");
60
- const async_js_1 = require("../../util_modules/fs/lib/async.js");
60
+ const sync_js_1 = require("../../util_modules/fs/lib/sync.js");
61
61
  const index_js_4 = __importDefault(require("../../execute/index.js"));
62
- const project_js_1 = require("../../util_modules/project.js");
63
- function getInputs(exeTarget) {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- const inputsFile = (0, path_1.resolve)(exeTarget.source, typeof exeTarget.inputs === 'string' ? exeTarget.inputs : index_js_3.FILENAME.catalyst_inputs);
66
- const projectRoot = (0, project_js_1.getProjectRoot)();
67
- if (!inputsFile.startsWith(projectRoot)) {
68
- throw new index_js_2.default(`Input file path ${exeTarget.inputs} is outside the project directory.`, {
69
- exit: 1,
70
- context: {
71
- resolvePath: inputsFile,
72
- targetSource: projectRoot,
73
- inputs: exeTarget.inputs
74
- }
75
- });
76
- }
77
- const targetInputs = yield (0, async_js_1.readJSONFile)(inputsFile).catch((err) => {
78
- throw new index_js_2.default('Unable to read the inputs file', {
79
- original: err,
80
- exit: 1,
81
- errorId: 'FEXE-2',
82
- arg: [(0, ansi_colors_1.italic)(inputsFile), ansi_colors_1.italic.red(err || '')]
83
- });
84
- });
85
- if (!targetInputs || Object.keys(targetInputs).length === 0) {
86
- throw new index_js_2.default('Empty inputs', {
87
- exit: 0,
88
- errorId: 'FEXE-3',
89
- arg: [
90
- (0, ansi_colors_1.bold)(index_js_3.FILENAME.catalyst_inputs),
91
- (0, ansi_colors_1.bold)(index_js_3.FILENAME.catalyst_config),
92
- (0, ansi_colors_1.bold)('execution.test_inputs')
93
- ]
94
- });
95
- }
96
- const inputKeys = Object.keys(targetInputs);
97
- const keyOpt = (0, option_js_1.getOptionValue)('key', undefined);
98
- if (keyOpt && !(keyOpt in targetInputs)) {
99
- throw new index_js_2.default('Key not present in inputs', {
100
- exit: 0,
101
- errorId: 'FEXE-4',
102
- arg: [
103
- ansi_colors_1.bold.italic('--key ' + (0, ansi_colors_1.red)(keyOpt)),
104
- (0, ansi_colors_1.bold)(inputKeys.map((key) => '* ' + key).join('\n'))
105
- ]
106
- });
107
- }
108
- const selectedKey = yield index_js_1.default.ask(index_js_1.default.question('key', 'Please select the input', {
109
- type: 'list',
110
- choices: inputKeys.map((key) => index_js_1.default.choice(key, { value: key, short: key })),
111
- when: !keyOpt && inputKeys.length > 1
112
- }));
113
- return inputKeys.length === 1
114
- ? targetInputs[inputKeys[0]]
115
- : targetInputs[selectedKey.key] || targetInputs[keyOpt];
116
- });
117
- }
62
+ const index_1 = require("../../util_modules/logger/index");
63
+ const execute_input_resolver_js_1 = require("../../execute/execute-input-resolver.js");
64
+ const command_utils_js_1 = require("../../execute/command-utils.js");
65
+ const util_1 = require("util");
118
66
  exports.default = new command_js_1.default('functions:execute')
119
67
  .argument('[function_name]', 'Name of the function to execute')
120
- .argument('[data]', 'Input data for the function', '')
68
+ .argument('[data]', 'Input data for the function (deprecated)', '')
121
69
  .description('Execute the Non-Http functions')
122
- .option('--key <input_key>', 'Specify the input to be provided incase of multiple inputs present')
70
+ .option('--input <value>', 'Function input: inline JSON, a JSON file path, or "-" for stdin')
71
+ .option('--key <input_key>', 'Specify the input to be provided in-case of multiple inputs present')
123
72
  .option('--debug [port]', 'the functions are invoked from local environment enabling debugging options on provided port.' +
124
73
  `(default: ${default_js_1.default.serve_port.debug.basicio})`)
125
74
  .option('--ignore-scripts', 'ignore teh pre and post lifecycle scripts')
@@ -127,6 +76,16 @@ exports.default = new command_js_1.default('functions:execute')
127
76
  .needs('config')
128
77
  .needs('rc')
129
78
  .action((functionName, data) => __awaiter(void 0, void 0, void 0, function* () {
79
+ const inputOption = (0, option_js_1.getOptionValue)('input', undefined);
80
+ if (!inputOption && data) {
81
+ (0, index_1.warning)('The positional [data] argument is deprecated and will be removed in a future release. Use --input <value> instead.');
82
+ }
83
+ if (!inputOption && !data) {
84
+ const stdinType = (0, sync_js_1.getStdinType)();
85
+ if (stdinType === 'pipe' || stdinType === 'file') {
86
+ (0, index_1.warning)('Piped stdin is ignored unless you pass --input -. Use --input - to consume piped JSON input.');
87
+ }
88
+ }
130
89
  const fnSource = FUNCTIONS_CONFIG.source();
131
90
  const rawFnTargets = FUNCTIONS_CONFIG.targets();
132
91
  if (!rawFnTargets || rawFnTargets.length === 0) {
@@ -185,23 +144,32 @@ exports.default = new command_js_1.default('functions:execute')
185
144
  ]
186
145
  });
187
146
  }
188
- let jsonData;
189
- try {
190
- jsonData = data ? JSON.parse(data) : undefined;
147
+ let fnInput;
148
+ if (typeof inputOption === 'string') {
149
+ const resolvedInput = yield (0, execute_input_resolver_js_1.resolveExecuteInputOption)(inputOption);
150
+ if (!resolvedInput.ok) {
151
+ throw (0, execute_input_resolver_js_1.resolveInputError)(resolvedInput, inputOption);
152
+ }
153
+ fnInput = resolvedInput.value;
191
154
  }
192
- catch (er) {
193
- throw new index_js_2.default('Error parsing the JSON input', {
194
- exit: 1,
195
- errorId: 'FEXE-6',
196
- arg: [ansi_colors_1.italic.red(data || '<empty-string>')]
197
- });
155
+ else if (data) {
156
+ try {
157
+ fnInput = JSON.parse(data);
158
+ }
159
+ catch (er) {
160
+ throw new index_js_2.default('Error parsing the JSON input', {
161
+ exit: 1,
162
+ errorId: 'FEXE-6',
163
+ arg: [ansi_colors_1.italic.red(data || '<empty-string>')]
164
+ });
165
+ }
198
166
  }
199
- const fnInput = jsonData || (yield getInputs(exeTarget));
200
- if (!fnInput || typeof fnInput !== 'object') {
167
+ fnInput = yield (0, command_utils_js_1.getInputs)(exeTarget, fnInput);
168
+ if (!fnInput || typeof fnInput !== 'object' || Array.isArray(fnInput.ip)) {
201
169
  throw new index_js_2.default('Invalid input', {
202
170
  exit: 1,
203
171
  errorId: 'FEXE-5',
204
- arg: [ansi_colors_1.bold.red(fnInput || '')]
172
+ arg: [ansi_colors_1.bold.red((0, util_1.inspect)(fnInput) || '')]
205
173
  });
206
174
  }
207
175
  const debugPort = (0, option_js_1.getOptionValue)('debug', false);
@@ -51,6 +51,8 @@ const runtime_store_1 = __importDefault(require("../../runtime-store"));
51
51
  const constants_1 = require("../../util_modules/constants");
52
52
  const scopes_js_1 = __importDefault(require("../../authentication/constants/scopes.js"));
53
53
  const index_1 = require("../../util_modules/logger/index");
54
+ const env_1 = require("../../util_modules/env");
55
+ const error_1 = __importDefault(require("../../error"));
54
56
  exports.default = new command_1.default('functions:setup')
55
57
  .description('Set up and configure the function directory in your project directory')
56
58
  .needs('auth', [scopes_js_1.default.functions])
@@ -58,6 +60,17 @@ exports.default = new command_1.default('functions:setup')
58
60
  .needs('rc')
59
61
  .ci(false)
60
62
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
63
+ if ((0, env_1.isNonInteractiveMode)()) {
64
+ throw new error_1.default('The functions:setup command is disabled in non-interactive mode. Please use the functions:add command to add functions in non-interactive mode.', {
65
+ exit: 1,
66
+ errorId: 'E_NON_INTERACTIVE_MODE_FUNCTIONS_SETUP',
67
+ arg: [
68
+ ansi_colors_1.italic.yellow('catalyst functions:setup'),
69
+ (0, ansi_colors_1.bold)('non-interactive'),
70
+ ansi_colors_1.italic.green('catalyst functions:add')
71
+ ]
72
+ });
73
+ }
61
74
  const config = runtime_store_1.default.get('config');
62
75
  yield (yield Promise.resolve().then(() => __importStar(require('../../init/features')))).functions();
63
76
  yield config.save();
@@ -55,6 +55,8 @@ const constants_1 = require("../../util_modules/constants");
55
55
  const index_1 = require("../../util_modules/logger/index");
56
56
  const option_1 = require("../../util_modules/option");
57
57
  const project_1 = require("../../util_modules/project");
58
+ const needed_scopes_1 = require("../../util_modules/server/needed-scopes");
59
+ const env_1 = require("../../util_modules/env");
58
60
  exports.default = new command_1.default('functions:shell')
59
61
  .description('Launch a node shell to test emulated functions of any stack or type, other than Advanced I/O functions')
60
62
  .option('--only <targets>', 'only serve specified, comma-separated targets (e.g. "f1,f2")')
@@ -70,11 +72,23 @@ exports.default = new command_1.default('functions:shell')
70
72
  '\n' +
71
73
  '(deprecated: The watch mode will be enabled by default. To disable watch mode use the --no-watch option)')
72
74
  .option('--no-watch', 'disable watching the files for changes')
73
- .needs('auth', constants_1.NEEDED_SCOPES.SERVE)
75
+ .needs('auth', needed_scopes_1.SERVE_SCOPES)
74
76
  .needs('config')
75
77
  .needs('rc')
76
78
  .ci(false)
77
79
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
80
+ if ((0, env_1.isNonInteractiveMode)()) {
81
+ throw new error_1.default('The functions:shell command cannot be run in non-interactive mode. Please run the command in an interactive shell.', {
82
+ exit: 1,
83
+ errorId: 'FSHELL-2',
84
+ arg: [
85
+ (0, ansi_colors_1.bold)('functions:shell'),
86
+ (0, ansi_colors_1.bold)('non-interactive'),
87
+ (0, ansi_colors_1.bold)('functions:execute'),
88
+ (0, ansi_colors_1.italic)(`${(0, ansi_colors_1.dim)('>')} catalyst functions:execute -h`)
89
+ ]
90
+ });
91
+ }
78
92
  const httpOpt = (0, option_1.getOptionValue)('http', false);
79
93
  if (httpOpt && typeof httpOpt !== 'boolean') {
80
94
  runtime_store_1.default.set('context.port.http.bio', httpOpt);
@@ -68,7 +68,7 @@ const js_1 = require("../../util_modules/js");
68
68
  const index_1 = require("../../util_modules/logger/index");
69
69
  const option_1 = require("../../util_modules/option");
70
70
  const shell_1 = require("../../util_modules/shell");
71
- const server_js_1 = require("../../util_modules/server.js");
71
+ const index_js_2 = require("../../util_modules/server/index.js");
72
72
  const project_1 = require("../../util_modules/project");
73
73
  const getZipAndTemplate = (filePath, stagedDeploy) => __awaiter(void 0, void 0, void 0, function* () {
74
74
  const zipFile = filePath
@@ -119,7 +119,7 @@ const ensureUserAction = (deployRes) => __awaiter(void 0, void 0, void 0, functi
119
119
  res(e);
120
120
  }
121
121
  }));
122
- const destroyer = new server_js_1.ConnectionDestroyer(server);
122
+ const destroyer = new index_js_2.ConnectionDestroyer(server);
123
123
  server.listen(callbackPort, '127.0.0.1', () => {
124
124
  const urlString = accessUrl.toString();
125
125
  (0, index_1.info)();
@@ -56,16 +56,23 @@ const fs_1 = require("../util_modules/fs");
56
56
  const js_1 = require("../util_modules/js");
57
57
  const index_1 = require("../util_modules/logger/index");
58
58
  const shell_1 = require("../util_modules/shell");
59
+ const project_1 = require("../util_modules/project");
60
+ const error_1 = __importDefault(require("../error"));
61
+ const env_1 = require("../util_modules/env");
59
62
  const saveAndComplete = (config) => __awaiter(void 0, void 0, void 0, function* () {
60
- yield config.save();
61
- (0, index_1.message)((0, ansi_colors_1.bold)(constants_1.FILENAME.config) + ' file has been successfully created with feature details.');
63
+ if (Object.keys(config.data).length > 0) {
64
+ yield config.save();
65
+ (0, index_1.message)((0, ansi_colors_1.bold)(constants_1.FILENAME.config) + ' file has been successfully created with feature details.');
66
+ }
62
67
  (0, index_1.info)();
63
68
  (0, index_1.success)('Catalyst initialization complete!');
64
69
  });
65
- exports.default = new command_1.default('init [feature]')
70
+ exports.default = new command_1.default('init')
66
71
  .description('Initialize a Catalyst project, function, and client resources in the local directory')
72
+ .argument('[feature]', 'feature to initialize')
67
73
  .option('--force', 'force initialise a project for this directory')
68
- .ignore(['project'])
74
+ .option('--project <project_id>', 'project id to initialize the project for')
75
+ .option('--org <org_id>', 'organization id to initialize the project for')
69
76
  .needs('auth', [scopes_js_1.default.projects, scopes_js_1.default.project_import_create])
70
77
  .needs('config', { optional: true })
71
78
  .needs('rc', { optional: true, resolveOnNotFound: true })
@@ -74,6 +81,7 @@ exports.default = new command_1.default('init [feature]')
74
81
  var _a;
75
82
  const config = runtime_store_1.default.get('config');
76
83
  const homeDir = (yield Promise.resolve().then(() => __importStar(require('os')))).homedir();
84
+ const projectId = (0, project_1.getDefaultProjectId)(false);
77
85
  const warnings = [];
78
86
  if (fs_1.SYNC.isPathOutside(homeDir, runtime_store_1.default.get('cwd'))) {
79
87
  warnings.push('You are currently outside your home directory');
@@ -81,7 +89,7 @@ exports.default = new command_1.default('init [feature]')
81
89
  if (runtime_store_1.default.get('cwd') === homeDir) {
82
90
  warnings.push('You are initializing your home directory as a Catalyst project');
83
91
  }
84
- if (config.loaded) {
92
+ if (projectId) {
85
93
  warnings.push('You are initializing in an existing Catalyst project directory');
86
94
  }
87
95
  let warningText = '';
@@ -89,8 +97,7 @@ exports.default = new command_1.default('init [feature]')
89
97
  warningText =
90
98
  '\nBefore we get started, keep in mind:\n\n ' +
91
99
  ansi_colors_1.yellow.bold('* ') +
92
- warnings.join('\n ' + ansi_colors_1.yellow.bold('* ')) +
93
- '\n';
100
+ warnings.join('\n ' + ansi_colors_1.yellow.bold('* '));
94
101
  }
95
102
  (0, shell_1.clearStdout)(true);
96
103
  const bannerString = yield fs_1.ASYNC.readFile(constants_1.TEMPLATE.banner);
@@ -100,16 +107,22 @@ exports.default = new command_1.default('init [feature]')
100
107
  (0, ansi_colors_1.bold)(runtime_store_1.default.get('project.root')) +
101
108
  '\n' +
102
109
  warningText);
103
- if (feature !== 'project') {
104
- try {
105
- yield (0, features_1.project)();
106
- }
107
- catch (er) {
108
- (0, index_1.debug)(er);
109
- return;
110
+ if ((0, env_1.isNonInteractiveMode)()) {
111
+ if (feature && feature !== 'project') {
112
+ throw new error_1.default('ni mode is only supported for project initialization.', {
113
+ exit: 1,
114
+ errorId: 'E_NON_INTERACTIVE_FEATURE_INIT'
115
+ });
110
116
  }
117
+ feature = 'project';
111
118
  }
112
- (0, index_1.info)();
119
+ yield (0, features_1.project)();
120
+ if (feature === 'project') {
121
+ return saveAndComplete(config);
122
+ }
123
+ const askFeatIp = !runtime_store_1.default.get('context.payload.project.import', false) &&
124
+ typeof feature !== 'string';
125
+ askFeatIp && (0, index_1.info)();
113
126
  const featureAns = yield prompt_1.default.ask(prompt_1.default.question('features', 'Which are the features you want to setup for this folder?\n This step is optional! Press ' +
114
127
  (0, ansi_colors_1.cyan)('<return> ') +
115
128
  'to proceed.\n', {
@@ -132,12 +145,13 @@ exports.default = new command_1.default('init [feature]')
132
145
  short: 'Slate'
133
146
  })
134
147
  ],
135
- when: !runtime_store_1.default.get('context.payload.project.import', false) &&
136
- typeof feature !== 'string'
148
+ when: askFeatIp
137
149
  }));
138
- if (!((_a = featureAns.features) === null || _a === void 0 ? void 0 : _a.length) &&
139
- (runtime_store_1.default.get('context.payload.project.import', false) ||
140
- typeof feature !== 'string')) {
150
+ if (!((_a = featureAns.features) === null || _a === void 0 ? void 0 : _a.length) && !feature) {
151
+ (0, index_1.message)('No features selected for setup. Exiting...');
152
+ return saveAndComplete(config);
153
+ }
154
+ if (runtime_store_1.default.get('context.payload.project.import', false)) {
141
155
  return saveAndComplete(config);
142
156
  }
143
157
  if (typeof feature === 'string') {
@@ -50,6 +50,7 @@ exports.default = new command_1.default('login')
50
50
  .description('Log the CLI in to your Catalyst account')
51
51
  .option('--no-localhost', 'login without browser')
52
52
  .option('--force', 'force re-authentication')
53
+ .option('--dc <us|eu|in|au|ca|sa|jp|uae>', 'data center to login to')
53
54
  .ci(false)
54
55
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
55
56
  const auth = yield Promise.resolve().then(() => __importStar(require('../authentication/index.js')));
@@ -56,13 +56,32 @@ const env_1 = require("../util_modules/env");
56
56
  const fs_1 = require("../util_modules/fs");
57
57
  const js_1 = require("../util_modules/js");
58
58
  const index_1 = require("../util_modules/logger/index");
59
- exports.default = new command_1.default('pull [feature]')
59
+ const utils_1 = require("../pull/utils");
60
+ const common_1 = require("../init/util/common");
61
+ const error_1 = __importDefault(require("../error"));
62
+ exports.default = new command_1.default('pull')
60
63
  .description('Pull resources of your project from the remote console to the local directory')
64
+ .argument('[feature]', 'The feature to pull from the remote console. Valid values are: functions, client, apig')
65
+ .option(utils_1.promptPullFields.get('overwrite'))
66
+ .option(utils_1.promptPullFields.get('resource'))
61
67
  .needs('auth', [scopes_js_1.default.functions, scopes_js_1.default.webapp])
62
68
  .needs('config', { optional: true })
63
69
  .needs('rc')
70
+ .niHelp([
71
+ 'In Non-Interactive mode at a time only one feature can be pulled.',
72
+ 'In case of pulling multiple features, run the command multiple times.'
73
+ ]
74
+ .map((_txt) => '* ' + _txt)
75
+ .join('\n'))
64
76
  .ci(false)
65
77
  .action((feature) => __awaiter(void 0, void 0, void 0, function* () {
78
+ if ((0, env_1.isNonInteractiveMode)() && !feature) {
79
+ throw new error_1.default('In Non-Interactive mode the feature to pull must be specified as an argument. For example: catalyst pull functions', {
80
+ exit: 1,
81
+ errorId: 'E_NON_INTERACTIVE_PULL_NO_FEATURE',
82
+ arg: [(0, ansi_colors_1.italic)('<feature>'), (0, ansi_colors_1.italic)(`catalyst pull ${(0, ansi_colors_1.green)('functions')}`)]
83
+ });
84
+ }
66
85
  const config = runtime_store_1.default.get('config');
67
86
  const homeDir = (yield Promise.resolve().then(() => __importStar(require('os')))).homedir();
68
87
  const warnings = [];
@@ -97,6 +116,8 @@ exports.default = new command_1.default('pull [feature]')
97
116
  (0, index_1.message)('Aborted by user.');
98
117
  return;
99
118
  }
119
+ !(0, env_1.isNonInteractiveMode)() &&
120
+ (0, common_1.ignorableOptsTest)(utils_1.promptPullFields.get('resource').optKey, 'The overwrite option is not applicable for this command in interactive mode.');
100
121
  let featureAns = { features: [feature] };
101
122
  if (feature === undefined) {
102
123
  const featureChoices = [
@@ -47,6 +47,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
47
47
  Object.defineProperty(exports, "__esModule", { value: true });
48
48
  const command_1 = __importDefault(require("../internal/command"));
49
49
  const constants_1 = require("../util_modules/constants");
50
+ const needed_scopes_1 = require("../util_modules/server/needed-scopes");
50
51
  exports.default = new command_1.default('serve')
51
52
  .description('Serve Basic I/O and Advanced I/O functions, Appsail and the client, to test them locally')
52
53
  .option('--http <port>', 'start the server at specified port ')
@@ -59,7 +60,7 @@ exports.default = new command_1.default('serve')
59
60
  .option('--except <targets>', 'serve all targets except specified (e.g. "client")')
60
61
  .option('--ignore-scripts', 'ignore the pre and post lifecycle scripts')
61
62
  .option('--no-open', 'disable opening the client automatically when served')
62
- .needs('auth', constants_1.NEEDED_SCOPES.SERVE)
63
+ .needs('auth', needed_scopes_1.SERVE_SCOPES)
63
64
  .needs('config')
64
65
  .needs('rc')
65
66
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
@@ -50,16 +50,19 @@ const command_1 = __importDefault(require("../../internal/command"));
50
50
  const runtime_store_1 = __importDefault(require("../../runtime-store"));
51
51
  const constants_1 = require("../../util_modules/constants");
52
52
  const logger_1 = require("../../util_modules/logger");
53
+ const common_1 = require("../../init/util/common");
54
+ const prompt_fields_1 = require("../../init/features/slate/prompt-fields");
53
55
  exports.default = new command_1.default('slate:create')
54
56
  .description('Generates a new Slate app with starter examples')
55
- .option('--name <app_name>', 'Please provide name for your slate app')
56
- .option('--framework <framework_name>', 'Specify framework name for your slate')
57
- .option('--template <template_url>', 'Provide template url for your slate')
58
- .option('--default', 'Set default app configurations')
57
+ .option(prompt_fields_1.slateAddPromptFields.get('name'))
58
+ .option(prompt_fields_1.slateAddPromptFields.get('framework'))
59
+ .option(prompt_fields_1.slateAddPromptFields.get('template'))
60
+ .option(prompt_fields_1.slateAddPromptFields.get('default'))
59
61
  .needs('auth')
60
62
  .needs('config', { optional: true })
61
63
  .needs('rc', { optional: true, generateRc: true })
62
64
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
65
+ (0, common_1.niIgnorableOptsTest)([prompt_fields_1.slateAddPromptFields.get('default').optKey], 'Ignoring the following options in non-interactive mode:');
63
66
  const config = runtime_store_1.default.get('config');
64
67
  yield (yield Promise.resolve().then(() => __importStar(require('../../init/features')))).slate();
65
68
  yield config.save();