zcatalyst-cli 1.26.2 → 1.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/lib/authentication/credential.d.ts +2 -1
- package/lib/authentication/credential.js +20 -3
- package/lib/authentication/crypt.d.ts +7 -3
- package/lib/authentication/crypt.js +87 -16
- package/lib/authentication/index.js +1 -0
- package/lib/authentication/key-manager.d.ts +7 -0
- package/lib/authentication/key-manager.js +62 -0
- package/lib/authentication/login.js +20 -20
- package/lib/bin/catalyst.js +1 -15
- package/lib/client.d.ts +3 -1
- package/lib/client.js +16 -5
- package/lib/command_needs/rc.js +13 -3
- package/lib/commands/appsail/add.js +10 -0
- package/lib/commands/client/delete.js +18 -6
- package/lib/commands/client/setup.js +7 -0
- package/lib/commands/deploy/index.js +3 -3
- package/lib/commands/deploy/slate.js +65 -4
- package/lib/commands/functions/add.js +7 -0
- package/lib/commands/functions/delete.js +22 -4
- package/lib/commands/functions/execute.js +39 -71
- package/lib/commands/functions/setup.js +13 -0
- package/lib/commands/functions/shell.js +15 -1
- package/lib/commands/iac/import.js +2 -2
- package/lib/commands/init.js +34 -20
- package/lib/commands/login.js +1 -0
- package/lib/commands/pull.js +22 -1
- package/lib/commands/serve.js +2 -1
- package/lib/commands/slate/create.js +7 -4
- package/lib/commands/slate/link.js +11 -5
- package/lib/commands/slate/unlink.js +7 -0
- package/lib/commands/zest/generate/index.js +28 -35
- package/lib/deploy/features/slate.d.ts +3 -1
- package/lib/deploy/features/slate.js +204 -5
- package/lib/docs/client-utils.toml +0 -5
- package/lib/docs/command_needs/rc.toml +9 -1
- package/lib/docs/commands/client/delete.toml +4 -0
- package/lib/docs/commands/deploy/slate.toml +3 -0
- package/lib/docs/commands/functions/delete.toml +10 -0
- package/lib/docs/commands/functions/execute.toml +1 -16
- package/lib/docs/commands/functions/setup.toml +3 -0
- package/lib/docs/commands/functions/shell.toml +8 -0
- package/lib/docs/commands/init.toml +3 -0
- package/lib/docs/commands/pull.toml +6 -0
- package/lib/docs/commands/slate/unlink.toml +6 -0
- package/lib/docs/execute/command-utils.toml +14 -0
- package/lib/docs/execute/execute-input-resolver.toml +37 -0
- package/lib/docs/init/features/project.toml +20 -0
- package/lib/docs/init/util/client.toml +4 -0
- package/lib/docs/prompt/index.toml +15 -0
- package/lib/docs/pull/features/apig.toml +6 -0
- package/lib/docs/pull/features/client.toml +20 -0
- package/lib/docs/pull/features/functions/index.toml +24 -0
- package/lib/endpoints/lib/slate.d.ts +14 -1
- package/lib/endpoints/lib/slate.js +35 -0
- package/lib/error/context-help.js +1 -1
- package/lib/error/index.js +9 -13
- package/lib/execute/command-utils.d.ts +5 -0
- package/lib/execute/command-utils.js +86 -0
- package/lib/execute/execute-input-resolver.d.ts +29 -0
- package/lib/execute/execute-input-resolver.js +207 -0
- package/lib/execute/index.d.ts +4 -1
- package/lib/execute/index.js +3 -2
- package/lib/fn-utils/lib/integ.js +22 -17
- package/lib/index.js +1 -0
- package/lib/init/dependencies/package-json.js +11 -7
- package/lib/init/features/appsail/index.js +75 -26
- package/lib/init/features/appsail/prompt-fields.d.ts +43 -0
- package/lib/init/features/appsail/prompt-fields.js +55 -0
- package/lib/init/features/appsail/utils/custom-runtime.d.ts +3 -0
- package/lib/init/features/appsail/utils/custom-runtime.js +161 -0
- package/lib/init/features/appsail/{utils.d.ts → utils/index.d.ts} +2 -2
- package/lib/init/features/appsail/utils/index.js +170 -0
- package/lib/init/features/client/index.js +4 -3
- package/lib/init/features/client/initializers/angular.js +3 -2
- package/lib/init/features/client/initializers/react.js +4 -3
- package/lib/init/features/client/prompt-fields.d.ts +37 -0
- package/lib/init/features/client/prompt-fields.js +48 -0
- package/lib/init/features/functions/index.js +37 -8
- package/lib/init/features/functions/languages/java.js +42 -7
- package/lib/init/features/functions/languages/node.js +42 -10
- package/lib/init/features/functions/languages/python.js +42 -7
- package/lib/init/features/functions/prompt-fields.d.ts +25 -0
- package/lib/init/features/functions/prompt-fields.js +34 -0
- package/lib/init/features/project.js +41 -6
- package/lib/init/features/slate/index.js +2 -0
- package/lib/init/features/slate/prompt-fields.d.ts +31 -0
- package/lib/init/features/slate/prompt-fields.js +41 -0
- package/lib/init/index.js +2 -1
- package/lib/init/util/client.js +11 -8
- package/lib/init/util/common.d.ts +2 -0
- package/lib/init/util/common.js +33 -3
- package/lib/init/util/prompt-fields.d.ts +7 -0
- package/lib/init/util/prompt-fields.js +13 -0
- package/lib/internal/command.d.ts +3 -0
- package/lib/internal/command.js +26 -3
- package/lib/migration/global/1.27.0.d.ts +2 -0
- package/lib/migration/global/1.27.0.js +39 -0
- package/lib/prompt/choice.d.ts +2 -0
- package/lib/prompt/choice.js +24 -0
- package/lib/prompt/cli-option-key.d.ts +1 -0
- package/lib/prompt/cli-option-key.js +10 -0
- package/lib/prompt/index.d.ts +6 -22
- package/lib/prompt/index.js +264 -67
- package/lib/prompt/overwrite-prompt.d.ts +11 -0
- package/lib/prompt/overwrite-prompt.js +16 -0
- package/lib/prompt/question-factory.d.ts +34 -0
- package/lib/prompt/question-factory.js +41 -0
- package/lib/prompt/register-fields.d.ts +24 -0
- package/lib/prompt/register-fields.js +37 -0
- package/lib/pull/features/apig.js +57 -6
- package/lib/pull/features/client.js +107 -24
- package/lib/pull/features/functions/index.js +100 -4
- package/lib/pull/index.js +1 -1
- package/lib/pull/utils.d.ts +13 -0
- package/lib/pull/utils.js +20 -0
- package/lib/repl-server.d.ts +4 -0
- package/lib/repl-server.js +9 -0
- package/lib/serve/server/lib/master/index.js +3 -3
- package/lib/serve/server/lib/slate/static-server.js +2 -2
- package/lib/serve/server/lib/web_client/server.js +2 -2
- package/lib/shell/format-functions.d.ts +4 -0
- package/lib/shell/format-functions.js +59 -0
- package/lib/shell/index.js +18 -0
- package/lib/util_modules/config/lib/appsail.d.ts +3 -2
- package/lib/util_modules/config/lib/appsail.js +6 -3
- package/lib/util_modules/config/lib/slate.d.ts +19 -0
- package/lib/util_modules/config-store.d.ts +1 -0
- package/lib/util_modules/config-store.js +29 -10
- package/lib/util_modules/constants/index.d.ts +0 -1
- package/lib/util_modules/constants/index.js +1 -3
- package/lib/util_modules/constants/lib/urls.d.ts +2 -0
- package/lib/util_modules/constants/lib/urls.js +4 -0
- package/lib/util_modules/dc.d.ts +6 -1
- package/lib/util_modules/dc.js +21 -8
- package/lib/util_modules/env.d.ts +3 -0
- package/lib/util_modules/env.js +41 -0
- package/lib/util_modules/fs/lib/sync.d.ts +1 -0
- package/lib/util_modules/fs/lib/sync.js +19 -0
- package/lib/util_modules/logger/utils.d.ts +1 -0
- package/lib/util_modules/logger/utils.js +5 -1
- package/lib/util_modules/option.d.ts +1 -0
- package/lib/util_modules/option.js +8 -0
- package/lib/util_modules/{server.js → server/index.js} +3 -3
- package/lib/util_modules/server/needed-scopes.d.ts +1 -0
- package/lib/util_modules/{constants/lib → server}/needed-scopes.js +7 -7
- package/package.json +3 -2
- package/lib/init/features/appsail/utils.js +0 -273
- package/lib/util_modules/constants/lib/needed-scopes.d.ts +0 -4
- /package/lib/docs/{dc.toml → util_modules/dc.toml} +0 -0
- /package/lib/util_modules/{server.d.ts → server/index.d.ts} +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[E_NON_INTERACTIVE_FNS_PULL-1]
|
|
2
|
+
context = '''In Non-Interactive mode the functions to pull must be specified using the ${arg[0]} option.'''
|
|
3
|
+
aid = '''Use the ${arg[0]} option to specify the functions to pull in non-interactive mode.
|
|
4
|
+
|
|
5
|
+
For example: ${arg[1]}
|
|
6
|
+
|
|
7
|
+
Available functions to pull:
|
|
8
|
+
${arg[2]}
|
|
9
|
+
'''
|
|
10
|
+
|
|
11
|
+
[E_NON_INTERACTIVE_FNS_PULL-2]
|
|
12
|
+
context = '''The functions specified in the ${arg[0]} option is not valid.'''
|
|
13
|
+
aid = '''Use the ${arg[1]} option to specify only the valid functions to pull in non-interactive mode.
|
|
14
|
+
|
|
15
|
+
Valid functions to pull:
|
|
16
|
+
${arg[2]}
|
|
17
|
+
'''
|
|
18
|
+
|
|
19
|
+
[E_NON_INTERACTIVE_FNS_PULL-3]
|
|
20
|
+
context = '''Unable to pull as the function with the same name${arg[0]} already exists in the local environment.'''
|
|
21
|
+
aid = '''Use the ${arg[1]} command with the ${arg[2]} option to overwrite the existing function in the local environment.
|
|
22
|
+
|
|
23
|
+
Example: ${arg[3]}
|
|
24
|
+
'''
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { ReadStream } from 'fs-extra';
|
|
2
2
|
import { IAPIOptions } from '../../internal/api';
|
|
3
|
-
import { FrameworkType, ISlateAppInfo } from '../../util_modules/config/lib/slate';
|
|
3
|
+
import { FrameworkType, ISlateAppInfo, ISlateDeploymentInfo, SlateBuildInfo } from '../../util_modules/config/lib/slate';
|
|
4
|
+
export interface ISlateBuildLogRecord {
|
|
5
|
+
_zl_timestamp: number;
|
|
6
|
+
job_id: string;
|
|
7
|
+
message: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ISlateBuildLogsResponse {
|
|
10
|
+
identifier: number;
|
|
11
|
+
records: Array<string>;
|
|
12
|
+
next_token: string;
|
|
13
|
+
}
|
|
4
14
|
declare class Slate {
|
|
5
15
|
opts: IAPIOptions;
|
|
6
16
|
projectId: string;
|
|
@@ -11,5 +21,8 @@ declare class Slate {
|
|
|
11
21
|
getAllApps(): Promise<Array<ISlateAppInfo>>;
|
|
12
22
|
downloadTemplate(): Promise<unknown>;
|
|
13
23
|
deploy(sourceStream: ReadStream, contentLength: number, appName: string, deploymentName?: string, appId?: string, config?: string, msg?: string): Promise<unknown>;
|
|
24
|
+
getBuildStatus(appId: string, deploymentId: string, buildId: string): Promise<SlateBuildInfo>;
|
|
25
|
+
getBuildLogs(appId: string, deploymentId: string, buildId: string, nextToken?: string, limit?: number): Promise<ISlateBuildLogsResponse>;
|
|
26
|
+
getDeployment(appId: string, deploymentId: string): Promise<ISlateDeploymentInfo>;
|
|
14
27
|
}
|
|
15
28
|
export default Slate;
|
|
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const error_1 = __importDefault(require("../../error"));
|
|
16
16
|
const api_1 = __importDefault(require("../../internal/api"));
|
|
17
17
|
const logger_1 = require("../../util_modules/logger");
|
|
18
|
+
const constants_1 = require("../../util_modules/constants");
|
|
18
19
|
class Slate {
|
|
19
20
|
constructor(projectId, opts) {
|
|
20
21
|
this.opts = opts;
|
|
@@ -87,5 +88,39 @@ class Slate {
|
|
|
87
88
|
});
|
|
88
89
|
});
|
|
89
90
|
}
|
|
91
|
+
getBuildStatus(appId, deploymentId, buildId) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
const response = yield new api_1.default(Object.assign({ origin: constants_1.ORIGIN.zgraphql }, this.opts)).get(`/slate/v1/project/${this.projectId}/app/${appId}/deployment/${deploymentId}/build/${buildId}`);
|
|
94
|
+
if (response.body && response.body.data) {
|
|
95
|
+
return response.body.data;
|
|
96
|
+
}
|
|
97
|
+
(0, logger_1.debug)('get build status response from server : ' + response.body);
|
|
98
|
+
throw new error_1.default('Error while fetching build status', { exit: 2 });
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
getBuildLogs(appId_1, deploymentId_1, buildId_1, nextToken_1) {
|
|
102
|
+
return __awaiter(this, arguments, void 0, function* (appId, deploymentId, buildId, nextToken, limit = 50) {
|
|
103
|
+
const qs = { limit };
|
|
104
|
+
if (nextToken) {
|
|
105
|
+
qs.next_token = nextToken;
|
|
106
|
+
}
|
|
107
|
+
const response = yield new api_1.default(Object.assign({ origin: constants_1.ORIGIN.zgraphql }, this.opts)).get(`/slate/v1/project/${this.projectId}/app/${appId}/deployment/${deploymentId}/build/${buildId}/logs`, { qs });
|
|
108
|
+
if (response.body && response.body.data) {
|
|
109
|
+
return response.body.data;
|
|
110
|
+
}
|
|
111
|
+
(0, logger_1.debug)('get build logs response from server : ' + response.body);
|
|
112
|
+
throw new error_1.default('Error while fetching build logs', { exit: 2 });
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
getDeployment(appId, deploymentId) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
const response = yield new api_1.default(Object.assign({ origin: constants_1.ORIGIN.zgraphql }, this.opts)).get(`/slate/v1/project/${this.projectId}/app/${appId}/deployment/${deploymentId}`);
|
|
118
|
+
if (response.body && response.body.data) {
|
|
119
|
+
return response.body.data;
|
|
120
|
+
}
|
|
121
|
+
(0, logger_1.debug)('get deployment response from server : ' + response.body);
|
|
122
|
+
throw new error_1.default('Error while fetching deployment details', { exit: 2 });
|
|
123
|
+
});
|
|
124
|
+
}
|
|
90
125
|
}
|
|
91
126
|
exports.default = Slate;
|
package/lib/error/index.js
CHANGED
|
@@ -17,20 +17,16 @@ class CatalystError extends Error {
|
|
|
17
17
|
this.arg = options.arg;
|
|
18
18
|
this.skipHelp = options.skipHelp || false;
|
|
19
19
|
try {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
throw new CatalystError('Invalid error path', { skipHelp: true });
|
|
27
|
-
}
|
|
28
|
-
options.docPath = options.docPath || DEFAULT_DOC;
|
|
29
|
-
this.filePath = errorPath.replace((0, path_1.dirname)(options.docPath), options.docPath);
|
|
30
|
-
utils_js_1.runtime.set(['context.log', this.filePath], utils_js_1.runtime
|
|
31
|
-
.get(['context.log', this.filePath], [])
|
|
32
|
-
.concat(this));
|
|
20
|
+
const stackArr = ((_a = this.stack) === null || _a === void 0 ? void 0 : _a.split(/\n {4}at /)) || [];
|
|
21
|
+
const errorPath = options.filePath === undefined && stackArr[1] !== undefined
|
|
22
|
+
? stackArr[1].replace(/\.[^.]+$/, '').replace(/^[^(]+\(/, '')
|
|
23
|
+
: (_b = options.filePath) === null || _b === void 0 ? void 0 : _b.replace(/\.[^.]+$/, '');
|
|
24
|
+
if (!errorPath) {
|
|
25
|
+
throw new CatalystError('Invalid error path', { skipHelp: true });
|
|
33
26
|
}
|
|
27
|
+
options.docPath = options.docPath || DEFAULT_DOC;
|
|
28
|
+
this.filePath = errorPath.replace((0, path_1.dirname)(options.docPath), options.docPath);
|
|
29
|
+
utils_js_1.runtime.set(['context.log', this.filePath], utils_js_1.runtime.get(['context.log', this.filePath], []).concat(this));
|
|
34
30
|
}
|
|
35
31
|
catch (e) {
|
|
36
32
|
utils_js_1.runtime.set('context.log.faultyError', utils_js_1.runtime.get('context.log.faultyError', []).concat(this));
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getInputs = getInputs;
|
|
16
|
+
const path_1 = require("path");
|
|
17
|
+
const ansi_colors_1 = require("ansi-colors");
|
|
18
|
+
const index_js_1 = require("../util_modules/constants/index.js");
|
|
19
|
+
const async_js_1 = require("../util_modules/fs/lib/async.js");
|
|
20
|
+
const sync_js_1 = require("../util_modules/fs/lib/sync.js");
|
|
21
|
+
const project_js_1 = require("../util_modules/project.js");
|
|
22
|
+
const error_1 = __importDefault(require("../error"));
|
|
23
|
+
const option_1 = require("../util_modules/option");
|
|
24
|
+
const index_js_2 = __importDefault(require("../prompt/index.js"));
|
|
25
|
+
function readInputFile(exeTarget) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const inputsFile = (0, path_1.resolve)(exeTarget.source, typeof exeTarget.inputs === 'string' ? exeTarget.inputs : index_js_1.FILENAME.catalyst_inputs);
|
|
28
|
+
const projectRoot = (0, project_js_1.getProjectRoot)();
|
|
29
|
+
if (!(0, sync_js_1.isPathInside)(projectRoot, inputsFile)) {
|
|
30
|
+
throw new error_1.default(`Input file path ${exeTarget.inputs} is outside the project directory.`, {
|
|
31
|
+
exit: 1,
|
|
32
|
+
context: {
|
|
33
|
+
resolvePath: inputsFile,
|
|
34
|
+
targetSource: projectRoot,
|
|
35
|
+
inputs: exeTarget.inputs
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return (0, async_js_1.readJSONFile)(inputsFile).catch((err) => {
|
|
40
|
+
throw new error_1.default('Unable to read the inputs file', {
|
|
41
|
+
original: err,
|
|
42
|
+
exit: 1,
|
|
43
|
+
errorId: 'FEXE-2',
|
|
44
|
+
arg: [(0, ansi_colors_1.italic)(inputsFile), ansi_colors_1.italic.red(err || '')]
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function getInputs(exeTarget, inputData) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const targetInputs = inputData || (yield readInputFile(exeTarget));
|
|
52
|
+
if (!targetInputs || Object.keys(targetInputs).length === 0) {
|
|
53
|
+
throw new error_1.default('Empty inputs', {
|
|
54
|
+
exit: 0,
|
|
55
|
+
errorId: 'FEXE-3',
|
|
56
|
+
arg: [
|
|
57
|
+
(0, ansi_colors_1.bold)(index_js_1.FILENAME.catalyst_inputs),
|
|
58
|
+
(0, ansi_colors_1.bold)(index_js_1.FILENAME.catalyst_config),
|
|
59
|
+
(0, ansi_colors_1.bold)('execution.test_inputs')
|
|
60
|
+
]
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
const inputKeys = Object.keys(targetInputs);
|
|
64
|
+
const keyOpt = (0, option_1.getOptionValue)('key', undefined);
|
|
65
|
+
if (keyOpt && !(keyOpt in targetInputs)) {
|
|
66
|
+
throw new error_1.default('Key not present in inputs', {
|
|
67
|
+
exit: 0,
|
|
68
|
+
errorId: 'FEXE-4',
|
|
69
|
+
arg: [
|
|
70
|
+
ansi_colors_1.bold.italic('--key ' + (0, ansi_colors_1.red)(keyOpt)),
|
|
71
|
+
(0, ansi_colors_1.bold)(inputKeys.map((key) => '* ' + key).join('\n'))
|
|
72
|
+
]
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
const selectedKey = yield index_js_2.default.ask(index_js_2.default.question('key', 'Please select the input', {
|
|
76
|
+
type: 'list',
|
|
77
|
+
choices: inputKeys.map((key) => index_js_2.default.choice(key, { value: key, short: key })),
|
|
78
|
+
when: !keyOpt && inputKeys.length > 1
|
|
79
|
+
}));
|
|
80
|
+
return inputKeys.length === 1
|
|
81
|
+
? { key: inputKeys.at(0) || 'unknown', ip: targetInputs[inputKeys[0]] }
|
|
82
|
+
: targetInputs[selectedKey.key]
|
|
83
|
+
? { key: selectedKey.key, ip: targetInputs[selectedKey.key] }
|
|
84
|
+
: { key: keyOpt, ip: targetInputs[keyOpt] };
|
|
85
|
+
});
|
|
86
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { readJSONFile, fileExists } from '../util_modules/fs/lib/async.js';
|
|
2
|
+
import { getStdinType } from '../util_modules/fs/lib/sync.js';
|
|
3
|
+
import CatalystError from '../error/index.js';
|
|
4
|
+
export type InputResolutionFailureReason = 'no-usable-input' | 'invalid-json' | 'file-not-found' | 'file-unreadable' | 'empty-stdin' | 'stdin-not-piped' | 'stdin-timeout';
|
|
5
|
+
type InputResolutionFailure = {
|
|
6
|
+
ok: false;
|
|
7
|
+
reason: InputResolutionFailureReason;
|
|
8
|
+
details?: string;
|
|
9
|
+
original?: unknown;
|
|
10
|
+
};
|
|
11
|
+
type InputResolutionSuccess = {
|
|
12
|
+
ok: true;
|
|
13
|
+
value: unknown;
|
|
14
|
+
};
|
|
15
|
+
export type InputResolutionResult = InputResolutionSuccess | InputResolutionFailure;
|
|
16
|
+
type ResolverDeps = {
|
|
17
|
+
stdin?: NodeJS.ReadableStream;
|
|
18
|
+
stdinTypeResolver?: typeof getStdinType;
|
|
19
|
+
jsonFileReader?: typeof readJSONFile;
|
|
20
|
+
fileExistsChecker?: typeof fileExists;
|
|
21
|
+
projectRoot?: string;
|
|
22
|
+
cwd?: string;
|
|
23
|
+
idleTimeoutMs?: number;
|
|
24
|
+
};
|
|
25
|
+
export declare function resolveExecuteInputOption(inputValue: string, deps?: ResolverDeps): Promise<InputResolutionResult>;
|
|
26
|
+
export declare function resolveInputError(resolvedInput: InputResolutionResult & {
|
|
27
|
+
ok: false;
|
|
28
|
+
}, inputOption: string): CatalystError;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.resolveExecuteInputOption = resolveExecuteInputOption;
|
|
16
|
+
exports.resolveInputError = resolveInputError;
|
|
17
|
+
const path_1 = require("path");
|
|
18
|
+
const ansi_colors_1 = require("ansi-colors");
|
|
19
|
+
const async_js_1 = require("../util_modules/fs/lib/async.js");
|
|
20
|
+
const sync_js_1 = require("../util_modules/fs/lib/sync.js");
|
|
21
|
+
const project_js_1 = require("../util_modules/project.js");
|
|
22
|
+
const index_js_1 = __importDefault(require("../error/index.js"));
|
|
23
|
+
const STDIN_IDLE_TIMEOUT_MS = 5000;
|
|
24
|
+
function getFirstNonWhitespaceChar(value) {
|
|
25
|
+
const trimmed = value.trimStart();
|
|
26
|
+
return trimmed.length > 0 ? trimmed[0] : '';
|
|
27
|
+
}
|
|
28
|
+
function parseJSON(value) {
|
|
29
|
+
try {
|
|
30
|
+
return { ok: true, value: JSON.parse(value) };
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
return {
|
|
34
|
+
ok: false,
|
|
35
|
+
reason: 'invalid-json',
|
|
36
|
+
details: value,
|
|
37
|
+
original: error
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function resolveFromStdin(_a) {
|
|
42
|
+
return __awaiter(this, arguments, void 0, function* ({ stdin, stdinTypeResolver, idleTimeoutMs }) {
|
|
43
|
+
const stdinType = stdinTypeResolver();
|
|
44
|
+
if (stdinType !== 'pipe' && stdinType !== 'file') {
|
|
45
|
+
return { ok: false, reason: 'stdin-not-piped' };
|
|
46
|
+
}
|
|
47
|
+
return new Promise((resolveResult) => {
|
|
48
|
+
const chunks = [];
|
|
49
|
+
let idleTimer;
|
|
50
|
+
const clearTimer = () => {
|
|
51
|
+
if (idleTimer) {
|
|
52
|
+
clearTimeout(idleTimer);
|
|
53
|
+
idleTimer = undefined;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const cleanup = () => {
|
|
57
|
+
clearTimer();
|
|
58
|
+
stdin.removeListener('data', onData);
|
|
59
|
+
stdin.removeListener('end', onEnd);
|
|
60
|
+
stdin.removeListener('error', onError);
|
|
61
|
+
if (typeof stdin.pause === 'function') {
|
|
62
|
+
stdin.pause();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const resetIdleTimer = () => {
|
|
66
|
+
clearTimer();
|
|
67
|
+
idleTimer = setTimeout(() => {
|
|
68
|
+
cleanup();
|
|
69
|
+
resolveResult({ ok: false, reason: 'stdin-timeout' });
|
|
70
|
+
}, idleTimeoutMs);
|
|
71
|
+
};
|
|
72
|
+
const onData = (chunk) => {
|
|
73
|
+
chunks.push(typeof chunk === 'string' ? chunk : chunk.toString());
|
|
74
|
+
resetIdleTimer();
|
|
75
|
+
};
|
|
76
|
+
const onEnd = () => {
|
|
77
|
+
cleanup();
|
|
78
|
+
const value = chunks.join('').trimEnd();
|
|
79
|
+
if (value.trim().length === 0) {
|
|
80
|
+
resolveResult({ ok: false, reason: 'empty-stdin' });
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
resolveResult(parseJSON(value));
|
|
84
|
+
};
|
|
85
|
+
const onError = (error) => {
|
|
86
|
+
cleanup();
|
|
87
|
+
resolveResult({
|
|
88
|
+
ok: false,
|
|
89
|
+
reason: 'file-unreadable',
|
|
90
|
+
details: 'stdin',
|
|
91
|
+
original: error
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
stdin.on('data', onData);
|
|
95
|
+
stdin.once('end', onEnd);
|
|
96
|
+
stdin.once('error', onError);
|
|
97
|
+
resetIdleTimer();
|
|
98
|
+
if (typeof stdin.resume === 'function') {
|
|
99
|
+
stdin.resume();
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function resolveExecuteInputOption(inputValue_1) {
|
|
105
|
+
return __awaiter(this, arguments, void 0, function* (inputValue, deps = {}) {
|
|
106
|
+
var _a;
|
|
107
|
+
const value = inputValue !== null && inputValue !== void 0 ? inputValue : '';
|
|
108
|
+
const trimmed = value.trim();
|
|
109
|
+
if (trimmed.length === 0) {
|
|
110
|
+
return { ok: false, reason: 'no-usable-input' };
|
|
111
|
+
}
|
|
112
|
+
if (trimmed === '-') {
|
|
113
|
+
return resolveFromStdin({
|
|
114
|
+
stdin: deps.stdin || process.stdin,
|
|
115
|
+
stdinTypeResolver: deps.stdinTypeResolver || sync_js_1.getStdinType,
|
|
116
|
+
idleTimeoutMs: (_a = deps.idleTimeoutMs) !== null && _a !== void 0 ? _a : STDIN_IDLE_TIMEOUT_MS
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
const firstChar = getFirstNonWhitespaceChar(value);
|
|
120
|
+
if (firstChar === '{' || firstChar === '[') {
|
|
121
|
+
return parseJSON(value);
|
|
122
|
+
}
|
|
123
|
+
const cwd = deps.cwd || process.cwd();
|
|
124
|
+
const absolutePath = (0, path_1.resolve)(cwd, value);
|
|
125
|
+
const projectRoot = deps.projectRoot || (0, project_js_1.getProjectRoot)();
|
|
126
|
+
if (!(0, sync_js_1.isPathInside)(projectRoot, absolutePath)) {
|
|
127
|
+
return {
|
|
128
|
+
ok: false,
|
|
129
|
+
reason: 'file-unreadable',
|
|
130
|
+
details: `${value} (outside project directory)`
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
const doesFileExist = deps.fileExistsChecker || async_js_1.fileExists;
|
|
134
|
+
if (!(yield doesFileExist(absolutePath))) {
|
|
135
|
+
return { ok: false, reason: 'file-not-found', details: value };
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
const jsonFileReader = deps.jsonFileReader || async_js_1.readJSONFile;
|
|
139
|
+
const parsedJSON = yield jsonFileReader(absolutePath);
|
|
140
|
+
return { ok: true, value: parsedJSON };
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
const message = (error === null || error === void 0 ? void 0 : error.message) || '';
|
|
144
|
+
if (/JSON|Unexpected token|parse/i.test(message)) {
|
|
145
|
+
return {
|
|
146
|
+
ok: false,
|
|
147
|
+
reason: 'invalid-json',
|
|
148
|
+
details: value,
|
|
149
|
+
original: error
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
ok: false,
|
|
154
|
+
reason: 'file-unreadable',
|
|
155
|
+
details: value,
|
|
156
|
+
original: error
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function resolveInputError(resolvedInput, inputOption) {
|
|
162
|
+
switch (resolvedInput.reason) {
|
|
163
|
+
case 'no-usable-input':
|
|
164
|
+
return new index_js_1.default('No usable input provided with --input', {
|
|
165
|
+
exit: 1,
|
|
166
|
+
errorId: 'FEXE-7',
|
|
167
|
+
arg: [ansi_colors_1.bold.italic('--input')]
|
|
168
|
+
});
|
|
169
|
+
case 'stdin-timeout':
|
|
170
|
+
return new index_js_1.default('Timed out waiting for stdin input', {
|
|
171
|
+
exit: 1,
|
|
172
|
+
errorId: 'FEXE-8',
|
|
173
|
+
arg: [ansi_colors_1.bold.italic('--input -')]
|
|
174
|
+
});
|
|
175
|
+
case 'stdin-not-piped':
|
|
176
|
+
return new index_js_1.default('Stdin is not piped', {
|
|
177
|
+
exit: 1,
|
|
178
|
+
errorId: 'FEXE-9',
|
|
179
|
+
arg: [ansi_colors_1.bold.italic('--input -')]
|
|
180
|
+
});
|
|
181
|
+
case 'empty-stdin':
|
|
182
|
+
return new index_js_1.default('Received empty stdin content', {
|
|
183
|
+
exit: 1,
|
|
184
|
+
errorId: 'FEXE-10',
|
|
185
|
+
arg: [ansi_colors_1.bold.italic('--input -')]
|
|
186
|
+
});
|
|
187
|
+
case 'file-not-found':
|
|
188
|
+
return new index_js_1.default('Input file not found', {
|
|
189
|
+
exit: 1,
|
|
190
|
+
errorId: 'FEXE-11',
|
|
191
|
+
arg: [(0, ansi_colors_1.italic)(resolvedInput.details || inputOption)]
|
|
192
|
+
});
|
|
193
|
+
case 'file-unreadable':
|
|
194
|
+
return new index_js_1.default('Unable to read input source', {
|
|
195
|
+
exit: 1,
|
|
196
|
+
errorId: 'FEXE-12',
|
|
197
|
+
arg: [(0, ansi_colors_1.italic)(resolvedInput.details || inputOption)]
|
|
198
|
+
});
|
|
199
|
+
case 'invalid-json':
|
|
200
|
+
default:
|
|
201
|
+
return new index_js_1.default('Error parsing the JSON input', {
|
|
202
|
+
exit: 1,
|
|
203
|
+
errorId: 'FEXE-6',
|
|
204
|
+
arg: [ansi_colors_1.italic.red(resolvedInput.details || inputOption)]
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
package/lib/execute/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { IFnTarget } from '../fn-utils/lib/common.js';
|
|
2
|
-
declare const _default: (target: IFnTarget, input:
|
|
2
|
+
declare const _default: (target: IFnTarget, input: {
|
|
3
|
+
key: string;
|
|
4
|
+
ip?: Record<string, unknown>;
|
|
5
|
+
}) => Promise<void>;
|
|
3
6
|
export default _default;
|
package/lib/execute/index.js
CHANGED
|
@@ -33,7 +33,8 @@ exports.default = (target, input) => __awaiter(void 0, void 0, void 0, function*
|
|
|
33
33
|
try {
|
|
34
34
|
(0, index_1.info)();
|
|
35
35
|
(0, index_1.info)((0, ansi_colors_1.bold)('=> Starting function execution'));
|
|
36
|
-
|
|
36
|
+
const exeInfo = ` name: ${(0, ansi_colors_1.green)(target.name)} | type: ${(0, ansi_colors_1.magenta)(target.type ? index_js_3.REMOTE_REF.functions.type[target.type] : '')} | stack: ${(0, ansi_colors_1.cyan)(target.stack || '')} | input: ${(0, ansi_colors_1.yellow)(input.key)}`;
|
|
37
|
+
(0, index_1.info)(exeInfo);
|
|
37
38
|
(0, index_1.info)();
|
|
38
39
|
if (yield index_js_4.ASYNC.isPathExists(buildFolder)) {
|
|
39
40
|
try {
|
|
@@ -84,7 +85,7 @@ exports.default = (target, input) => __awaiter(void 0, void 0, void 0, function*
|
|
|
84
85
|
isAlive: null
|
|
85
86
|
}, new stream_1.EventEmitter());
|
|
86
87
|
utils_1.serverEvent.once('stop', () => caller.kill());
|
|
87
|
-
yield caller.call(input);
|
|
88
|
+
yield caller.call(input.ip || {});
|
|
88
89
|
utils_1.serverEvent.emit('stop');
|
|
89
90
|
yield index_js_4.ASYNC.deleteDir(buildFolder).catch();
|
|
90
91
|
yield index_js_1.fnUtils.common.executeHook({ prefix: 'post', command: 'serve' });
|
|
@@ -23,6 +23,8 @@ const constants_1 = require("../../util_modules/constants");
|
|
|
23
23
|
const runtime_1 = __importDefault(require("../../util_modules/constants/lib/runtime"));
|
|
24
24
|
const fs_1 = require("../../util_modules/fs");
|
|
25
25
|
const js_1 = require("../../util_modules/js");
|
|
26
|
+
const prompt_fields_1 = require("../../init/features/functions/prompt-fields");
|
|
27
|
+
const env_js_1 = require("../../util_modules/env.js");
|
|
26
28
|
const serviceChoiceMap = {
|
|
27
29
|
[constants_1.INTEG.services.cliq]: prompt_1.default.choice('Cliq', {
|
|
28
30
|
value: constants_1.INTEG.services.cliq,
|
|
@@ -41,7 +43,7 @@ function integHelper(services) {
|
|
|
41
43
|
exit: 2
|
|
42
44
|
});
|
|
43
45
|
}
|
|
44
|
-
const serviceAns = yield prompt_1.default.ask(prompt_1.default.question('service', 'Select one of the services to continue:', {
|
|
46
|
+
const serviceAns = yield prompt_1.default.ask(prompt_1.default.question(prompt_fields_1.functionsAddPromptFields.get('service'), 'Select one of the services to continue:', {
|
|
45
47
|
type: 'list',
|
|
46
48
|
choices: serviceChoices
|
|
47
49
|
}));
|
|
@@ -55,23 +57,26 @@ function integHelper(services) {
|
|
|
55
57
|
checked: true
|
|
56
58
|
});
|
|
57
59
|
});
|
|
58
|
-
const handlerSelection =
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
'
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
60
|
+
const handlerSelection = (0, env_js_1.isNonInteractiveMode)()
|
|
61
|
+
? { selectionAnswer: constants_1.CLIQ.component_handlers }
|
|
62
|
+
: yield prompt_1.default.ask(prompt_1.default.question('selectionAnswer', 'Pick the handlers to be initialized', {
|
|
63
|
+
type: 'checkbox',
|
|
64
|
+
defaultAns: constants_1.CLIQ.component_handlers,
|
|
65
|
+
choices: handlerChoice,
|
|
66
|
+
validate: (ansArr) => {
|
|
67
|
+
if (js_1.JS.isEmpty(ansArr)) {
|
|
68
|
+
return ('Must select at least one handler.\n' +
|
|
69
|
+
'(Press ' +
|
|
70
|
+
(0, ansi_colors_1.cyan)('<space>') +
|
|
71
|
+
' to select, ' +
|
|
72
|
+
(0, ansi_colors_1.cyan)('<a>') +
|
|
73
|
+
' to toggle all, ' +
|
|
74
|
+
(0, ansi_colors_1.cyan)('<i>') +
|
|
75
|
+
' to invert selection)');
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
71
78
|
}
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
}));
|
|
79
|
+
}));
|
|
75
80
|
runtime_store_1.default.set('context.function.integration.cliq.handlers', handlerSelection.selectionAnswer);
|
|
76
81
|
break;
|
|
77
82
|
default:
|
package/lib/index.js
CHANGED
|
@@ -30,6 +30,7 @@ program.option('--token <token>', 'Supply an authentication token for a command'
|
|
|
30
30
|
program.option('--dc <us|eu|in|au>', 'Supply a data center for a command');
|
|
31
31
|
program.option('--org <org_id>', 'Supply a Org ID to be used for a command');
|
|
32
32
|
program.option('--verbose', 'Change the log level to verbose for debugging purposes');
|
|
33
|
+
program.option('-ni, --non-interactive', 'Do not prompt for input; fail if required answers are not supplied (see also ZCATALYST_NON_INTERACTIVE)');
|
|
33
34
|
program.helpOption('-h, --help', 'Display help for a Catalyst command');
|
|
34
35
|
program.showSuggestionAfterError();
|
|
35
36
|
program.showHelpAfterError(`For more usage information use the ${(0, ansi_colors_1.bold)('catalyst help')} command`);
|
|
@@ -20,11 +20,13 @@ const constants_1 = require("../../util_modules/constants");
|
|
|
20
20
|
const js_1 = require("../../util_modules/js");
|
|
21
21
|
const index_1 = require("../../util_modules/logger/index");
|
|
22
22
|
const project_1 = require("../../util_modules/project");
|
|
23
|
+
const prompt_fields_1 = require("../features/functions/prompt-fields");
|
|
24
|
+
const env_1 = require("../../util_modules/env");
|
|
23
25
|
exports.default = (keys) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
26
|
const qns = keys.map((qn) => {
|
|
25
27
|
switch (qn) {
|
|
26
28
|
case 'name':
|
|
27
|
-
return prompt_1.default.question('name', 'package name: ', {
|
|
29
|
+
return prompt_1.default.question(prompt_fields_1.functionsAddPromptFields.get('name'), 'package name: ', {
|
|
28
30
|
defaultAns: js_1.JS.snakeCase((0, project_1.getProjectName)('sample') + '_function'),
|
|
29
31
|
validate: (ans) => {
|
|
30
32
|
if (ans.match(constants_1.REGEX.functions.package.name)) {
|
|
@@ -51,11 +53,13 @@ exports.default = (keys) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
51
53
|
throw new error_1.default('unknown key provided', { exit: 2 });
|
|
52
54
|
}
|
|
53
55
|
});
|
|
54
|
-
(0,
|
|
55
|
-
(0,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
(0,
|
|
59
|
-
|
|
56
|
+
if (!(0, env_1.isNonInteractiveMode)()) {
|
|
57
|
+
(0, index_1.info)('This utility will ask series of questions with sensible defaults for creating ' +
|
|
58
|
+
(0, ansi_colors_1.cyan)('package.json') +
|
|
59
|
+
'\nFeel free to modify them if needed.\n');
|
|
60
|
+
(0, index_1.info)('Use `' +
|
|
61
|
+
(0, ansi_colors_1.bold)('npm install <pkg> --save') +
|
|
62
|
+
'` afterwards to install a package and \nsave it as a dependency in the package.json file.\n');
|
|
63
|
+
}
|
|
60
64
|
return prompt_1.default.ask(...qns);
|
|
61
65
|
});
|