zcatalyst-cli 1.15.0-beta.0 → 1.15.0-beta.2

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.
@@ -64,20 +64,25 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
64
64
  if (target.type !== undefined && target.type === constants_1.FN_TYPE.advanced) {
65
65
  resp = (yield appAPI.deploy(target.zip_stream, {
66
66
  stack: target.stack,
67
- name: target.name
67
+ name: target.name,
68
+ memory: target.memory,
69
+ envVariables: target.env_var
68
70
  }));
69
71
  }
70
72
  else {
71
73
  resp = (yield fnAPI.deploy(target.zip_stream, {
72
74
  stack: target.stack,
73
75
  name: target.name,
74
- type: constants_1.REMOTE_REF.functions.type[target.type]
76
+ type: constants_1.REMOTE_REF.functions.type[target.type],
77
+ memory: target.type === constants_1.FN_TYPE.browserLogic
78
+ ? !target.memory && !target.id
79
+ ? 512
80
+ : target.memory
81
+ : target.memory,
82
+ envVariables: target.env_var
75
83
  }));
76
84
  }
77
85
  target.id = resp.id + '';
78
- if (target.id && target.env_var && Object.keys(target.env_var).length > 0) {
79
- yield fnAPI.updateConfig(target.id, target.env_var);
80
- }
81
86
  fn_utils_1.fnUtils.common.generateUrlForTarget(target);
82
87
  }
83
88
  catch (e) {
@@ -20,7 +20,7 @@ class Applogic {
20
20
  this.opts = opts;
21
21
  this.projectId = projectId;
22
22
  }
23
- deploy(sourceFsStream, { stack, name, memory }) {
23
+ deploy(sourceFsStream, { stack, name, memory, envVariables }) {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
25
  const formData = {
26
26
  stack,
@@ -29,8 +29,17 @@ class Applogic {
29
29
  if (sourceFsStream !== undefined) {
30
30
  formData.code = sourceFsStream;
31
31
  }
32
+ const configuration = {};
32
33
  if (memory !== undefined) {
33
- formData.memory = memory;
34
+ configuration.memory = memory;
35
+ }
36
+ if (envVariables !== undefined) {
37
+ configuration.environment = {
38
+ variables: envVariables
39
+ };
40
+ }
41
+ if (Object.keys(configuration).length > 0) {
42
+ formData.configuration = JSON.stringify(configuration);
34
43
  }
35
44
  const res = yield new api_1.default(this.opts).put(`/baas/v1/project/${this.projectId}/server/upsert`, {
36
45
  formData,
@@ -73,18 +73,27 @@ class Functions {
73
73
  });
74
74
  });
75
75
  }
76
- deploy(sourceFsStream, { stack, name, type, memory }) {
76
+ deploy(sourceFsStream, { stack, name, type, memory, envVariables }) {
77
77
  return __awaiter(this, void 0, void 0, function* () {
78
78
  const formData = {
79
79
  stack,
80
80
  name,
81
81
  type
82
82
  };
83
+ const configuration = {};
83
84
  if (sourceFsStream !== undefined) {
84
85
  formData.code = sourceFsStream;
85
86
  }
86
87
  if (memory !== undefined) {
87
- formData.memory = memory;
88
+ configuration.memory = memory;
89
+ }
90
+ if (envVariables !== undefined) {
91
+ configuration.environment = {
92
+ variables: envVariables
93
+ };
94
+ }
95
+ if (Object.keys(configuration).length > 0) {
96
+ formData.configuration = JSON.stringify(configuration);
88
97
  }
89
98
  const res = yield new api_1.default(this.opts).put(`/baas/v1/project/${this.projectId}/function/upsert`, {
90
99
  formData,
@@ -25,13 +25,19 @@ exports.default = (proxyInstance, customProxyUrl) => (req, res) => {
25
25
  });
26
26
  }
27
27
  else {
28
+ const headers = {};
29
+ if (req.url.match(/accounts\/p\/[0-9]+\/webclient\/v1\/captcha/g)) {
30
+ headers['origin'] = `https://${req.headers['x-zc-project-domain']}`;
31
+ }
32
+ if (req.url.includes('/__catalyst/auth/')) {
33
+ const masterPort = runtime_store_1.default.get('context.port.http.master', 3000);
34
+ headers['catalyst-redirect-domain'] = `http://localhost:${masterPort}`;
35
+ }
28
36
  proxyInstance.web(req, res, {
29
37
  target: `https://${req.headers['x-zc-project-domain']}`,
30
38
  changeOrigin: true,
31
39
  ws: true,
32
- headers: req.url.match(/accounts\/p\/[0-9]+\/webclient\/v1\/captcha/g)
33
- ? { origin: `https://${req.headers['x-zc-project-domain']}` }
34
- : undefined
40
+ headers
35
41
  });
36
42
  }
37
43
  };
@@ -126,7 +126,7 @@ function validate() {
126
126
  exports.validate = validate;
127
127
  function refineTargets(rawTargets, mapRemoteFn = true) {
128
128
  return __awaiter(this, void 0, void 0, function* () {
129
- let remoteFnIdMap = {};
129
+ let remoteFnMap = {};
130
130
  let runtimeDetails = runtime_store_1.default.get('context.catalyst.runtime', { runtimes: [] });
131
131
  if (mapRemoteFn) {
132
132
  const fnAPI = yield (0, endpoints_1.functionsAPI)();
@@ -141,12 +141,13 @@ function refineTargets(rawTargets, mapRemoteFn = true) {
141
141
  if (!Array.isArray(allRemoteFns) || allRemoteFns.length === 0) {
142
142
  allRemoteFns = [];
143
143
  }
144
- remoteFnIdMap = allRemoteFns.reduce((accumulator, fn) => {
145
- accumulator[fn.name] = fn.id + '';
144
+ remoteFnMap = allRemoteFns.reduce((accumulator, fn) => {
145
+ accumulator[fn.name] = fn;
146
146
  return accumulator;
147
- }, remoteFnIdMap);
147
+ }, remoteFnMap);
148
148
  }
149
149
  return Promise.all(rawTargets.map((fnPath) => __awaiter(this, void 0, void 0, function* () {
150
+ var _a;
150
151
  fnPath = (0, project_1.resolveProjectPath)(fnPath);
151
152
  const catalystJsonPth = (0, path_1.join)(fnPath, constants_1.FILENAME.catalyst_config);
152
153
  const catalystJson = yield fs_1.ASYNC.readJSONFile(catalystJsonPth, {
@@ -193,7 +194,7 @@ function refineTargets(rawTargets, mapRemoteFn = true) {
193
194
  switch (eol) {
194
195
  case 1:
195
196
  case 2:
196
- if (eol === 2 && remoteFnIdMap[fnName] === undefined) {
197
+ if (eol === 2 && remoteFnMap[fnName] === undefined) {
197
198
  return {
198
199
  name: fnName,
199
200
  source: fnPath,
@@ -223,6 +224,16 @@ function refineTargets(rawTargets, mapRemoteFn = true) {
223
224
  const catalystJsonString = JSON.stringify(catalystJson, null, 2) + '\n';
224
225
  yield fs_1.ASYNC.writeFile(catalystJsonPth, catalystJsonString, 'utf8');
225
226
  }
227
+ const fnMemory = js_1.JS.get(catalystJson, 'deployment.memory', js_1.JS.get(remoteFnMap[fnName], 'configuration.memory'));
228
+ if (fnMemory && !runtime_1.default.memory.includes(fnMemory)) {
229
+ return {
230
+ name: fnName,
231
+ source: fnPath,
232
+ valid: false,
233
+ type: fnType,
234
+ failure_reason: `The memory configuration ${fnMemory} is not supported. The supported values are ${runtime_1.default.memory.join(', ')}.`
235
+ };
236
+ }
226
237
  const fnTarget = {
227
238
  name: fnName,
228
239
  stack: userStack,
@@ -231,10 +242,11 @@ function refineTargets(rawTargets, mapRemoteFn = true) {
231
242
  source: fnPath,
232
243
  valid: true,
233
244
  integ_config: js_1.JS.get(catalystJson, 'deployment.integration_config'),
234
- env_var: refineEnvVariables(js_1.JS.get(catalystJson, 'deployment.env_variables'))
245
+ env_var: refineEnvVariables(js_1.JS.get(catalystJson, 'deployment.env_variables')),
246
+ memory: fnMemory
235
247
  };
236
- if (mapRemoteFn && remoteFnIdMap[fnTarget.name] !== undefined) {
237
- fnTarget.id = remoteFnIdMap[fnTarget.name];
248
+ if (mapRemoteFn && remoteFnMap[fnTarget.name] !== undefined) {
249
+ fnTarget.id = (_a = remoteFnMap[fnTarget.name]) === null || _a === void 0 ? void 0 : _a.id;
238
250
  }
239
251
  return fnTarget;
240
252
  })));
@@ -54,7 +54,7 @@ const proxyResponseHandler = (systemRoutes) => (proxyRes, req, res) => {
54
54
  proxyRes.headers['set-cookie'] = result;
55
55
  }
56
56
  }
57
- else if (req.url.startsWith('/baas')) {
57
+ else if (req.url.startsWith('/baas') || req.url.startsWith('/__catalyst')) {
58
58
  if (req.url.includes('/signin-redirect')) {
59
59
  if (systemRoutes === undefined) {
60
60
  redirectByAuth(req, res, '/app/local-redirect');
@@ -41,4 +41,4 @@ export const close = async (REQUEST, RESPONSE, driver) => {
41
41
  catch (ERROR) {
42
42
  console.error(ERROR);
43
43
  }
44
- };
44
+ };
@@ -18,4 +18,4 @@ export default class DeferredPromise {
18
18
  get [Symbol.toStringTag]() {
19
19
  return 'Promise';
20
20
  }
21
- };
21
+ };
@@ -31,4 +31,4 @@ async function getBrowser() {
31
31
  })
32
32
  }
33
33
 
34
- export default { getBrowser };
34
+ export default { getBrowser };
@@ -32,4 +32,4 @@ async function getBrowser(path) {
32
32
  })
33
33
  }
34
34
 
35
- export default {getBrowser}
35
+ export default {getBrowser}
@@ -56,4 +56,4 @@ function isConnected()
56
56
  return false;
57
57
  }
58
58
 
59
- export default {getBrowser}
59
+ export default {getBrowser}
@@ -44,7 +44,7 @@ app.all('/server/:fnId/execute', async (req, res) => {
44
44
  }
45
45
  });
46
46
 
47
- app.all('/', async (req, res) => {
47
+ app.all('/*', async (req, res) => {
48
48
  try {
49
49
  if (index === undefined) {
50
50
  throw new Error(`index of ${type} function is undefined`);
@@ -46,13 +46,7 @@ exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
46
46
  const httpServer = new http_functions_1.default({ repl: replServer });
47
47
  const projectRoot = runtime_store_1.default.get('project.root');
48
48
  try {
49
- yield (0, prepare_1.default)([
50
- constants_1.FN_TYPE.basic,
51
- constants_1.FN_TYPE.cron,
52
- constants_1.FN_TYPE.event,
53
- constants_1.FN_TYPE.integration,
54
- constants_1.FN_TYPE.browserLogic
55
- ]);
49
+ yield (0, prepare_1.default)([constants_1.FN_TYPE.basic, constants_1.FN_TYPE.cron, constants_1.FN_TYPE.event, constants_1.FN_TYPE.integration]);
56
50
  const targets = runtime_store_1.default
57
51
  .get('context.functions.targets', [])
58
52
  .filter((target) => {
@@ -5,6 +5,7 @@ const RUNTIME = Object.freeze({
5
5
  nodejs: 'node',
6
6
  java: 'java',
7
7
  python: 'python'
8
- }
8
+ },
9
+ memory: [128, 256, 512]
9
10
  });
10
11
  exports.default = RUNTIME;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zcatalyst-cli",
3
- "version": "1.15.0-beta.0",
3
+ "version": "1.15.0-beta.2",
4
4
  "description": "Command Line Tool for CATALYST",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {
@@ -8,4 +8,4 @@
8
8
  "execution": {
9
9
  "main": "{{_MAIN_}}"
10
10
  }
11
- }
11
+ }
@@ -8,4 +8,4 @@
8
8
  "execution": {
9
9
  "main": "{{_MAIN_}}"
10
10
  }
11
- }
11
+ }
@@ -8,4 +8,4 @@
8
8
  "execution": {
9
9
  "main": "{{_MAIN_}}"
10
10
  }
11
- }
11
+ }