@botpress/cli 0.0.8 → 0.0.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/dist/api-client.js +107 -0
- package/dist/app/api-utils.js +9 -3
- package/dist/app/base.js +1 -3
- package/dist/app/errors.js +8 -0
- package/dist/app/file-paths.js +28 -31
- package/dist/app/index.js +18 -11
- package/dist/app/project.js +4 -4
- package/dist/app/user.js +73 -23
- package/dist/code-generation/action.js +70 -0
- package/dist/code-generation/channel.js +51 -0
- package/dist/code-generation/configuration.js +40 -0
- package/dist/code-generation/const.js +31 -0
- package/dist/code-generation/event.js +41 -0
- package/dist/code-generation/index.js +80 -0
- package/dist/code-generation/integration-impl.js +147 -0
- package/dist/code-generation/integration-instance.js +79 -0
- package/dist/code-generation/message.js +41 -0
- package/dist/code-generation/module.js +115 -0
- package/dist/code-generation/typings.js +16 -0
- package/dist/command-definitions.js +61 -0
- package/dist/command-implementations/add-command.js +124 -0
- package/dist/command-implementations/base-command.js +53 -0
- package/dist/command-implementations/bot-commands.js +89 -0
- package/dist/command-implementations/build-command.js +48 -0
- package/dist/command-implementations/bundle-command.js +58 -0
- package/dist/command-implementations/deploy-command.js +162 -0
- package/dist/command-implementations/dev-command.js +168 -0
- package/dist/command-implementations/gen-command.js +58 -0
- package/dist/command-implementations/global-command.js +111 -0
- package/dist/command-implementations/index.js +78 -0
- package/dist/command-implementations/init-command.js +85 -0
- package/dist/command-implementations/integration-commands.js +107 -0
- package/dist/command-implementations/login-command.js +75 -0
- package/dist/command-implementations/logout-command.js +34 -0
- package/dist/command-implementations/project-command.js +115 -0
- package/dist/command-implementations/serve-command.js +53 -0
- package/dist/command-tree.js +59 -0
- package/dist/config.js +18 -8
- package/dist/consts.js +24 -9
- package/dist/errors.js +156 -0
- package/dist/index.js +33 -20
- package/dist/integration-ref.js +61 -0
- package/dist/path-utils.js +7 -4
- package/dist/register-yargs.js +85 -0
- package/dist/typings.js +16 -0
- package/dist/utils/cache-utils.js +99 -0
- package/dist/utils/esbuild-utils.js +89 -0
- package/dist/utils/event-emitter.js +62 -0
- package/dist/utils/file-watcher.js +68 -0
- package/dist/utils/index.js +55 -0
- package/dist/utils/path-utils.js +83 -0
- package/dist/utils/prompt-utils.js +75 -0
- package/dist/utils/require-utils.js +49 -0
- package/dist/utils/string-utils.js +38 -0
- package/package.json +7 -5
- package/templates/echo-bot/.botpress/project.cache.json +1 -0
- package/templates/echo-bot/package.json +22 -0
- package/templates/echo-bot/readme.md +5 -0
- package/templates/echo-bot/src/index.ts +44 -0
- package/templates/echo-bot/tsconfig.json +15 -0
- package/templates/empty-integration/.botpress/implementation/actions/index.ts +7 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/audio.ts +10 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/card.ts +17 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/carousel.ts +19 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/choice.ts +14 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/dropdown.ts +14 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/file.ts +11 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/image.ts +10 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/index.ts +40 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/location.ts +11 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/markdown.ts +10 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/text.ts +10 -0
- package/templates/empty-integration/.botpress/implementation/channels/channel/video.ts +10 -0
- package/templates/empty-integration/.botpress/implementation/channels/index.ts +10 -0
- package/templates/empty-integration/.botpress/implementation/configuration.ts +10 -0
- package/templates/empty-integration/.botpress/implementation/events/index.ts +7 -0
- package/templates/empty-integration/.botpress/implementation/index.ts +17 -0
- package/templates/empty-integration/.botpress/index.ts +1 -0
- package/templates/empty-integration/.botpress/project.cache.json +1 -0
- package/templates/empty-integration/integration.definition.ts +13 -0
- package/templates/empty-integration/package.json +22 -0
- package/templates/empty-integration/readme.md +5 -0
- package/templates/empty-integration/src/index.ts +58 -0
- package/templates/empty-integration/tsconfig.json +15 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var logout_command_exports = {};
|
|
20
|
+
__export(logout_command_exports, {
|
|
21
|
+
LogoutCommand: () => LogoutCommand
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(logout_command_exports);
|
|
24
|
+
var import_global_command = require("./global-command");
|
|
25
|
+
class LogoutCommand extends import_global_command.GlobalCommand {
|
|
26
|
+
async run() {
|
|
27
|
+
await this.globalCache.clear();
|
|
28
|
+
this.logger.success("Logged Out");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
LogoutCommand
|
|
34
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
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 project_command_exports = {};
|
|
26
|
+
__export(project_command_exports, {
|
|
27
|
+
ProjectCommand: () => ProjectCommand
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(project_command_exports);
|
|
30
|
+
var import_chalk = __toESM(require("chalk"));
|
|
31
|
+
var import_fs = __toESM(require("fs"));
|
|
32
|
+
var import_lodash = __toESM(require("lodash"));
|
|
33
|
+
var import_path = __toESM(require("path"));
|
|
34
|
+
var consts = __toESM(require("../consts"));
|
|
35
|
+
var errors = __toESM(require("../errors"));
|
|
36
|
+
var utils = __toESM(require("../utils"));
|
|
37
|
+
var import_global_command = require("./global-command");
|
|
38
|
+
class ProjectPaths extends utils.path.PathStore {
|
|
39
|
+
constructor(argv) {
|
|
40
|
+
const absWorkDir = utils.path.absoluteFrom(utils.path.cwd(), argv.workDir);
|
|
41
|
+
const absEntrypoint = utils.path.absoluteFrom(absWorkDir, argv.entryPoint);
|
|
42
|
+
const absOutDir = utils.path.absoluteFrom(absWorkDir, argv.outDir);
|
|
43
|
+
super({
|
|
44
|
+
workDir: absWorkDir,
|
|
45
|
+
entryPoint: absEntrypoint,
|
|
46
|
+
outDir: absOutDir,
|
|
47
|
+
...import_lodash.default.mapValues(consts.fromOutDir, (p) => utils.path.absoluteFrom(absOutDir, p)),
|
|
48
|
+
...import_lodash.default.mapValues(consts.fromWorkDir, (p) => utils.path.absoluteFrom(absWorkDir, p))
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
class ProjectCommand extends import_global_command.GlobalCommand {
|
|
53
|
+
get projectPaths() {
|
|
54
|
+
return new ProjectPaths(this.argv);
|
|
55
|
+
}
|
|
56
|
+
get projectCache() {
|
|
57
|
+
return new utils.cache.FSKeyValueCache(this.projectPaths.abs.projectCacheFile);
|
|
58
|
+
}
|
|
59
|
+
async readIntegrationDefinitionFromFS() {
|
|
60
|
+
const abs = this.projectPaths.abs;
|
|
61
|
+
const rel = this.projectPaths.rel("workDir");
|
|
62
|
+
if (!import_fs.default.existsSync(abs.definition)) {
|
|
63
|
+
this.logger.debug(`Integration definition not found at ${rel.definition}`);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const { outputFiles } = await utils.esbuild.buildEntrypoint({
|
|
67
|
+
cwd: abs.workDir,
|
|
68
|
+
outfile: "",
|
|
69
|
+
entrypoint: rel.definition,
|
|
70
|
+
write: false
|
|
71
|
+
});
|
|
72
|
+
const artifact = outputFiles[0];
|
|
73
|
+
if (!artifact) {
|
|
74
|
+
throw new errors.BotpressCLIError("Could not read integration definition");
|
|
75
|
+
}
|
|
76
|
+
const { default: definition } = utils.require.requireJsCode(artifact.text);
|
|
77
|
+
return definition;
|
|
78
|
+
}
|
|
79
|
+
async writeGeneratedFilesToOutFolder(files) {
|
|
80
|
+
for (const file of files) {
|
|
81
|
+
const filePath = utils.path.absoluteFrom(this.projectPaths.abs.outDir, file.path);
|
|
82
|
+
const dirPath = import_path.default.dirname(filePath);
|
|
83
|
+
await import_fs.default.promises.mkdir(dirPath, { recursive: true });
|
|
84
|
+
await import_fs.default.promises.writeFile(filePath, file.content);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
prepareIntegrations(botImpl, botInfo) {
|
|
88
|
+
const { integrations: integrationList } = botImpl;
|
|
89
|
+
const integrationsToUninstall = (0, import_lodash.default)(botInfo.integrations).keys().filter((key) => !integrationList?.map((i) => i.id).includes(key)).zipObject().mapValues(() => null).value();
|
|
90
|
+
const integrationsToInstall = (0, import_lodash.default)(integrationList ?? []).keyBy((i) => i.id).mapValues(({ enabled, configuration }) => ({ enabled, configuration })).value();
|
|
91
|
+
return { ...integrationsToUninstall, ...integrationsToInstall };
|
|
92
|
+
}
|
|
93
|
+
displayWebhookUrls(bot) {
|
|
94
|
+
if (!import_lodash.default.keys(bot.integrations).length) {
|
|
95
|
+
this.logger.log("No integrations in bot");
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
this.logger.log("Integrations:");
|
|
99
|
+
for (const integration of Object.values(bot.integrations)) {
|
|
100
|
+
if (!integration.enabled) {
|
|
101
|
+
this.logger.log(`${import_chalk.default.grey(integration.name)} ${import_chalk.default.italic("(disabled)")}: ${integration.webhookUrl}`, {
|
|
102
|
+
prefix: { symbol: "\u25CB", indent: 2 }
|
|
103
|
+
});
|
|
104
|
+
} else {
|
|
105
|
+
this.logger.log(`${import_chalk.default.bold(integration.name)} : ${integration.webhookUrl}`, {
|
|
106
|
+
prefix: { symbol: "\u25CF", indent: 2 }
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
113
|
+
0 && (module.exports = {
|
|
114
|
+
ProjectCommand
|
|
115
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
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 serve_command_exports = {};
|
|
26
|
+
__export(serve_command_exports, {
|
|
27
|
+
ServeCommand: () => ServeCommand
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(serve_command_exports);
|
|
30
|
+
var fs = __toESM(require("fs"));
|
|
31
|
+
var errors = __toESM(require("../errors"));
|
|
32
|
+
var utils = __toESM(require("../utils"));
|
|
33
|
+
var import_project_command = require("./project-command");
|
|
34
|
+
class ServeCommand extends import_project_command.ProjectCommand {
|
|
35
|
+
async run() {
|
|
36
|
+
const outfile = this.projectPaths.abs.outFile;
|
|
37
|
+
if (!fs.existsSync(outfile)) {
|
|
38
|
+
throw new errors.NoBundleFoundError();
|
|
39
|
+
}
|
|
40
|
+
const isIntegration = !!await this.readIntegrationDefinitionFromFS();
|
|
41
|
+
this.logger.log(`Serving ${isIntegration ? "integration" : "bot"}...`);
|
|
42
|
+
const { default: serveable } = utils.require.requireJsFile(outfile);
|
|
43
|
+
const server = await serveable.start(this.argv.port);
|
|
44
|
+
await new Promise((resolve, reject) => {
|
|
45
|
+
server.on("error", reject);
|
|
46
|
+
server.on("close", resolve);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
ServeCommand
|
|
53
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var command_tree_exports = {};
|
|
20
|
+
__export(command_tree_exports, {
|
|
21
|
+
guards: () => guards,
|
|
22
|
+
zipTree: () => zipTree
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(command_tree_exports);
|
|
25
|
+
const guards = {
|
|
26
|
+
definition: {
|
|
27
|
+
isDef: (x) => "schema" in x,
|
|
28
|
+
isSubTree: (x) => "subcommands" in x
|
|
29
|
+
},
|
|
30
|
+
implementation: {
|
|
31
|
+
isImpl: (x) => typeof x === "function",
|
|
32
|
+
isSubTree: (x) => typeof x === "object"
|
|
33
|
+
},
|
|
34
|
+
command: {
|
|
35
|
+
isLeaf: (x) => "handler" in x,
|
|
36
|
+
isSubTree: (x) => "subcommands" in x
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const zipTree = (defTree, implTree) => {
|
|
40
|
+
const tree = {};
|
|
41
|
+
for (const key in defTree) {
|
|
42
|
+
const def = defTree[key];
|
|
43
|
+
const impl = implTree[key];
|
|
44
|
+
if (guards.definition.isDef(def) && guards.implementation.isImpl(impl)) {
|
|
45
|
+
tree[key] = { ...def, handler: impl };
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (guards.definition.isSubTree(def) && guards.implementation.isSubTree(impl)) {
|
|
49
|
+
tree[key] = { ...def, subcommands: zipTree(def.subcommands, impl.subcommands) };
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return tree;
|
|
54
|
+
};
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
guards,
|
|
58
|
+
zipTree
|
|
59
|
+
});
|
package/dist/config.js
CHANGED
|
@@ -6,8 +6,8 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __export = (target, all) => {
|
|
9
|
-
for (var
|
|
10
|
-
__defProp(target,
|
|
9
|
+
for (var name2 in all)
|
|
10
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
11
11
|
};
|
|
12
12
|
var __copyProps = (to, from, except, desc) => {
|
|
13
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -35,6 +35,7 @@ __export(config_exports, {
|
|
|
35
35
|
devSchema: () => devSchema,
|
|
36
36
|
generateSchema: () => generateSchema,
|
|
37
37
|
globalSchema: () => globalSchema,
|
|
38
|
+
initSchema: () => initSchema,
|
|
38
39
|
integrationRef: () => integrationRef,
|
|
39
40
|
listBotsSchema: () => listBotsSchema,
|
|
40
41
|
listIntegrationsSchema: () => listIntegrationsSchema,
|
|
@@ -80,11 +81,6 @@ const entryPoint = {
|
|
|
80
81
|
description: "The entry point of the project",
|
|
81
82
|
default: consts.defaultEntrypoint
|
|
82
83
|
};
|
|
83
|
-
const definition = {
|
|
84
|
-
type: "string",
|
|
85
|
-
description: "The integration definition file to use. If file not found, the project is treated as a bot",
|
|
86
|
-
default: consts.defaultIntegrationConfigScript
|
|
87
|
-
};
|
|
88
84
|
const outDir = {
|
|
89
85
|
type: "string",
|
|
90
86
|
description: "The output directory",
|
|
@@ -125,6 +121,14 @@ const workspaceId = {
|
|
|
125
121
|
type: "string",
|
|
126
122
|
description: "The Workspace Id to deploy to"
|
|
127
123
|
};
|
|
124
|
+
const type = {
|
|
125
|
+
type: "string",
|
|
126
|
+
choices: ["bot", "integration"]
|
|
127
|
+
};
|
|
128
|
+
const name = {
|
|
129
|
+
type: "string",
|
|
130
|
+
description: "The name of the project"
|
|
131
|
+
};
|
|
128
132
|
const botRef = {
|
|
129
133
|
type: "string",
|
|
130
134
|
description: "The bot ID. Bot Name is not supported.",
|
|
@@ -144,7 +148,6 @@ const globalSchema = {
|
|
|
144
148
|
const projectSchema = {
|
|
145
149
|
...globalSchema,
|
|
146
150
|
entryPoint,
|
|
147
|
-
definition,
|
|
148
151
|
outDir,
|
|
149
152
|
workDir
|
|
150
153
|
};
|
|
@@ -224,6 +227,12 @@ const deleteIntegrationSchema = {
|
|
|
224
227
|
...globalSchema,
|
|
225
228
|
...loggedInSchema
|
|
226
229
|
};
|
|
230
|
+
const initSchema = {
|
|
231
|
+
...globalSchema,
|
|
232
|
+
workDir,
|
|
233
|
+
type,
|
|
234
|
+
name
|
|
235
|
+
};
|
|
227
236
|
// Annotate the CommonJS export names for ESM import in node:
|
|
228
237
|
0 && (module.exports = {
|
|
229
238
|
addSchema,
|
|
@@ -237,6 +246,7 @@ const deleteIntegrationSchema = {
|
|
|
237
246
|
devSchema,
|
|
238
247
|
generateSchema,
|
|
239
248
|
globalSchema,
|
|
249
|
+
initSchema,
|
|
240
250
|
integrationRef,
|
|
241
251
|
listBotsSchema,
|
|
242
252
|
listIntegrationsSchema,
|
package/dist/consts.js
CHANGED
|
@@ -28,10 +28,13 @@ __export(consts_exports, {
|
|
|
28
28
|
defaultBotpressApp: () => defaultBotpressApp,
|
|
29
29
|
defaultBotpressHome: () => defaultBotpressHome,
|
|
30
30
|
defaultEntrypoint: () => defaultEntrypoint,
|
|
31
|
-
defaultIntegrationConfigScript: () => defaultIntegrationConfigScript,
|
|
32
31
|
defaultOutputFolder: () => defaultOutputFolder,
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
echoBotName: () => echoBotName,
|
|
33
|
+
emptyIntegrationName: () => emptyIntegrationName,
|
|
34
|
+
fromCliRootDir: () => fromCliRootDir,
|
|
35
|
+
fromHomeDir: () => fromHomeDir,
|
|
36
|
+
fromOutDir: () => fromOutDir,
|
|
37
|
+
fromWorkDir: () => fromWorkDir
|
|
35
38
|
});
|
|
36
39
|
module.exports = __toCommonJS(consts_exports);
|
|
37
40
|
var import_os = __toESM(require("os"));
|
|
@@ -39,13 +42,22 @@ var import_path = __toESM(require("path"));
|
|
|
39
42
|
const defaultBotpressHome = import_path.default.join(import_os.default.homedir(), ".botpress");
|
|
40
43
|
const defaultOutputFolder = ".botpress";
|
|
41
44
|
const defaultEntrypoint = import_path.default.join("src", "index.ts");
|
|
42
|
-
const defaultIntegrationConfigScript = "integration.definition.ts";
|
|
43
45
|
const defaultBotpressApi = "https://api.botpress.cloud";
|
|
44
46
|
const defaultBotpressApp = "https://app.botpress.cloud";
|
|
45
|
-
const
|
|
47
|
+
const echoBotName = "echo-bot";
|
|
48
|
+
const emptyIntegrationName = "empty-integration";
|
|
49
|
+
const fromCliRootDir = {
|
|
50
|
+
packageJson: "package.json",
|
|
51
|
+
echoBotTemplate: import_path.default.join("templates", echoBotName),
|
|
52
|
+
emptyIntegrationTemplate: import_path.default.join("templates", emptyIntegrationName)
|
|
53
|
+
};
|
|
54
|
+
const fromHomeDir = {
|
|
46
55
|
userCacheFile: "user.cache.json"
|
|
47
56
|
};
|
|
48
|
-
const
|
|
57
|
+
const fromWorkDir = {
|
|
58
|
+
definition: "integration.definition.ts"
|
|
59
|
+
};
|
|
60
|
+
const fromOutDir = {
|
|
49
61
|
distDir: "dist",
|
|
50
62
|
outFile: import_path.default.join("dist", "index.js"),
|
|
51
63
|
installDir: "installations",
|
|
@@ -58,8 +70,11 @@ const relativeToOutFolder = {
|
|
|
58
70
|
defaultBotpressApp,
|
|
59
71
|
defaultBotpressHome,
|
|
60
72
|
defaultEntrypoint,
|
|
61
|
-
defaultIntegrationConfigScript,
|
|
62
73
|
defaultOutputFolder,
|
|
63
|
-
|
|
64
|
-
|
|
74
|
+
echoBotName,
|
|
75
|
+
emptyIntegrationName,
|
|
76
|
+
fromCliRootDir,
|
|
77
|
+
fromHomeDir,
|
|
78
|
+
fromOutDir,
|
|
79
|
+
fromWorkDir
|
|
65
80
|
});
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
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 errors_exports = {};
|
|
26
|
+
__export(errors_exports, {
|
|
27
|
+
BotpressCLIError: () => BotpressCLIError,
|
|
28
|
+
ExclusiveBotFeatureError: () => ExclusiveBotFeatureError,
|
|
29
|
+
ExclusiveIntegrationFeatureError: () => ExclusiveIntegrationFeatureError,
|
|
30
|
+
HTTPError: () => HTTPError,
|
|
31
|
+
InvalidIntegrationReferenceError: () => InvalidIntegrationReferenceError,
|
|
32
|
+
NoBotsFoundError: () => NoBotsFoundError,
|
|
33
|
+
NoBundleFoundError: () => NoBundleFoundError,
|
|
34
|
+
NoWorkspacesFoundError: () => NoWorkspacesFoundError,
|
|
35
|
+
NotLoggedInError: () => NotLoggedInError,
|
|
36
|
+
ParamRequiredError: () => ParamRequiredError
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(errors_exports);
|
|
39
|
+
var import_client = require("@botpress/client");
|
|
40
|
+
var import_axios = __toESM(require("axios"));
|
|
41
|
+
var import_verror = require("verror");
|
|
42
|
+
var consts = __toESM(require("./consts"));
|
|
43
|
+
const isKnownApiError = (e) => (0, import_client.isApiError)(e) && !(e instanceof import_client.UnknownError);
|
|
44
|
+
class BotpressCLIError extends import_verror.VError {
|
|
45
|
+
static wrap(thrown, message) {
|
|
46
|
+
const err = BotpressCLIError.map(thrown);
|
|
47
|
+
return new BotpressCLIError(err, message ?? "");
|
|
48
|
+
}
|
|
49
|
+
static map(thrown) {
|
|
50
|
+
if (thrown instanceof import_client.UnknownError) {
|
|
51
|
+
return new HTTPError(500, "An unknown error has occurred.");
|
|
52
|
+
}
|
|
53
|
+
if (isKnownApiError(thrown)) {
|
|
54
|
+
return HTTPError.fromApi(thrown);
|
|
55
|
+
}
|
|
56
|
+
if (import_axios.default.isAxiosError(thrown)) {
|
|
57
|
+
return HTTPError.fromAxios(thrown);
|
|
58
|
+
}
|
|
59
|
+
if (thrown instanceof Error) {
|
|
60
|
+
const { message } = thrown;
|
|
61
|
+
return new BotpressCLIError(message);
|
|
62
|
+
}
|
|
63
|
+
return new BotpressCLIError(`${thrown}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
class ExclusiveBotFeatureError extends BotpressCLIError {
|
|
67
|
+
constructor() {
|
|
68
|
+
const message = "This feature is only available for bots. This project is an integration";
|
|
69
|
+
super(message);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
class ExclusiveIntegrationFeatureError extends BotpressCLIError {
|
|
73
|
+
constructor() {
|
|
74
|
+
const message = "This feature is only available for integration. This project is a bot";
|
|
75
|
+
super(message);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
class HTTPError extends BotpressCLIError {
|
|
79
|
+
constructor(status, message) {
|
|
80
|
+
super(message);
|
|
81
|
+
this.status = status;
|
|
82
|
+
}
|
|
83
|
+
static fromAxios(e) {
|
|
84
|
+
const message = this._axiosMsg(e);
|
|
85
|
+
return new HTTPError(e.response?.status, message);
|
|
86
|
+
}
|
|
87
|
+
static fromApi(e) {
|
|
88
|
+
const { message, code } = e;
|
|
89
|
+
return new HTTPError(code, message);
|
|
90
|
+
}
|
|
91
|
+
static _axiosMsg(e) {
|
|
92
|
+
let message = e.message;
|
|
93
|
+
if (e.response?.statusText) {
|
|
94
|
+
message += `
|
|
95
|
+
${e.response?.statusText}`;
|
|
96
|
+
}
|
|
97
|
+
if (e.response?.status && e.request?.method && e.request?.path) {
|
|
98
|
+
message += `
|
|
99
|
+
(${e.response?.status}) ${e.request.method} ${e.request.path}`;
|
|
100
|
+
}
|
|
101
|
+
if (e.response?.data?.message) {
|
|
102
|
+
message += `
|
|
103
|
+
${e.response?.data?.message}`;
|
|
104
|
+
}
|
|
105
|
+
return message;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
class NoBundleFoundError extends BotpressCLIError {
|
|
109
|
+
constructor() {
|
|
110
|
+
const message = "No bundle found. Please run `bp bundle` first.";
|
|
111
|
+
super(message);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
class NoBotsFoundError extends BotpressCLIError {
|
|
115
|
+
constructor() {
|
|
116
|
+
const message = `No Bot found in your Workspace. Please create one first at ${consts.defaultBotpressApp}.`;
|
|
117
|
+
super(message);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
class NoWorkspacesFoundError extends BotpressCLIError {
|
|
121
|
+
constructor() {
|
|
122
|
+
const message = "No Workspace found. Please create one first.";
|
|
123
|
+
super(message);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
class NotLoggedInError extends BotpressCLIError {
|
|
127
|
+
constructor() {
|
|
128
|
+
const message = "Not logged in. Please run `bp login` first.";
|
|
129
|
+
super(message);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
class ParamRequiredError extends BotpressCLIError {
|
|
133
|
+
constructor(param) {
|
|
134
|
+
const message = `${param} is required.`;
|
|
135
|
+
super(message);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
class InvalidIntegrationReferenceError extends BotpressCLIError {
|
|
139
|
+
constructor(ref) {
|
|
140
|
+
const message = `Invalid integration reference "${ref}".`;
|
|
141
|
+
super(message);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
145
|
+
0 && (module.exports = {
|
|
146
|
+
BotpressCLIError,
|
|
147
|
+
ExclusiveBotFeatureError,
|
|
148
|
+
ExclusiveIntegrationFeatureError,
|
|
149
|
+
HTTPError,
|
|
150
|
+
InvalidIntegrationReferenceError,
|
|
151
|
+
NoBotsFoundError,
|
|
152
|
+
NoBundleFoundError,
|
|
153
|
+
NoWorkspacesFoundError,
|
|
154
|
+
NotLoggedInError,
|
|
155
|
+
ParamRequiredError
|
|
156
|
+
});
|