zcatalyst-cli 1.18.0-beta.0 → 1.18.0-beta.1
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.
- package/docs/commands/event/generate/job.toml +7 -0
- package/docs/endpoints/lib/job-scheduling.toml +3 -0
- package/docs/internal/command.toml +5 -0
- package/lib/appsail-utils.js +4 -10
- package/lib/authentication/index.js +1 -0
- package/lib/bin/catalyst.js +1 -1
- package/lib/command_needs/rc.js +1 -1
- package/lib/commands/appsail/add.js +1 -0
- package/lib/commands/client/setup.js +1 -0
- package/lib/commands/event/generate/index.js +2 -1
- package/lib/commands/event/generate/integ.js +2 -1
- package/lib/commands/event/generate/job.js +82 -0
- package/lib/commands/functions/add.js +1 -0
- package/lib/commands/functions/delete.js +2 -4
- package/lib/commands/functions/setup.js +1 -0
- package/lib/commands/functions/shell.js +1 -0
- package/lib/commands/index.js +3 -1
- package/lib/commands/init.js +2 -6
- package/lib/commands/login.js +1 -0
- package/lib/commands/logout.js +1 -0
- package/lib/commands/pull.js +1 -0
- package/lib/commands/serve.js +1 -1
- package/lib/commands/whoami.js +1 -0
- package/lib/deploy/features/appsail/index.js +19 -17
- package/lib/deploy/features/appsail/utils.js +4 -5
- package/lib/endpoints/index.js +8 -1
- package/lib/endpoints/lib/appsail.js +7 -1
- package/lib/endpoints/lib/job-scheduling.js +61 -0
- package/lib/express_middlewares/logger.js +2 -4
- package/lib/fn-utils/lib/common.js +2 -3
- package/lib/fn-utils/lib/java.js +1 -1
- package/lib/fn-utils/lib/python.js +2 -2
- package/lib/fn-watcher.js +1 -1
- package/lib/init/dependencies/python/ensure-python.js +6 -8
- package/lib/init/features/appsail/index.js +14 -10
- package/lib/init/features/client/index.js +2 -1
- package/lib/init/features/functions/index.js +4 -0
- package/lib/init/features/functions/languages/python.js +21 -5
- package/lib/internal/api.js +12 -1
- package/lib/internal/command.js +30 -6
- package/lib/migration/index.js +4 -2
- package/lib/optional-import.js +3 -2
- package/lib/prompt/types/tree.js +3 -3
- package/lib/serve/features/appsail.js +2 -3
- package/lib/serve/index.js +1 -2
- package/lib/serve/server/index.js +8 -9
- package/lib/serve/server/lib/appsail/index.js +24 -34
- package/lib/serve/server/lib/java/aio_server/lib/catalyst-cli-java-runtime-1.0.0.jar +0 -0
- package/lib/serve/server/lib/java/aio_server/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/lib/serve/server/lib/java/aio_server/lib/catalyst-java-runtime-1.0.0.jar +0 -0
- package/lib/serve/server/lib/java/index.js +2 -2
- package/lib/serve/server/lib/master/appsail.js +53 -0
- package/lib/serve/server/lib/master/functions.js +34 -0
- package/lib/serve/server/lib/master/index.js +155 -0
- package/lib/{express_middlewares/unknownReqProxy.js → serve/server/lib/master/unknown-req-proxy.js} +4 -7
- package/lib/serve/server/lib/master/utils.js +130 -0
- package/lib/serve/server/lib/master/web-client.js +39 -0
- package/lib/serve/server/lib/node/index.js +3 -3
- package/lib/serve/server/lib/python/index.js +3 -3
- package/lib/shell/dependencies/invoker/bio/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/lib/shell/dependencies/invoker/cron/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +2 -1
- package/lib/shell/dependencies/invoker/event/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/lib/shell/dependencies/invoker/event/node.mjs +1 -0
- package/lib/shell/dependencies/invoker/integ/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/lib/shell/dependencies/invoker/job/java/JavajobInvoker.java +254 -0
- package/lib/shell/dependencies/invoker/job/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/lib/shell/dependencies/invoker/job/java/lib/org.json.jar +0 -0
- package/lib/shell/dependencies/invoker/job/node.mjs +93 -0
- package/lib/shell/dependencies/local-function.js +121 -13
- package/lib/shell/index.js +7 -1
- package/lib/shell/prepare/languages/index.js +4 -4
- package/lib/shell/prepare/languages/java.js +1 -2
- package/lib/shell/prepare/languages/python.js +10 -16
- package/lib/throbber/index.js +6 -1
- package/lib/userConfig.js +7 -1
- package/lib/util_modules/config/index.js +1 -1
- package/lib/util_modules/config/lib/{appSail.js → appsail.js} +61 -9
- package/lib/util_modules/config/lib/client.js +6 -8
- package/lib/util_modules/config/lib/functions.js +6 -8
- package/lib/util_modules/constants/lib/default.js +9 -9
- package/lib/util_modules/constants/lib/fn-type.js +2 -1
- package/lib/util_modules/constants/lib/needed-scopes.js +53 -44
- package/lib/util_modules/constants/lib/placeholders.js +6 -0
- package/lib/util_modules/constants/lib/ref-mapping.js +2 -1
- package/lib/util_modules/constants/lib/remote-mapping.js +2 -1
- package/lib/util_modules/constants/lib/scopes.js +5 -1
- package/lib/util_modules/constants/lib/template.js +9 -4
- package/lib/util_modules/constants/lib/urls.js +8 -0
- package/lib/util_modules/fs/lib/async.js +7 -2
- package/lib/util_modules/fs/lib/sync.js +12 -1
- package/lib/util_modules/server.js +2 -4
- package/lib/winston.js +17 -11
- package/package.json +1 -1
- package/templates/event/job.json +30 -0
- package/templates/init/functions/java/job/.classpath +6 -0
- package/templates/init/functions/java/job/.project +17 -0
- package/templates/init/functions/java/job/catalyst-config.json +11 -0
- package/templates/init/functions/java/job/sample.java +34 -0
- package/templates/init/functions/node/aio/package.json +1 -1
- package/templates/init/functions/node/bio/package.json +1 -1
- package/templates/init/functions/node/cron/package.json +1 -1
- package/templates/init/functions/node/event/package.json +1 -1
- package/templates/init/functions/node/integ/cliq/package.json +1 -1
- package/templates/init/functions/node/integ/convokraft/package.json +1 -1
- package/templates/init/functions/node/{stream → job}/catalyst-config.json +3 -2
- package/templates/init/functions/node/{stream → job}/package.json +1 -1
- package/templates/init/functions/node/job/sample.js +28 -0
- package/templates/init/functions/node/job/types/job.d.ts +66 -0
- package/templates/init/functions/python/job/catalyst-config.json +11 -0
- package/templates/init/functions/python/job/requirements.txt +1 -0
- package/templates/init/functions/python/job/sample.py +23 -0
- package/templates/init.txt +13 -0
- package/lib/serve/server/lib/master.js +0 -326
- package/templates/init/functions/node/stream/sample.js +0 -15
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import java.util.logging.Level;
|
|
2
|
+
import java.util.logging.Logger;
|
|
3
|
+
|
|
4
|
+
import com.catalyst.Context;
|
|
5
|
+
import com.catalyst.job.JOB_STATUS;
|
|
6
|
+
import com.catalyst.job.JobRequest;
|
|
7
|
+
import com.catalyst.job.CatalystJobHandler;
|
|
8
|
+
|
|
9
|
+
import com.zc.common.ZCProject;
|
|
10
|
+
import com.zc.component.cache.ZCCache;
|
|
11
|
+
|
|
12
|
+
public class {{_CLASS_}} implements CatalystJobHandler {
|
|
13
|
+
|
|
14
|
+
private static final Logger LOGGER = Logger.getLogger({{_CLASS_}}.class.getName());
|
|
15
|
+
|
|
16
|
+
@Override
|
|
17
|
+
public JOB_STATUS handleJobExecute(JobRequest request, Context arg1) throws Exception {
|
|
18
|
+
try {
|
|
19
|
+
ZCProject.initProject();
|
|
20
|
+
Object eventData = request.getAllJobParams();
|
|
21
|
+
if(eventData != null) {
|
|
22
|
+
LOGGER.log(Level.SEVERE, "Data is" + eventData.toString());
|
|
23
|
+
}
|
|
24
|
+
LOGGER.log(Level.SEVERE, "Project Details " + request.getProjectDetails().toString());
|
|
25
|
+
ZCCache.getInstance().putCacheValue("JobSample", "Working", 1l);
|
|
26
|
+
LOGGER.log(Level.SEVERE, "Inserted SucessFully:)");
|
|
27
|
+
} catch (Exception e) {
|
|
28
|
+
LOGGER.log(Level.SEVERE, "Exception in Job Function", e);
|
|
29
|
+
return JOB_STATUS.FAILURE;
|
|
30
|
+
}
|
|
31
|
+
return JOB_STATUS.SUCCESS;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {import("./types/job").JobRequest} jobRequest
|
|
4
|
+
* @param {import("./types/job").Context} context
|
|
5
|
+
*/
|
|
6
|
+
module.exports = (jobRequest, context) => {
|
|
7
|
+
console.log('Hello from {{_MAIN_}}');
|
|
8
|
+
|
|
9
|
+
// function input: { job_details: { job_meta_details: { params: { key: 'value' } } } }
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* JOB REQUEST FUNCTIONALITIES
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const projectDetails = jobRequest.getProjectDetails(); // to get the current project details
|
|
16
|
+
const jobDetails = jobRequest.getJobDetails(); // to get the current job details
|
|
17
|
+
const jobMetaDetails = jobRequest.getJobMetaDetails(); // to get the current job's meta details
|
|
18
|
+
const jobpoolDetails = jobRequest.getJobpoolDetails(); // to get the current function job pool's details
|
|
19
|
+
const getJobCapacityAttributes = jobRequest.getJobCapacityAttributes(); // to get the current jobs capacity
|
|
20
|
+
const allJobParams = jobRequest.getAllJobParams(); // to get all the parameters supplied to the job function
|
|
21
|
+
const jobParam = jobRequest.getJobParam('key'); // to get the value of a particular parameter supplied to the job function
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* CONTEXT FUNCTIONALITIES
|
|
25
|
+
*/
|
|
26
|
+
context.closeWithSuccess(); //end of application with success
|
|
27
|
+
// context.closeWithFailure(); //end of application with failure
|
|
28
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a utility file with the type declaration of the job function parameters
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Type of the Job Request object. Contains the required details of the current job.
|
|
7
|
+
*/
|
|
8
|
+
export interface JobRequest {
|
|
9
|
+
/**
|
|
10
|
+
* @returns Current project details
|
|
11
|
+
*/
|
|
12
|
+
getProjectDetails: () => Record<string, unknown>;
|
|
13
|
+
/**
|
|
14
|
+
* @returns Details of the current job
|
|
15
|
+
*/
|
|
16
|
+
getJobDetails: () => Record<string, unknown>;
|
|
17
|
+
/**
|
|
18
|
+
* @returns Meta details of the current job
|
|
19
|
+
*/
|
|
20
|
+
getJobMetaDetails: () => Record<string, unknown>;
|
|
21
|
+
/**
|
|
22
|
+
* @returns Job pool details of the current job
|
|
23
|
+
*/
|
|
24
|
+
getJobpoolDetails: () => Record<string, unknown>;
|
|
25
|
+
/**
|
|
26
|
+
* @returns Capacity attributes of the current job
|
|
27
|
+
*/
|
|
28
|
+
getJobCapacityAttributes: () => Record<string, string | number>;
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @returns All parameters passed to the job function
|
|
32
|
+
*/
|
|
33
|
+
getAllJobParams: () => Record<string, string>;
|
|
34
|
+
/**
|
|
35
|
+
* @param key Name of the job param
|
|
36
|
+
* @returns Value of the job param
|
|
37
|
+
*/
|
|
38
|
+
getJobParam: (key: string) => string | undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Type of the context object. This object is used to initialize the Catalyst sdk
|
|
43
|
+
*/
|
|
44
|
+
export interface Context extends Record<string, unknown> {
|
|
45
|
+
/**
|
|
46
|
+
* Contains the necessary headers to initialize the sdk
|
|
47
|
+
*/
|
|
48
|
+
catalystHeaders: Record<string, string | number>;
|
|
49
|
+
/**
|
|
50
|
+
* @returns Maximum allowed execution time of the function
|
|
51
|
+
*/
|
|
52
|
+
getMaxExecutionTimeMs: () => number;
|
|
53
|
+
/**
|
|
54
|
+
* This values is the difference between time Maximum execution time and the current time
|
|
55
|
+
* @returns Remaining execution time of the function
|
|
56
|
+
*/
|
|
57
|
+
getRemainingExecutionTimeMs: () => number;
|
|
58
|
+
/**
|
|
59
|
+
* Conclude the function execution with a success response
|
|
60
|
+
*/
|
|
61
|
+
closeWithSuccess: () => void;
|
|
62
|
+
/**
|
|
63
|
+
* Conclude the function execution with a failure response
|
|
64
|
+
*/
|
|
65
|
+
closeWithFailure: () => void;
|
|
66
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
zcatalyst-sdk=={{_VERSION_}}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def handler(job_request, context):
|
|
5
|
+
logger = logging.getLogger()
|
|
6
|
+
logger.info('Hello from {{_MAIN_}}')
|
|
7
|
+
|
|
8
|
+
# function input: { job_details: { job_meta_details: { params: { key: 'value' } } } }
|
|
9
|
+
|
|
10
|
+
'''JobRequest Functionalities'''
|
|
11
|
+
job_details = job_request.get_job_details() # get the details of the current job
|
|
12
|
+
project_details = job_request.get_project_details() # get the details of the current project
|
|
13
|
+
job_meta_details = job_request.get_job_meta_details() # get the job meta of the current job
|
|
14
|
+
job_pool_details = job_request.get_job_pool_details() # get the current functions job pool details
|
|
15
|
+
job_capacity_attributes = job_request.get_job_capacity_attributes() # get the current jobs capacity
|
|
16
|
+
all_job_params = job_request.get_all_job_params() # get all the parameters supplied to the job function
|
|
17
|
+
job_param = job_request.get_job_param('key') # get the value of a particular parameter supplied to the job function
|
|
18
|
+
|
|
19
|
+
'''Context Functionalities'''
|
|
20
|
+
remaining_execution_time_ms = context.get_remaining_execution_time_ms() # get the maximum allowed execution time for the job functions
|
|
21
|
+
max_execution_time_ms = context.get_max_execution_time_ms() # get the remaining execution time for this job function
|
|
22
|
+
# context.close_with_failure() # conclude the function execution with a failure response
|
|
23
|
+
context.close_with_success() # conclude the function execution with a success response
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
if (typeof catalyst === 'undefined'){
|
|
2
|
+
throw new Error('Catalyst Web SDK not included. You must include it before /__catalyst/sdk/init.js');
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
catalyst.initApp({
|
|
6
|
+
project_Id : "{{__PROJECT_ID__}}", //No I18N
|
|
7
|
+
zaid : "{{__ZAID__}}", //No I18N
|
|
8
|
+
auth_domain : "{{__AUTH_DOMAIN__}}",
|
|
9
|
+
is_appsail : "true",
|
|
10
|
+
api_domain : ""
|
|
11
|
+
},{
|
|
12
|
+
org_id: "{{__ORG_ID__}}" //No I18N
|
|
13
|
+
});
|
|
@@ -1,326 +0,0 @@
|
|
|
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 express_1 = __importDefault(require("express"));
|
|
16
|
-
const http_1 = require("http");
|
|
17
|
-
const error_1 = __importDefault(require("../../../error"));
|
|
18
|
-
const apig_matcher_1 = __importDefault(require("../../../express_middlewares/apig-matcher"));
|
|
19
|
-
const auth_checker_1 = __importDefault(require("../../../express_middlewares/auth-checker"));
|
|
20
|
-
const authenticator_1 = __importDefault(require("../../../express_middlewares/authenticator"));
|
|
21
|
-
const cookie_parser_1 = __importDefault(require("../../../express_middlewares/cookie-parser"));
|
|
22
|
-
const error_handler_1 = __importDefault(require("../../../express_middlewares/error-handler"));
|
|
23
|
-
const logger_1 = __importDefault(require("../../../express_middlewares/logger"));
|
|
24
|
-
const project_1 = __importDefault(require("../../../express_middlewares/project"));
|
|
25
|
-
const unknownReqProxy_1 = __importDefault(require("../../../express_middlewares/unknownReqProxy"));
|
|
26
|
-
const url_rewriter_1 = __importDefault(require("../../../express_middlewares/url-rewriter"));
|
|
27
|
-
const runtime_store_1 = __importDefault(require("../../../runtime-store"));
|
|
28
|
-
const constants_1 = require("../../../util_modules/constants");
|
|
29
|
-
const js_1 = require("../../../util_modules/js");
|
|
30
|
-
const logger_2 = require("../../../util_modules/logger");
|
|
31
|
-
const project_2 = require("../../../util_modules/project");
|
|
32
|
-
const option_1 = require("../../../util_modules/option");
|
|
33
|
-
const server_js_1 = require("../../../util_modules/server.js");
|
|
34
|
-
const http_proxy_1 = require("http-proxy");
|
|
35
|
-
const appsail_utils_1 = require("../../../appsail-utils");
|
|
36
|
-
const removeSecure = (str) => str.replace(/;\s?Secure/i, '').replace(/;\s?SameSite=None/i, '');
|
|
37
|
-
const redirectByAuth = (req, res, redirectUrl) => {
|
|
38
|
-
if (req.headers['x-zc-user-cred-token'] === undefined) {
|
|
39
|
-
res.writeHead(302, { Location: redirectUrl });
|
|
40
|
-
res.end();
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
res.writeHead(302, { Location: '/app/' });
|
|
44
|
-
res.end();
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
const proxyResponseHandler = (systemRoutes) => (proxyRes, req, res) => {
|
|
48
|
-
if (!req.url) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
if (req.url.startsWith('/oauthorize')) {
|
|
52
|
-
const set = proxyRes.headers['set-cookie'];
|
|
53
|
-
if (set) {
|
|
54
|
-
const result = Array.isArray(set) ? set.map(removeSecure) : removeSecure(set);
|
|
55
|
-
proxyRes.headers['set-cookie'] = result;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
else if (req.url.startsWith('/baas') || req.url.startsWith('/__catalyst')) {
|
|
59
|
-
if (req.url.includes('/signin-redirect')) {
|
|
60
|
-
if (systemRoutes === undefined) {
|
|
61
|
-
redirectByAuth(req, res, '/app/local-redirect');
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const sourceRedirectUrl = Object.keys(systemRoutes).find((sourceUrl) => {
|
|
65
|
-
const methodByConfig = systemRoutes ? systemRoutes[sourceUrl] : undefined;
|
|
66
|
-
if (methodByConfig) {
|
|
67
|
-
return !!Object.values(methodByConfig).find((config) => {
|
|
68
|
-
return config.name === 'Login Redirect';
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
return false;
|
|
72
|
-
});
|
|
73
|
-
if (sourceRedirectUrl === undefined) {
|
|
74
|
-
res.end('INVALID_URL');
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
redirectByAuth(req, res, sourceRedirectUrl);
|
|
78
|
-
}
|
|
79
|
-
else if (req.url.includes('/logout')) {
|
|
80
|
-
const set = proxyRes.headers['set-cookie'];
|
|
81
|
-
if (set) {
|
|
82
|
-
const result = set.map((cookie) => cookie.replace(new RegExp('Domain=[\\S^;]*', 'g'), 'Domain=localhost;'));
|
|
83
|
-
proxyRes.headers['set-cookie'] = result;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
else if (req.url.startsWith('/accounts') && req.url.includes('/signin')) {
|
|
88
|
-
const set = proxyRes.headers['set-cookie'];
|
|
89
|
-
set
|
|
90
|
-
? set.push('IAM_TEST_COOKIE=IAM_TEST_COOKIE; Domain=localhost; Path=/')
|
|
91
|
-
: ['IAM_TEST_COOKIE=IAM_TEST_COOKIE; Domain=localhost; Path=/'];
|
|
92
|
-
proxyRes.headers['set-cookie'] = set;
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
function spinUpMaster(listenPort, otherServerDetails) {
|
|
96
|
-
var _a, _b, _c, _d;
|
|
97
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
const projectDetails = ((_b = (_a = otherServerDetails.appSail) === null || _a === void 0 ? void 0 : _a.at(0)) === null || _b === void 0 ? void 0 : _b.target) !== undefined
|
|
99
|
-
? {
|
|
100
|
-
id: (0, project_2.getProjectId)(),
|
|
101
|
-
domain_prefix: (0, appsail_utils_1.getDomainPrefix)((_c = otherServerDetails.appSail.at(0)) === null || _c === void 0 ? void 0 : _c.target),
|
|
102
|
-
domain: constants_1.ORIGIN.appSailDomain.replace('https://', ''),
|
|
103
|
-
key: (0, project_2.getDomainKey)(),
|
|
104
|
-
env_name: (0, project_2.getEnvName)()
|
|
105
|
-
}
|
|
106
|
-
: {
|
|
107
|
-
id: (0, project_2.getProjectId)(),
|
|
108
|
-
domain_prefix: (0, project_2.getDomainPrefix)(),
|
|
109
|
-
domain: constants_1.ORIGIN.app.replace('https://', ''),
|
|
110
|
-
key: (0, project_2.getDomainKey)(),
|
|
111
|
-
env_name: (0, project_2.getEnvName)()
|
|
112
|
-
};
|
|
113
|
-
const rules = runtime_store_1.default.get('context.apig.local.config', -1);
|
|
114
|
-
const customProxyUrl = (0, option_1.getOptionValue)('proxy');
|
|
115
|
-
const app = (0, express_1.default)();
|
|
116
|
-
let systemRoutes;
|
|
117
|
-
const nonApigURL = ['/accounts', '/clientoauth', '/_wms', '/wmssrv'];
|
|
118
|
-
app.use((0, logger_1.default)((_d = otherServerDetails.appSail) === null || _d === void 0 ? void 0 : _d.at(0)));
|
|
119
|
-
app.use(cookie_parser_1.default);
|
|
120
|
-
app.use((0, project_1.default)(projectDetails));
|
|
121
|
-
app.use(authenticator_1.default);
|
|
122
|
-
app.use(nonApigURL, (req, res) => {
|
|
123
|
-
req.url = req.originalUrl;
|
|
124
|
-
(0, unknownReqProxy_1.default)(proxy, customProxyUrl)(req, res);
|
|
125
|
-
});
|
|
126
|
-
app.use('*/.catalyst%2Freload-script.js', (req, res) => {
|
|
127
|
-
var _a;
|
|
128
|
-
req.url = '/.catalyst%2Freload-script.js';
|
|
129
|
-
(_a = otherServerDetails.client) === null || _a === void 0 ? void 0 : _a.forEach((clientDetails) => {
|
|
130
|
-
const appTarget = `http://127.0.0.1:${clientDetails.httpPort}/app/`;
|
|
131
|
-
proxy.web(req, res, {
|
|
132
|
-
target: appTarget,
|
|
133
|
-
changeOrigin: true
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
if (rules !== -1) {
|
|
138
|
-
for (const [sourceURL, methodByConfig] of Object.entries(rules)) {
|
|
139
|
-
const router = app.route(sourceURL);
|
|
140
|
-
for (const [method, config] of Object.entries(methodByConfig)) {
|
|
141
|
-
if (config.system) {
|
|
142
|
-
if (systemRoutes === undefined) {
|
|
143
|
-
systemRoutes = {};
|
|
144
|
-
}
|
|
145
|
-
js_1.JS.set(systemRoutes, [sourceURL, method], config);
|
|
146
|
-
}
|
|
147
|
-
router[method]((req, res, next) => {
|
|
148
|
-
if (res.locals.apigRules === undefined) {
|
|
149
|
-
res.locals.apigRules = [];
|
|
150
|
-
}
|
|
151
|
-
res.locals.apigRules.push(Object.assign({ source_endpoint: sourceURL, params: req.params }, config));
|
|
152
|
-
next();
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
app.use('/', apig_matcher_1.default, auth_checker_1.default, url_rewriter_1.default);
|
|
157
|
-
}
|
|
158
|
-
const proxy = (0, http_proxy_1.createProxyServer)({
|
|
159
|
-
hostRewrite: `localhost:${listenPort}`,
|
|
160
|
-
protocolRewrite: 'http'
|
|
161
|
-
})
|
|
162
|
-
.on('error', (err, req, res) => {
|
|
163
|
-
if (res.writableEnded) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
if (res instanceof http_1.ServerResponse) {
|
|
167
|
-
res.writeHead(502, { 'Content-Type': 'json' });
|
|
168
|
-
}
|
|
169
|
-
res.end(JSON.stringify({ error: 'unable to serve the request' }));
|
|
170
|
-
console.log();
|
|
171
|
-
console.log('Unable to reach the servers to serve the request: ', req.url);
|
|
172
|
-
console.error(err);
|
|
173
|
-
})
|
|
174
|
-
.on('econnreset', (err, req, res, targetUrl) => {
|
|
175
|
-
if (res.writableEnded) {
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
if (res instanceof http_1.ServerResponse) {
|
|
179
|
-
res.writeHead(502, { 'Content-Type': 'json' });
|
|
180
|
-
}
|
|
181
|
-
res.end(JSON.stringify({ error: 'unable to serve the request. ECONNRESET.' }));
|
|
182
|
-
console.log();
|
|
183
|
-
console.log('Connection reset while trying to serve the request ', req.url);
|
|
184
|
-
(0, logger_2.debug)('Connection reset from target URL : ', targetUrl);
|
|
185
|
-
console.error(err);
|
|
186
|
-
})
|
|
187
|
-
.on('proxyRes', proxyResponseHandler(systemRoutes))
|
|
188
|
-
.on('close', () => (0, logger_2.debug)('proxy closed'));
|
|
189
|
-
const proxyDestroyer = new server_js_1.ConnectionDestroyer(proxy);
|
|
190
|
-
Object.keys(otherServerDetails).forEach((targ) => {
|
|
191
|
-
var _a, _b, _c, _d;
|
|
192
|
-
switch (targ) {
|
|
193
|
-
case 'client': {
|
|
194
|
-
(_a = otherServerDetails.client) === null || _a === void 0 ? void 0 : _a.forEach((clientDetails) => {
|
|
195
|
-
const appTarget = `http://127.0.0.1:${clientDetails.httpPort}/app/`;
|
|
196
|
-
app.use('/app', (req, res) => {
|
|
197
|
-
const target = clientDetails.target;
|
|
198
|
-
if (req.url === '/' && target.homepage.includes('/__catalyst')) {
|
|
199
|
-
req.url = target.homepage;
|
|
200
|
-
(0, unknownReqProxy_1.default)(proxy, customProxyUrl)(req, res);
|
|
201
|
-
}
|
|
202
|
-
else if (req.url.startsWith('/local-redirect') && target.login_redirect) {
|
|
203
|
-
const isUrl = target.login_redirect.startsWith('/');
|
|
204
|
-
if (isUrl) {
|
|
205
|
-
res.redirect(target.login_redirect);
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
res.redirect('/app/' + target.login_redirect);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
proxy.web(req, res, {
|
|
213
|
-
target: appTarget,
|
|
214
|
-
changeOrigin: true
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
const appTargetUrl = new URL(appTarget);
|
|
219
|
-
appTargetUrl.pathname = '';
|
|
220
|
-
appTargetUrl.protocol = 'ws';
|
|
221
|
-
app.addListener('upgrade', (...upgradeParam) => {
|
|
222
|
-
proxy.ws(upgradeParam[0], upgradeParam[1], upgradeParam[2], {
|
|
223
|
-
target: appTargetUrl.href,
|
|
224
|
-
ws: true,
|
|
225
|
-
changeOrigin: true
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
break;
|
|
230
|
-
}
|
|
231
|
-
case 'server': {
|
|
232
|
-
(_b = otherServerDetails.server) === null || _b === void 0 ? void 0 : _b.forEach((serverDetail) => {
|
|
233
|
-
var _a;
|
|
234
|
-
app.use('/server/' + ((_a = serverDetail.target) === null || _a === void 0 ? void 0 : _a.name), (req, res) => {
|
|
235
|
-
proxy.web(req, res, {
|
|
236
|
-
target: `http://127.0.0.1:${serverDetail.httpPort}`
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
break;
|
|
241
|
-
}
|
|
242
|
-
case 'functions': {
|
|
243
|
-
(_c = otherServerDetails.functions) === null || _c === void 0 ? void 0 : _c.forEach((fnDetails) => {
|
|
244
|
-
const fnTarget = fnDetails.target;
|
|
245
|
-
app.use(`/server/${fnTarget.name}`, (req, res) => {
|
|
246
|
-
proxy.web(req, res, {
|
|
247
|
-
target: `http://127.0.0.1:${fnDetails.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic
|
|
248
|
-
? `/server/${fnTarget.name}/execute`
|
|
249
|
-
: ''}`,
|
|
250
|
-
ws: true
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
app.use(`/baas/v1/project/:projectId/function/${fnTarget.name}`, (req, res) => {
|
|
254
|
-
proxy.web(req, res, {
|
|
255
|
-
target: `http://127.0.0.1:${fnDetails.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic
|
|
256
|
-
? `/server/${fnTarget.name}/execute`
|
|
257
|
-
: ''}`,
|
|
258
|
-
ws: true
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
if (fnTarget.id) {
|
|
262
|
-
app.use(`/server/${fnTarget.id}`, (req, res) => {
|
|
263
|
-
proxy.web(req, res, {
|
|
264
|
-
target: `http://127.0.0.1:${fnDetails.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic
|
|
265
|
-
? `/server/${fnTarget.id}/execute`
|
|
266
|
-
: ''}`,
|
|
267
|
-
ws: true
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
app.use(`/baas/v1/project/:projectId/function/${fnTarget.id}`, (req, res) => {
|
|
271
|
-
proxy.web(req, res, {
|
|
272
|
-
target: `http://127.0.0.1:${fnDetails.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic
|
|
273
|
-
? `/server/${fnTarget.id}/execute`
|
|
274
|
-
: ''}`,
|
|
275
|
-
ws: true
|
|
276
|
-
});
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
case 'appSail': {
|
|
283
|
-
(_d = otherServerDetails.appSail) === null || _d === void 0 ? void 0 : _d.forEach((appSailDetails) => {
|
|
284
|
-
app.use('/', (req, res) => {
|
|
285
|
-
var _a;
|
|
286
|
-
if ((_a = req.url) === null || _a === void 0 ? void 0 : _a.includes('/__catalyst/sdk/init.js')) {
|
|
287
|
-
(0, unknownReqProxy_1.default)(proxy, customProxyUrl)(req, res);
|
|
288
|
-
}
|
|
289
|
-
else {
|
|
290
|
-
proxy.web(req, res, {
|
|
291
|
-
target: `http://127.0.0.1:${appSailDetails.target.port
|
|
292
|
-
.appsail}`,
|
|
293
|
-
ws: true
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
});
|
|
298
|
-
break;
|
|
299
|
-
}
|
|
300
|
-
default:
|
|
301
|
-
throw new error_1.default('Unknown type provided to master server ' + targ, {
|
|
302
|
-
exit: 2
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
app.use('/', (0, unknownReqProxy_1.default)(proxy, customProxyUrl));
|
|
307
|
-
app.use(error_handler_1.default);
|
|
308
|
-
const expressServer = app.listen(listenPort, '127.0.0.1').on('error', (err) => {
|
|
309
|
-
if (proxy) {
|
|
310
|
-
proxyDestroyer.destroy();
|
|
311
|
-
}
|
|
312
|
-
console.error(err);
|
|
313
|
-
});
|
|
314
|
-
const expressDestroyer = new server_js_1.ConnectionDestroyer(expressServer);
|
|
315
|
-
expressServer.maxConnections = 100;
|
|
316
|
-
process.on('SIGINT', () => expressDestroyer.destroy(false));
|
|
317
|
-
expressServer.on('close', () => __awaiter(this, void 0, void 0, function* () {
|
|
318
|
-
yield proxyDestroyer.destroy().catch((err) => (0, logger_2.debug)(err));
|
|
319
|
-
}));
|
|
320
|
-
expressServer.on('upgrade', (...upgradeParam) => {
|
|
321
|
-
app.emit('upgrade', ...upgradeParam);
|
|
322
|
-
});
|
|
323
|
-
return expressServer;
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
exports.default = spinUpMaster;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
module.exports = (inputStream, outputStream, context) => {
|
|
2
|
-
console.log('Hello from {{_MAIN_}}');
|
|
3
|
-
|
|
4
|
-
// inputStream.getContentType();
|
|
5
|
-
// inputStream.getContentLength();
|
|
6
|
-
// inputStream.getParameter('name');
|
|
7
|
-
|
|
8
|
-
let response = 'stream response';
|
|
9
|
-
outputStream.setContentType('text/plain');
|
|
10
|
-
outputStream.setStatus(201);
|
|
11
|
-
outputStream.setContentLength(response.length);
|
|
12
|
-
outputStream.getStream().write(response);
|
|
13
|
-
|
|
14
|
-
context.close();
|
|
15
|
-
};
|