zcatalyst-cli 1.26.1 → 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 (155) hide show
  1. package/README.md +1 -0
  2. package/lib/appsail-utils.d.ts +1 -1
  3. package/lib/appsail-utils.js +170 -129
  4. package/lib/authentication/credential.d.ts +2 -1
  5. package/lib/authentication/credential.js +20 -3
  6. package/lib/authentication/crypt.d.ts +7 -3
  7. package/lib/authentication/crypt.js +87 -16
  8. package/lib/authentication/index.js +1 -0
  9. package/lib/authentication/key-manager.d.ts +7 -0
  10. package/lib/authentication/key-manager.js +62 -0
  11. package/lib/authentication/login.js +20 -20
  12. package/lib/bin/catalyst.js +1 -15
  13. package/lib/client.d.ts +3 -1
  14. package/lib/client.js +16 -5
  15. package/lib/command_needs/rc.js +13 -3
  16. package/lib/commands/appsail/add.js +10 -0
  17. package/lib/commands/client/delete.js +18 -6
  18. package/lib/commands/client/setup.js +7 -0
  19. package/lib/commands/deploy/index.js +3 -3
  20. package/lib/commands/deploy/slate.js +65 -4
  21. package/lib/commands/functions/add.js +7 -0
  22. package/lib/commands/functions/delete.js +22 -4
  23. package/lib/commands/functions/execute.js +39 -71
  24. package/lib/commands/functions/setup.js +13 -0
  25. package/lib/commands/functions/shell.js +15 -1
  26. package/lib/commands/iac/import.js +2 -2
  27. package/lib/commands/init.js +34 -20
  28. package/lib/commands/login.js +1 -0
  29. package/lib/commands/pull.js +22 -1
  30. package/lib/commands/serve.js +2 -1
  31. package/lib/commands/slate/create.js +7 -4
  32. package/lib/commands/slate/link.js +11 -5
  33. package/lib/commands/slate/unlink.js +7 -0
  34. package/lib/commands/zest/generate/index.js +28 -35
  35. package/lib/deploy/features/appsail/index.js +2 -1
  36. package/lib/deploy/features/slate.d.ts +3 -1
  37. package/lib/deploy/features/slate.js +204 -5
  38. package/lib/docs/client-utils.toml +0 -5
  39. package/lib/docs/command_needs/rc.toml +9 -1
  40. package/lib/docs/commands/client/delete.toml +4 -0
  41. package/lib/docs/commands/deploy/slate.toml +3 -0
  42. package/lib/docs/commands/functions/delete.toml +10 -0
  43. package/lib/docs/commands/functions/execute.toml +1 -16
  44. package/lib/docs/commands/functions/setup.toml +3 -0
  45. package/lib/docs/commands/functions/shell.toml +8 -0
  46. package/lib/docs/commands/init.toml +3 -0
  47. package/lib/docs/commands/pull.toml +6 -0
  48. package/lib/docs/commands/slate/unlink.toml +6 -0
  49. package/lib/docs/execute/command-utils.toml +14 -0
  50. package/lib/docs/execute/execute-input-resolver.toml +37 -0
  51. package/lib/docs/init/features/project.toml +20 -0
  52. package/lib/docs/init/util/client.toml +4 -0
  53. package/lib/docs/prompt/index.toml +15 -0
  54. package/lib/docs/pull/features/apig.toml +6 -0
  55. package/lib/docs/pull/features/client.toml +20 -0
  56. package/lib/docs/pull/features/functions/index.toml +24 -0
  57. package/lib/endpoints/lib/slate.d.ts +14 -1
  58. package/lib/endpoints/lib/slate.js +35 -0
  59. package/lib/error/context-help.js +1 -1
  60. package/lib/error/index.js +9 -13
  61. package/lib/execute/command-utils.d.ts +5 -0
  62. package/lib/execute/command-utils.js +86 -0
  63. package/lib/execute/execute-input-resolver.d.ts +29 -0
  64. package/lib/execute/execute-input-resolver.js +207 -0
  65. package/lib/execute/index.d.ts +4 -1
  66. package/lib/execute/index.js +3 -2
  67. package/lib/fn-utils/lib/integ.js +22 -17
  68. package/lib/index.js +1 -0
  69. package/lib/init/dependencies/package-json.js +11 -7
  70. package/lib/init/features/appsail/index.js +75 -26
  71. package/lib/init/features/appsail/prompt-fields.d.ts +43 -0
  72. package/lib/init/features/appsail/prompt-fields.js +55 -0
  73. package/lib/init/features/appsail/utils/custom-runtime.d.ts +3 -0
  74. package/lib/init/features/appsail/utils/custom-runtime.js +161 -0
  75. package/lib/init/features/appsail/{utils.d.ts → utils/index.d.ts} +2 -2
  76. package/lib/init/features/appsail/utils/index.js +170 -0
  77. package/lib/init/features/client/index.js +4 -3
  78. package/lib/init/features/client/initializers/angular.js +3 -2
  79. package/lib/init/features/client/initializers/react.js +4 -3
  80. package/lib/init/features/client/prompt-fields.d.ts +37 -0
  81. package/lib/init/features/client/prompt-fields.js +48 -0
  82. package/lib/init/features/functions/index.js +37 -8
  83. package/lib/init/features/functions/languages/java.js +42 -7
  84. package/lib/init/features/functions/languages/node.js +42 -10
  85. package/lib/init/features/functions/languages/python.js +42 -7
  86. package/lib/init/features/functions/prompt-fields.d.ts +25 -0
  87. package/lib/init/features/functions/prompt-fields.js +34 -0
  88. package/lib/init/features/project.js +41 -6
  89. package/lib/init/features/slate/index.js +2 -0
  90. package/lib/init/features/slate/prompt-fields.d.ts +31 -0
  91. package/lib/init/features/slate/prompt-fields.js +41 -0
  92. package/lib/init/index.js +2 -1
  93. package/lib/init/util/client.js +11 -8
  94. package/lib/init/util/common.d.ts +2 -0
  95. package/lib/init/util/common.js +33 -3
  96. package/lib/init/util/prompt-fields.d.ts +7 -0
  97. package/lib/init/util/prompt-fields.js +13 -0
  98. package/lib/internal/command.d.ts +3 -0
  99. package/lib/internal/command.js +26 -3
  100. package/lib/migration/global/1.27.0.d.ts +2 -0
  101. package/lib/migration/global/1.27.0.js +39 -0
  102. package/lib/prompt/choice.d.ts +2 -0
  103. package/lib/prompt/choice.js +24 -0
  104. package/lib/prompt/cli-option-key.d.ts +1 -0
  105. package/lib/prompt/cli-option-key.js +10 -0
  106. package/lib/prompt/index.d.ts +6 -22
  107. package/lib/prompt/index.js +264 -67
  108. package/lib/prompt/overwrite-prompt.d.ts +11 -0
  109. package/lib/prompt/overwrite-prompt.js +16 -0
  110. package/lib/prompt/question-factory.d.ts +34 -0
  111. package/lib/prompt/question-factory.js +41 -0
  112. package/lib/prompt/register-fields.d.ts +24 -0
  113. package/lib/prompt/register-fields.js +37 -0
  114. package/lib/pull/features/apig.js +57 -6
  115. package/lib/pull/features/client.js +107 -24
  116. package/lib/pull/features/functions/index.js +100 -4
  117. package/lib/pull/index.js +1 -1
  118. package/lib/pull/utils.d.ts +13 -0
  119. package/lib/pull/utils.js +20 -0
  120. package/lib/repl-server.d.ts +4 -0
  121. package/lib/repl-server.js +9 -0
  122. package/lib/serve/features/appsail.js +2 -45
  123. package/lib/serve/server/lib/master/index.js +3 -3
  124. package/lib/serve/server/lib/slate/static-server.js +2 -2
  125. package/lib/serve/server/lib/web_client/server.js +2 -2
  126. package/lib/shell/format-functions.d.ts +4 -0
  127. package/lib/shell/format-functions.js +59 -0
  128. package/lib/shell/index.js +18 -0
  129. package/lib/util_modules/config/lib/appsail.d.ts +3 -2
  130. package/lib/util_modules/config/lib/appsail.js +21 -5
  131. package/lib/util_modules/config/lib/slate.d.ts +19 -0
  132. package/lib/util_modules/config-store.d.ts +1 -0
  133. package/lib/util_modules/config-store.js +29 -10
  134. package/lib/util_modules/constants/index.d.ts +0 -1
  135. package/lib/util_modules/constants/index.js +1 -3
  136. package/lib/util_modules/constants/lib/urls.d.ts +2 -0
  137. package/lib/util_modules/constants/lib/urls.js +4 -0
  138. package/lib/util_modules/dc.d.ts +6 -1
  139. package/lib/util_modules/dc.js +21 -8
  140. package/lib/util_modules/env.d.ts +3 -0
  141. package/lib/util_modules/env.js +41 -0
  142. package/lib/util_modules/fs/lib/sync.d.ts +1 -0
  143. package/lib/util_modules/fs/lib/sync.js +19 -0
  144. package/lib/util_modules/logger/utils.d.ts +1 -0
  145. package/lib/util_modules/logger/utils.js +5 -1
  146. package/lib/util_modules/option.d.ts +1 -0
  147. package/lib/util_modules/option.js +8 -0
  148. package/lib/util_modules/{server.js → server/index.js} +3 -3
  149. package/lib/util_modules/server/needed-scopes.d.ts +1 -0
  150. package/lib/util_modules/{constants/lib → server}/needed-scopes.js +7 -7
  151. package/package.json +3 -2
  152. package/lib/init/features/appsail/utils.js +0 -273
  153. package/lib/util_modules/constants/lib/needed-scopes.d.ts +0 -4
  154. /package/lib/docs/{dc.toml → util_modules/dc.toml} +0 -0
  155. /package/lib/util_modules/{server.d.ts → server/index.d.ts} +0 -0
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const crypto_1 = require("crypto");
7
+ const fs_1 = require("fs");
8
+ const path_1 = require("path");
9
+ const os_1 = require("os");
10
+ const config_store_js_1 = __importDefault(require("../util_modules/config-store.js"));
11
+ const KEY_FILE_NAME = '.zcatalyst-cli-key';
12
+ const KEY_BYTE_LENGTH = 32;
13
+ const FILE_MODE = 0o600;
14
+ const DIR_MODE = 0o700;
15
+ class KeyManager {
16
+ static get keyFilePath() {
17
+ const storeDir = config_store_js_1.default.path;
18
+ const baseDir = storeDir && storeDir.length > 0 ? storeDir : (0, os_1.homedir)();
19
+ return (0, path_1.join)(baseDir, KEY_FILE_NAME);
20
+ }
21
+ static getEncryptionKey() {
22
+ if (KeyManager.cachedKey) {
23
+ return KeyManager.cachedKey;
24
+ }
25
+ const filePath = KeyManager.keyFilePath;
26
+ if ((0, fs_1.existsSync)(filePath)) {
27
+ const key = (0, fs_1.readFileSync)(filePath);
28
+ KeyManager._lockDownPermissions(filePath);
29
+ KeyManager.cachedKey = key;
30
+ return key;
31
+ }
32
+ const dir = (0, path_1.dirname)(filePath);
33
+ if (!(0, fs_1.existsSync)(dir)) {
34
+ (0, fs_1.mkdirSync)(dir, { recursive: true, mode: DIR_MODE });
35
+ }
36
+ const key = (0, crypto_1.randomBytes)(KEY_BYTE_LENGTH);
37
+ try {
38
+ (0, fs_1.writeFileSync)(filePath, key, { mode: FILE_MODE, flag: 'wx' });
39
+ }
40
+ catch (err) {
41
+ if (err.code === 'EEXIST') {
42
+ const existingKey = (0, fs_1.readFileSync)(filePath);
43
+ KeyManager._lockDownPermissions(filePath);
44
+ KeyManager.cachedKey = existingKey;
45
+ return existingKey;
46
+ }
47
+ throw err;
48
+ }
49
+ KeyManager._lockDownPermissions(filePath);
50
+ KeyManager.cachedKey = key;
51
+ return key;
52
+ }
53
+ static _lockDownPermissions(filePath) {
54
+ try {
55
+ (0, fs_1.chmodSync)(filePath, FILE_MODE);
56
+ }
57
+ catch (err) {
58
+ }
59
+ }
60
+ }
61
+ KeyManager.cachedKey = null;
62
+ exports.default = KeyManager;
@@ -48,7 +48,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
48
48
  exports.missingScopes = void 0;
49
49
  const ansi_colors_1 = require("ansi-colors");
50
50
  const http_1 = require("http");
51
- const server_js_1 = require("../util_modules/server.js");
51
+ const index_js_1 = require("../util_modules/server/index.js");
52
52
  const open_1 = __importDefault(require("open"));
53
53
  const path_1 = require("path");
54
54
  const portfinder_1 = require("portfinder");
@@ -57,9 +57,9 @@ const dc_js_1 = require("../util_modules/dc.js");
57
57
  const error_js_1 = __importDefault(require("./error.js"));
58
58
  const api_js_1 = __importDefault(require("../internal/api.js"));
59
59
  const credential_js_1 = __importDefault(require("./credential.js"));
60
- const index_js_1 = __importDefault(require("../prompt/index.js"));
61
- const index_js_2 = __importDefault(require("../throbber/index.js"));
62
- const index_js_3 = require("../util_modules/constants/index.js");
60
+ const index_js_2 = __importDefault(require("../prompt/index.js"));
61
+ const index_js_3 = __importDefault(require("../throbber/index.js"));
62
+ const index_js_4 = require("../util_modules/constants/index.js");
63
63
  const auth_js_1 = __importDefault(require("./constants/auth.js"));
64
64
  const dc_type_js_1 = __importDefault(require("../util_modules/constants/lib/dc-type.js"));
65
65
  const scopes_js_1 = __importDefault(require("./constants/scopes.js"));
@@ -68,16 +68,16 @@ const js_js_1 = require("../util_modules/js.js");
68
68
  const index_1 = require("../util_modules/logger/index");
69
69
  const option_js_1 = require("../util_modules/option.js");
70
70
  const events_1 = __importDefault(require("events"));
71
- const index_js_4 = __importDefault(require("../error/index.js"));
71
+ const index_js_5 = __importDefault(require("../error/index.js"));
72
72
  const crypto_1 = require("crypto");
73
73
  const env_js_1 = require("../util_modules/env.js");
74
74
  exports.missingScopes = {
75
- [index_js_3.DC_TYPE.in.value]: getScopes(['dataverse']),
76
- [index_js_3.DC_TYPE.eu.value]: getScopes(['dataverse']),
77
- [index_js_3.DC_TYPE.au.value]: getScopes(['dataverse']),
78
- [index_js_3.DC_TYPE.ca.value]: getScopes(['quick_ml', 'dataverse']),
79
- [index_js_3.DC_TYPE.sa.value]: getScopes(['quick_ml', 'dataverse']),
80
- [index_js_3.DC_TYPE.jp.value]: getScopes(['dataverse'])
75
+ [index_js_4.DC_TYPE.in.value]: getScopes(['dataverse']),
76
+ [index_js_4.DC_TYPE.eu.value]: getScopes(['dataverse']),
77
+ [index_js_4.DC_TYPE.au.value]: getScopes(['dataverse']),
78
+ [index_js_4.DC_TYPE.ca.value]: getScopes(['quick_ml', 'dataverse']),
79
+ [index_js_4.DC_TYPE.sa.value]: getScopes(['quick_ml', 'dataverse']),
80
+ [index_js_4.DC_TYPE.jp.value]: getScopes(['dataverse'])
81
81
  };
82
82
  function getScopes(keys) {
83
83
  return Object.keys(scopes_js_1.default).filter((scope) => keys.some((prefix) => scope.startsWith(prefix)));
@@ -106,7 +106,7 @@ class Login {
106
106
  return 'http://localhost:' + port;
107
107
  }
108
108
  _getLoginUrl(callbackUrl, state) {
109
- return (index_js_3.ORIGIN.auth +
109
+ return (index_js_4.ORIGIN.auth +
110
110
  '/oauth/v2/auth?' +
111
111
  js_js_1.JS.map({
112
112
  client_id: auth_js_1.default.web.id,
@@ -124,7 +124,7 @@ class Login {
124
124
  return __awaiter(this, void 0, void 0, function* () {
125
125
  const authCodeResponse = yield new api_js_1.default()
126
126
  .post('/oauth/v2/token', {
127
- origin: index_js_3.ORIGIN.auth,
127
+ origin: index_js_4.ORIGIN.auth,
128
128
  qs: {
129
129
  code,
130
130
  client_id: auth_js_1.default.web.id,
@@ -164,7 +164,7 @@ class Login {
164
164
  return __awaiter(this, void 0, void 0, function* () {
165
165
  const deviceCodeResponse = yield new api_js_1.default()
166
166
  .post('/oauth/v3/device/token', {
167
- origin: index_js_3.ORIGIN.auth,
167
+ origin: index_js_4.ORIGIN.auth,
168
168
  qs: {
169
169
  client_id: auth_js_1.default.mobile.id,
170
170
  client_secret: auth_js_1.default.mobile.secret,
@@ -240,7 +240,7 @@ class Login {
240
240
  }
241
241
  const userInfoResponse = yield new api_js_1.default()
242
242
  .get('/oauth/user/info', {
243
- origin: index_js_3.ORIGIN.auth,
243
+ origin: index_js_4.ORIGIN.auth,
244
244
  authNeeded: true
245
245
  })
246
246
  .catch((err) => {
@@ -266,11 +266,11 @@ class Login {
266
266
  (0, index_1.debug)('Error while login with server : ' + err.message);
267
267
  }
268
268
  this.salt = 'm';
269
- const throbber = index_js_2.default.getInstance();
269
+ const throbber = index_js_3.default.getInstance();
270
270
  const throbberName = 'authentication';
271
271
  const deviceCodeResponse = yield new api_js_1.default()
272
272
  .post('/oauth/v3/device/code', {
273
- origin: index_js_3.ORIGIN.auth,
273
+ origin: index_js_4.ORIGIN.auth,
274
274
  qs: {
275
275
  client_id: auth_js_1.default.mobile.id,
276
276
  scope: js_js_1.JS.values(this._getScopes()).join(' '),
@@ -356,7 +356,7 @@ class Login {
356
356
  const queryParamsObj = new url_1.URL(req.url, `http://${req.headers.host}`)
357
357
  .searchParams;
358
358
  if (queryParamsObj.get('state') !== nonce) {
359
- throw new index_js_4.default('Invalid state param received.', { exit: 2 });
359
+ throw new index_js_5.default('Invalid state param received.', { exit: 2 });
360
360
  }
361
361
  const code = queryParamsObj !== undefined && queryParamsObj.get('code');
362
362
  const _location = queryParamsObj !== undefined && queryParamsObj.get('location');
@@ -367,7 +367,7 @@ class Login {
367
367
  typeof location === 'string' &&
368
368
  location !== dcRef) {
369
369
  (0, index_1.warning)('Your credentials does not match the DC opted!!!');
370
- const ans = yield index_js_1.default.ask(index_js_1.default.question('DC', `Do you wish to continue with login by making ${location.toUpperCase()} DC as active ?`, {
370
+ const ans = yield index_js_2.default.ask(index_js_2.default.question('DC', `Do you wish to continue with login by making ${location.toUpperCase()} DC as active ?`, {
371
371
  type: 'confirm',
372
372
  defaultAns: true
373
373
  }));
@@ -410,7 +410,7 @@ class Login {
410
410
  }));
411
411
  }
412
412
  }));
413
- const destroyer = new server_js_1.ConnectionDestroyer(server);
413
+ const destroyer = new index_js_1.ConnectionDestroyer(server);
414
414
  server.listen(port, '127.0.0.1', () => {
415
415
  (0, index_1.info)();
416
416
  (0, index_1.info)('Visit this URL on this device to log in:');
@@ -129,18 +129,4 @@ process.on('unhandledRejection', (reason, promise) => {
129
129
  (0, errorOut_1.default)((0, util_1.inspect)(reason || promise));
130
130
  process.exitCode = runtime_store_js_1.default.get('exitCode', 2);
131
131
  });
132
- let cmdPromise;
133
- if (process.stdin.isTTY) {
134
- cmdPromise = index_js_1.Catalyst.processArgs(...process.argv);
135
- }
136
- else {
137
- let stdin = '';
138
- process.stdin.on('data', (chunk) => {
139
- if (chunk !== null) {
140
- stdin += chunk;
141
- }
142
- });
143
- process.stdin.on('end', () => {
144
- cmdPromise = index_js_1.Catalyst.processArgs(...process.argv, stdin.toString().trimEnd());
145
- });
146
- }
132
+ const cmdPromise = index_js_1.Catalyst.processArgs(...process.argv);
package/lib/client.d.ts CHANGED
@@ -9,11 +9,13 @@ export declare class Client {
9
9
  processArgs(...args: Array<string>): Promise<Command>;
10
10
  getCommand(name: string): Command | null;
11
11
  getAllCommandNames(): Array<string>;
12
+ private static execOptionKeyToCliFlag;
12
13
  private convertOptions;
13
- exec(command: string, projectRoot: string, cwd: string, { args, options, inputs }?: {
14
+ exec(command: string, projectRoot: string, cwd: string, { args, options, inputs, nonInteractive }?: {
14
15
  args?: Array<string>;
15
16
  options?: Record<string, string | boolean | Array<string>>;
16
17
  inputs?: Record<string, unknown>;
18
+ nonInteractive?: boolean;
17
19
  }): Promise<{
18
20
  exitCode: 0 | 1 | 2;
19
21
  error?: CatalystError;
package/lib/client.js CHANGED
@@ -104,26 +104,37 @@ class Client {
104
104
  return cmd.name();
105
105
  });
106
106
  }
107
+ static execOptionKeyToCliFlag(key) {
108
+ if (key === 'nonInteractive') {
109
+ return 'non-interactive';
110
+ }
111
+ return key;
112
+ }
107
113
  convertOptions(options) {
108
114
  const optionsArr = [];
109
115
  Object.entries(options).forEach(([key, value]) => {
116
+ const flag = Client.execOptionKeyToCliFlag(key);
110
117
  if (typeof value === 'boolean') {
111
- value && optionsArr.push('--' + key);
118
+ value && optionsArr.push('--' + flag);
112
119
  return;
113
120
  }
114
- optionsArr.push('--' + key);
121
+ optionsArr.push('--' + flag);
115
122
  optionsArr.push(typeof value === 'string' ? value : value.join(','));
116
123
  });
117
124
  return optionsArr;
118
125
  }
119
126
  exec(command_1, projectRoot_1, cwd_1) {
120
- return __awaiter(this, arguments, void 0, function* (command, projectRoot, cwd, { args = [], options = {}, inputs } = {}) {
127
+ return __awaiter(this, arguments, void 0, function* (command, projectRoot, cwd, { args = [], options = {}, inputs = {}, nonInteractive } = {}) {
121
128
  runtime_store_1.default.set('context', {});
122
129
  utils_js_1.runtime.set('context', {});
123
130
  runtime_store_1.default.set('cwd', cwd);
124
131
  runtime_store_1.default.set('project.root', projectRoot);
125
- runtime_store_1.default.set('prompt', inputs);
126
- const programArgs = [...args, ...this.convertOptions(options)];
132
+ runtime_store_1.default.set('context.prompt', inputs);
133
+ const mergedOptions = Object.assign({}, options);
134
+ if (nonInteractive) {
135
+ mergedOptions.nonInteractive = true;
136
+ }
137
+ const programArgs = [...args, ...this.convertOptions(mergedOptions)];
127
138
  this._cli = new commander_1.Command();
128
139
  yield this.init(command);
129
140
  yield this.processArgs('node', 'catalyst', command, ...programArgs);
@@ -50,13 +50,23 @@ exports.default = (...args_1) => __awaiter(void 0, [...args_1], void 0, function
50
50
  const orgApi = yield (0, endpoints_1.orgAPI)();
51
51
  if (orgOpt !== null) {
52
52
  const orgList = yield orgApi.getAllOrgs();
53
- const found = orgList.find((org) => org.id + '' === orgOpt);
53
+ const found = orgList.find((org) => org.id + '' === orgOpt || org.name === orgOpt);
54
54
  if (!found) {
55
+ if ((0, env_1.isNonInteractiveMode)())
56
+ throw new index_js_1.default('Invalid "org" option supplied', {
57
+ exit: 1,
58
+ errorId: 'RC-7',
59
+ arg: [
60
+ (0, ansi_colors_1.red)(orgOpt),
61
+ (0, ansi_colors_1.italic)('--org'),
62
+ (0, ansi_colors_1.bold)(orgList.map((org) => '* ' + org.name + ' (' + org.id + ')').join('\n'))
63
+ ]
64
+ });
55
65
  throw new index_js_1.default('Invalid "org" option supplied', {
56
- exit: 2
66
+ exit: 1
57
67
  });
58
68
  }
59
- runtime_store_1.default.set('project.env.id', orgOpt + '');
69
+ runtime_store_1.default.set('project.env.id', found.id + '');
60
70
  }
61
71
  let projectApi = yield (0, endpoints_1.projectAPI)();
62
72
  let envApi = yield (0, endpoints_1.envAPI)();
@@ -51,12 +51,22 @@ const runtime_store_1 = __importDefault(require("../../runtime-store"));
51
51
  const constants_1 = require("../../util_modules/constants");
52
52
  const index_1 = require("../../util_modules/logger/index");
53
53
  const scopes_1 = __importDefault(require("../../authentication/constants/scopes"));
54
+ const prompt_fields_1 = require("../../init/features/appsail/prompt-fields");
55
+ const prompt_fields_2 = require("../../init/util/prompt-fields");
54
56
  exports.default = new command_1.default('appsail:add')
55
57
  .description('Link an already existing AppSail to Catalyst Project')
56
58
  .needs('auth', [scopes_1.default.functions])
57
59
  .needs('config', { optional: true })
58
60
  .needs('rc')
59
61
  .ci(false)
62
+ .option(prompt_fields_1.appsailAddPromptFields.get('name'))
63
+ .option(prompt_fields_2.initCommonPromptFields.get('stack'))
64
+ .option(prompt_fields_1.appsailAddPromptFields.get('source'))
65
+ .option(prompt_fields_1.appsailAddPromptFields.get('overwrite'))
66
+ .option(prompt_fields_1.appsailAddPromptFields.get('buildPath'))
67
+ .option(prompt_fields_1.appsailAddPromptFields.get('platform'))
68
+ .option(prompt_fields_1.appsailAddPromptFields.get('command'))
69
+ .option(prompt_fields_1.appsailAddPromptFields.get('port'))
60
70
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
61
71
  const config = runtime_store_1.default.get('config');
62
72
  yield (yield Promise.resolve().then(() => __importStar(require('../../init/features')))).appsail();
@@ -27,8 +27,10 @@ const fs_1 = require("../../util_modules/fs");
27
27
  const js_1 = require("../../util_modules/js");
28
28
  const index_1 = require("../../util_modules/logger/index");
29
29
  const option_1 = require("../../util_modules/option");
30
- exports.default = new command_1.default('client:delete [client_version]')
30
+ const env_1 = require("../../util_modules/env");
31
+ exports.default = new command_1.default('client:delete')
31
32
  .description('Delete a version of the client from the remote console or the local directory')
33
+ .argument('[client_version]', 'version of the client to delete')
32
34
  .option('--local', 'removes the client from local machine')
33
35
  .option('--remote', 'removes the selected client from remote console')
34
36
  .needs('auth', [scopes_js_1.default.webapp])
@@ -48,6 +50,9 @@ exports.default = new command_1.default('client:delete [client_version]')
48
50
  arg: [(0, ansi_colors_1.bold)('--local'), (0, ansi_colors_1.bold)('--remote')]
49
51
  });
50
52
  }
53
+ if (!localOpt && !remoteOpt && (0, env_1.isNonInteractiveMode)()) {
54
+ localOpt = true;
55
+ }
51
56
  if (!localOpt && !remoteOpt) {
52
57
  const locationAns = yield prompt_1.default.ask(prompt_1.default.question('location', 'Choose a location to get more information', {
53
58
  type: 'list',
@@ -77,7 +82,7 @@ exports.default = new command_1.default('client:delete [client_version]')
77
82
  location: local
78
83
  };
79
84
  try {
80
- const configFile = fs_1.ASYNC.readJSONFile(packageJsonFile, {
85
+ const configFile = yield fs_1.ASYNC.readJSONFile(packageJsonFile, {
81
86
  checkpath: true
82
87
  });
83
88
  if (configFile === undefined) {
@@ -116,6 +121,13 @@ exports.default = new command_1.default('client:delete [client_version]')
116
121
  }
117
122
  }
118
123
  if (remoteOpt) {
124
+ if ((0, env_1.isNonInteractiveMode)()) {
125
+ throw new index_js_1.default('Remote deletion is not supported in non-interactive mode', {
126
+ exit: 1,
127
+ errorId: 'CDEL-8',
128
+ arg: [(0, ansi_colors_1.bold)('catalyst client:delete --local')]
129
+ });
130
+ }
119
131
  const choicesArray = [];
120
132
  let historyArr = (yield clientApi.getAllHistory());
121
133
  if (js_1.JS.isEmpty(historyArr)) {
@@ -171,7 +183,7 @@ exports.default = new command_1.default('client:delete [client_version]')
171
183
  : false
172
184
  }));
173
185
  });
174
- const choiceAns = yield prompt_1.default.ask(prompt_1.default.question('choice', 'Select all the client versions you want to delete', {
186
+ const choiceAns = yield prompt_1.default.ask(prompt_1.default.question('clientsToDelete', 'Select all the client versions you want to delete', {
175
187
  type: 'checkbox',
176
188
  choices: choicesArray,
177
189
  validate: (answers) => {
@@ -184,8 +196,8 @@ exports.default = new command_1.default('client:delete [client_version]')
184
196
  return choicesArray.length > 2;
185
197
  }
186
198
  }));
187
- if (choiceAns.choice !== undefined) {
188
- appsToBeDeleted.push(...choiceAns.choice);
199
+ if (choiceAns.clientsToDelete !== undefined) {
200
+ appsToBeDeleted.push(...choiceAns.clientsToDelete);
189
201
  }
190
202
  else if (choicesArray.length === 2 && !choicesArray[1].disabled) {
191
203
  appsToBeDeleted.push(choicesArray[1].value);
@@ -204,7 +216,7 @@ exports.default = new command_1.default('client:delete [client_version]')
204
216
  const consentAns = yield prompt_1.default.ask(prompt_1.default.question('consent', 'Are you sure you want to delete the clients : ' +
205
217
  appsToBeDeleted.map((app) => `${app.version}(${app.location})`).join(','), {
206
218
  type: 'confirm',
207
- defaultAns: false,
219
+ defaultAns: (0, env_1.isNonInteractiveMode)(),
208
220
  when: () => {
209
221
  return appsToBeDeleted.length > 0;
210
222
  }
@@ -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');