zcatalyst-cli 1.14.1 → 1.15.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/lib/endpoints/index.js +8 -1
  2. package/lib/endpoints/lib/catalyst-details.js +8 -4
  3. package/lib/endpoints/lib/common.js +46 -0
  4. package/lib/endpoints/lib/env.js +2 -4
  5. package/lib/endpoints/lib/project.js +3 -6
  6. package/lib/endpoints/lib/sdk.js +20 -11
  7. package/lib/errorResponse.js +2 -1
  8. package/lib/fn-utils/lib/browserLogic.js +70 -0
  9. package/lib/fn-utils/lib/common.js +9 -2
  10. package/lib/fn-utils/lib/java.js +11 -3
  11. package/lib/init/dependencies/package-json.js +2 -18
  12. package/lib/init/dependencies/python/pip-install.js +21 -1
  13. package/lib/init/features/functions/index.js +6 -3
  14. package/lib/init/features/functions/languages/java.js +22 -3
  15. package/lib/init/features/functions/languages/node.js +25 -7
  16. package/lib/init/features/index.js +1 -1
  17. package/lib/internal/api.js +26 -13
  18. package/lib/progress.js +6 -1
  19. package/lib/serve/features/index.js +1 -1
  20. package/lib/serve/index.js +4 -1
  21. package/lib/serve/server/index.js +6 -3
  22. package/lib/serve/server/lib/java/lib/catalyst-cli-java-runtime-1.0.0.jar +0 -0
  23. package/lib/serve/server/lib/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  24. package/lib/serve/server/lib/java/lib/catalyst-java-runtime-1.0.0.jar +0 -0
  25. package/lib/serve/server/lib/master.js +16 -14
  26. package/lib/serve/server/lib/node/browserlogic/browserlogic-playwright.js +25 -0
  27. package/lib/serve/server/lib/node/browserlogic/browserlogic-puppeteer.js +22 -0
  28. package/lib/serve/server/lib/node/browserlogic/browserlogic-selenium.js +44 -0
  29. package/lib/serve/server/lib/node/browserlogic/index.js +24 -0
  30. package/lib/serve/server/lib/node/browserlogic/utils/deferred_promise.js +21 -0
  31. package/lib/serve/server/lib/node/browserlogic/utils/playwright-handler.js +34 -0
  32. package/lib/serve/server/lib/node/browserlogic/utils/puppeteer-handler.js +35 -0
  33. package/lib/serve/server/lib/node/browserlogic/utils/selenium-handler.js +59 -0
  34. package/lib/serve/server/lib/node/index.js +75 -0
  35. package/lib/serve/server/lib/node/package.json +7 -0
  36. package/lib/shell/dependencies/local-function.js +2 -1
  37. package/lib/shell/index.js +7 -1
  38. package/lib/shell/prepare/languages/java.js +3 -1
  39. package/lib/util_modules/constants/lib/browserLogic.js +14 -0
  40. package/lib/util_modules/constants/lib/default.js +4 -2
  41. package/lib/util_modules/constants/lib/fn-type.js +2 -1
  42. package/lib/util_modules/constants/lib/placeholders.js +2 -1
  43. package/lib/util_modules/constants/lib/ref-mapping.js +2 -1
  44. package/lib/util_modules/constants/lib/remote-mapping.js +2 -1
  45. package/lib/util_modules/constants/lib/template.js +9 -0
  46. package/lib/util_modules/context-help.js +5 -2
  47. package/package.json +1 -1
  48. package/templates/init/functions/java/browserLogic/playwright/.classpath +6 -0
  49. package/templates/init/functions/java/browserLogic/playwright/.project +17 -0
  50. package/templates/init/functions/java/browserLogic/playwright/catalyst-config.json +11 -0
  51. package/templates/init/functions/java/browserLogic/playwright/sample.java +38 -0
  52. package/templates/init/functions/java/browserLogic/selenium/.classpath +6 -0
  53. package/templates/init/functions/java/browserLogic/selenium/.project +17 -0
  54. package/templates/init/functions/java/browserLogic/selenium/catalyst-config.json +11 -0
  55. package/templates/init/functions/java/browserLogic/selenium/sample.java +38 -0
  56. package/templates/init/functions/node/browserlogic/playwright/catalyst-config.json +11 -0
  57. package/templates/init/functions/node/browserlogic/playwright/package.json +7 -0
  58. package/templates/init/functions/node/browserlogic/playwright/sample.js +10 -0
  59. package/templates/init/functions/node/browserlogic/puppeteer/catalyst-config.json +11 -0
  60. package/templates/init/functions/node/browserlogic/puppeteer/package.json +7 -0
  61. package/templates/init/functions/node/browserlogic/puppeteer/sample.js +10 -0
  62. package/templates/init/functions/node/browserlogic/selenium/catalyst-config.json +11 -0
  63. package/templates/init/functions/node/browserlogic/selenium/package.json +7 -0
  64. package/templates/init/functions/node/browserlogic/selenium/sample.js +10 -0
  65. package/templates/init/functions/python/aio/sample.py +5 -2
  66. package/templates/init/functions/python/integ/cliq/handlers/bot_handler.py +4 -4
  67. package/templates/init/functions/python/integ/cliq/handlers/command_handler.py +2 -2
  68. package/templates/init/functions/python/integ/cliq/handlers/function_handler.py +5 -5
  69. package/templates/init/functions/python/integ/cliq/handlers/widget_handler.py +15 -15
  70. package/lib/serve/server/lib/node.mjs +0 -41
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
32
  });
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.logAPI = exports.eventBusAPI = exports.functionsAPI = exports.applogicAPI = exports.bulkDSAPI = exports.apigAPI = exports.clientAPI = exports.datastoreAPI = exports.zcqlAPI = exports.queueAPI = exports.filestoreAPI = exports.cacheAPI = exports.sdkAPI = exports.envAPI = exports.projectAPI = exports.orgAPI = void 0;
35
+ exports.commonAPI = exports.logAPI = exports.eventBusAPI = exports.functionsAPI = exports.applogicAPI = exports.bulkDSAPI = exports.apigAPI = exports.clientAPI = exports.datastoreAPI = exports.zcqlAPI = exports.queueAPI = exports.filestoreAPI = exports.cacheAPI = exports.sdkAPI = exports.envAPI = exports.projectAPI = exports.orgAPI = void 0;
36
36
  const project_1 = require("../util_modules/project");
37
37
  function orgAPI({ auth = true } = {}) {
38
38
  return __awaiter(this, void 0, void 0, function* () {
@@ -149,3 +149,10 @@ function logAPI({ auth = true, projectId = (0, project_1.getProjectId)(-1), env
149
149
  });
150
150
  }
151
151
  exports.logAPI = logAPI;
152
+ function commonAPI() {
153
+ return __awaiter(this, void 0, void 0, function* () {
154
+ const common = (yield Promise.resolve().then(() => __importStar(require('./lib/common')))).default;
155
+ return new common();
156
+ });
157
+ }
158
+ exports.commonAPI = commonAPI;
@@ -19,12 +19,16 @@ class CatalystDetailsAPI {
19
19
  constructor(opts) {
20
20
  this.opts = opts;
21
21
  }
22
- getDetails(feature) {
22
+ getDetails(feature, fnType) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
+ const qs = {
25
+ feature_name: feature
26
+ };
27
+ if (fnType) {
28
+ qs.function_type = fnType;
29
+ }
24
30
  const res = yield new api_1.default(this.opts).get('/baas/get-details', {
25
- qs: {
26
- feature_name: feature
27
- }
31
+ qs
28
32
  });
29
33
  if (res.body && res.body.data) {
30
34
  return res.body.data;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const ansi_colors_1 = require("ansi-colors");
16
+ const api_1 = __importDefault(require("../../internal/api"));
17
+ class Common {
18
+ download(url, title) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const _url = new URL(url);
21
+ const reqOpts = {
22
+ json: false,
23
+ encoding: null,
24
+ resolveOnError: true,
25
+ origin: _url.origin
26
+ };
27
+ if (title) {
28
+ reqOpts.log = {
29
+ progress: {
30
+ title,
31
+ failure: (err) => {
32
+ return (0, ansi_colors_1.red)(`Download failure with error: ` +
33
+ (err instanceof Error ? err.message : err) || 'Unknown error');
34
+ }
35
+ }
36
+ };
37
+ }
38
+ const res = yield new api_1.default({ isExternal: true, authNeeded: false }).get(_url.pathname, reqOpts);
39
+ if (res.status === 200 && res.body) {
40
+ return res.body;
41
+ }
42
+ return;
43
+ });
44
+ }
45
+ }
46
+ exports.default = Common;
@@ -18,13 +18,11 @@ const logger_1 = require("../../util_modules/logger");
18
18
  class Env {
19
19
  constructor(opts, org) {
20
20
  this.opts = opts;
21
- this.envId = org;
21
+ this.opts.envId = org;
22
22
  }
23
23
  getEnvs(projectId) {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
- const res = yield new api_1.default(this.opts).get('/baas/v1/project/' + projectId + '/environment', {
26
- envId: this.envId
27
- });
25
+ const res = yield new api_1.default(this.opts).get('/baas/v1/project/' + projectId + '/environment');
28
26
  if (res.body && res.body.data) {
29
27
  return res.body.data;
30
28
  }
@@ -18,13 +18,11 @@ const logger_1 = require("../../util_modules/logger");
18
18
  class ProjectAPI {
19
19
  constructor(opts, org) {
20
20
  this.opts = opts;
21
- this.envId = org;
21
+ this.opts.envId = org;
22
22
  }
23
23
  getProject(projectId) {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
- const res = yield new api_1.default(this.opts).get('/baas/v1/project/' + projectId, {
26
- envId: this.envId
27
- });
25
+ const res = yield new api_1.default(this.opts).get('/baas/v1/project/' + projectId);
28
26
  if (res.body && res.body.data) {
29
27
  return res.body.data;
30
28
  }
@@ -36,7 +34,7 @@ class ProjectAPI {
36
34
  }
37
35
  getAllProjects() {
38
36
  return __awaiter(this, void 0, void 0, function* () {
39
- const res = yield new api_1.default(this.opts).get('/baas/v1/project', { envId: this.envId });
37
+ const res = yield new api_1.default(this.opts).get('/baas/v1/project');
40
38
  if (res.body && res.body.data) {
41
39
  return res.body.data;
42
40
  }
@@ -49,7 +47,6 @@ class ProjectAPI {
49
47
  createProject(name) {
50
48
  return __awaiter(this, void 0, void 0, function* () {
51
49
  const res = yield new api_1.default(this.opts).post('/baas/v1/project', {
52
- envId: this.envId,
53
50
  body: {
54
51
  project_name: name
55
52
  }
@@ -20,24 +20,33 @@ class SDK {
20
20
  constructor(opts) {
21
21
  this.opts = opts;
22
22
  }
23
+ getSdkUrl(fnType, service) {
24
+ switch (fnType) {
25
+ case constants_1.FN_TYPE.integration: {
26
+ if (!service) {
27
+ throw new error_1.default('Invalid integration service');
28
+ }
29
+ return `/downloads/sdk/java/${constants_1.INTEG.service_map[service]}/${constants_1.INTEG.java_dependencies[service]}_latest.zip`;
30
+ }
31
+ case constants_1.FN_TYPE.browserLogic: {
32
+ return `/downloads/sdk/java/catalyst-java-sdk-1.12.0-beta01.zip`;
33
+ }
34
+ default: {
35
+ return `/downloads/sdk/java/catalyst_java_sdk_latest.zip`;
36
+ }
37
+ }
38
+ }
23
39
  java(fnType, service) {
40
+ var _a;
24
41
  return __awaiter(this, void 0, void 0, function* () {
25
- const targetSDK = fnType === constants_1.FN_TYPE.integration && service !== undefined
26
- ? constants_1.INTEG.java_dependencies[service]
27
- : 'catalyst_java_sdk';
28
- const targetUrl = fnType === constants_1.FN_TYPE.integration && service !== undefined
29
- ? constants_1.INTEG.service_map[service] + '/' + targetSDK
30
- : targetSDK;
31
- if (targetSDK === undefined || targetUrl === undefined) {
32
- throw new error_1.default('SDK target missing', { exit: 2 });
33
- }
34
- const res = yield new api_1.default(this.opts).get(`/downloads/sdk/java/${targetUrl}_latest.zip`, {
42
+ const targetSDK = this.getSdkUrl(fnType, service);
43
+ const res = yield new api_1.default(this.opts).get(targetSDK, {
35
44
  json: false,
36
45
  encoding: null,
37
46
  origin: constants_1.ORIGIN.catalystStatic,
38
47
  log: {
39
48
  progress: {
40
- title: targetSDK.replace(new RegExp('_', 'g'), '-')
49
+ title: (_a = targetSDK.split('/').pop()) === null || _a === void 0 ? void 0 : _a.replace(new RegExp('_', 'g'), '-')
41
50
  }
42
51
  }
43
52
  });
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const error_1 = __importDefault(require("./error"));
7
7
  const js_1 = require("./util_modules/js");
8
- exports.default = (response, body) => {
8
+ exports.default = (response, body, skipHelp = false) => {
9
9
  body =
10
10
  js_1.JS.includes(response.headers['content-type'], 'json') && typeof body === 'string'
11
11
  ? JSON.parse(body)
@@ -28,6 +28,7 @@ exports.default = (response, body) => {
28
28
  response
29
29
  },
30
30
  status: response.statusCode,
31
+ skipHelp,
31
32
  exit: exitCode
32
33
  });
33
34
  };
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.downloadJavaDependencies = exports.getBrowserLogicFramework = void 0;
16
+ const path_1 = require("path");
17
+ const util_1 = require("util");
18
+ const archiver_1 = __importDefault(require("../../archiver"));
19
+ const endpoints_1 = require("../../endpoints");
20
+ const prompt_1 = __importDefault(require("../../prompt"));
21
+ const browserLogic_1 = __importDefault(require("../../util_modules/constants/lib/browserLogic"));
22
+ const fs_1 = require("../../util_modules/fs");
23
+ const logger_1 = require("../../util_modules/logger");
24
+ function getBrowserLogicFramework(stack) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const choices = Object.keys(browserLogic_1.default[stack]).map((framework) => {
27
+ return prompt_1.default.choice(framework, {
28
+ value: framework,
29
+ short: framework
30
+ });
31
+ });
32
+ if (choices.length === 0) {
33
+ return '';
34
+ }
35
+ const framework = yield prompt_1.default.ask(prompt_1.default.question('name', 'Please choose a framework to initialize', {
36
+ type: 'list',
37
+ choices
38
+ }));
39
+ return framework.name;
40
+ });
41
+ }
42
+ exports.getBrowserLogicFramework = getBrowserLogicFramework;
43
+ function downloadJavaDependencies(path, deps, isZip = true) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ const _commonAPI = yield (0, endpoints_1.commonAPI)();
46
+ return Promise.all(deps.map((dep) => {
47
+ return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
48
+ try {
49
+ const fileName = (0, path_1.basename)(dep);
50
+ const res = yield _commonAPI.download(dep, fileName);
51
+ yield fs_1.ASYNC.ensureDir(path);
52
+ if (isZip) {
53
+ const zip = new archiver_1.default();
54
+ zip.load(res).extract(path);
55
+ yield zip.finalize();
56
+ }
57
+ else {
58
+ yield fs_1.ASYNC.writeFile((0, path_1.join)(path, fileName), res);
59
+ }
60
+ }
61
+ catch (err) {
62
+ (0, logger_1.labeled)(`Browser Logic[${name}]`, 'Unable to download the dependencies because of the following error');
63
+ (0, logger_1.error)((0, util_1.inspect)(err));
64
+ }
65
+ resolve();
66
+ }));
67
+ }));
68
+ });
69
+ }
70
+ exports.downloadJavaDependencies = downloadJavaDependencies;
@@ -158,6 +158,7 @@ function refineTargets(rawTargets, mapRemoteFn = true) {
158
158
  name: (0, path_1.basename)(fnPath),
159
159
  source: fnPath,
160
160
  valid: false,
161
+ type: constants_1.FN_TYPE.basic,
161
162
  failure_reason: 'there is no valid ' + constants_1.FILENAME.catalyst_config + ' file present'
162
163
  };
163
164
  }
@@ -177,12 +178,14 @@ function refineTargets(rawTargets, mapRemoteFn = true) {
177
178
  }
178
179
  const fnName = js_1.JS.get(catalystJson, 'deployment.name');
179
180
  const userStack = js_1.JS.get(catalystJson, 'deployment.stack');
181
+ const fnType = constants_1.REFERENCE.functions.type[js_1.JS.get(catalystJson, 'deployment.type')];
180
182
  if (!userStack ||
181
183
  (runtimeDetails.runtimes.length > 0 && !runtimeDetails.runtimes.includes(userStack))) {
182
184
  return {
183
185
  name: (0, path_1.basename)(fnPath),
184
186
  source: fnPath,
185
187
  valid: false,
188
+ type: fnType,
186
189
  failure_reason: 'deployment.stack is unknown in ' + constants_1.FILENAME.catalyst_config + ' file.'
187
190
  };
188
191
  }
@@ -195,6 +198,7 @@ function refineTargets(rawTargets, mapRemoteFn = true) {
195
198
  name: fnName,
196
199
  source: fnPath,
197
200
  valid: false,
201
+ type: fnType,
198
202
  failure_reason: `Stack ${userStack} is no longer supported for creation. Kindly change the stack in ${constants_1.FILENAME.catalyst_config} and try again.`
199
203
  };
200
204
  }
@@ -205,6 +209,7 @@ function refineTargets(rawTargets, mapRemoteFn = true) {
205
209
  name: fnName,
206
210
  source: fnPath,
207
211
  valid: false,
212
+ type: fnType,
208
213
  failure_reason: `Stack ${userStack} is no longer support. Kindly change the stack in ${constants_1.FILENAME.catalyst_config} and try again.`
209
214
  };
210
215
  default:
@@ -221,7 +226,7 @@ function refineTargets(rawTargets, mapRemoteFn = true) {
221
226
  const fnTarget = {
222
227
  name: fnName,
223
228
  stack: userStack,
224
- type: constants_1.REFERENCE.functions.type[js_1.JS.get(catalystJson, 'deployment.type')],
229
+ type: fnType,
225
230
  index: js_1.JS.get(catalystJson, 'execution.main'),
226
231
  source: fnPath,
227
232
  valid: true,
@@ -324,6 +329,7 @@ function generateUrlForTarget(target) {
324
329
  const urlDefault = 'https://' + (0, project_1.getDomainPrefix)() + '.' + constants_1.ORIGIN.app.replace('https://', '');
325
330
  switch (target.type) {
326
331
  case constants_1.FN_TYPE.basic:
332
+ case constants_1.FN_TYPE.browserLogic:
327
333
  target.url = `${urlDefault}/server/${target.name}/execute`;
328
334
  if (target.id !== undefined) {
329
335
  target.url_with_id = `${urlDefault}/server/${target.id}/execute`;
@@ -365,7 +371,8 @@ function resolveAllFnPorts(targets, idx = 0) {
365
371
  case 'serve':
366
372
  const isPyBio = currentTargetType === constants_1.FN_TYPE.basic &&
367
373
  ((_a = currentTarget.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.python));
368
- httpPort = yield port_resolver_1.default.getPort(constants_1.REMOTE_REF.functions.type[currentTargetType], 'http', currentTarget.name, currentTargetType === constants_1.FN_TYPE.advanced, isPyBio);
374
+ httpPort = yield port_resolver_1.default.getPort(constants_1.REMOTE_REF.functions.type[currentTargetType], 'http', currentTarget.name, currentTargetType === constants_1.FN_TYPE.advanced ||
375
+ currentTargetType === constants_1.FN_TYPE.browserLogic, isPyBio);
369
376
  runtime_store_1.default.set('context.port.http.functions.' + currentTarget.name, httpPort);
370
377
  const debugOptValue = (0, option_1.getOptionValue)('debug', false);
371
378
  if (debugOptValue &&
@@ -431,7 +431,15 @@ function cleanUp(files) {
431
431
  }
432
432
  function getTemplatePath(target) {
433
433
  const targetType = target.type;
434
- return target.type === constants_1.FN_TYPE.integration
435
- ? js_1.JS.get(constants_1.TEMPLATE.functions.java[targetType], js_1.JS.get(target.integ_config[0], 'service', ''))
436
- : constants_1.TEMPLATE.functions.java[targetType];
434
+ switch (targetType) {
435
+ case constants_1.FN_TYPE.integration: {
436
+ return js_1.JS.get(constants_1.TEMPLATE.functions.java.integ, js_1.JS.get(target.integ_config[0], 'service', ''));
437
+ }
438
+ case constants_1.FN_TYPE.browserLogic: {
439
+ return constants_1.TEMPLATE.functions.java.browserlogic.selenium;
440
+ }
441
+ default: {
442
+ return constants_1.TEMPLATE.functions.java[targetType];
443
+ }
444
+ }
437
445
  }
@@ -13,17 +13,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const ansi_colors_1 = require("ansi-colors");
16
- const path_1 = require("path");
17
16
  const error_1 = __importDefault(require("../../error"));
18
17
  const prompt_1 = __importDefault(require("../../prompt"));
19
18
  const runtime_store_1 = __importDefault(require("../../runtime-store"));
20
19
  const constants_1 = require("../../util_modules/constants");
21
- const fs_1 = require("../../util_modules/fs");
22
20
  const js_1 = require("../../util_modules/js");
23
21
  const logger_1 = require("../../util_modules/logger");
24
22
  const project_1 = require("../../util_modules/project");
25
- exports.default = (templateJsonDir = 'package.json', keys) => __awaiter(void 0, void 0, void 0, function* () {
26
- const templateJsonPath = (0, path_1.join)(templateJsonDir, 'package.json');
23
+ exports.default = (keys) => __awaiter(void 0, void 0, void 0, function* () {
27
24
  const qns = keys.map((qn) => {
28
25
  switch (qn) {
29
26
  case 'name':
@@ -60,18 +57,5 @@ exports.default = (templateJsonDir = 'package.json', keys) => __awaiter(void 0,
60
57
  (0, logger_1.info)('Use `' +
61
58
  (0, ansi_colors_1.bold)('npm install <pkg> --save') +
62
59
  '` afterwards to install a package and \nsave it as a dependency in the package.json file.\n');
63
- const answers = yield prompt_1.default.ask(...qns);
64
- let content = yield fs_1.ASYNC.readFile(templateJsonPath);
65
- if (content === undefined) {
66
- throw new error_1.default('content of : ' + templateJsonPath + ' is undefined', {
67
- exit: 2
68
- });
69
- }
70
- Object.keys(answers).forEach((placeholder) => {
71
- if (answers[placeholder] !== undefined) {
72
- const template = constants_1.PLACEHOLDER.functions.node_package[placeholder];
73
- content = content === null || content === void 0 ? void 0 : content.replace(new RegExp(template, 'g'), answers[placeholder]);
74
- }
75
- });
76
- return JSON.parse(content);
60
+ return prompt_1.default.ask(...qns);
77
61
  });
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.installRequirements = exports.pypiRes = exports.ensurePyRuntime = void 0;
15
+ exports.installPkgs = exports.installRequirements = exports.pypiRes = exports.ensurePyRuntime = void 0;
16
16
  const error_1 = __importDefault(require("../../../error"));
17
17
  const prompt_1 = __importDefault(require("../../../prompt"));
18
18
  const shell_1 = require("../../../util_modules/shell");
@@ -187,3 +187,23 @@ function installRequirements(reqFile, pth, stackVersion, linuxMode = false) {
187
187
  });
188
188
  }
189
189
  exports.installRequirements = installRequirements;
190
+ function installPkgs(pkgs, stackVersion, pth = undefined) {
191
+ return __awaiter(this, void 0, void 0, function* () {
192
+ const spawnOpts = ['-m', 'pip', 'install', ...pkgs, '--upgrade'];
193
+ if (pth) {
194
+ spawnOpts.push(...['-t', pth]);
195
+ }
196
+ return (0, shell_1.spawn)(userConfig_1.default.get(`python${stackVersion}.bin`), spawnOpts, {
197
+ cwd: pth,
198
+ stdio: 'ignore'
199
+ })
200
+ .ASYNC()
201
+ .catch((err) => {
202
+ throw error_1.default.getErrorInstance(err, {
203
+ message: `unable to install the package - ${pkgs.join(',')}`,
204
+ skipHelp: true
205
+ });
206
+ });
207
+ });
208
+ }
209
+ exports.installPkgs = installPkgs;
@@ -49,8 +49,6 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
49
49
  }
50
50
  yield fs_1.ASYNC.deleteDir(functionsDirPath).catch();
51
51
  }
52
- const catalystDetailsAPI = new catalyst_details_1.default();
53
- const runtimeDetailsPromise = catalystDetailsAPI.getDetails('runtime');
54
52
  const fnTypeChoices = [
55
53
  prompt_1.default.choice('BasicIO', {
56
54
  value: constants_1.FN_TYPE.basic,
@@ -67,6 +65,10 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
67
65
  prompt_1.default.choice('Cron', {
68
66
  value: constants_1.FN_TYPE.cron,
69
67
  short: 'cron'
68
+ }),
69
+ prompt_1.default.choice('Browser Logic', {
70
+ value: constants_1.FN_TYPE.browserLogic,
71
+ short: 'browser logic'
70
72
  })
71
73
  ];
72
74
  if ((0, dc_1.getActiveDC)() === constants_1.DC_TYPE.us.value) {
@@ -83,7 +85,8 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
83
85
  if (fnTypeAns.type === constants_1.FN_TYPE.integration) {
84
86
  yield (0, integ_1.integHelper)();
85
87
  }
86
- const runtimeDetails = (yield runtimeDetailsPromise);
88
+ const catalystDetailsAPI = new catalyst_details_1.default();
89
+ const runtimeDetails = yield catalystDetailsAPI.getDetails('runtime', constants_1.REMOTE_REF.functions.type[fnTypeAns.type]);
87
90
  const runtimeChoices = runtimeDetails.runtimes.reduce((acc, value) => {
88
91
  const langArr = value.match(/^([a-zA-Z]+)([0-9_]+)$/);
89
92
  if (langArr === null ||
@@ -25,10 +25,24 @@ const integ_1 = require("../../../../fn-utils/lib/integ");
25
25
  const common_1 = require("../../../../fn-utils/lib/common");
26
26
  const runtime_1 = __importDefault(require("../../../../util_modules/constants/lib/runtime"));
27
27
  const functions_1 = require("../../../util/functions");
28
+ const browserLogic_1 = require("../../../../fn-utils/lib/browserLogic");
29
+ const browserLogic_2 = __importDefault(require("../../../../util_modules/constants/lib/browserLogic"));
30
+ function getTemplatePath(fnType, add) {
31
+ switch (fnType) {
32
+ case constants_1.FN_TYPE.browserLogic:
33
+ case constants_1.FN_TYPE.integration: {
34
+ return js_1.JS.get(constants_1.TEMPLATE.functions.java[fnType], add.toLowerCase());
35
+ }
36
+ default: {
37
+ return constants_1.TEMPLATE.functions.java[fnType];
38
+ }
39
+ }
40
+ }
28
41
  exports.default = (stack) => () => __awaiter(void 0, void 0, void 0, function* () {
29
42
  const fnType = runtime_store_1.default.get('context.functions.type');
30
43
  const fnDirPath = (0, path_1.join)(runtime_store_1.default.get('context.functions.dir_path'));
31
44
  yield fs_1.ASYNC.ensureDir(fnDirPath);
45
+ const framework = fnType === constants_1.FN_TYPE.browserLogic ? yield (0, browserLogic_1.getBrowserLogicFramework)('java') : undefined;
32
46
  const functionAns = yield prompt_1.default.ask(prompt_1.default.question('name', 'What will be the name of the java function? This will also be the folder name. ', {
33
47
  defaultAns: 'sample',
34
48
  validate: (ans) => {
@@ -63,9 +77,7 @@ exports.default = (stack) => () => __awaiter(void 0, void 0, void 0, function* (
63
77
  }
64
78
  yield fs_1.ASYNC.deleteDir(targetPath).catch();
65
79
  const service = runtime_store_1.default.get('context.functions.integration.service', '');
66
- const templatePath = fnType === constants_1.FN_TYPE.integration
67
- ? js_1.JS.get(constants_1.TEMPLATE.functions.java[fnType], service)
68
- : constants_1.TEMPLATE.functions.java[fnType];
80
+ const templatePath = getTemplatePath(fnType, service || framework || '');
69
81
  if (fnType === constants_1.FN_TYPE.integration) {
70
82
  yield (0, integ_1.copyIntegHandlers)(templatePath, targetPath, runtime_1.default.language.java);
71
83
  }
@@ -80,9 +92,16 @@ exports.default = (stack) => () => __awaiter(void 0, void 0, void 0, function* (
80
92
  integ_config
81
93
  });
82
94
  yield fs_1.ASYNC.rename((0, path_1.join)(fnDirPath, functionAns.name, constants_1.FILENAME.functions.java_main), () => functionAns.class + '.java');
95
+ if (fnType === constants_1.FN_TYPE.browserLogic && framework) {
96
+ (0, logger_1.info)();
97
+ (0, logger_1.info)((0, ansi_colors_1.white)('==> ') + 'Downloading dependencies');
98
+ const dependencies = browserLogic_2.default.java[framework];
99
+ yield (0, browserLogic_1.downloadJavaDependencies)((0, path_1.join)(fnDirPath, functionAns.name, constants_1.FOLDERNAME.java_fn_lib), dependencies, false);
100
+ }
83
101
  yield (0, common_1.getSDK)(fnType, (0, path_1.join)(fnDirPath, functionAns.name, constants_1.FOLDERNAME.java_fn_lib), 'java', {
84
102
  service
85
103
  });
104
+ (0, logger_1.info)();
86
105
  const userFnClassPath = (0, path_1.join)(fnDirPath, functionAns.name, constants_1.FILENAME.functions.java_classpath);
87
106
  const userFnLibPath = (0, path_1.join)(fnDirPath, functionAns.name, constants_1.FOLDERNAME.java_fn_lib);
88
107
  yield fn_utils_1.fnUtils.java.rewriteClasspath(userFnClassPath, userFnLibPath);
@@ -26,15 +26,27 @@ const js_1 = require("../../../../util_modules/js");
26
26
  const integ_1 = require("../../../../fn-utils/lib/integ");
27
27
  const runtime_1 = __importDefault(require("../../../../util_modules/constants/lib/runtime"));
28
28
  const functions_1 = require("../../../util/functions");
29
+ const browserLogic_1 = require("../../../../fn-utils/lib/browserLogic");
30
+ const browserLogic_2 = __importDefault(require("../../../../util_modules/constants/lib/browserLogic"));
31
+ function getTemplatePath(fnType, add) {
32
+ switch (fnType) {
33
+ case constants_1.FN_TYPE.browserLogic:
34
+ case constants_1.FN_TYPE.integration: {
35
+ return js_1.JS.get(constants_1.TEMPLATE.functions.node[fnType], add.toLowerCase());
36
+ }
37
+ default: {
38
+ return constants_1.TEMPLATE.functions.node[fnType];
39
+ }
40
+ }
41
+ }
29
42
  exports.default = (stack) => () => __awaiter(void 0, void 0, void 0, function* () {
30
43
  const fnType = runtime_store_1.default.get('context.functions.type');
31
44
  const service = runtime_store_1.default.get('context.functions.integration.service', '');
32
- const templatePath = fnType === constants_1.FN_TYPE.integration
33
- ? js_1.JS.get(constants_1.TEMPLATE.functions.node[fnType], service)
34
- : constants_1.TEMPLATE.functions.node[fnType];
35
45
  const functionsDirPath = runtime_store_1.default.get('context.functions.dir_path');
36
46
  yield fs_1.ASYNC.ensureDir(functionsDirPath);
37
- const finalJson = yield (0, package_json_1.default)(templatePath, ['name', 'main', 'author']);
47
+ const framework = fnType === constants_1.FN_TYPE.browserLogic ? yield (0, browserLogic_1.getBrowserLogicFramework)('nodejs') : '';
48
+ const finalJson = Object.assign(Object.assign({}, (yield (0, package_json_1.default)(['name', 'main', 'author']))), { framework: framework.toLowerCase(), dependencies: JSON.stringify(browserLogic_2.default.nodejs[framework] || {}, null, '\t').replace(new RegExp('\n', 'g'), '\n\t'), stack });
49
+ const templatePath = getTemplatePath(fnType, service || framework || '');
38
50
  const targetPath = (0, path_1.join)(functionsDirPath, finalJson.name);
39
51
  const dirExists = yield fs_1.ASYNC.dirExists(targetPath);
40
52
  const overwriteAns = dirExists
@@ -57,11 +69,17 @@ exports.default = (stack) => () => __awaiter(void 0, void 0, void 0, function* (
57
69
  yield fs_1.ASYNC.copyDir(templatePath, targetPath);
58
70
  }
59
71
  yield fs_1.ASYNC.rename((0, path_1.join)(targetPath, constants_1.FILENAME.functions.node_main), () => finalJson.main);
72
+ const placeHolders = Object.assign(Object.assign({}, constants_1.PLACEHOLDER.functions.node_package), { stack: constants_1.PLACEHOLDER.catalyst_config.stack });
60
73
  const placeholderArr = [];
61
74
  const replaceArr = [];
62
- Object.keys(constants_1.PLACEHOLDER.functions.node_package).forEach((key) => {
63
- placeholderArr.push(constants_1.PLACEHOLDER.functions.node_package[key]);
64
- replaceArr.push(key === 'name' ? finalJson[key].toLowerCase() : finalJson[key]);
75
+ Object.keys(placeHolders).forEach((key) => {
76
+ placeholderArr.push(placeHolders[key]);
77
+ if (key === 'name') {
78
+ finalJson[key] = finalJson[key].toLowerCase();
79
+ }
80
+ replaceArr.push(typeof finalJson[key] === 'string'
81
+ ? finalJson[key]
82
+ : JSON.stringify(finalJson[key]));
65
83
  });
66
84
  yield fs_1.ASYNC.findAndReplace(targetPath)(placeholderArr, replaceArr);
67
85
  const integ_config = runtime_store_1.default.get('context.functions.integration.config', '');
@@ -96,7 +96,7 @@ function setFnConfig(featureName, add) {
96
96
  ? js_1.JS.uniq(ignoreArr.concat([constants_1.FOLDERNAME.output]))
97
97
  : ignoreArr);
98
98
  if (config.get(featureName + '.source') !== targetSource) {
99
- (0, logger_1.warning)(featureName + ' source has been modified');
99
+ (0, logger_1.debug)(featureName + ' source has been modified');
100
100
  config.set(featureName + '.source', targetSource);
101
101
  }
102
102
  break;