zcatalyst-cli 1.16.0 → 1.16.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.
- package/lib/authentication/login.js +12 -6
- package/lib/command_needs/auth.js +2 -2
- package/lib/command_needs/rc.js +7 -2
- package/lib/commands/iac/import.js +1 -1
- package/lib/commands/serve.js +1 -1
- package/lib/express_middlewares/unknownReqProxy.js +4 -0
- package/lib/internal/credential.js +7 -0
- package/lib/serve/server/lib/master.js +10 -4
- package/lib/serve/server/lib/node/server/index.js +1 -1
- package/lib/serve/server/lib/web_client/server.js +1 -1
- package/lib/shell/dependencies/http-functions.js +1 -1
- package/lib/util_modules/constants/lib/plugin.js +1 -1
- package/lib/util_modules/constants/lib/scopes.js +3 -1
- package/package.json +4 -4
|
@@ -31,9 +31,10 @@ const fs_1 = require("../util_modules/fs");
|
|
|
31
31
|
const js_1 = require("../util_modules/js");
|
|
32
32
|
const logger_1 = require("../util_modules/logger");
|
|
33
33
|
const option_1 = require("../util_modules/option");
|
|
34
|
+
const crypto_1 = require("crypto");
|
|
34
35
|
exports.missingScopes = {
|
|
35
|
-
[constants_1.DC_TYPE.au.value]: ['
|
|
36
|
-
[constants_1.DC_TYPE.eu.value]: ['
|
|
36
|
+
[constants_1.DC_TYPE.au.value]: ['quick_ml'],
|
|
37
|
+
[constants_1.DC_TYPE.eu.value]: ['quick_ml']
|
|
37
38
|
};
|
|
38
39
|
class Login {
|
|
39
40
|
constructor(localhost = true, user = true) {
|
|
@@ -58,7 +59,7 @@ class Login {
|
|
|
58
59
|
_getCallbackUrl(port) {
|
|
59
60
|
return 'http://localhost:' + port;
|
|
60
61
|
}
|
|
61
|
-
_getLoginUrl(callbackUrl) {
|
|
62
|
+
_getLoginUrl(callbackUrl, state) {
|
|
62
63
|
return (constants_1.ORIGIN.auth +
|
|
63
64
|
'/oauth/v2/auth?' +
|
|
64
65
|
js_1.JS.map({
|
|
@@ -67,7 +68,8 @@ class Login {
|
|
|
67
68
|
response_type: 'code',
|
|
68
69
|
access_type: 'offline',
|
|
69
70
|
prompt: 'consent',
|
|
70
|
-
redirect_uri: callbackUrl
|
|
71
|
+
redirect_uri: callbackUrl,
|
|
72
|
+
state
|
|
71
73
|
}, (v, k) => {
|
|
72
74
|
return k + '=' + encodeURIComponent(v);
|
|
73
75
|
}).join('&'));
|
|
@@ -281,7 +283,8 @@ class Login {
|
|
|
281
283
|
var _a;
|
|
282
284
|
const dcRef = (_a = (0, dc_1.getActiveDCType)()) === null || _a === void 0 ? void 0 : _a.ref;
|
|
283
285
|
const callbackUrl = this._getCallbackUrl(port);
|
|
284
|
-
const
|
|
286
|
+
const nonce = encodeURIComponent((0, crypto_1.randomBytes)(16).toString());
|
|
287
|
+
const authUrl = this._getLoginUrl(callbackUrl, nonce);
|
|
285
288
|
let reqCount = 0;
|
|
286
289
|
const server = (0, http_1.createServer)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
287
290
|
try {
|
|
@@ -296,6 +299,9 @@ class Login {
|
|
|
296
299
|
reqCount += 1;
|
|
297
300
|
const queryParamsObj = new url_1.URL(req.url, `http://${req.headers.host}`)
|
|
298
301
|
.searchParams;
|
|
302
|
+
if (queryParamsObj.get('state') !== nonce) {
|
|
303
|
+
throw new error_1.default('Invalid state param received.', { exit: 2 });
|
|
304
|
+
}
|
|
299
305
|
const code = queryParamsObj !== undefined && queryParamsObj.get('code');
|
|
300
306
|
const _location = queryParamsObj !== undefined && queryParamsObj.get('location');
|
|
301
307
|
const location = _location === 'dev' ? 'us' : _location;
|
|
@@ -348,7 +354,7 @@ class Login {
|
|
|
348
354
|
}
|
|
349
355
|
}));
|
|
350
356
|
const destroyer = new server_js_1.ConnectionDestroyer(server);
|
|
351
|
-
server.listen(port, () => {
|
|
357
|
+
server.listen(port, '127.0.0.1', () => {
|
|
352
358
|
(0, logger_1.info)();
|
|
353
359
|
(0, logger_1.info)('Visit this URL on this device to log in:');
|
|
354
360
|
(0, logger_1.info)(ansi_colors_1.bold.underline(authUrl));
|
|
@@ -53,6 +53,6 @@ exports.default = (inScopes = []) => {
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
runtime_store_1.default.set('auth_scopes', requiredScopes);
|
|
56
|
-
runtime_store_1.default.set('user', config_store_1.default.get(`${activeDC}.user
|
|
57
|
-
runtime_store_1.default.set('credential', credential_1.default.
|
|
56
|
+
runtime_store_1.default.set('user', config_store_1.default.get(`${activeDC}.user`));
|
|
57
|
+
runtime_store_1.default.set('credential', credential_1.default.initToken(tokenObj.token, tokenObj.temp));
|
|
58
58
|
};
|
package/lib/command_needs/rc.js
CHANGED
|
@@ -26,9 +26,14 @@ const option_1 = require("../util_modules/option");
|
|
|
26
26
|
const project_2 = require("../util_modules/project");
|
|
27
27
|
const config_store_1 = __importDefault(require("../config-store"));
|
|
28
28
|
const dc_1 = require("../dc");
|
|
29
|
+
const env_1 = require("../util_modules/env");
|
|
29
30
|
exports.default = ({ optional = false, resolveOnNotFound = false, skipOrgCheck = true } = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
-
const
|
|
31
|
-
const
|
|
31
|
+
const globOrgOpt = (0, option_1.getGlobalOptionValue)('org', null);
|
|
32
|
+
const orgOpt = globOrgOpt ? globOrgOpt : (0, env_1.getEnvVariable)('CATALYST_ORG', null);
|
|
33
|
+
const globProjectOpt = (0, option_1.getGlobalOptionValue)('project', null);
|
|
34
|
+
const projectOpt = globProjectOpt
|
|
35
|
+
? globProjectOpt
|
|
36
|
+
: (0, env_1.getEnvVariable)('CATALYST_PROJECT', null);
|
|
32
37
|
if (projectOpt !== null && orgOpt === null) {
|
|
33
38
|
throw new error_1.default('Org option is needed when project option is supplied', {
|
|
34
39
|
exit: 2
|
|
@@ -106,7 +106,7 @@ const ensureUserAction = (deployRes) => __awaiter(void 0, void 0, void 0, functi
|
|
|
106
106
|
}
|
|
107
107
|
}));
|
|
108
108
|
const destroyer = new server_js_1.ConnectionDestroyer(server);
|
|
109
|
-
server.listen(callbackPort, () => {
|
|
109
|
+
server.listen(callbackPort, '127.0.0.1', () => {
|
|
110
110
|
const urlString = accessUrl.toString();
|
|
111
111
|
(0, logger_1.info)();
|
|
112
112
|
(0, logger_1.info)('Visit this URL on this device to proceed:');
|
package/lib/commands/serve.js
CHANGED
|
@@ -49,7 +49,7 @@ exports.default = new command_1.default('serve')
|
|
|
49
49
|
.option('--except <targets>', 'serve all targets except specified (e.g. "client")')
|
|
50
50
|
.option('--ignore-scripts', 'ignore the pre and post lifescycle scripts')
|
|
51
51
|
.option('--no-open', 'disable opening the client automatically when served')
|
|
52
|
-
.needs('auth', [constants_1.SCOPE.functions, constants_1.SCOPE.functions_execution, constants_1.SCOPE.webapp])
|
|
52
|
+
.needs('auth', [constants_1.SCOPE.functions, constants_1.SCOPE.functions_execution, constants_1.SCOPE.webapp, constants_1.SCOPE.pdf_shot])
|
|
53
53
|
.needs('config')
|
|
54
54
|
.needs('rc')
|
|
55
55
|
.action(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -9,6 +9,10 @@ exports.default = (proxyInstance, 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.match(/accounts\/p\/[0-9]+\/clientidprequest/g)) {
|
|
13
|
+
res.redirect(308, `https://${req.headers['x-zc-project-domain']}${req.url}`);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
12
16
|
else if (typeof customProxyUrl === 'string' &&
|
|
13
17
|
!req.url.match(/^(\/baas|\/app|\/server|\/oauthorize|\/__catalyst).*/g)) {
|
|
14
18
|
(0, logger_1.debug)(`proxying "${req.url}" to "${customProxyUrl}"`);
|
|
@@ -182,6 +182,13 @@ class Credential {
|
|
|
182
182
|
get createdTime() {
|
|
183
183
|
return this.cTime;
|
|
184
184
|
}
|
|
185
|
+
static initToken(token, temp = false) {
|
|
186
|
+
if (token.slice(1, 2) !== '_' && !Credential.crypt.isEncrypted(token)) {
|
|
187
|
+
Credential.oneTimeToken = token;
|
|
188
|
+
return Credential.oneTimeToken;
|
|
189
|
+
}
|
|
190
|
+
return this.init(token, temp);
|
|
191
|
+
}
|
|
185
192
|
static init(token, temp = false) {
|
|
186
193
|
let tokenObj;
|
|
187
194
|
if (typeof token === 'string') {
|
|
@@ -116,6 +116,7 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
116
116
|
});
|
|
117
117
|
app.use('*/.catalyst%2Freload-script.js', (req, res) => {
|
|
118
118
|
var _a;
|
|
119
|
+
req.url = '/.catalyst%2Freload-script.js';
|
|
119
120
|
(_a = otherServerDetails.client) === null || _a === void 0 ? void 0 : _a.forEach((clientDetails) => {
|
|
120
121
|
const appTarget = `http://127.0.0.1:${clientDetails.httpPort}/app/`;
|
|
121
122
|
proxy.web(req, res, {
|
|
@@ -150,6 +151,9 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
150
151
|
protocolRewrite: 'http'
|
|
151
152
|
})
|
|
152
153
|
.on('error', (err, req, res) => {
|
|
154
|
+
if (res.writableEnded) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
153
157
|
if (res instanceof http_1.ServerResponse) {
|
|
154
158
|
res.writeHead(502, { 'Content-Type': 'json' });
|
|
155
159
|
}
|
|
@@ -159,6 +163,9 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
159
163
|
console.error(err);
|
|
160
164
|
})
|
|
161
165
|
.on('econnreset', (err, req, res, targetUrl) => {
|
|
166
|
+
if (res.writableEnded) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
162
169
|
if (res instanceof http_1.ServerResponse) {
|
|
163
170
|
res.writeHead(502, { 'Content-Type': 'json' });
|
|
164
171
|
}
|
|
@@ -266,9 +273,8 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
266
273
|
case 'appSail': {
|
|
267
274
|
(_d = otherServerDetails.appSail) === null || _d === void 0 ? void 0 : _d.forEach((appSailDetails) => {
|
|
268
275
|
app.use('/', (req, res) => {
|
|
269
|
-
var _a
|
|
270
|
-
if ((
|
|
271
|
-
req.url = (_c = appSailDetails.target) === null || _c === void 0 ? void 0 : _c.url;
|
|
276
|
+
var _a;
|
|
277
|
+
if ((_a = req.url) === null || _a === void 0 ? void 0 : _a.includes('/__catalyst/sdk/init.js')) {
|
|
272
278
|
(0, unknownReqProxy_1.default)(proxy, customProxyUrl)(req, res);
|
|
273
279
|
}
|
|
274
280
|
else {
|
|
@@ -290,7 +296,7 @@ function spinUpMaster(listenPort, otherServerDetails) {
|
|
|
290
296
|
});
|
|
291
297
|
app.use('/', (0, unknownReqProxy_1.default)(proxy, customProxyUrl));
|
|
292
298
|
app.use(error_handler_1.default);
|
|
293
|
-
const expressServer = app.listen(listenPort).on('error', (err) => {
|
|
299
|
+
const expressServer = app.listen(listenPort, '127.0.0.1').on('error', (err) => {
|
|
294
300
|
if (proxy) {
|
|
295
301
|
proxyDestroyer.destroy();
|
|
296
302
|
}
|
|
@@ -69,7 +69,7 @@ const browserLogicHandler = async (req, res) => {
|
|
|
69
69
|
|
|
70
70
|
const server = createServer(type === 'browserlogic' ? browserLogicHandler : aioHandler);
|
|
71
71
|
|
|
72
|
-
server.listen(listenPort).on('error', (err) => {
|
|
72
|
+
server.listen(listenPort, '127.0.0.1').on('error', (err) => {
|
|
73
73
|
// eslint-disable-next-line no-console
|
|
74
74
|
console.error(err);
|
|
75
75
|
});
|
|
@@ -174,7 +174,7 @@ function webClientServer(httpPort, source, { homepage = 'index.html', enableWatc
|
|
|
174
174
|
res.send('Error fetching the resource');
|
|
175
175
|
});
|
|
176
176
|
}));
|
|
177
|
-
const server = app.listen(httpPort).on('error', (err) => {
|
|
177
|
+
const server = app.listen(httpPort, '127.0.0.1').on('error', (err) => {
|
|
178
178
|
eventListener.emit('error', err);
|
|
179
179
|
});
|
|
180
180
|
const expressDestroyer = new server_js_1.ConnectionDestroyer(server);
|
|
@@ -326,7 +326,7 @@ class HttpFunctions {
|
|
|
326
326
|
}
|
|
327
327
|
});
|
|
328
328
|
return new Promise((res) => {
|
|
329
|
-
const server = this.app.listen(httpPort, () => {
|
|
329
|
+
const server = this.app.listen(httpPort, '127.0.0.1', () => {
|
|
330
330
|
this.targets.forEach((target) => {
|
|
331
331
|
var _a, _b;
|
|
332
332
|
(_a = target.watcher) === null || _a === void 0 ? void 0 : _a.on('preparing', () => {
|
|
@@ -47,7 +47,9 @@ exports.default = Object.freeze({
|
|
|
47
47
|
notification_web: 'ZohoCatalyst.notifications.web',
|
|
48
48
|
search_read: 'ZohoCatalyst.search.READ',
|
|
49
49
|
zia: 'ZohoCatalyst.mlkit.READ',
|
|
50
|
-
|
|
50
|
+
quick_ml: 'QuickML.deployment.READ',
|
|
51
|
+
pdf_shot: 'ZohoCatalyst.pdfshot.execute',
|
|
52
|
+
dataverse: 'ZohoCatalyst.dataverse.execute',
|
|
51
53
|
circuits_execute: 'ZohoCatalyst.circuits.execute',
|
|
52
54
|
circuits_exe_read: 'ZohoCatalyst.circuits.execution.READ',
|
|
53
55
|
circuits_exe_delete: 'ZohoCatalyst.circuits.execution.DELETE',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zcatalyst-cli",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.2",
|
|
4
4
|
"description": "Command Line Tool for CATALYST",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"functions",
|
|
22
22
|
"zcatalyst"
|
|
23
23
|
],
|
|
24
|
-
"author": "Catalyst (https://
|
|
25
|
-
"homepage": "https://
|
|
24
|
+
"author": "Catalyst (https://catalyst.zoho.com)",
|
|
25
|
+
"homepage": "https://catalyst.zoho.com",
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"ansi-colors": "^4.1.1",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"ws": "^8.5.0",
|
|
58
58
|
"xml2js": "^0.4.23",
|
|
59
59
|
"yaml": "^2.0.1",
|
|
60
|
-
"zcatalyst-angular-schematics": "^
|
|
60
|
+
"zcatalyst-angular-schematics": "^1.0.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/app-module-path": "^2.2.0",
|