zcatalyst-cli 1.18.0-beta.0 → 1.18.0-beta.10

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 (160) hide show
  1. package/docs/command_needs/rc.toml +8 -8
  2. package/docs/commands/ds/import.toml +5 -5
  3. package/docs/commands/event/generate/job.toml +7 -0
  4. package/docs/commands/zest/generate/index.toml +4 -0
  5. package/docs/endpoints/lib/job-scheduling.toml +3 -0
  6. package/docs/internal/command.toml +5 -0
  7. package/docs/serve/server/lib/appsail/index.toml +22 -1
  8. package/lib/appsail-utils.js +4 -10
  9. package/lib/authentication/index.js +1 -0
  10. package/lib/authentication/login.js +8 -4
  11. package/lib/bin/catalyst.js +1 -1
  12. package/lib/code-deck.js +7 -7
  13. package/lib/command_needs/rc.js +8 -8
  14. package/lib/commands/appsail/add.js +3 -2
  15. package/lib/commands/client/setup.js +2 -1
  16. package/lib/commands/codelib/install.js +6 -2
  17. package/lib/commands/ds/import.js +37 -21
  18. package/lib/commands/event/generate/index.js +16 -3
  19. package/lib/commands/event/generate/integ.js +2 -1
  20. package/lib/commands/event/generate/job.js +82 -0
  21. package/lib/commands/functions/add.js +2 -1
  22. package/lib/commands/functions/delete.js +2 -4
  23. package/lib/commands/functions/setup.js +2 -1
  24. package/lib/commands/functions/shell.js +1 -0
  25. package/lib/commands/iac/export.js +5 -1
  26. package/lib/commands/iac/import.js +4 -1
  27. package/lib/commands/index.js +4 -1
  28. package/lib/commands/init.js +10 -7
  29. package/lib/commands/login.js +1 -0
  30. package/lib/commands/logout.js +1 -0
  31. package/lib/commands/pull.js +1 -0
  32. package/lib/commands/serve.js +1 -1
  33. package/lib/commands/whoami.js +1 -0
  34. package/lib/commands/zest/generate/index.js +304 -0
  35. package/lib/deploy/features/appsail/index.js +42 -25
  36. package/lib/deploy/features/appsail/utils.js +4 -5
  37. package/lib/endpoints/index.js +24 -3
  38. package/lib/endpoints/lib/appsail.js +7 -1
  39. package/lib/endpoints/lib/ds-bulk.js +1 -0
  40. package/lib/endpoints/lib/job-scheduling.js +61 -0
  41. package/lib/endpoints/lib/stratus.js +63 -0
  42. package/lib/endpoints/lib/tunnel.js +18 -0
  43. package/lib/endpoints/lib/zest.js +124 -0
  44. package/lib/event_generate/stratus.js +52 -0
  45. package/lib/express_middlewares/logger.js +2 -4
  46. package/lib/fn-utils/lib/common.js +8 -4
  47. package/lib/fn-utils/lib/java.js +1 -1
  48. package/lib/fn-utils/lib/python.js +2 -2
  49. package/lib/fn-watcher.js +1 -1
  50. package/lib/iac/status/deploy.js +1 -5
  51. package/lib/init/dependencies/python/ensure-python.js +6 -8
  52. package/lib/init/features/appsail/index.js +38 -27
  53. package/lib/init/features/client/index.js +2 -1
  54. package/lib/init/features/functions/index.js +4 -0
  55. package/lib/init/features/functions/languages/python.js +21 -5
  56. package/lib/init/features/project.js +6 -15
  57. package/lib/internal/api.js +26 -7
  58. package/lib/internal/command.js +31 -7
  59. package/lib/migration/index.js +4 -2
  60. package/lib/optional-import.js +3 -2
  61. package/lib/prompt/index.js +5 -2
  62. package/lib/prompt/types/file-path.js +1 -1
  63. package/lib/prompt/types/search-box.js +281 -0
  64. package/lib/prompt/types/tree.js +3 -3
  65. package/lib/serve/features/appsail.js +3 -4
  66. package/lib/serve/index.js +1 -2
  67. package/lib/serve/server/index.js +52 -23
  68. package/lib/serve/server/lib/appsail/index.js +89 -39
  69. package/lib/serve/server/lib/appsail/start.js +9 -1
  70. package/lib/serve/server/lib/java/aio_server/lib/catalyst-cli-java-runtime-1.0.0.jar +0 -0
  71. package/lib/serve/server/lib/java/aio_server/lib/{catalyst-function-sdk-1.0.0.jar → catalyst-function-sdk-1.1.0.jar} +0 -0
  72. package/lib/serve/server/lib/java/aio_server/lib/catalyst-java-runtime-1.0.0.jar +0 -0
  73. package/lib/serve/server/lib/java/index.js +2 -2
  74. package/lib/serve/server/lib/master/appsail.js +53 -0
  75. package/lib/serve/server/lib/master/functions.js +34 -0
  76. package/lib/serve/server/lib/master/index.js +155 -0
  77. package/lib/{express_middlewares/unknownReqProxy.js → serve/server/lib/master/unknown-req-proxy.js} +9 -9
  78. package/lib/serve/server/lib/master/utils.js +142 -0
  79. package/lib/serve/server/lib/master/web-client.js +39 -0
  80. package/lib/serve/server/lib/node/index.js +3 -3
  81. package/lib/serve/server/lib/node/server/package-lock.json +12 -0
  82. package/lib/serve/server/lib/python/index.js +3 -3
  83. package/lib/shell/dependencies/http-functions.js +1 -1
  84. package/lib/shell/dependencies/invoker/bio/java/lib/catalyst-function-sdk-1.1.0.jar +0 -0
  85. package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +1 -1
  86. package/lib/shell/dependencies/invoker/cron/java/lib/catalyst-function-sdk-1.1.0.jar +0 -0
  87. package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +2 -1
  88. package/lib/shell/dependencies/invoker/event/java/lib/catalyst-function-sdk-1.1.0.jar +0 -0
  89. package/lib/shell/dependencies/invoker/event/node.mjs +1 -0
  90. package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +15 -0
  91. package/lib/shell/dependencies/invoker/integ/java/lib/catalyst-function-sdk-1.1.0.jar +0 -0
  92. package/lib/shell/dependencies/invoker/integ/node.mjs +13 -0
  93. package/lib/shell/dependencies/invoker/job/java/JavajobInvoker.java +268 -0
  94. package/lib/shell/dependencies/invoker/job/java/lib/catalyst-function-sdk-1.1.0.jar +0 -0
  95. package/lib/shell/dependencies/invoker/job/java/lib/org.json.jar +0 -0
  96. package/lib/shell/dependencies/invoker/job/node.mjs +93 -0
  97. package/lib/shell/dependencies/local-function.js +122 -13
  98. package/lib/shell/dependencies/tunnel-server.js +52 -23
  99. package/lib/shell/index.js +22 -22
  100. package/lib/shell/prepare/languages/index.js +4 -4
  101. package/lib/shell/prepare/languages/java.js +1 -2
  102. package/lib/shell/prepare/languages/python.js +10 -16
  103. package/lib/throbber/index.js +6 -1
  104. package/lib/userConfig.js +7 -1
  105. package/lib/util_modules/config/index.js +1 -1
  106. package/lib/util_modules/config/lib/{appSail.js → appsail.js} +64 -10
  107. package/lib/util_modules/config/lib/client.js +6 -8
  108. package/lib/util_modules/config/lib/functions.js +6 -8
  109. package/lib/util_modules/constants/lib/dc-type.js +8 -0
  110. package/lib/util_modules/constants/lib/default.js +9 -9
  111. package/lib/util_modules/constants/lib/event-action.js +1 -0
  112. package/lib/util_modules/constants/lib/event-source.js +1 -0
  113. package/lib/util_modules/constants/lib/fn-type.js +2 -1
  114. package/lib/util_modules/constants/lib/needed-scopes.js +53 -44
  115. package/lib/util_modules/constants/lib/placeholders.js +7 -0
  116. package/lib/util_modules/constants/lib/ref-mapping.js +2 -1
  117. package/lib/util_modules/constants/lib/remote-mapping.js +2 -1
  118. package/lib/util_modules/constants/lib/scopes.js +17 -2
  119. package/lib/util_modules/constants/lib/template.js +9 -4
  120. package/lib/util_modules/constants/lib/urls.js +16 -0
  121. package/lib/util_modules/fs/lib/async.js +14 -4
  122. package/lib/util_modules/fs/lib/sync.js +12 -1
  123. package/lib/util_modules/server.js +2 -4
  124. package/lib/winston.js +17 -11
  125. package/package.json +4 -2
  126. package/templates/event/job.json +30 -0
  127. package/templates/init/client/react/react_js/template/src/index.js +3 -3
  128. package/templates/init/client/react/react_ts/template/src/index.tsx +3 -3
  129. package/templates/init/client/react/react_ts/template.json +3 -3
  130. package/templates/init/functions/java/job/.classpath +6 -0
  131. package/templates/init/functions/java/job/.project +17 -0
  132. package/templates/init/functions/java/job/catalyst-config.json +11 -0
  133. package/templates/init/functions/java/job/sample.java +34 -0
  134. package/templates/init/functions/node/aio/package.json +1 -1
  135. package/templates/init/functions/node/aio/sample.js +7 -0
  136. package/templates/init/functions/node/bio/package.json +1 -1
  137. package/templates/init/functions/node/bio/sample.js +5 -0
  138. package/templates/init/functions/node/bio/types/basicio.d.ts +57 -0
  139. package/templates/init/functions/node/cron/package.json +1 -1
  140. package/templates/init/functions/node/cron/sample.js +5 -0
  141. package/templates/init/functions/node/cron/types/cron.d.ts +64 -0
  142. package/templates/init/functions/node/event/package.json +1 -1
  143. package/templates/init/functions/node/event/sample.js +11 -8
  144. package/templates/init/functions/node/event/types/event.d.ts +82 -0
  145. package/templates/init/functions/node/integ/cliq/package.json +1 -1
  146. package/templates/init/functions/node/integ/convokraft/package.json +1 -1
  147. package/templates/init/functions/node/{stream → job}/catalyst-config.json +3 -2
  148. package/templates/init/functions/node/{stream → job}/package.json +1 -1
  149. package/templates/init/functions/node/job/sample.js +27 -0
  150. package/templates/init/functions/node/job/types/job.d.ts +62 -0
  151. package/templates/init/functions/python/job/catalyst-config.json +11 -0
  152. package/templates/init/functions/python/job/requirements.txt +1 -0
  153. package/templates/init/functions/python/job/sample.py +22 -0
  154. package/templates/init.txt +14 -0
  155. package/lib/serve/server/lib/master.js +0 -326
  156. package/lib/shell/dependencies/invoker/bio/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  157. package/lib/shell/dependencies/invoker/cron/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  158. package/lib/shell/dependencies/invoker/event/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  159. package/lib/shell/dependencies/invoker/integ/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  160. package/templates/init/functions/node/stream/sample.js +0 -15
@@ -43,8 +43,9 @@ const logger_1 = require("../../util_modules/logger");
43
43
  exports.default = new command_1.default('functions:setup')
44
44
  .description('Set up and configure the function directory in your project directory')
45
45
  .needs('auth', [constants_1.SCOPE.functions])
46
- .needs('config')
46
+ .needs('config', { optional: true })
47
47
  .needs('rc')
48
+ .ci(false)
48
49
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
49
50
  const config = runtime_store_1.default.get('config');
50
51
  yield (yield Promise.resolve().then(() => __importStar(require('../../init/features')))).functions();
@@ -61,6 +61,7 @@ exports.default = new command_1.default('functions:shell')
61
61
  .needs('auth', constants_1.NEEDED_SCOPES.SERVE)
62
62
  .needs('config')
63
63
  .needs('rc')
64
+ .ci(false)
64
65
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
65
66
  const httpOpt = (0, option_1.getOptionValue)('http', false);
66
67
  if (httpOpt && typeof httpOpt !== 'boolean') {
@@ -73,7 +73,11 @@ exports.default = new command_1.default('iac:export')
73
73
  arr.push(allGlobalOpts[key]);
74
74
  }
75
75
  return arr;
76
- }, (env === 'Production' ? ['--production'] : []));
76
+ }, [
77
+ '--org',
78
+ (0, project_1.getEnvId)(),
79
+ ...(env === 'Production' ? ['--production'] : [])
80
+ ]);
77
81
  (0, shell_1.spawn)('catalyst', ['iac:status', 'export', ...optsArr], {
78
82
  shell: true,
79
83
  stdio: 'inherit'
@@ -58,6 +58,7 @@ const logger_1 = require("../../util_modules/logger");
58
58
  const option_1 = require("../../util_modules/option");
59
59
  const shell_1 = require("../../util_modules/shell");
60
60
  const server_js_1 = require("../../util_modules/server.js");
61
+ const project_1 = require("../../util_modules/project");
61
62
  const getZipAndTemplate = (filePath, stagedDeploy) => __awaiter(void 0, void 0, void 0, function* () {
62
63
  const zipFile = filePath
63
64
  ? yield ASYNC.readFile((0, utils_js_1.untildify)(filePath), 'buffer')
@@ -84,6 +85,8 @@ const ensureUserAction = (deployRes) => __awaiter(void 0, void 0, void 0, functi
84
85
  const callbackPort = yield port_resolver_1.default.getFreePort(3000, 10, false);
85
86
  const accessUrl = new url_1.URL(`/baas/v1/project/import/${deployRes.id}/deploy`, `${constants_1.ORIGIN.admin}`);
86
87
  accessUrl.searchParams.set('redirect_url', `http://localhost:${callbackPort}/success`);
88
+ const orgId = (0, project_1.getEnvId)();
89
+ orgId && accessUrl.searchParams.set('catalyst_org', orgId);
87
90
  const server = (0, http_1.createServer)((req, resp) => __awaiter(void 0, void 0, void 0, function* () {
88
91
  try {
89
92
  if (req.url !== '/success') {
@@ -136,7 +139,7 @@ const ensureUserAction = (deployRes) => __awaiter(void 0, void 0, void 0, functi
136
139
  arr.push(allGlobalOpts[key]);
137
140
  }
138
141
  return arr;
139
- }, ['--id', deployRes.id]);
142
+ }, ['--id', deployRes.id, '--org', (0, project_1.getEnvId)() || '']);
140
143
  yield (0, shell_1.spawn)('catalyst', ['iac:status', 'import', ...optsArr], {
141
144
  shell: true,
142
145
  stdio: 'inherit'
@@ -36,7 +36,8 @@ exports.default = (client) => {
36
36
  function loadCommand(name) {
37
37
  return __awaiter(this, void 0, void 0, function* () {
38
38
  return new Promise((resolve, reject) => setTimeout(() => __awaiter(this, void 0, void 0, function* () {
39
- const cmd = (yield Promise.resolve().then(() => __importStar(require('./' + name.split(':').join('/'))))).default;
39
+ var _a;
40
+ const cmd = (yield (_a = './' + name.split(':').join('/'), Promise.resolve().then(() => __importStar(require(_a))))).default;
40
41
  try {
41
42
  cmd.register(client);
42
43
  resolve();
@@ -79,6 +80,8 @@ exports.default = (client) => {
79
80
  loadCommand('codelib:install'),
80
81
  loadCommand('event:generate'),
81
82
  loadCommand('event:generate:integ'),
83
+ loadCommand('zest:generate'),
84
+ loadCommand('event:generate:job'),
82
85
  loadCommand('serve'),
83
86
  loadCommand('deploy'),
84
87
  loadCommand('help'),
@@ -56,14 +56,10 @@ exports.default = new command_1.default('init [feature]')
56
56
  .description('Initialize a Catalyst project, function, and client resources in the local directory')
57
57
  .option('--force', 'force initialise a project for this directory')
58
58
  .ignore(['project'])
59
- .needs('auth', [
60
- constants_1.SCOPE.projects,
61
- constants_1.SCOPE.stratus_create,
62
- constants_1.SCOPE.stratus_read,
63
- constants_1.SCOPE.project_import_create
64
- ])
59
+ .needs('auth', [constants_1.SCOPE.projects, constants_1.SCOPE.project_import_create])
65
60
  .needs('config', { optional: true })
66
61
  .needs('rc', { optional: true, resolveOnNotFound: true })
62
+ .ci(false)
67
63
  .action((feature) => __awaiter(void 0, void 0, void 0, function* () {
68
64
  var _a;
69
65
  const config = runtime_store_1.default.get('config');
@@ -104,8 +100,15 @@ exports.default = new command_1.default('init [feature]')
104
100
  return;
105
101
  }
106
102
  if (feature !== 'project') {
107
- yield (0, features_1.project)();
103
+ try {
104
+ yield (0, features_1.project)();
105
+ }
106
+ catch (er) {
107
+ (0, logger_1.debug)(er);
108
+ return;
109
+ }
108
110
  }
111
+ (0, logger_1.info)();
109
112
  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 ' +
110
113
  (0, ansi_colors_1.cyan)('<return> ') +
111
114
  'to proceed.\n', {
@@ -40,6 +40,7 @@ exports.default = new command_1.default('login')
40
40
  .description('Log the CLI in to your Catalyst account')
41
41
  .option('--no-localhost', 'login without browser')
42
42
  .option('--force', 'force reauthentication')
43
+ .ci(false)
43
44
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
44
45
  const auth = yield Promise.resolve().then(() => __importStar(require('../authentication')));
45
46
  return auth.login();
@@ -38,6 +38,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
38
38
  const command_1 = __importDefault(require("../internal/command"));
39
39
  exports.default = new command_1.default('logout')
40
40
  .description('Log the CLI out of your Catalyst account')
41
+ .ci(false)
41
42
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
42
43
  const auth = yield Promise.resolve().then(() => __importStar(require('../authentication')));
43
44
  return auth.logout();
@@ -50,6 +50,7 @@ exports.default = new command_1.default('pull [feature]')
50
50
  .needs('auth', [constants_1.SCOPE.functions, constants_1.SCOPE.webapp])
51
51
  .needs('config', { optional: true })
52
52
  .needs('rc')
53
+ .ci(false)
53
54
  .action((feature) => __awaiter(void 0, void 0, void 0, function* () {
54
55
  const config = runtime_store_1.default.get('config');
55
56
  const homeDir = (yield Promise.resolve().then(() => __importStar(require('os')))).homedir();
@@ -47,7 +47,7 @@ exports.default = new command_1.default('serve')
47
47
  .option('--only <targets>', 'only serve specified, comma-separated targets (e.g. "client,functions:f1")')
48
48
  .option('--no-watch', 'disable watching the files for changes')
49
49
  .option('--except <targets>', 'serve all targets except specified (e.g. "client")')
50
- .option('--ignore-scripts', 'ignore the pre and post lifescycle scripts')
50
+ .option('--ignore-scripts', 'ignore the pre and post lifecycle scripts')
51
51
  .option('--no-open', 'disable opening the client automatically when served')
52
52
  .needs('auth', constants_1.NEEDED_SCOPES.SERVE)
53
53
  .needs('config')
@@ -19,6 +19,7 @@ const command_1 = __importDefault(require("../internal/command"));
19
19
  const logger_1 = require("../util_modules/logger");
20
20
  exports.default = new command_1.default('whoami')
21
21
  .description('Print the email address of the user currently logged in')
22
+ .ci(false)
22
23
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
23
24
  const activeDC = (0, dc_1.getActiveDC)();
24
25
  const user = config_store_1.default.get(`${activeDC}.user`);
@@ -0,0 +1,304 @@
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ const command_1 = __importDefault(require("../../../internal/command"));
39
+ const constants_1 = require("../../../util_modules/constants");
40
+ const prompt_1 = __importDefault(require("../../../prompt"));
41
+ const js_1 = require("../../../util_modules/js");
42
+ const endpoints_1 = require("../../../endpoints");
43
+ const runtime_store_1 = __importDefault(require("../../../runtime-store"));
44
+ const archiver_1 = __importDefault(require("../../../archiver"));
45
+ const logger_1 = require("../../../util_modules/logger");
46
+ const inquirer_1 = __importStar(require("inquirer"));
47
+ const error_1 = __importDefault(require("../../../error"));
48
+ const project_1 = require("../../../util_modules/project");
49
+ const features_1 = require("../../../init/features");
50
+ const path_1 = require("path");
51
+ const throbber_1 = __importDefault(require("../../../throbber"));
52
+ const config_1 = require("../../../util_modules/config");
53
+ const common_1 = require("../../../init/util/common");
54
+ const ansi_colors_1 = require("ansi-colors");
55
+ const fs_1 = require("../../../util_modules/fs");
56
+ const console_1 = require("console");
57
+ function getSpecification(specs = []) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const res = (yield (yield (0, endpoints_1.zestAPI)()).getSpecifications());
60
+ if (!res) {
61
+ return specs;
62
+ }
63
+ specs.push(...res.specifications);
64
+ if (res.info.more_records) {
65
+ yield getSpecification(specs);
66
+ }
67
+ return specs;
68
+ });
69
+ }
70
+ function searchSpecification(filter, specArray = []) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ if (filter) {
73
+ const response = [];
74
+ specArray.forEach((spec) => {
75
+ if (spec.name.includes(filter)) {
76
+ response.push(spec);
77
+ }
78
+ });
79
+ return response;
80
+ }
81
+ return specArray;
82
+ });
83
+ }
84
+ function pollScheduledJob(job_id) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ const throbber = throbber_1.default.getInstance();
87
+ try {
88
+ const res = (yield (yield (0, endpoints_1.zestAPI)()).getScheduledJob(job_id));
89
+ const status = js_1.JS.capitalize(res.scheduled_jobs[0].status);
90
+ if (status === 'Completed') {
91
+ throbber.succeed('processing', { text: `Status >> ${status}` });
92
+ return res;
93
+ }
94
+ throbber.add('processing', { text: `Status >> ${status}` });
95
+ if (status === 'Failed') {
96
+ throbber.fail('processing', { text: `Status >> ${status}` });
97
+ throw new error_1.default('zest generation failed', {
98
+ exit: 2,
99
+ original: `${res.scheduled_jobs[0].action_info.failure_reason}`
100
+ });
101
+ }
102
+ yield js_1.JS.sleep(1000);
103
+ }
104
+ catch (err) {
105
+ throw new error_1.default('Error while processing scheduled job', {
106
+ exit: 2,
107
+ original: err
108
+ });
109
+ }
110
+ return yield pollScheduledJob(job_id);
111
+ });
112
+ }
113
+ function downloadSourceCode(fileId, outputDir, srcType, srcName) {
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ const zestZip = (yield (yield (0, endpoints_1.zestAPI)()).getFile(fileId, srcType, srcName));
116
+ yield new archiver_1.default().load(zestZip).extract(outputDir).finalize();
117
+ });
118
+ }
119
+ exports.default = new command_1.default('zest:generate')
120
+ .description('Generate the functions or appsail source code for your ZEST Specifications')
121
+ .needs('auth', [
122
+ constants_1.SCOPE.zest_spec_all,
123
+ constants_1.SCOPE.zest_schedule_job_read,
124
+ constants_1.SCOPE.zest_spec_all,
125
+ constants_1.SCOPE.zest_spec_src_action
126
+ ])
127
+ .needs('config', { optional: true })
128
+ .needs('rc', { skipOrgCheck: false })
129
+ .action(() => __awaiter(void 0, void 0, void 0, function* () {
130
+ var _a;
131
+ const specArray = yield getSpecification();
132
+ if (specArray.length === 0) {
133
+ throw new error_1.default('No Specifications Found', {
134
+ exit: 1,
135
+ errorId: 'ZEST-GEN-1'
136
+ });
137
+ }
138
+ yield prompt_1.default.register('search-box');
139
+ const specName = yield inquirer_1.default.prompt([
140
+ {
141
+ type: 'search-box',
142
+ name: 'specs',
143
+ searchable: true,
144
+ pageSize: 10,
145
+ highlight: true,
146
+ notFoundMsg: 'No specifications found!',
147
+ searchMsg: 'Search specifications...',
148
+ message: 'Please search and select the specifications(Use space key to select)',
149
+ source(_answersSoFar, input) {
150
+ input || (input = '');
151
+ return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
152
+ const fuzzyResult = yield searchSpecification(input, specArray);
153
+ const data = fuzzyResult.map((element) => {
154
+ return {
155
+ name: `${element.name}(${element.version})`,
156
+ value: element.id
157
+ };
158
+ });
159
+ resolve(data);
160
+ }));
161
+ },
162
+ validate: (ansArr) => {
163
+ if (js_1.JS.isEmpty(ansArr)) {
164
+ return 'Must select one specification.';
165
+ }
166
+ return true;
167
+ }
168
+ }
169
+ ]);
170
+ const srcTypeAns = yield prompt_1.default.ask(prompt_1.default.question('source', 'Please specify which source type you want to download', {
171
+ type: 'list',
172
+ choices: [
173
+ prompt_1.default.choice('Function', {
174
+ value: 'functions'
175
+ }),
176
+ prompt_1.default.choice('AppSail', {
177
+ value: 'appsail'
178
+ })
179
+ ]
180
+ }));
181
+ const srcType = srcTypeAns.source;
182
+ const sourceLabel = srcType.replace('functions', 'function');
183
+ const runtimeChoices = yield (0, common_1.getRuntimeChoices)({ fnType: 'aio' });
184
+ const ignoreRuntimes = ['node14', 'node12', 'node20'];
185
+ const stackChoices = runtimeChoices.filter((choice) => {
186
+ if (!(choice instanceof inquirer_1.Separator)) {
187
+ return !ignoreRuntimes.includes(choice.value.runtime);
188
+ }
189
+ return choice;
190
+ });
191
+ const srcStackAns = yield prompt_1.default.ask(prompt_1.default.question('stack', `Please select the language for your ${sourceLabel}`, {
192
+ type: 'list',
193
+ choices: stackChoices.map((choice) => {
194
+ if (!(choice instanceof inquirer_1.Separator)) {
195
+ return choice;
196
+ }
197
+ return choice;
198
+ }),
199
+ when: () => {
200
+ return runtimeChoices.length > 1;
201
+ }
202
+ }));
203
+ const srcStack = srcStackAns.stack.runtime;
204
+ const existingSails = config_1.appSailConfig.raw() || [];
205
+ const existingFuncs = ((_a = config_1.functionsConfig.raw()) === null || _a === void 0 ? void 0 : _a.targets) || [];
206
+ const source = yield prompt_1.default.ask(prompt_1.default.question('name', `Please provide a name for your ${(0, ansi_colors_1.bold)(sourceLabel)} `, {
207
+ type: 'input',
208
+ default: 'sample',
209
+ validate: (input) => __awaiter(void 0, void 0, void 0, function* () {
210
+ if (input === '') {
211
+ return 'Please provide a valid name.';
212
+ }
213
+ if (input === '' || !input.match(constants_1.REGEX.functions.package.name)) {
214
+ return `Special characters are not allowed. Includes only alphabets, numbers, hyphen and underscores.`;
215
+ }
216
+ if (srcType === 'functions' &&
217
+ existingFuncs.findIndex((func) => func === input) !== -1) {
218
+ return 'function name already exists';
219
+ }
220
+ if (srcType === 'appsail' &&
221
+ existingSails.findIndex((appSail) => appSail.name === input) !== -1) {
222
+ return 'appsail name already exists';
223
+ }
224
+ return true;
225
+ })
226
+ }));
227
+ const srcName = source.name;
228
+ let sourceCodeRes;
229
+ const resources = [];
230
+ specName.specs.forEach((element) => {
231
+ resources.push({ id: element });
232
+ });
233
+ const config = runtime_store_1.default.get('config');
234
+ let payload, outputDir;
235
+ if (srcType === 'appsail') {
236
+ const generateAppsailParams = {
237
+ resources: resources,
238
+ stack: srcStack,
239
+ name: srcName
240
+ };
241
+ outputDir = (0, project_1.resolveProjectPath)(`appsail-${srcName}`);
242
+ payload = {
243
+ source: outputDir,
244
+ name: srcName
245
+ };
246
+ if (srcStackAns.stack.lang.startsWith('java')) {
247
+ const basePackage = yield prompt_1.default.ask(prompt_1.default.question('basePkg', 'Please specify the base package name', {
248
+ type: 'input',
249
+ default: 'com.zoho'
250
+ }));
251
+ const install = yield prompt_1.default.ask(prompt_1.default.question('consent', 'Do you wish to install dependencies ? ', {
252
+ type: 'confirm',
253
+ default: true
254
+ }));
255
+ Object.assign(generateAppsailParams, {
256
+ with_dependency: install.consent,
257
+ config: {
258
+ base_package: basePackage.basePkg
259
+ }
260
+ });
261
+ }
262
+ sourceCodeRes = yield (yield (0, endpoints_1.zestAPI)()).generateAppsail(generateAppsailParams);
263
+ }
264
+ else {
265
+ const functionsDirPath = (0, project_1.resolveProjectPath)(config.get('functions.source') || constants_1.FOLDERNAME.functions);
266
+ outputDir = (0, path_1.join)(functionsDirPath, srcName);
267
+ payload = {
268
+ source: outputDir,
269
+ name: srcName,
270
+ stack: srcStack,
271
+ type: 'aio'
272
+ };
273
+ sourceCodeRes = yield (yield (0, endpoints_1.zestAPI)()).generateFunction(resources, srcStack, srcName);
274
+ }
275
+ const folderExists = yield fs_1.ASYNC.dirExists(outputDir);
276
+ const overwriteAns = folderExists
277
+ ? yield prompt_1.default.ask(prompt_1.default.question('overwrite', 'Directory ' + (0, ansi_colors_1.underline)(outputDir) + ' already exists. Overwrite ?', {
278
+ type: 'confirm',
279
+ defaultAns: false
280
+ }))
281
+ : { overwrite: true };
282
+ if (!overwriteAns.overwrite) {
283
+ (0, logger_1.labeled)('zest', `${sourceLabel} generation skipped.`).WARN();
284
+ return;
285
+ }
286
+ yield fs_1.ASYNC.deleteDir(outputDir);
287
+ runtime_store_1.default.set(`payload.${srcType}.targets`, [payload]);
288
+ const job_id = sourceCodeRes.job_id;
289
+ const throbber = throbber_1.default.getInstance();
290
+ (0, console_1.info)('\n' + (0, ansi_colors_1.white)('==> ') + `Generating ${js_1.JS.capitalize(sourceLabel)}`);
291
+ const fileId = yield pollScheduledJob(job_id).then((data) => {
292
+ throbber.remove('processing');
293
+ return data.scheduled_jobs[0].action_info.file_id;
294
+ });
295
+ (0, console_1.info)('\n' + (0, ansi_colors_1.white)('==> ') + `Downloading ${js_1.JS.capitalize(sourceLabel)}`);
296
+ yield downloadSourceCode(fileId, outputDir, sourceLabel, srcName);
297
+ (0, features_1.setCatalystConfig)(srcType, true);
298
+ yield config.save();
299
+ (0, console_1.info)();
300
+ (0, logger_1.message)((0, ansi_colors_1.bold)(constants_1.FILENAME.config) +
301
+ ` file has been successfully updated with ${sourceLabel} details.`);
302
+ (0, console_1.info)();
303
+ (0, logger_1.success)(`Zest successfully generated in ${(0, ansi_colors_1.bold)((0, path_1.join)(outputDir))}.`);
304
+ }));
@@ -31,6 +31,7 @@ const option_1 = require("../../../util_modules/option");
31
31
  const project_1 = require("../../../util_modules/project");
32
32
  const utils_1 = require("./utils");
33
33
  const throbber_1 = __importDefault(require("../../../throbber"));
34
+ const minimatch_1 = __importDefault(require("minimatch"));
34
35
  function executeHook(script, name, moduleSource) {
35
36
  if ((0, option_1.getOptionValue)('ignoreScripts', false)) {
36
37
  (0, logger_1.debug)(`skipping ${name} hook`);
@@ -57,7 +58,7 @@ function getConfigJsonInputs() {
57
58
  when: () => optValues.build_path === false,
58
59
  rootPath: cwd,
59
60
  validate: ({ value }) => __awaiter(this, void 0, void 0, function* () {
60
- const pathRes = (0, utils_1.validateBuildPath)(value);
61
+ const pathRes = yield (0, utils_1.validateBuildPath)(value);
61
62
  if (!pathRes) {
62
63
  return `Invalid path: ${value}`;
63
64
  }
@@ -142,7 +143,9 @@ function getStandAloneTarget() {
142
143
  configJson.stack = configJson.stack.runtime;
143
144
  }
144
145
  return {
145
- appSail: Object.assign({ name: nameOpt === false ? appSailName.name : nameOpt, source: cwd }, configJson),
146
+ name: nameOpt === false ? appSailName.name : nameOpt,
147
+ source: cwd,
148
+ config: configJson,
146
149
  validity: { valid: true }
147
150
  };
148
151
  });
@@ -157,15 +160,15 @@ exports.default = (standAlone = false) => __awaiter(void 0, void 0, void 0, func
157
160
  const filtered = (0, appsail_utils_1.filterTargets)(targets);
158
161
  let pythonPrompt = false;
159
162
  const validTargets = (0, appsail_utils_1.validateAppSail)(filtered).filter((targ) => {
160
- var _a, _b;
163
+ var _a;
161
164
  if (targ.validity.valid) {
162
165
  if (!pythonPrompt &&
163
- ((_a = targ.appSail) === null || _a === void 0 ? void 0 : _a.stack.startsWith(constants_1.RUNTIME.language.python.value))) {
166
+ ((_a = targ.config) === null || _a === void 0 ? void 0 : _a.stack.startsWith(constants_1.RUNTIME.language.python.value))) {
164
167
  pythonPrompt = true;
165
168
  }
166
169
  return targ;
167
170
  }
168
- (0, logger_1.labeled)('AppSail: ', 'Invalid AppSail service ' + (0, ansi_colors_1.bold)(((_b = targ.appSail) === null || _b === void 0 ? void 0 : _b.name) || 'Unknown')).ERROR();
171
+ (0, logger_1.labeled)('AppSail: ', 'Invalid AppSail service ' + (0, ansi_colors_1.bold)(targ.name || 'Unknown')).ERROR();
169
172
  (0, logger_1.error)('Reason: ' + targ.validity.reason);
170
173
  (0, logger_1.info)();
171
174
  return false;
@@ -179,32 +182,44 @@ exports.default = (standAlone = false) => __awaiter(void 0, void 0, void 0, func
179
182
  const throbber = throbber_1.default.getInstance();
180
183
  const deployRes = yield validTargets.reduce((result, _targ) => __awaiter(void 0, void 0, void 0, function* () {
181
184
  var _a, _b;
182
- const targ = _targ.appSail;
185
+ const targ = _targ.config;
183
186
  const prevRes = yield result;
187
+ const throbberName = `prepare_appsail_${_targ.name}`;
184
188
  try {
185
189
  if ((_a = targ.scripts) === null || _a === void 0 ? void 0 : _a.predeploy) {
186
- executeHook(targ.scripts.predeploy, 'predeploy', targ.source);
190
+ executeHook(targ.scripts.predeploy, 'predeploy', _targ.source);
187
191
  }
188
- const throbberName = `prepare_appsail_${targ.name}`;
189
192
  throbber.add(throbberName, {
190
- text: `Preparing AppSail[${targ.name}]`
193
+ text: `Preparing AppSail[${_targ.name}]`
191
194
  });
192
- const zip = new archiver_1.default();
193
- const buildPath = targ.buildPath ? targ.buildPath : targ.build_path;
194
- const folderPath = (0, project_1.resolveProjectPath)(buildPath);
195
- const ignoreFile = yield fs_1.ASYNC.readFile((0, path_1.join)(folderPath, constants_1.FILENAME.catalyst_ignore));
195
+ const folderPath = targ.build_path;
196
+ const isBuildPath = yield fs_1.ASYNC.isPathExists(folderPath);
197
+ if (!isBuildPath) {
198
+ throw new error_1.default(`the build path doesn't exists: ${folderPath}`, {
199
+ exit: 1,
200
+ skipHelp: true
201
+ });
202
+ }
203
+ const ignoreFile = yield fs_1.ASYNC.readFile((0, path_1.join)(_targ.source, constants_1.FILENAME.catalyst_ignore));
204
+ const excludePatterns = [
205
+ '**/.DS_Store',
206
+ '**/.vscode/**/*',
207
+ `**/${constants_1.FILENAME.log}`,
208
+ `**/${constants_1.FILENAME.config}`,
209
+ `**/${constants_1.FILENAME.rc}`,
210
+ `**/${constants_1.FILENAME.app_config}`,
211
+ `**/${constants_1.FILENAME.catalyst_ignore}`,
212
+ ...((ignoreFile === null || ignoreFile === void 0 ? void 0 : ignoreFile.split('\n')) || [])
213
+ ];
196
214
  const folderContents = yield fs_1.ASYNC.walk(folderPath, {
197
215
  filter: {
198
- exclude: [
199
- '**/.DS_Store',
200
- '**/.vscode/**/*',
201
- `**/${constants_1.FILENAME.app_config}`,
202
- `**/${constants_1.FILENAME.catalyst_ignore}`,
203
- ...((ignoreFile === null || ignoreFile === void 0 ? void 0 : ignoreFile.split('\n')) || [])
204
- ],
216
+ exclude: (path) => __awaiter(void 0, void 0, void 0, function* () {
217
+ return !!excludePatterns.find((glob) => (0, minimatch_1.default)(path.replace(folderPath + path_1.sep, ''), glob, { dot: true }));
218
+ }),
205
219
  excludeDir: true
206
220
  }
207
221
  });
222
+ const zip = new archiver_1.default();
208
223
  folderContents.forEach((content) => {
209
224
  zip.add(content.path === folderPath
210
225
  ? (0, path_1.basename)(content.path)
@@ -215,22 +230,25 @@ exports.default = (standAlone = false) => __awaiter(void 0, void 0, void 0, func
215
230
  const finalized = yield zip.finalize();
216
231
  const zipStream = yield finalized.fsStream();
217
232
  throbber.remove(throbberName);
218
- const { stack, name, command, memory, platform, env_variables } = targ;
233
+ const { stack, command, memory, platform, env_variables, catalyst_auth, login_redirect } = targ;
219
234
  const apiRes = yield sailAPI.deploy(zipStream.stream, {
220
235
  stack,
221
- name,
236
+ name: _targ.name,
222
237
  memory,
223
238
  platform,
224
239
  command,
240
+ catalystAuth: catalyst_auth,
241
+ loginRedirect: login_redirect,
225
242
  envVariables: env_variables,
226
243
  contentLength: zipStream.length
227
244
  });
228
245
  _targ.url = apiRes.url;
229
246
  if ((_b = targ.scripts) === null || _b === void 0 ? void 0 : _b.postdeploy) {
230
- executeHook(targ.scripts.postdeploy, 'postdeploy', targ.source);
247
+ executeHook(targ.scripts.postdeploy, 'postdeploy', _targ.source);
231
248
  }
232
249
  }
233
250
  catch (err) {
251
+ throbber.remove(throbberName);
234
252
  (0, logger_1.debug)(err);
235
253
  _targ.validity = {
236
254
  valid: false,
@@ -241,10 +259,9 @@ exports.default = (standAlone = false) => __awaiter(void 0, void 0, void 0, func
241
259
  return Promise.resolve(prevRes);
242
260
  }), Promise.resolve([]));
243
261
  const deployedValidTargets = deployRes.filter((targ) => {
244
- var _a;
245
262
  if (!targ.validity.valid) {
246
263
  (0, logger_1.warning)('Deploy of AppSail [' +
247
- ((_a = targ.appSail) === null || _a === void 0 ? void 0 : _a.name) +
264
+ targ.name +
248
265
  '] was unsuccessful since ' +
249
266
  targ.validity.reason);
250
267
  }
@@ -36,10 +36,10 @@ function validateOptions(validationFn, option, ...args) {
36
36
  exports.validateOptions = validateOptions;
37
37
  function validateBuildPath(path) {
38
38
  return __awaiter(this, void 0, void 0, function* () {
39
- const cwd = process.cwd();
39
+ const cwd = runtime_store_1.default.get('cwd');
40
40
  if (path) {
41
41
  const buildPath = (0, path_1.isAbsolute)(path) ? path : (0, path_1.resolve)(cwd, path);
42
- return (yield fs_1.ASYNC.dirExists(buildPath)) ? path : false;
42
+ return (yield fs_1.ASYNC.isPathExists(buildPath)) ? path : false;
43
43
  }
44
44
  return false;
45
45
  });
@@ -79,11 +79,10 @@ exports.validateName = validateName;
79
79
  function urlLogger() {
80
80
  const deployTargets = runtime_store_1.default.get('payload.appsail.targets', []);
81
81
  deployTargets.forEach((sail) => {
82
- var _a, _b;
83
82
  if (sail.url !== undefined) {
84
- (0, logger_1.labeled)(`AppSail(${(_a = sail.appSail) === null || _a === void 0 ? void 0 : _a.name})`, 'URL => ' + sail.url).MESSAGE();
83
+ (0, logger_1.labeled)(`AppSail(${sail.name})`, 'URL => ' + sail.url).MESSAGE();
85
84
  }
86
- (0, logger_1.labeled)(`AppSail(${(_b = sail.appSail) === null || _b === void 0 ? void 0 : _b.name})`, 'deploy successful').SUCCESS();
85
+ (0, logger_1.labeled)(`AppSail(${sail.name})`, 'deploy successful').SUCCESS();
87
86
  (0, logger_1.info)();
88
87
  });
89
88
  return deployTargets;