@botpress/cli 0.0.3 → 0.0.5
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/bin.js +0 -0
- package/dist/app/api-utils.js +5 -4
- package/dist/app/base.js +39 -1
- package/dist/app/errors.js +18 -19
- package/dist/app/file-paths.js +82 -0
- package/dist/app/generator/module.js +1 -1
- package/dist/app/index.js +15 -10
- package/dist/app/project.js +198 -240
- package/dist/app/user.js +5 -16
- package/dist/config.js +8 -3
- package/dist/{const.js → consts.js} +12 -34
- package/dist/{app/esbuild.js → esbuild-utils.js} +3 -3
- package/dist/index.js +1 -1
- package/dist/logger/index.js +5 -5
- package/dist/{paths.js → path-utils.js} +3 -3
- package/dist/{requires.js → require-utils.js} +3 -3
- package/dist/worker/child-entrypoint.js +4 -2
- package/package.json +2 -2
- package/readme.md +0 -1
- package/dist/index.js.map +0 -7
- package/dist/init.js.map +0 -7
- package/dist/type-utils.js +0 -16
package/bin.js
CHANGED
|
File without changes
|
package/dist/app/api-utils.js
CHANGED
|
@@ -71,7 +71,7 @@ class ApiUtils {
|
|
|
71
71
|
throw errors.BotpressCLIError.wrap(thrown, "Authentication failed. Please check your credentials");
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
async listAllPages(lister,
|
|
74
|
+
async listAllPages(lister, map) {
|
|
75
75
|
let nextToken;
|
|
76
76
|
const all = [];
|
|
77
77
|
do {
|
|
@@ -79,17 +79,18 @@ class ApiUtils {
|
|
|
79
79
|
all.push(r);
|
|
80
80
|
nextToken = meta.nextToken;
|
|
81
81
|
} while (nextToken);
|
|
82
|
-
if (!
|
|
82
|
+
if (!map) {
|
|
83
83
|
return all;
|
|
84
84
|
}
|
|
85
|
-
|
|
85
|
+
const mapped = all.flatMap((r) => map(r));
|
|
86
|
+
return mapped;
|
|
86
87
|
}
|
|
87
88
|
async validateStatus(fn, allowedStatuses) {
|
|
88
89
|
try {
|
|
89
90
|
const v = await fn();
|
|
90
91
|
return v;
|
|
91
92
|
} catch (thrown) {
|
|
92
|
-
const err = errors.
|
|
93
|
+
const err = errors.BotpressCLIError.map(thrown);
|
|
93
94
|
const allowedStatusesArray = import_lodash.default.isArray(allowedStatuses) ? allowedStatuses : [allowedStatuses];
|
|
94
95
|
const isAllowed = err instanceof errors.HTTPError && err.status && allowedStatusesArray.includes(err.status);
|
|
95
96
|
if (isAllowed) {
|
package/dist/app/base.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,19 +17,55 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
18
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
25
|
var base_exports = {};
|
|
20
26
|
__export(base_exports, {
|
|
21
27
|
BaseCommands: () => BaseCommands
|
|
22
28
|
});
|
|
23
29
|
module.exports = __toCommonJS(base_exports);
|
|
30
|
+
var bpclient = __toESM(require("@botpress/client"));
|
|
31
|
+
var import_prompts = __toESM(require("prompts"));
|
|
32
|
+
var import_api_utils = require("./api-utils");
|
|
33
|
+
var errors = __toESM(require("./errors"));
|
|
24
34
|
class BaseCommands {
|
|
25
|
-
constructor(_logger) {
|
|
35
|
+
constructor(_props, _userCache, _logger) {
|
|
36
|
+
this._props = _props;
|
|
37
|
+
this._userCache = _userCache;
|
|
26
38
|
this._logger = _logger;
|
|
27
39
|
}
|
|
28
40
|
teardown() {
|
|
29
41
|
this._logger.cleanup();
|
|
30
42
|
}
|
|
43
|
+
async _ensureLoginAndCreateClient(argv) {
|
|
44
|
+
const token = await this._userCache.get("token");
|
|
45
|
+
const workspaceId = argv.workspaceId ?? await this._userCache.get("workspaceId");
|
|
46
|
+
const host = argv.host ?? await this._userCache.get("host");
|
|
47
|
+
if (!(token && workspaceId && host)) {
|
|
48
|
+
throw new errors.NotLoggedInError();
|
|
49
|
+
}
|
|
50
|
+
const client = new bpclient.Client({ host, token, workspaceId });
|
|
51
|
+
return new import_api_utils.ApiUtils(client, host, token, workspaceId, this._logger);
|
|
52
|
+
}
|
|
53
|
+
async _confirm(message) {
|
|
54
|
+
if (this._props.confirm) {
|
|
55
|
+
this._logger.debug(`Confirming automatically: ${message}`);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
const { confirm } = await (0, import_prompts.default)({
|
|
59
|
+
type: "confirm",
|
|
60
|
+
name: "confirm",
|
|
61
|
+
message,
|
|
62
|
+
initial: false
|
|
63
|
+
});
|
|
64
|
+
if (!confirm) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
31
69
|
}
|
|
32
70
|
// Annotate the CommonJS export names for ESM import in node:
|
|
33
71
|
0 && (module.exports = {
|
package/dist/app/errors.js
CHANGED
|
@@ -32,30 +32,30 @@ __export(errors_exports, {
|
|
|
32
32
|
NoBotsFoundError: () => NoBotsFoundError,
|
|
33
33
|
NoBundleFoundError: () => NoBundleFoundError,
|
|
34
34
|
NotLoggedInError: () => NotLoggedInError,
|
|
35
|
-
ParamRequiredError: () => ParamRequiredError
|
|
36
|
-
mapThrown: () => mapThrown
|
|
35
|
+
ParamRequiredError: () => ParamRequiredError
|
|
37
36
|
});
|
|
38
37
|
module.exports = __toCommonJS(errors_exports);
|
|
39
38
|
var import_client = require("@botpress/client");
|
|
40
39
|
var import_axios = __toESM(require("axios"));
|
|
41
40
|
var import_verror = require("verror");
|
|
42
|
-
var consts = __toESM(require("../
|
|
43
|
-
const mapThrown = (thrown) => {
|
|
44
|
-
if ((0, import_client.isApiError)(thrown)) {
|
|
45
|
-
return HTTPError.fromApi(thrown);
|
|
46
|
-
}
|
|
47
|
-
if (import_axios.default.isAxiosError(thrown)) {
|
|
48
|
-
return HTTPError.fromAxios(thrown);
|
|
49
|
-
}
|
|
50
|
-
if (thrown instanceof Error) {
|
|
51
|
-
return thrown;
|
|
52
|
-
}
|
|
53
|
-
return new BotpressCLIError(`${thrown}`);
|
|
54
|
-
};
|
|
41
|
+
var consts = __toESM(require("../consts"));
|
|
55
42
|
class BotpressCLIError extends import_verror.VError {
|
|
56
43
|
static wrap(thrown, message) {
|
|
57
|
-
const err =
|
|
58
|
-
return new BotpressCLIError(err, message);
|
|
44
|
+
const err = BotpressCLIError.map(thrown);
|
|
45
|
+
return new BotpressCLIError(err, message ?? "");
|
|
46
|
+
}
|
|
47
|
+
static map(thrown) {
|
|
48
|
+
if ((0, import_client.isApiError)(thrown)) {
|
|
49
|
+
return HTTPError.fromApi(thrown);
|
|
50
|
+
}
|
|
51
|
+
if (import_axios.default.isAxiosError(thrown)) {
|
|
52
|
+
return HTTPError.fromAxios(thrown);
|
|
53
|
+
}
|
|
54
|
+
if (thrown instanceof Error) {
|
|
55
|
+
const { message } = thrown;
|
|
56
|
+
return new BotpressCLIError(message);
|
|
57
|
+
}
|
|
58
|
+
return new BotpressCLIError(`${thrown}`);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
class ExclusiveBotFeatureError extends BotpressCLIError {
|
|
@@ -140,6 +140,5 @@ class InvalidIntegrationReferenceError extends BotpressCLIError {
|
|
|
140
140
|
NoBotsFoundError,
|
|
141
141
|
NoBundleFoundError,
|
|
142
142
|
NotLoggedInError,
|
|
143
|
-
ParamRequiredError
|
|
144
|
-
mapThrown
|
|
143
|
+
ParamRequiredError
|
|
145
144
|
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var file_paths_exports = {};
|
|
26
|
+
__export(file_paths_exports, {
|
|
27
|
+
ProjectPaths: () => ProjectPaths,
|
|
28
|
+
UserPaths: () => UserPaths
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(file_paths_exports);
|
|
31
|
+
var import_lodash = __toESM(require("lodash"));
|
|
32
|
+
var consts = __toESM(require("../consts"));
|
|
33
|
+
var pathutils = __toESM(require("../path-utils"));
|
|
34
|
+
class ProjectPaths {
|
|
35
|
+
abs;
|
|
36
|
+
rel;
|
|
37
|
+
constructor({ workDir, definition, entryPoint: entrypoint, outDir }) {
|
|
38
|
+
const absWorkdir = pathutils.absoluteFrom(pathutils.cwd(), workDir);
|
|
39
|
+
const absDefinition = pathutils.absoluteFrom(absWorkdir, definition);
|
|
40
|
+
const absEntrypoint = pathutils.absoluteFrom(absWorkdir, entrypoint);
|
|
41
|
+
const absOutdir = pathutils.absoluteFrom(absWorkdir, outDir);
|
|
42
|
+
this.abs = {
|
|
43
|
+
workDir: absWorkdir,
|
|
44
|
+
definition: absDefinition,
|
|
45
|
+
entryPoint: absEntrypoint,
|
|
46
|
+
outDir: absOutdir,
|
|
47
|
+
...import_lodash.default.mapValues(consts.relativeToOutFolder, (p) => pathutils.absoluteFrom(absOutdir, p))
|
|
48
|
+
};
|
|
49
|
+
const relDefinition = pathutils.relativeFrom(this.abs.workDir, this.abs.definition);
|
|
50
|
+
const relEntrypoint = pathutils.relativeFrom(this.abs.workDir, this.abs.entryPoint);
|
|
51
|
+
const relOutdir = pathutils.relativeFrom(this.abs.workDir, this.abs.outDir);
|
|
52
|
+
const relWorkdir = ".";
|
|
53
|
+
this.rel = {
|
|
54
|
+
workDir: relWorkdir,
|
|
55
|
+
definition: relDefinition,
|
|
56
|
+
entryPoint: relEntrypoint,
|
|
57
|
+
outDir: relOutdir,
|
|
58
|
+
...import_lodash.default.mapValues(consts.relativeToOutFolder, (p) => pathutils.relativeFrom(this.abs.outDir, p))
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
class UserPaths {
|
|
63
|
+
abs;
|
|
64
|
+
rel;
|
|
65
|
+
constructor({ botpressHome }) {
|
|
66
|
+
const absBotpressHome = pathutils.absoluteFrom(pathutils.cwd(), botpressHome);
|
|
67
|
+
this.abs = {
|
|
68
|
+
botpressHome: absBotpressHome,
|
|
69
|
+
...import_lodash.default.mapValues(consts.relativeToHomeFolder, (p) => pathutils.absoluteFrom(absBotpressHome, p))
|
|
70
|
+
};
|
|
71
|
+
const relBotpressHome = ".";
|
|
72
|
+
this.rel = {
|
|
73
|
+
botpressHome: relBotpressHome,
|
|
74
|
+
...import_lodash.default.mapValues(consts.relativeToHomeFolder, (p) => pathutils.relativeFrom(this.abs.botpressHome, p))
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
79
|
+
0 && (module.exports = {
|
|
80
|
+
ProjectPaths,
|
|
81
|
+
UserPaths
|
|
82
|
+
});
|
|
@@ -29,7 +29,7 @@ __export(module_exports, {
|
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(module_exports);
|
|
31
31
|
var import_path = require("path");
|
|
32
|
-
var pathutils = __toESM(require("../../
|
|
32
|
+
var pathutils = __toESM(require("../../path-utils"));
|
|
33
33
|
var import_const = require("./const");
|
|
34
34
|
class Module {
|
|
35
35
|
constructor(_def) {
|
package/dist/app/index.js
CHANGED
|
@@ -31,13 +31,14 @@ __export(app_exports, {
|
|
|
31
31
|
module.exports = __toCommonJS(app_exports);
|
|
32
32
|
var import_chalk = __toESM(require("chalk"));
|
|
33
33
|
var import_fs = __toESM(require("fs"));
|
|
34
|
-
var consts = __toESM(require("../
|
|
34
|
+
var consts = __toESM(require("../consts"));
|
|
35
35
|
var import_logger = require("../logger");
|
|
36
36
|
var import_cache = require("./cache");
|
|
37
|
+
var import_file_paths = require("./file-paths");
|
|
37
38
|
var import_project = require("./project");
|
|
38
39
|
var import_user = require("./user");
|
|
39
40
|
var errors = __toESM(require("./errors"));
|
|
40
|
-
const
|
|
41
|
+
const logBootInfo = (logger, props) => {
|
|
41
42
|
const versionText = import_chalk.default.bold(`v${props.version}`);
|
|
42
43
|
logger.log(`Botpress CLI ${versionText}`, { prefix: "\u{1F916}" });
|
|
43
44
|
if (props.botpressHome !== consts.defaultBotpressHome) {
|
|
@@ -46,18 +47,22 @@ const logVersion = (logger, props) => {
|
|
|
46
47
|
};
|
|
47
48
|
const forProject = async (props) => {
|
|
48
49
|
const logger = new import_logger.Logger(props);
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
const projectCachePath =
|
|
50
|
+
logBootInfo(logger, props);
|
|
51
|
+
const projectPaths = new import_file_paths.ProjectPaths(props);
|
|
52
|
+
const projectCachePath = projectPaths.abs.projectCacheFile;
|
|
52
53
|
const projectCache = await import_cache.FSConfigCache.loadFrom(projectCachePath);
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
const userPaths = new import_file_paths.UserPaths(props);
|
|
55
|
+
const userCacheFile = userPaths.abs.userCacheFile;
|
|
56
|
+
const userCache = await import_cache.FSConfigCache.loadFrom(userCacheFile);
|
|
57
|
+
await import_fs.default.promises.mkdir(projectPaths.abs.distDir, { recursive: true });
|
|
58
|
+
return new import_project.ProjectCommands(props, projectPaths, projectCache, userCache, logger);
|
|
56
59
|
};
|
|
57
60
|
const forUser = async (props) => {
|
|
58
61
|
const logger = new import_logger.Logger(props);
|
|
59
|
-
|
|
60
|
-
const
|
|
62
|
+
logBootInfo(logger, props);
|
|
63
|
+
const userPaths = new import_file_paths.UserPaths(props);
|
|
64
|
+
const userCacheFile = userPaths.abs.userCacheFile;
|
|
65
|
+
const userCache = await import_cache.FSConfigCache.loadFrom(userCacheFile);
|
|
61
66
|
return new import_user.UserCommands(props, userCache, logger);
|
|
62
67
|
};
|
|
63
68
|
// Annotate the CommonJS export names for ESM import in node:
|