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.
- package/docs/command_needs/rc.toml +8 -8
- package/docs/commands/ds/import.toml +5 -5
- package/docs/commands/event/generate/job.toml +7 -0
- package/docs/commands/zest/generate/index.toml +4 -0
- package/docs/endpoints/lib/job-scheduling.toml +3 -0
- package/docs/internal/command.toml +5 -0
- package/docs/serve/server/lib/appsail/index.toml +22 -1
- package/lib/appsail-utils.js +4 -10
- package/lib/authentication/index.js +1 -0
- package/lib/authentication/login.js +8 -4
- package/lib/bin/catalyst.js +1 -1
- package/lib/code-deck.js +7 -7
- package/lib/command_needs/rc.js +8 -8
- package/lib/commands/appsail/add.js +3 -2
- package/lib/commands/client/setup.js +2 -1
- package/lib/commands/codelib/install.js +6 -2
- package/lib/commands/ds/import.js +37 -21
- package/lib/commands/event/generate/index.js +16 -3
- package/lib/commands/event/generate/integ.js +2 -1
- package/lib/commands/event/generate/job.js +82 -0
- package/lib/commands/functions/add.js +2 -1
- package/lib/commands/functions/delete.js +2 -4
- package/lib/commands/functions/setup.js +2 -1
- package/lib/commands/functions/shell.js +1 -0
- package/lib/commands/iac/export.js +5 -1
- package/lib/commands/iac/import.js +4 -1
- package/lib/commands/index.js +4 -1
- package/lib/commands/init.js +10 -7
- 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/commands/zest/generate/index.js +304 -0
- package/lib/deploy/features/appsail/index.js +42 -25
- package/lib/deploy/features/appsail/utils.js +4 -5
- package/lib/endpoints/index.js +24 -3
- package/lib/endpoints/lib/appsail.js +7 -1
- package/lib/endpoints/lib/ds-bulk.js +1 -0
- package/lib/endpoints/lib/job-scheduling.js +61 -0
- package/lib/endpoints/lib/stratus.js +63 -0
- package/lib/endpoints/lib/tunnel.js +18 -0
- package/lib/endpoints/lib/zest.js +124 -0
- package/lib/event_generate/stratus.js +52 -0
- package/lib/express_middlewares/logger.js +2 -4
- package/lib/fn-utils/lib/common.js +8 -4
- 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/iac/status/deploy.js +1 -5
- package/lib/init/dependencies/python/ensure-python.js +6 -8
- package/lib/init/features/appsail/index.js +38 -27
- 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/init/features/project.js +6 -15
- package/lib/internal/api.js +26 -7
- package/lib/internal/command.js +31 -7
- package/lib/migration/index.js +4 -2
- package/lib/optional-import.js +3 -2
- package/lib/prompt/index.js +5 -2
- package/lib/prompt/types/file-path.js +1 -1
- package/lib/prompt/types/search-box.js +281 -0
- package/lib/prompt/types/tree.js +3 -3
- package/lib/serve/features/appsail.js +3 -4
- package/lib/serve/index.js +1 -2
- package/lib/serve/server/index.js +52 -23
- package/lib/serve/server/lib/appsail/index.js +89 -39
- package/lib/serve/server/lib/appsail/start.js +9 -1
- 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 → catalyst-function-sdk-1.1.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} +9 -9
- package/lib/serve/server/lib/master/utils.js +142 -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/node/server/package-lock.json +12 -0
- package/lib/serve/server/lib/python/index.js +3 -3
- package/lib/shell/dependencies/http-functions.js +1 -1
- package/lib/shell/dependencies/invoker/bio/java/lib/catalyst-function-sdk-1.1.0.jar +0 -0
- package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +1 -1
- package/lib/shell/dependencies/invoker/cron/java/lib/catalyst-function-sdk-1.1.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.1.0.jar +0 -0
- package/lib/shell/dependencies/invoker/event/node.mjs +1 -0
- package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +15 -0
- package/lib/shell/dependencies/invoker/integ/java/lib/catalyst-function-sdk-1.1.0.jar +0 -0
- package/lib/shell/dependencies/invoker/integ/node.mjs +13 -0
- package/lib/shell/dependencies/invoker/job/java/JavajobInvoker.java +268 -0
- package/lib/shell/dependencies/invoker/job/java/lib/catalyst-function-sdk-1.1.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 +122 -13
- package/lib/shell/dependencies/tunnel-server.js +52 -23
- package/lib/shell/index.js +22 -22
- 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} +64 -10
- 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/dc-type.js +8 -0
- package/lib/util_modules/constants/lib/default.js +9 -9
- package/lib/util_modules/constants/lib/event-action.js +1 -0
- package/lib/util_modules/constants/lib/event-source.js +1 -0
- 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 +7 -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 +17 -2
- package/lib/util_modules/constants/lib/template.js +9 -4
- package/lib/util_modules/constants/lib/urls.js +16 -0
- package/lib/util_modules/fs/lib/async.js +14 -4
- 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 +4 -2
- package/templates/event/job.json +30 -0
- package/templates/init/client/react/react_js/template/src/index.js +3 -3
- package/templates/init/client/react/react_ts/template/src/index.tsx +3 -3
- package/templates/init/client/react/react_ts/template.json +3 -3
- 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/aio/sample.js +7 -0
- package/templates/init/functions/node/bio/package.json +1 -1
- package/templates/init/functions/node/bio/sample.js +5 -0
- package/templates/init/functions/node/bio/types/basicio.d.ts +57 -0
- package/templates/init/functions/node/cron/package.json +1 -1
- package/templates/init/functions/node/cron/sample.js +5 -0
- package/templates/init/functions/node/cron/types/cron.d.ts +64 -0
- package/templates/init/functions/node/event/package.json +1 -1
- package/templates/init/functions/node/event/sample.js +11 -8
- package/templates/init/functions/node/event/types/event.d.ts +82 -0
- 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 +27 -0
- package/templates/init/functions/node/job/types/job.d.ts +62 -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 +22 -0
- package/templates/init.txt +14 -0
- package/lib/serve/server/lib/master.js +0 -326
- 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/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/lib/shell/dependencies/invoker/integ/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/templates/init/functions/node/stream/sample.js +0 -15
|
@@ -25,6 +25,7 @@ const option_1 = require("../../../../util_modules/option");
|
|
|
25
25
|
const execute_script_1 = require("../../../../execute-script");
|
|
26
26
|
const master_1 = __importDefault(require("../master"));
|
|
27
27
|
const ansi_colors_1 = require("ansi-colors");
|
|
28
|
+
const common_1 = require("../../../../init/util/common");
|
|
28
29
|
function executeHook(script, name, moduleSource) {
|
|
29
30
|
if ((0, option_1.getOptionValue)('ignoreScripts', false)) {
|
|
30
31
|
(0, logger_1.debug)(`skipping ${name} hook`);
|
|
@@ -38,56 +39,72 @@ const startAppSail = (port, opts) => {
|
|
|
38
39
|
if (opts.command) {
|
|
39
40
|
_opts.push('-c', opts.command);
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
+
const child = (0, shell_1.spawn)('node', _opts, {
|
|
42
43
|
cwd: opts.target,
|
|
43
44
|
stdio: 'pipe',
|
|
44
|
-
env: Object.assign({ X_ZOHO_CATALYST_LISTEN_PORT: port + '', X_ZOHO_CATALYST_RUNTIME_MEMORY: opts.memory + '', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, (opts.env || {}))
|
|
45
|
+
env: Object.assign({ X_ZOHO_CATALYST_LISTEN_PORT: port + '', X_ZOHO_CATALYST_RUNTIME_MEMORY: opts.memory + '', X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_STRATUS_RESOURCE_SUFFIX: constants_1.ORIGIN.stratusSuffix, X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZC_RESOURCE_NAME: opts.name + '', CATALYST_PORTAL_DOMAIN: constants_1.ORIGIN.iamPortal, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, (opts.env || {}))
|
|
45
46
|
}).RAW();
|
|
47
|
+
return new Promise((_res, _rej) => {
|
|
48
|
+
child.on('spawn', () => _res(child));
|
|
49
|
+
child.on('error', (reason) => _rej(reason));
|
|
50
|
+
});
|
|
46
51
|
};
|
|
47
52
|
exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
-
var _a, _b, _c, _d;
|
|
53
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
49
54
|
let child;
|
|
50
55
|
const targetSail = serverDetails.target;
|
|
51
|
-
if (!targetSail || !targetSail.
|
|
56
|
+
if (!targetSail || !targetSail.config) {
|
|
52
57
|
throw new error_1.default('AppSail details not found');
|
|
53
58
|
}
|
|
54
|
-
if ((_a = targetSail.
|
|
55
|
-
executeHook(targetSail.
|
|
59
|
+
if ((_a = targetSail.config.scripts) === null || _a === void 0 ? void 0 : _a.preserve) {
|
|
60
|
+
executeHook(targetSail.config.scripts.preserve, `AppSail [PRESERVE] [${targetSail.name}]`, targetSail.source);
|
|
56
61
|
}
|
|
57
|
-
const buildPath = targetSail.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
const buildPath = (_b = targetSail.config) === null || _b === void 0 ? void 0 : _b.build_path;
|
|
63
|
+
const target = (yield fs_1.ASYNC.fileExists(buildPath)) ? (0, path_1.dirname)(buildPath) : buildPath;
|
|
64
|
+
if (!(yield fs_1.ASYNC.isPathExists(target))) {
|
|
65
|
+
if ((0, path_1.isAbsolute)(((_c = targetSail.config) === null || _c === void 0 ? void 0 : _c.raw.build_path) || '')) {
|
|
66
|
+
throw new error_1.default('The given AppSail build path does not exists', {
|
|
67
|
+
exit: 1,
|
|
68
|
+
errorId: 'SERVE-APPSAIL-1',
|
|
69
|
+
arg: [ansi_colors_1.italic.underline.red(target), (0, ansi_colors_1.bold)(targetSail.name)]
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
throw new error_1.default('The given AppSail build path does not exists: ' + targetSail.name, {
|
|
62
73
|
exit: 1,
|
|
63
|
-
errorId: 'SERVE-APPSAIL-
|
|
64
|
-
arg: [
|
|
74
|
+
errorId: 'SERVE-APPSAIL-2',
|
|
75
|
+
arg: [
|
|
76
|
+
(0, ansi_colors_1.underline)(((_d = targetSail.config) === null || _d === void 0 ? void 0 : _d.raw.build_path) || ''),
|
|
77
|
+
ansi_colors_1.italic.underline(targetSail.config.raw.source_path || ''),
|
|
78
|
+
ansi_colors_1.italic.underline(((_e = targetSail.config) === null || _e === void 0 ? void 0 : _e.raw.build_path) || ''),
|
|
79
|
+
ansi_colors_1.italic.underline(target)
|
|
80
|
+
]
|
|
65
81
|
});
|
|
66
82
|
}
|
|
67
|
-
const target = (yield fs_1.ASYNC.fileExists(buildPath)) ? (0, path_1.dirname)(buildPath) : buildPath;
|
|
68
83
|
switch (true) {
|
|
69
|
-
case targetSail.
|
|
70
|
-
child = startAppSail(targetSail.port.appsail, {
|
|
84
|
+
case targetSail.config.stack.startsWith('node'): {
|
|
85
|
+
child = yield startAppSail(targetSail.port.appsail, {
|
|
71
86
|
type: 'nodejs',
|
|
72
87
|
target,
|
|
73
|
-
command: targetSail.
|
|
74
|
-
memory: targetSail.
|
|
75
|
-
env: targetSail.
|
|
88
|
+
command: targetSail.config.command,
|
|
89
|
+
memory: targetSail.config.memory || 256,
|
|
90
|
+
env: targetSail.config.env_variables,
|
|
91
|
+
name: targetSail.name
|
|
76
92
|
});
|
|
77
93
|
break;
|
|
78
94
|
}
|
|
79
|
-
case targetSail.
|
|
80
|
-
child = startAppSail(targetSail.port.appsail, {
|
|
95
|
+
case targetSail.config.stack.startsWith('python'): {
|
|
96
|
+
child = yield startAppSail(targetSail.port.appsail, {
|
|
81
97
|
type: 'python',
|
|
82
98
|
target,
|
|
83
|
-
command: targetSail.
|
|
84
|
-
memory: targetSail.
|
|
85
|
-
env: targetSail.
|
|
99
|
+
command: targetSail.config.command,
|
|
100
|
+
memory: targetSail.config.memory || 256,
|
|
101
|
+
env: targetSail.config.env_variables,
|
|
102
|
+
name: targetSail.name
|
|
86
103
|
});
|
|
87
104
|
break;
|
|
88
105
|
}
|
|
89
|
-
case targetSail.
|
|
90
|
-
if (targetSail.
|
|
106
|
+
case targetSail.config.stack.startsWith('java'): {
|
|
107
|
+
if (targetSail.config.platform === 'war') {
|
|
91
108
|
const jettyPath = (0, path_1.join)(constants_1.ENVPATH.runtimes.data, 'jetty');
|
|
92
109
|
if (!(yield fs_1.ASYNC.fileExists((0, path_1.join)(jettyPath, 'start.jar')).catch((err) => (0, logger_1.debug)(err)))) {
|
|
93
110
|
try {
|
|
@@ -108,30 +125,41 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
|
|
|
108
125
|
}
|
|
109
126
|
}
|
|
110
127
|
const jettyCommand = `java -jar "${(0, path_1.join)(jettyPath, 'start.jar')}" -Djetty.deploy.monitoredPath="${(0, project_1.resolveProjectPath)(target)}" -Djetty.http.port=${targetSail.port.appsail}`;
|
|
111
|
-
child = startAppSail(targetSail.port.appsail, {
|
|
128
|
+
child = yield startAppSail(targetSail.port.appsail, {
|
|
112
129
|
target,
|
|
113
130
|
type: 'war',
|
|
114
131
|
command: jettyCommand,
|
|
115
|
-
memory: targetSail.
|
|
116
|
-
env: Object.assign({ JETTY_BASE: (0, path_1.join)(jettyPath, 'JETTY_BASE') }, targetSail.
|
|
132
|
+
memory: targetSail.config.memory || 256,
|
|
133
|
+
env: Object.assign({ JETTY_BASE: (0, path_1.join)(jettyPath, 'JETTY_BASE') }, targetSail.config.env_variables),
|
|
134
|
+
name: targetSail.name
|
|
117
135
|
});
|
|
118
136
|
break;
|
|
119
137
|
}
|
|
120
|
-
child = startAppSail(targetSail.port.appsail, {
|
|
138
|
+
child = yield startAppSail(targetSail.port.appsail, {
|
|
121
139
|
target,
|
|
122
|
-
command: targetSail.
|
|
140
|
+
command: targetSail.config.command,
|
|
123
141
|
type: 'javase',
|
|
124
|
-
memory: targetSail.
|
|
125
|
-
env: targetSail.
|
|
142
|
+
memory: targetSail.config.memory || 256,
|
|
143
|
+
env: targetSail.config.env_variables,
|
|
144
|
+
name: targetSail.name
|
|
126
145
|
});
|
|
127
146
|
break;
|
|
128
147
|
}
|
|
129
148
|
default: {
|
|
130
|
-
|
|
149
|
+
const appSailRuntime = yield (0, common_1.getRuntimeDetails)();
|
|
150
|
+
throw new error_1.default('Invalid AppSail stack', {
|
|
151
|
+
exit: 1,
|
|
152
|
+
errorId: 'SERVE-APPSAIL-4',
|
|
153
|
+
arg: [
|
|
154
|
+
(0, ansi_colors_1.bold)(targetSail.name),
|
|
155
|
+
ansi_colors_1.bold.red(targetSail.config.stack),
|
|
156
|
+
appSailRuntime.runtimes.map((val) => (0, ansi_colors_1.bold)(`* ${val}`)).join('\n')
|
|
157
|
+
]
|
|
158
|
+
});
|
|
131
159
|
}
|
|
132
160
|
}
|
|
133
161
|
const masterServe = yield (0, master_1.default)(targetSail.port.proxy, {
|
|
134
|
-
|
|
162
|
+
appSailDetails: serverDetails
|
|
135
163
|
});
|
|
136
164
|
child.once('exit', () => {
|
|
137
165
|
masterServe.close((err) => {
|
|
@@ -140,14 +168,36 @@ exports.default = (serverDetails) => __awaiter(void 0, void 0, void 0, function*
|
|
|
140
168
|
}
|
|
141
169
|
});
|
|
142
170
|
});
|
|
143
|
-
if ((
|
|
171
|
+
if ((_g = (_f = targetSail.config) === null || _f === void 0 ? void 0 : _f.scripts) === null || _g === void 0 ? void 0 : _g.postserve) {
|
|
144
172
|
child.once('exit', () => {
|
|
145
|
-
var _a, _b, _c
|
|
146
|
-
if (!((_a = targetSail.
|
|
173
|
+
var _a, _b, _c;
|
|
174
|
+
if (!((_a = targetSail.config) === null || _a === void 0 ? void 0 : _a.scripts)) {
|
|
147
175
|
return;
|
|
148
176
|
}
|
|
149
|
-
executeHook((_b = targetSail.
|
|
177
|
+
executeHook((_c = (_b = targetSail.config) === null || _b === void 0 ? void 0 : _b.scripts) === null || _c === void 0 ? void 0 : _c.postserve, `AppSail [POSTSERVE] [${targetSail.name}]`, targetSail.source);
|
|
150
178
|
});
|
|
151
179
|
}
|
|
180
|
+
process.on('SIGINT', () => {
|
|
181
|
+
targetSail.trigger.kill = true;
|
|
182
|
+
});
|
|
183
|
+
child.once('exit', (code) => {
|
|
184
|
+
var _a, _b, _c;
|
|
185
|
+
if (code === 150) {
|
|
186
|
+
targetSail.validity = {
|
|
187
|
+
valid: false,
|
|
188
|
+
reason: 'Unable to start the AppSail'
|
|
189
|
+
};
|
|
190
|
+
throw new error_1.default('Unable to start the AppSail', {
|
|
191
|
+
exit: 1,
|
|
192
|
+
errorId: 'SERVE-APPSAIL-3',
|
|
193
|
+
arg: [
|
|
194
|
+
(0, ansi_colors_1.bold)(targetSail.name),
|
|
195
|
+
((_a = targetSail.config) === null || _a === void 0 ? void 0 : _a.command) || '',
|
|
196
|
+
(0, ansi_colors_1.underline)(((_b = targetSail.config) === null || _b === void 0 ? void 0 : _b.build_path) || ''),
|
|
197
|
+
((_c = targetSail.config) === null || _c === void 0 ? void 0 : _c.stack) || ''
|
|
198
|
+
]
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
});
|
|
152
202
|
return child;
|
|
153
203
|
});
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
3
|
+
|
|
4
|
+
// exit codes
|
|
5
|
+
// 150 - start up command failure
|
|
6
|
+
|
|
3
7
|
const EXEC_SYNC = require('child_process').execSync;
|
|
4
8
|
|
|
5
9
|
const WAR = 'war';
|
|
@@ -58,7 +62,11 @@ function main() {
|
|
|
58
62
|
throw new Error(`invalid runtime type: ${CMD_ARGS.rtType}`);
|
|
59
63
|
}
|
|
60
64
|
|
|
61
|
-
|
|
65
|
+
try {
|
|
66
|
+
EXEC_SYNC(command.toString(), { stdio: 'inherit', cwd });
|
|
67
|
+
} catch (er) {
|
|
68
|
+
process.exit(150);
|
|
69
|
+
}
|
|
62
70
|
}
|
|
63
71
|
|
|
64
72
|
main();
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -23,7 +23,7 @@ const logger_1 = require("../../../../util_modules/logger");
|
|
|
23
23
|
const project_1 = require("../../../../util_modules/project");
|
|
24
24
|
const shell_1 = require("../../../../util_modules/shell");
|
|
25
25
|
exports.default = (details, masterPort) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
-
var _a, _b, _c, _d, _e;
|
|
26
|
+
var _a, _b, _c, _d, _e, _f;
|
|
27
27
|
const projectRoot = runtime_store_1.default.get('project.root');
|
|
28
28
|
const javaServer = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, '.catalyst', 'aioserver', 'JavaaioServer');
|
|
29
29
|
const targetDir = (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, (_a = details.target) === null || _a === void 0 ? void 0 : _a.name);
|
|
@@ -54,6 +54,6 @@ exports.default = (details, masterPort) => __awaiter(void 0, void 0, void 0, fun
|
|
|
54
54
|
return (0, shell_1.spawn)(spawnCommand, opts, {
|
|
55
55
|
cwd: targetSource === null || targetSource === void 0 ? void 0 : targetSource.replace(projectRoot, (0, path_1.join)(projectRoot, constants_1.FOLDERNAME.build)),
|
|
56
56
|
stdio: 'pipe',
|
|
57
|
-
env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_CODE_LOCATION: targetDir + path_1.sep, X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, details.target.env_var)
|
|
57
|
+
env: Object.assign({ X_ZOHO_CATALYST_IS_LOCAL: 'true', X_ZOHO_CATALYST_FUNCTION_LOADED: 'true', X_ZOHO_CATALYST_CODE_LOCATION: targetDir + path_1.sep, X_ZOHO_CATALYST_ACCOUNTS_URL: constants_1.ORIGIN.auth, X_ZOHO_CATALYST_CONSOLE_URL: constants_1.ORIGIN.admin, X_ZOHO_CATALYST_RESOURCE_ID: (_f = details.target) === null || _f === void 0 ? void 0 : _f.id, X_ZOHO_STRATUS_RESOURCE_SUFFIX: constants_1.ORIGIN.stratusSuffix, CATALYST_PORTAL_DOMAIN: constants_1.ORIGIN.iamPortal, CATALYST_PROJECT_TIMEZONE: (0, project_1.getProjectTimezone)(Intl.DateTimeFormat().resolvedOptions().timeZone) }, details.target.env_var)
|
|
58
58
|
}).RAW();
|
|
59
59
|
});
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.addAppSailRoutes = void 0;
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
function addAppSailRoutes(app, details, proxy, unknownProxy) {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
app.use('/__catalyst/sdk/init.js', (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const initJs = yield (0, utils_1.appsailInitJs)();
|
|
18
|
+
const _write = res.write;
|
|
19
|
+
res.write = () => {
|
|
20
|
+
res.setHeader('Content-Length', initJs.length);
|
|
21
|
+
return _write.call(res, initJs, 'utf-8');
|
|
22
|
+
};
|
|
23
|
+
req.url = req.originalUrl;
|
|
24
|
+
unknownProxy(req, res);
|
|
25
|
+
}));
|
|
26
|
+
app.use('/__catalyst', (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
req.url = req.originalUrl;
|
|
28
|
+
unknownProxy(req, res);
|
|
29
|
+
}));
|
|
30
|
+
((_b = (_a = details.target) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.catalyst_auth) === true &&
|
|
31
|
+
app.use(['/accounts', '/oauthorize'], (req, res) => {
|
|
32
|
+
if (req.url.includes('/appsail/logout_redirect')) {
|
|
33
|
+
res.redirect(typeof req.query.service_url === 'string' ? req.query.service_url : '/');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
req.url = req.originalUrl;
|
|
37
|
+
unknownProxy(req, res);
|
|
38
|
+
});
|
|
39
|
+
app.use('/', (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
var _c, _d;
|
|
41
|
+
if (req.header('catalyst-component') === 'true') {
|
|
42
|
+
((_d = (_c = details.target) === null || _c === void 0 ? void 0 : _c.config) === null || _d === void 0 ? void 0 : _d.catalyst_auth) === true
|
|
43
|
+
? unknownProxy(req, res)
|
|
44
|
+
: res.sendStatus(400);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
proxy.web(req, res, {
|
|
48
|
+
target: `http://127.0.0.1:${details.target.port.appsail}`,
|
|
49
|
+
ws: true
|
|
50
|
+
});
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
exports.addAppSailRoutes = addAppSailRoutes;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addFnRoutes = void 0;
|
|
4
|
+
const constants_1 = require("../../../../util_modules/constants");
|
|
5
|
+
function addFnRoutes(app, details, proxy) {
|
|
6
|
+
const fnTarget = details.target;
|
|
7
|
+
app.use(`/server/${fnTarget.name}`, (req, res) => {
|
|
8
|
+
proxy.web(req, res, {
|
|
9
|
+
target: `http://127.0.0.1:${details.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic ? `/server/${fnTarget.name}/execute` : ''}`,
|
|
10
|
+
ws: true
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
app.use(`/baas/v1/project/:projectId/function/${fnTarget.name}`, (req, res) => {
|
|
14
|
+
proxy.web(req, res, {
|
|
15
|
+
target: `http://127.0.0.1:${details.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic ? `/server/${fnTarget.name}/execute` : ''}`,
|
|
16
|
+
ws: true
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
if (fnTarget.id) {
|
|
20
|
+
app.use(`/server/${fnTarget.id}`, (req, res) => {
|
|
21
|
+
proxy.web(req, res, {
|
|
22
|
+
target: `http://127.0.0.1:${details.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic ? `/server/${fnTarget.id}/execute` : ''}`,
|
|
23
|
+
ws: true
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
app.use(`/baas/v1/project/:projectId/function/${fnTarget.id}`, (req, res) => {
|
|
27
|
+
proxy.web(req, res, {
|
|
28
|
+
target: `http://127.0.0.1:${details.httpPort}${fnTarget.type === constants_1.FN_TYPE.basic ? `/server/${fnTarget.id}/execute` : ''}`,
|
|
29
|
+
ws: true
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.addFnRoutes = addFnRoutes;
|
|
@@ -0,0 +1,155 @@
|
|
|
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 error_1 = __importDefault(require("../../../../error"));
|
|
17
|
+
const apig_matcher_1 = __importDefault(require("../../../../express_middlewares/apig-matcher"));
|
|
18
|
+
const auth_checker_1 = __importDefault(require("../../../../express_middlewares/auth-checker"));
|
|
19
|
+
const authenticator_1 = __importDefault(require("../../../../express_middlewares/authenticator"));
|
|
20
|
+
const cookie_parser_1 = __importDefault(require("../../../../express_middlewares/cookie-parser"));
|
|
21
|
+
const error_handler_1 = __importDefault(require("../../../../express_middlewares/error-handler"));
|
|
22
|
+
const logger_1 = __importDefault(require("../../../../express_middlewares/logger"));
|
|
23
|
+
const project_1 = __importDefault(require("../../../../express_middlewares/project"));
|
|
24
|
+
const unknown_req_proxy_1 = __importDefault(require("./unknown-req-proxy"));
|
|
25
|
+
const url_rewriter_1 = __importDefault(require("../../../../express_middlewares/url-rewriter"));
|
|
26
|
+
const runtime_store_1 = __importDefault(require("../../../../runtime-store"));
|
|
27
|
+
const constants_1 = require("../../../../util_modules/constants");
|
|
28
|
+
const js_1 = require("../../../../util_modules/js");
|
|
29
|
+
const logger_2 = require("../../../../util_modules/logger");
|
|
30
|
+
const project_2 = require("../../../../util_modules/project");
|
|
31
|
+
const option_1 = require("../../../../util_modules/option");
|
|
32
|
+
const server_js_1 = require("../../../../util_modules/server.js");
|
|
33
|
+
const utils_1 = require("./utils");
|
|
34
|
+
const appsail_1 = require("./appsail");
|
|
35
|
+
const web_client_1 = require("./web-client");
|
|
36
|
+
const functions_1 = require("./functions");
|
|
37
|
+
function spinUpMaster(listenPort, { otherServerDetails, appSailDetails }) {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
if ((otherServerDetails && appSailDetails) || (!otherServerDetails && !appSailDetails)) {
|
|
41
|
+
throw new error_1.default('Either functions/client or AppSail is need to start the master server. But both cannot use the same master', { exit: 2 });
|
|
42
|
+
}
|
|
43
|
+
const projectDetails = {
|
|
44
|
+
id: (0, project_2.getProjectId)(),
|
|
45
|
+
domain_prefix: (0, project_2.getDomainPrefix)(),
|
|
46
|
+
domain: constants_1.ORIGIN.app.replace('https://', ''),
|
|
47
|
+
key: (0, project_2.getDomainKey)(),
|
|
48
|
+
env_name: (0, project_2.getEnvName)()
|
|
49
|
+
};
|
|
50
|
+
const rules = runtime_store_1.default.get('context.apig.local.config', -1);
|
|
51
|
+
const customProxyUrl = (0, option_1.getOptionValue)('proxy');
|
|
52
|
+
const app = (0, express_1.default)();
|
|
53
|
+
let systemRoutes;
|
|
54
|
+
const nonApigURL = ['/accounts', '/clientoauth', '/_wms', '/wmssrv'];
|
|
55
|
+
app.use((0, logger_1.default)(appSailDetails));
|
|
56
|
+
app.use(cookie_parser_1.default);
|
|
57
|
+
app.use((0, project_1.default)(projectDetails));
|
|
58
|
+
app.use(authenticator_1.default);
|
|
59
|
+
!appSailDetails &&
|
|
60
|
+
app.use(nonApigURL, (req, res) => {
|
|
61
|
+
req.url = req.originalUrl;
|
|
62
|
+
unknownProxy(req, res);
|
|
63
|
+
});
|
|
64
|
+
!appSailDetails &&
|
|
65
|
+
app.use('*/.catalyst%2Freload-script.js', (req, res) => {
|
|
66
|
+
var _a;
|
|
67
|
+
req.url = '/.catalyst%2Freload-script.js';
|
|
68
|
+
(_a = otherServerDetails === null || otherServerDetails === void 0 ? void 0 : otherServerDetails.client) === null || _a === void 0 ? void 0 : _a.forEach((clientDetails) => {
|
|
69
|
+
const appTarget = `http://127.0.0.1:${clientDetails.httpPort}/app/`;
|
|
70
|
+
proxy.web(req, res, {
|
|
71
|
+
target: appTarget,
|
|
72
|
+
changeOrigin: true
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
if (rules !== -1 && !appSailDetails) {
|
|
77
|
+
for (const [sourceURL, methodByConfig] of Object.entries(rules)) {
|
|
78
|
+
const router = app.route(sourceURL);
|
|
79
|
+
for (const [method, config] of Object.entries(methodByConfig)) {
|
|
80
|
+
if (config.system) {
|
|
81
|
+
if (systemRoutes === undefined) {
|
|
82
|
+
systemRoutes = {};
|
|
83
|
+
}
|
|
84
|
+
js_1.JS.set(systemRoutes, [sourceURL, method], config);
|
|
85
|
+
}
|
|
86
|
+
router[method]((req, res, next) => {
|
|
87
|
+
if (res.locals.apigRules === undefined) {
|
|
88
|
+
res.locals.apigRules = [];
|
|
89
|
+
}
|
|
90
|
+
res.locals.apigRules.push(Object.assign({ source_endpoint: sourceURL, params: req.params }, config));
|
|
91
|
+
next();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
app.use('/', apig_matcher_1.default, auth_checker_1.default, url_rewriter_1.default);
|
|
96
|
+
}
|
|
97
|
+
const proxy = (0, utils_1.createProxyServer)(listenPort);
|
|
98
|
+
appSailDetails && ((_b = (_a = appSailDetails.target) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.catalyst_auth) === true
|
|
99
|
+
? proxy.on('proxyRes', (0, utils_1.proxyResponseHandler)({
|
|
100
|
+
signInRedirect: appSailDetails.target.config.login_redirect || '/'
|
|
101
|
+
}))
|
|
102
|
+
: proxy.on('proxyRes', (0, utils_1.proxyResponseHandler)({ systemRoutes }));
|
|
103
|
+
const proxyDestroyer = new server_js_1.ConnectionDestroyer(proxy);
|
|
104
|
+
const unknownProxy = (0, unknown_req_proxy_1.default)(proxy, listenPort, customProxyUrl);
|
|
105
|
+
otherServerDetails &&
|
|
106
|
+
Object.keys(otherServerDetails).forEach((targ) => {
|
|
107
|
+
var _a, _b, _c;
|
|
108
|
+
switch (targ) {
|
|
109
|
+
case 'client': {
|
|
110
|
+
(_a = otherServerDetails.client) === null || _a === void 0 ? void 0 : _a.forEach((clientDetails) => (0, web_client_1.addWebClientRoutes)(app, clientDetails, proxy, unknownProxy));
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
case 'server': {
|
|
114
|
+
(_b = otherServerDetails.server) === null || _b === void 0 ? void 0 : _b.forEach((serverDetail) => {
|
|
115
|
+
var _a;
|
|
116
|
+
app.use('/server/' + ((_a = serverDetail.target) === null || _a === void 0 ? void 0 : _a.name), (req, res) => {
|
|
117
|
+
proxy.web(req, res, {
|
|
118
|
+
target: `http://127.0.0.1:${serverDetail.httpPort}`
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
case 'functions': {
|
|
125
|
+
(_c = otherServerDetails.functions) === null || _c === void 0 ? void 0 : _c.forEach((fnDetails) => (0, functions_1.addFnRoutes)(app, fnDetails, proxy));
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
default:
|
|
129
|
+
throw new error_1.default('Unknown type provided to master server ' + targ, {
|
|
130
|
+
exit: 2
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
appSailDetails && (0, appsail_1.addAppSailRoutes)(app, appSailDetails, proxy, unknownProxy);
|
|
135
|
+
app.use('/', (0, unknown_req_proxy_1.default)(proxy, listenPort, customProxyUrl));
|
|
136
|
+
app.use(error_handler_1.default);
|
|
137
|
+
const expressServer = app.listen(listenPort, '127.0.0.1').on('error', (err) => {
|
|
138
|
+
if (proxy) {
|
|
139
|
+
proxyDestroyer.destroy();
|
|
140
|
+
}
|
|
141
|
+
console.error(err);
|
|
142
|
+
});
|
|
143
|
+
const expressDestroyer = new server_js_1.ConnectionDestroyer(expressServer);
|
|
144
|
+
expressServer.maxConnections = 100;
|
|
145
|
+
process.on('SIGINT', () => expressDestroyer.destroy(false));
|
|
146
|
+
expressServer.on('close', () => __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
yield proxyDestroyer.destroy().catch((err) => (0, logger_2.debug)(err));
|
|
148
|
+
}));
|
|
149
|
+
expressServer.on('upgrade', (...upgradeParam) => {
|
|
150
|
+
app.emit('upgrade', ...upgradeParam);
|
|
151
|
+
});
|
|
152
|
+
return expressServer;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
exports.default = spinUpMaster;
|
package/lib/{express_middlewares/unknownReqProxy.js → serve/server/lib/master/unknown-req-proxy.js}
RENAMED
|
@@ -3,13 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const runtime_store_1 = __importDefault(require("
|
|
7
|
-
const logger_1 = require("
|
|
8
|
-
exports.default = (proxyInstance, customProxyUrl) => (req, res) => {
|
|
6
|
+
const runtime_store_1 = __importDefault(require("../../../../runtime-store"));
|
|
7
|
+
const logger_1 = require("../../../../util_modules/logger");
|
|
8
|
+
exports.default = (proxyInstance, masterPort, customProxyUrl) => (req, res) => {
|
|
9
9
|
if (req.url.length === 1 && req.url.startsWith('/')) {
|
|
10
10
|
res.redirect('/app/');
|
|
11
11
|
}
|
|
12
|
-
else if (req.url.
|
|
12
|
+
else if (req.url.startsWith('/accounts') && req.url.endsWith('clientidprequest')) {
|
|
13
13
|
res.redirect(308, `https://${req.headers['x-zc-project-domain']}${req.url}`);
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
@@ -30,20 +30,20 @@ exports.default = (proxyInstance, customProxyUrl) => (req, res) => {
|
|
|
30
30
|
}
|
|
31
31
|
else {
|
|
32
32
|
const headers = {};
|
|
33
|
-
if (req.url.
|
|
33
|
+
if (req.url.startsWith('/accounts') && req.url.endsWith('captcha')) {
|
|
34
34
|
headers['origin'] = `https://${req.headers['x-zc-project-domain']}`;
|
|
35
35
|
}
|
|
36
36
|
if (req.url.includes('/__catalyst/auth/')) {
|
|
37
|
-
|
|
38
|
-
headers['catalyst-redirect-domain'] = `http://localhost:${masterPort}`;
|
|
37
|
+
headers['catalyst-redirect-domain'] = `http://localhost:${masterPort || 3000}`;
|
|
39
38
|
}
|
|
40
39
|
proxyInstance.web(req, res, {
|
|
41
40
|
target: `https://${req.headers['x-zc-project-domain']}`,
|
|
42
41
|
changeOrigin: true,
|
|
42
|
+
cookieDomainRewrite: {
|
|
43
|
+
[req.headers['x-zc-project-domain'] + '']: 'localhost'
|
|
44
|
+
},
|
|
43
45
|
ws: true,
|
|
44
46
|
headers
|
|
45
|
-
}, (err) => {
|
|
46
|
-
(0, logger_1.debug)('Unknown proxy error: ', err);
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
};
|