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
@@ -1,4 +1,37 @@
1
1
  'use strict';
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -17,51 +50,101 @@ const archiver_1 = __importDefault(require("../../archiver"));
17
50
  const client_utils_1 = require("../../client-utils");
18
51
  const endpoints_1 = require("../../endpoints");
19
52
  const error_1 = __importDefault(require("../../error"));
20
- const prompt_1 = __importDefault(require("../../prompt"));
53
+ const prompt_1 = __importStar(require("../../prompt"));
21
54
  const runtime_store_1 = __importDefault(require("../../runtime-store"));
22
55
  const config_1 = require("../../util_modules/config");
23
56
  const fs_1 = require("../../util_modules/fs");
24
57
  const js_1 = require("../../util_modules/js");
25
58
  const index_1 = require("../../util_modules/logger/index");
26
59
  const path_1 = require("path");
60
+ const env_1 = require("../../util_modules/env");
61
+ const option_1 = require("../../util_modules/option");
62
+ const utils_1 = require("../utils");
63
+ function getPullClientVersion() {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ const webappAPI = yield (0, endpoints_1.clientAPI)();
66
+ const historyArr = (yield webappAPI.getAllHistory());
67
+ if (historyArr.length === 0) {
68
+ (0, index_1.warning)('No Web Client app version found, Ensure that a Web Client is deployed in catalyst console before pulling it.');
69
+ return;
70
+ }
71
+ const resource = (0, option_1.getOptionValue)(utils_1.promptPullFields.get('resource').optKey, undefined);
72
+ if (resource) {
73
+ const resources = resource.split(',');
74
+ if (resources.length > 1) {
75
+ throw new error_1.default('Multiple resources are not allowed for client pull. Please specify only one client version to pull.', {
76
+ exit: 1,
77
+ errorId: 'E_NON_INTERACTIVE_CLIENT_PULL_MULTIPLE_RESOURCES',
78
+ arg: [(0, ansi_colors_1.italic)('catalyst pull client --resource <client_version>')]
79
+ });
80
+ }
81
+ const _appVersion = historyArr.find((history) => history.app_version === resources[0]);
82
+ return _appVersion ? _appVersion.history_id : undefined;
83
+ }
84
+ else if ((0, env_1.isNonInteractiveMode)()) {
85
+ throw new error_1.default('Client pull failed. Please specify the client version to pull using --resource option in non-interactive mode.', {
86
+ exit: 1,
87
+ errorId: 'E_NON_INTERACTIVE_CLIENT_PULL_NO_RESOURCE',
88
+ arg: [
89
+ (0, ansi_colors_1.italic)('--resource'),
90
+ (0, ansi_colors_1.italic)(`catalyst pull client ${(0, ansi_colors_1.green)('--resource <client_version>')}`),
91
+ (0, ansi_colors_1.bold)(historyArr.map((history) => '* ' + history.app_version).join('\n'))
92
+ ]
93
+ });
94
+ }
95
+ const choices = historyArr.map((history) => {
96
+ let live = '';
97
+ if (js_1.JS.get(history, 'status', false)) {
98
+ live = (0, ansi_colors_1.cyan)(' (LIVE)');
99
+ }
100
+ return prompt_1.default.choice(history.app_version + live, {
101
+ value: history.history_id,
102
+ short: history.app_version,
103
+ id: history.app_version
104
+ });
105
+ });
106
+ const historyAns = yield prompt_1.default.ask(prompt_1.default.question('history', 'Select a Catalyst client app version : ', {
107
+ type: 'list',
108
+ choices
109
+ }));
110
+ return historyAns.history;
111
+ });
112
+ }
27
113
  exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
28
114
  const clientDirName = config_1.clientConfig.source();
29
115
  const clientDirPath = clientDirName;
30
116
  const webappAPI = yield (0, endpoints_1.clientAPI)();
31
- const historyArr = (yield webappAPI.getAllHistory());
32
- if (historyArr.length === 0) {
33
- (0, index_1.info)('No history details found in remote console');
117
+ const historyAns = yield getPullClientVersion();
118
+ if (!historyAns)
34
119
  return;
35
- }
36
120
  const folderExits = yield fs_1.ASYNC.dirExists(clientDirPath);
37
121
  const overwriteAns = folderExits
38
- ? yield prompt_1.default.ask(prompt_1.default.question('overwrite', 'Directory ' + (0, ansi_colors_1.underline)(clientDirName) + ' already exists. Overwrite ?', {
39
- type: 'confirm',
40
- defaultAns: false
122
+ ? yield prompt_1.default.ask((0, prompt_1.overwritePromptQuestion)({
123
+ resourceName: clientDirName,
124
+ defaultAns: (0, env_1.isNonInteractiveMode)() &&
125
+ (0, option_1.getOptionValue)(utils_1.promptPullFields.get('overwrite').optKey, false)
126
+ ? true
127
+ : false
41
128
  }))
42
129
  : { overwrite: true };
43
130
  if (!overwriteAns.overwrite) {
131
+ if ((0, env_1.isNonInteractiveMode)()) {
132
+ throw new error_1.default('Client pull failed as the client directory already exists and the --overwrite option is not used to overwrite the file in local', {
133
+ exit: 1,
134
+ errorId: 'E_NON_INTERACTIVE_CLIENT_PULL_NO_OVERWRITE',
135
+ arg: [
136
+ ansi_colors_1.italic.red(clientDirPath),
137
+ (0, ansi_colors_1.italic)('--overwrite'),
138
+ (0, ansi_colors_1.italic)(`catalyst pull client ${(0, ansi_colors_1.green)('--overwrite')}`)
139
+ ]
140
+ });
141
+ }
44
142
  (0, index_1.info)('Skipping client pull');
45
143
  return;
46
144
  }
47
145
  yield fs_1.ASYNC.deleteDir(clientDirPath).catch();
48
- const choices = historyArr.map((history) => {
49
- let live = '';
50
- if (js_1.JS.get(history, 'status', false)) {
51
- live = (0, ansi_colors_1.cyan)(' (LIVE)');
52
- }
53
- return prompt_1.default.choice(history.app_version + live, {
54
- value: history.history_id,
55
- short: history.app_version,
56
- id: history.app_version
57
- });
58
- });
59
- const historyAns = yield prompt_1.default.ask(prompt_1.default.question('history', 'Select a Catalyst client app version : ', {
60
- type: 'list',
61
- choices
62
- }));
63
146
  try {
64
- const clientZip = (yield webappAPI.download(historyAns.history));
147
+ const clientZip = (yield webappAPI.download(historyAns));
65
148
  yield new archiver_1.default().load(clientZip).extract(clientDirPath).finalize();
66
149
  yield client_utils_1.clientUtils.validate({ skipPluginValidation: true });
67
150
  }
@@ -1,4 +1,37 @@
1
1
  'use strict';
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -17,7 +50,7 @@ const path_1 = require("path");
17
50
  const languages_1 = require("./languages");
18
51
  const archiver_1 = __importDefault(require("../../../archiver"));
19
52
  const endpoints_1 = require("../../../endpoints");
20
- const prompt_1 = __importDefault(require("../../../prompt"));
53
+ const prompt_1 = __importStar(require("../../../prompt"));
21
54
  const runtime_store_1 = __importDefault(require("../../../runtime-store"));
22
55
  const config_1 = require("../../../util_modules/config");
23
56
  const constants_1 = require("../../../util_modules/constants");
@@ -30,8 +63,12 @@ const python_1 = require("../../../fn-utils/lib/python");
30
63
  const throbber_1 = __importDefault(require("../../../throbber"));
31
64
  const ensure_java_userconfig_1 = require("../../../fn-utils/lib/java/ensure-java-userconfig");
32
65
  const logger_1 = require("../../../util_modules/logger");
66
+ const env_1 = require("../../../util_modules/env");
67
+ const utils_1 = require("../../utils");
68
+ const option_1 = require("../../../util_modules/option");
33
69
  function selFnsPrompt(targs, fnDirPath) {
34
70
  return __awaiter(this, void 0, void 0, function* () {
71
+ var _a;
35
72
  const choicesObj = targs.reduce((accumulator, fn) => {
36
73
  const name = fn.name;
37
74
  const type = fn.type === constants_1.REMOTE_REF.functions.type[constants_1.FN_TYPE.applogic]
@@ -58,6 +95,49 @@ function selFnsPrompt(targs, fnDirPath) {
58
95
  result.push(...value);
59
96
  return result;
60
97
  }, []);
98
+ if ((0, env_1.isNonInteractiveMode)()) {
99
+ const fns = ((_a = ((0, option_1.getOptionValue)(utils_1.promptPullFields.get('resource').optKey, undefined) ||
100
+ undefined)) === null || _a === void 0 ? void 0 : _a.split(',')) || [];
101
+ if (fns.length === 0) {
102
+ throw new error_1.default('Fns to pull not specified in non-interactive mode', {
103
+ exit: 1,
104
+ errorId: 'E_NON_INTERACTIVE_FNS_PULL-1',
105
+ arg: [
106
+ (0, ansi_colors_1.italic)('--resource'),
107
+ (0, ansi_colors_1.italic)('catalyst pull functions --resource fn1,fn2,fn3'),
108
+ (0, ansi_colors_1.bold)(choicesArr
109
+ .filter((_choice) => { var _a; return !!_choice.id || !!((_a = _choice.value) === null || _a === void 0 ? void 0 : _a.name); })
110
+ .map((choice) => '* ' + (choice.id || choice.value.name))
111
+ .join('\n'))
112
+ ]
113
+ });
114
+ }
115
+ return fns.reduce((_fnsArr, _fn) => {
116
+ const _choice = choicesArr.find((_choice) => {
117
+ var _a;
118
+ return (_choice.id && _choice.id === _fn) ||
119
+ (((_a = _choice.value) === null || _a === void 0 ? void 0 : _a.name) && _choice.value.name === _fn);
120
+ });
121
+ if (_choice) {
122
+ _fnsArr.push(_choice.value);
123
+ }
124
+ else {
125
+ throw new error_1.default('Cannot find the function in remote: ' + _fn, {
126
+ exit: 1,
127
+ errorId: 'E_NON_INTERACTIVE_FNS_PULL-2',
128
+ arg: [
129
+ (0, ansi_colors_1.italic)(`--resource ${(0, ansi_colors_1.red)(_fn)}`),
130
+ (0, ansi_colors_1.italic)('--resource'),
131
+ (0, ansi_colors_1.bold)(choicesArr
132
+ .filter((_choice) => { var _a; return !!_choice.id || !!((_a = _choice.value) === null || _a === void 0 ? void 0 : _a.name); })
133
+ .map((choice) => '* ' + (choice.id || choice.value.name))
134
+ .join('\n'))
135
+ ]
136
+ });
137
+ }
138
+ return _fnsArr;
139
+ }, []);
140
+ }
61
141
  const functionsAns = yield prompt_1.default.ask(prompt_1.default.question('functions', 'Select all the functions that you want to pull from remote console : ', {
62
142
  type: 'checkbox',
63
143
  choices: choicesArr,
@@ -108,15 +188,31 @@ exports.default = (_fns) => __awaiter(void 0, void 0, void 0, function* () {
108
188
  yield Promise.all(fns.map((fn) => __awaiter(void 0, void 0, void 0, function* () {
109
189
  const folderExists = yield fs_1.ASYNC.dirExists(fn.source);
110
190
  if (folderExists) {
111
- dirOverwriteQns.push(prompt_1.default.question(fn.name, 'Directory ' + (0, ansi_colors_1.underline)(fn.source) + ' already exists. Overwrite ?', {
112
- type: 'confirm',
113
- defaultAns: false
191
+ dirOverwriteQns.push((0, prompt_1.overwritePromptQuestion)({
192
+ fieldOrName: fn.name,
193
+ resourceName: fn.source,
194
+ defaultAns: (0, env_1.isNonInteractiveMode)() ? true : false
114
195
  }));
115
196
  }
116
197
  })));
117
198
  const dirOverwriteAns = yield prompt_1.default.ask(...dirOverwriteQns);
118
199
  const targets = fns.filter((fn) => {
119
200
  if (dirOverwriteAns[fn.name] === undefined || dirOverwriteAns[fn.name]) {
201
+ if ((0, env_1.isNonInteractiveMode)()) {
202
+ const overWriteOpt = (0, option_1.getOptionValue)(utils_1.promptPullFields.get('overwrite').optKey, false);
203
+ if (!overWriteOpt) {
204
+ throw new error_1.default('Cannot overwrite existing function directory in non-interactive mode as the --overwrite option is not specified', {
205
+ exit: 1,
206
+ errorId: 'E_NON_INTERACTIVE_FNS_PULL-3',
207
+ arg: [
208
+ (0, ansi_colors_1.bold)(`(${fn.name})`),
209
+ (0, ansi_colors_1.italic)('catalyst pull'),
210
+ (0, ansi_colors_1.italic)('--overwrite'),
211
+ (0, ansi_colors_1.italic)(`catalyst pull functions --resource ${(0, option_1.getOptionValue)(utils_1.promptPullFields.get('resource').optKey, 'fn1,fn2,fn3')} ${(0, ansi_colors_1.bold)('--overwrite')}`)
212
+ ]
213
+ });
214
+ }
215
+ }
120
216
  return true;
121
217
  }
122
218
  (0, index_1.message)('skipping pull of function: ' + fn.name);
package/lib/pull/index.js CHANGED
@@ -41,7 +41,7 @@ function pull() {
41
41
  (0, index_1.info)((0, ansi_colors_1.bold)('\n' + (0, ansi_colors_1.white)('===> ') + js_1.JS.capitalize(feature) + ' Setup'));
42
42
  yield MODULE().catch((err) => {
43
43
  (0, index_1.info)();
44
- (0, index_1.warning)(`Skipping pull of ${feature}. Since ${err.message}.\nContact Catalyst Support with catalyst-debug.log file.`);
44
+ (0, index_1.warning)(`Skipping pull of ${feature}. Since ${err.message}.`);
45
45
  });
46
46
  if (runtime_store_1.default.get('context.payload.' + feature, false)) {
47
47
  runtime_store_1.default.set('context.payload.features', runtime_store_1.default.get('context.payload.features', []).concat(feature));
@@ -0,0 +1,13 @@
1
+ export declare const promptPullFields: import("../prompt").PromptFieldsRegistry<readonly [{
2
+ readonly name: "overwrite";
3
+ readonly cliOption: {
4
+ readonly option: "--overwrite";
5
+ readonly description: "Overwrite existing resources such as functions/client/apig in the local directory if present";
6
+ };
7
+ }, {
8
+ readonly name: "resource";
9
+ readonly cliOption: {
10
+ readonly option: "--resource <fn_name|client_version>";
11
+ readonly description: "Specify the name of the resource to pull as comma separated values. For example: --resource func1,func2 (only applicable for Non-Interactive mode)";
12
+ };
13
+ }]>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.promptPullFields = void 0;
4
+ const prompt_1 = require("../prompt");
5
+ exports.promptPullFields = (0, prompt_1.definePromptFields)([
6
+ {
7
+ name: 'overwrite',
8
+ cliOption: {
9
+ option: '--overwrite',
10
+ description: 'Overwrite existing resources such as functions/client/apig in the local directory if present'
11
+ }
12
+ },
13
+ {
14
+ name: 'resource',
15
+ cliOption: {
16
+ option: '--resource <fn_name|client_version>',
17
+ description: 'Specify the name of the resource to pull as comma separated values. For example: --resource func1,func2 (only applicable for Non-Interactive mode)'
18
+ }
19
+ }
20
+ ]);
@@ -21,6 +21,10 @@ declare class Repl {
21
21
  start(): Repl;
22
22
  emit(eventName: string, ...inputs: Array<any>): boolean;
23
23
  showPrompt(): void;
24
+ defineCommand(keyword: string, cmd: {
25
+ help?: string;
26
+ action: (this: REPLServer, args: string) => void;
27
+ }): Repl;
24
28
  setContext(command: string, exe: unknown): Repl;
25
29
  close(): void;
26
30
  pause(): void;
@@ -58,6 +58,15 @@ class Repl {
58
58
  this.server.displayPrompt();
59
59
  }
60
60
  }
61
+ defineCommand(keyword, cmd) {
62
+ if (this.server === null) {
63
+ throw new index_js_1.default('command cannot be defined before server is started', {
64
+ exit: 2
65
+ });
66
+ }
67
+ this.server.defineCommand(keyword, cmd);
68
+ return this;
69
+ }
61
70
  setContext(command, exe) {
62
71
  if (this.server === null) {
63
72
  throw new index_js_1.default('context cannot be set before server is started', { exit: 2 });
@@ -29,7 +29,7 @@ const js_1 = require("../../../../util_modules/js");
29
29
  const index_1 = require("../../../../util_modules/logger/index");
30
30
  const project_2 = require("../../../../util_modules/project");
31
31
  const option_1 = require("../../../../util_modules/option");
32
- const server_js_1 = require("../../../../util_modules/server.js");
32
+ const index_js_1 = require("../../../../util_modules/server/index.js");
33
33
  const utils_1 = require("./utils");
34
34
  const appsail_1 = require("./appsail");
35
35
  const web_client_1 = require("./web-client");
@@ -104,7 +104,7 @@ function spinUpMaster(listenPort_1, _a) {
104
104
  signInRedirect: appSailDetails.target.config.login_redirect || '/'
105
105
  }))
106
106
  : proxy.on('proxyRes', (0, utils_1.proxyResponseHandler)({ systemRoutes, signInRedirect: signRedirectUrl }));
107
- const proxyDestroyer = new server_js_1.ConnectionDestroyer(proxy);
107
+ const proxyDestroyer = new index_js_1.ConnectionDestroyer(proxy);
108
108
  const unknownProxy = (0, unknown_req_proxy_1.default)(proxy, listenPort, customProxyUrl);
109
109
  otherServerDetails &&
110
110
  Object.keys(otherServerDetails).forEach((targ) => {
@@ -148,7 +148,7 @@ function spinUpMaster(listenPort_1, _a) {
148
148
  }
149
149
  console.error(err);
150
150
  });
151
- const expressDestroyer = new server_js_1.ConnectionDestroyer(expressServer);
151
+ const expressDestroyer = new index_js_1.ConnectionDestroyer(expressServer);
152
152
  expressServer.maxConnections = 100;
153
153
  const stopServer = () => expressDestroyer.destroy(!!appSailDetails);
154
154
  utils_1.serverEvent.once('stop', () => {
@@ -24,7 +24,7 @@ const path_1 = require("path");
24
24
  const ws_1 = require("ws");
25
25
  const port_resolver_js_1 = __importDefault(require("../../../../port-resolver.js"));
26
26
  const ansi_colors_1 = require("ansi-colors");
27
- const server_js_1 = require("../../../../util_modules/server.js");
27
+ const index_js_2 = require("../../../../util_modules/server/index.js");
28
28
  const env_1 = require("../../../../util_modules/env");
29
29
  function prepareScriptFile(dir, port) {
30
30
  return __awaiter(this, void 0, void 0, function* () {
@@ -180,7 +180,7 @@ function slateServer(httpPort_1, source_1) {
180
180
  const server = app.listen(httpPort, '127.0.0.1').on('error', (err) => {
181
181
  eventListener.emit('error', err);
182
182
  });
183
- const expressDestroyer = new server_js_1.ConnectionDestroyer(server);
183
+ const expressDestroyer = new index_js_2.ConnectionDestroyer(server);
184
184
  eventListener.on('error', (err) => {
185
185
  (0, logger_1.error)('Error when serving the web-client: ' + err.message);
186
186
  (0, logger_1.info)('Please exit the command to get more info');
@@ -24,7 +24,7 @@ const path_1 = require("path");
24
24
  const ws_1 = require("ws");
25
25
  const port_resolver_js_1 = __importDefault(require("../../../../port-resolver.js"));
26
26
  const ansi_colors_1 = require("ansi-colors");
27
- const server_js_1 = require("../../../../util_modules/server.js");
27
+ const index_js_4 = require("../../../../util_modules/server/index.js");
28
28
  const env_1 = require("../../../../util_modules/env");
29
29
  function prepareScriptFile(dir, port) {
30
30
  return __awaiter(this, void 0, void 0, function* () {
@@ -180,7 +180,7 @@ function webClientServer(httpPort_1, source_1) {
180
180
  const server = app.listen(httpPort, '127.0.0.1').on('error', (err) => {
181
181
  eventListener.emit('error', err);
182
182
  });
183
- const expressDestroyer = new server_js_1.ConnectionDestroyer(server);
183
+ const expressDestroyer = new index_js_4.ConnectionDestroyer(server);
184
184
  eventListener.on('error', (err) => {
185
185
  (0, index_1.error)('Error when serving the web-client: ' + err.message);
186
186
  (0, index_1.info)('Please exit the command to get more info');
@@ -0,0 +1,4 @@
1
+ import { IFnTarget } from '../fn-utils/lib/common';
2
+ export declare function resolveTypeLabel(type?: string): string;
3
+ export declare function resolveLanguage(stack?: string): string | undefined;
4
+ export declare function formatFunctionList(targets: Array<IFnTarget>): string;
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveTypeLabel = resolveTypeLabel;
4
+ exports.resolveLanguage = resolveLanguage;
5
+ exports.formatFunctionList = formatFunctionList;
6
+ const ansi_colors_1 = require("ansi-colors");
7
+ const constants_1 = require("../util_modules/constants");
8
+ const UNGROUPED_TYPE = 'other';
9
+ const TYPE_LABEL_BY_CODE = Object.fromEntries(Object.entries(constants_1.FN_TYPE).map(([label, code]) => [code, label]));
10
+ function resolveTypeLabel(type) {
11
+ if (!type) {
12
+ return UNGROUPED_TYPE;
13
+ }
14
+ return TYPE_LABEL_BY_CODE[type] || type;
15
+ }
16
+ function resolveLanguage(stack) {
17
+ if (!stack) {
18
+ return undefined;
19
+ }
20
+ const { node, java, python } = constants_1.RUNTIME.language;
21
+ if (stack.startsWith(node.value)) {
22
+ return node.label;
23
+ }
24
+ if (stack.startsWith(java.value)) {
25
+ return java.label;
26
+ }
27
+ if (stack.startsWith(python.value)) {
28
+ return python.label;
29
+ }
30
+ return undefined;
31
+ }
32
+ function formatFunctionList(targets) {
33
+ if (!targets || targets.length === 0) {
34
+ return 'No functions are attached to this shell.';
35
+ }
36
+ const groups = new Map();
37
+ for (const target of targets) {
38
+ const type = resolveTypeLabel(target.type);
39
+ const bucket = groups.get(type) || [];
40
+ bucket.push(target);
41
+ groups.set(type, bucket);
42
+ }
43
+ const longestName = targets.reduce((max, target) => Math.max(max, target.name.length), 0);
44
+ const lines = [];
45
+ lines.push((0, ansi_colors_1.bold)(`Available functions (${targets.length}):`));
46
+ lines.push('');
47
+ for (const [type, bucket] of groups) {
48
+ lines.push(' ' + (0, ansi_colors_1.cyan)(type));
49
+ for (const target of bucket) {
50
+ const language = resolveLanguage(target.stack);
51
+ const name = (0, ansi_colors_1.green)(target.name.padEnd(longestName));
52
+ const suffix = language ? ' ' + (0, ansi_colors_1.dim)(`(${language})`) : '';
53
+ lines.push(' • ' + name + suffix);
54
+ }
55
+ }
56
+ lines.push('');
57
+ lines.push((0, ansi_colors_1.dim)('Invoke a function by calling it, e.g. ') + (0, ansi_colors_1.bold)(targets[0].name + '({ ... })'));
58
+ return lines.join('\n');
59
+ }
@@ -59,6 +59,7 @@ const option_1 = require("../util_modules/option");
59
59
  const http_functions_1 = __importDefault(require("./dependencies/http-functions"));
60
60
  const non_http_function_1 = __importDefault(require("./dependencies/non-http-function"));
61
61
  const prepare_1 = __importDefault(require("./prepare"));
62
+ const format_functions_1 = require("./format-functions");
62
63
  const fn_watcher_1 = __importDefault(require("../fn-watcher"));
63
64
  const tunnel_server_1 = __importDefault(require("./dependencies/tunnel-server"));
64
65
  const endpoints_1 = require("../endpoints");
@@ -125,6 +126,9 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
125
126
  });
126
127
  }
127
128
  try {
129
+ (0, index_2.info)();
130
+ (0, index_2.info)((0, format_functions_1.formatFunctionList)(targets));
131
+ (0, index_2.info)();
128
132
  replServer.start();
129
133
  yield tunnelServer.startServer();
130
134
  const tunnelUrl = runtime_store_1.default.get('context.fn_shell.enable_tunnel', undefined);
@@ -167,6 +171,20 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
167
171
  tunnelServer.addContext(target.id || target.name, localFn);
168
172
  target.localFn = localFn;
169
173
  })));
174
+ const listFunctions = () => {
175
+ var _a, _b;
176
+ (_a = replServer.server) === null || _a === void 0 ? void 0 : _a.clearBufferedCommand();
177
+ (0, index_2.info)((0, format_functions_1.formatFunctionList)(targets));
178
+ (_b = replServer.server) === null || _b === void 0 ? void 0 : _b.displayPrompt();
179
+ };
180
+ replServer.defineCommand('functions', {
181
+ help: 'List the Catalyst functions available in this shell',
182
+ action: listFunctions
183
+ });
184
+ replServer.defineCommand('list', {
185
+ help: 'Alias for .functions — list the Catalyst functions available in this shell',
186
+ action: listFunctions
187
+ });
170
188
  if (runtime_store_1.default.get('context.port.http.' + constants_1.FN_TYPE.basic, false)) {
171
189
  yield httpServer.start();
172
190
  }
@@ -4,8 +4,8 @@ export interface IAppSailConfig {
4
4
  command?: string;
5
5
  memory?: number;
6
6
  port?: {
7
- http: number;
8
- debug: number;
7
+ http?: number;
8
+ debug?: number;
9
9
  };
10
10
  }
11
11
  export interface IAppSailServerConfig extends Record<string, unknown> {
@@ -44,6 +44,7 @@ export declare const CONTAINER_IMAGE_PROTOCOLS: {
44
44
  docker: string;
45
45
  dockerArchive: string;
46
46
  };
47
+ export declare function isCustomAppSailSource(source: string): boolean;
47
48
  export declare function raw(throwError?: boolean): Array<TAppSailDetails> | undefined;
48
49
  export declare function getTargetDetails(name: string): Promise<TAppSailDetails | undefined>;
49
50
  export declare function getAllTargetDetails(throwErr?: boolean): Promise<Array<TAppSailDetails> | undefined>;
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.CONTAINER_IMAGE_PROTOCOLS = void 0;
16
+ exports.isCustomAppSailSource = isCustomAppSailSource;
16
17
  exports.raw = raw;
17
18
  exports.getTargetDetails = getTargetDetails;
18
19
  exports.getAllTargetDetails = getAllTargetDetails;
@@ -27,6 +28,10 @@ exports.CONTAINER_IMAGE_PROTOCOLS = {
27
28
  docker: 'docker://',
28
29
  dockerArchive: 'docker-archive://'
29
30
  };
31
+ function isCustomAppSailSource(source) {
32
+ return (source.startsWith(exports.CONTAINER_IMAGE_PROTOCOLS.docker) ||
33
+ source.startsWith(exports.CONTAINER_IMAGE_PROTOCOLS.dockerArchive));
34
+ }
30
35
  function validateManagedAppConfig(source, configJson) {
31
36
  if (!configJson) {
32
37
  return {
@@ -105,9 +110,7 @@ function raw(throwError = false) {
105
110
  return `${exports.CONTAINER_IMAGE_PROTOCOLS.dockerArchive}${normalized}`;
106
111
  };
107
112
  return appsailConfig === null || appsailConfig === void 0 ? void 0 : appsailConfig.map((_conf) => {
108
- if (Object.values(exports.CONTAINER_IMAGE_PROTOCOLS)
109
- .flat()
110
- .find((proto) => _conf.source.startsWith(proto))) {
113
+ if (isCustomAppSailSource(_conf.source)) {
111
114
  return {
112
115
  name: _conf.name,
113
116
  source: _conf.source.startsWith(exports.CONTAINER_IMAGE_PROTOCOLS.dockerArchive)
@@ -32,6 +32,25 @@ export interface SlateBuildInfo {
32
32
  deployment_id: string;
33
33
  build_meta: Record<string, unknown>;
34
34
  }
35
+ export interface ISlateDeploymentInfo {
36
+ id: string;
37
+ app_id: string;
38
+ name: string;
39
+ auto_deploy: boolean;
40
+ created_time: string;
41
+ modified_time: string;
42
+ created_by: IAppUpdatedByDetails;
43
+ modified_by: IAppUpdatedByDetails;
44
+ status: string;
45
+ is_function_mapped: boolean;
46
+ org_restriction_enabled: boolean;
47
+ type: string;
48
+ value: string;
49
+ current_build: SlateBuildInfo | null;
50
+ upcoming_build: SlateBuildInfo | null;
51
+ origin_domain: string;
52
+ domain: string;
53
+ }
35
54
  export interface IAppUpdatedByDetails {
36
55
  zuid: string;
37
56
  is_confirmed: boolean;
@@ -1,6 +1,7 @@
1
1
  export default class Store {
2
2
  private static _store;
3
3
  static changeStore(store: 'cli' | 'vscode' | 'zcode', path?: string): void;
4
+ static _lockDownPermissions(): void;
4
5
  private static get istore();
5
6
  static get path(): string | undefined;
6
7
  static get store(): Record<string, unknown>;