@botpress/cli 0.0.9 → 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.
Files changed (86) hide show
  1. package/dist/api-client.js +107 -0
  2. package/dist/app/api-utils.js +9 -3
  3. package/dist/app/base.js +1 -3
  4. package/dist/app/errors.js +8 -0
  5. package/dist/app/file-paths.js +4 -2
  6. package/dist/app/index.js +17 -12
  7. package/dist/app/user.js +73 -23
  8. package/dist/code-generation/action.js +70 -0
  9. package/dist/code-generation/channel.js +51 -0
  10. package/dist/code-generation/configuration.js +40 -0
  11. package/dist/code-generation/const.js +31 -0
  12. package/dist/code-generation/event.js +41 -0
  13. package/dist/code-generation/index.js +80 -0
  14. package/dist/code-generation/integration-impl.js +147 -0
  15. package/dist/code-generation/integration-instance.js +79 -0
  16. package/dist/code-generation/message.js +41 -0
  17. package/dist/code-generation/module.js +115 -0
  18. package/dist/code-generation/typings.js +16 -0
  19. package/dist/command-definitions.js +61 -0
  20. package/dist/command-implementations/add-command.js +124 -0
  21. package/dist/command-implementations/base-command.js +53 -0
  22. package/dist/command-implementations/bot-commands.js +89 -0
  23. package/dist/command-implementations/build-command.js +48 -0
  24. package/dist/command-implementations/bundle-command.js +58 -0
  25. package/dist/command-implementations/deploy-command.js +162 -0
  26. package/dist/command-implementations/dev-command.js +168 -0
  27. package/dist/command-implementations/gen-command.js +58 -0
  28. package/dist/command-implementations/global-command.js +111 -0
  29. package/dist/command-implementations/index.js +78 -0
  30. package/dist/command-implementations/init-command.js +85 -0
  31. package/dist/command-implementations/integration-commands.js +107 -0
  32. package/dist/command-implementations/login-command.js +75 -0
  33. package/dist/command-implementations/logout-command.js +34 -0
  34. package/dist/command-implementations/project-command.js +115 -0
  35. package/dist/command-implementations/serve-command.js +53 -0
  36. package/dist/command-tree.js +59 -0
  37. package/dist/config.js +18 -2
  38. package/dist/consts.js +13 -0
  39. package/dist/errors.js +156 -0
  40. package/dist/index.js +33 -20
  41. package/dist/integration-ref.js +61 -0
  42. package/dist/path-utils.js +6 -0
  43. package/dist/register-yargs.js +85 -0
  44. package/dist/typings.js +16 -0
  45. package/dist/utils/cache-utils.js +99 -0
  46. package/dist/utils/esbuild-utils.js +89 -0
  47. package/dist/utils/event-emitter.js +62 -0
  48. package/dist/utils/file-watcher.js +68 -0
  49. package/dist/utils/index.js +55 -0
  50. package/dist/utils/path-utils.js +83 -0
  51. package/dist/utils/prompt-utils.js +75 -0
  52. package/dist/utils/require-utils.js +49 -0
  53. package/dist/utils/string-utils.js +38 -0
  54. package/package.json +6 -4
  55. package/templates/echo-bot/.botpress/project.cache.json +1 -0
  56. package/templates/echo-bot/package.json +22 -0
  57. package/templates/echo-bot/readme.md +5 -0
  58. package/templates/echo-bot/src/index.ts +44 -0
  59. package/templates/echo-bot/tsconfig.json +15 -0
  60. package/templates/empty-integration/.botpress/implementation/actions/index.ts +7 -0
  61. package/templates/empty-integration/.botpress/implementation/channels/channel/audio.ts +10 -0
  62. package/templates/empty-integration/.botpress/implementation/channels/channel/card.ts +17 -0
  63. package/templates/empty-integration/.botpress/implementation/channels/channel/carousel.ts +19 -0
  64. package/templates/empty-integration/.botpress/implementation/channels/channel/choice.ts +14 -0
  65. package/templates/empty-integration/.botpress/implementation/channels/channel/dropdown.ts +14 -0
  66. package/templates/empty-integration/.botpress/implementation/channels/channel/file.ts +11 -0
  67. package/templates/empty-integration/.botpress/implementation/channels/channel/image.ts +10 -0
  68. package/templates/empty-integration/.botpress/implementation/channels/channel/index.ts +40 -0
  69. package/templates/empty-integration/.botpress/implementation/channels/channel/location.ts +11 -0
  70. package/templates/empty-integration/.botpress/implementation/channels/channel/markdown.ts +10 -0
  71. package/templates/empty-integration/.botpress/implementation/channels/channel/text.ts +10 -0
  72. package/templates/empty-integration/.botpress/implementation/channels/channel/video.ts +10 -0
  73. package/templates/empty-integration/.botpress/implementation/channels/index.ts +10 -0
  74. package/templates/empty-integration/.botpress/implementation/configuration.ts +10 -0
  75. package/templates/empty-integration/.botpress/implementation/events/index.ts +7 -0
  76. package/templates/empty-integration/.botpress/implementation/index.ts +17 -0
  77. package/templates/empty-integration/.botpress/index.ts +1 -0
  78. package/templates/empty-integration/.botpress/project.cache.json +1 -0
  79. package/templates/empty-integration/integration.definition.ts +13 -0
  80. package/templates/empty-integration/package.json +22 -0
  81. package/templates/empty-integration/readme.md +5 -0
  82. package/templates/empty-integration/src/index.ts +58 -0
  83. package/templates/empty-integration/tsconfig.json +15 -0
  84. package/.ignore.me.github/index.ts +0 -38
  85. package/dist/github-download.js +0 -159
  86. package/dist/github-fetch.js +0 -173
@@ -0,0 +1,111 @@
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 global_command_exports = {};
26
+ __export(global_command_exports, {
27
+ GlobalCommand: () => GlobalCommand
28
+ });
29
+ module.exports = __toCommonJS(global_command_exports);
30
+ var import_chalk = __toESM(require("chalk"));
31
+ var import_fs = __toESM(require("fs"));
32
+ var import_latest_version = __toESM(require("latest-version"));
33
+ var import_lodash = __toESM(require("lodash"));
34
+ var pathlib = __toESM(require("path"));
35
+ var consts = __toESM(require("../consts"));
36
+ var errors = __toESM(require("../errors"));
37
+ var utils = __toESM(require("../utils"));
38
+ var import_base_command = require("./base-command");
39
+ class GlobalPaths extends utils.path.PathStore {
40
+ constructor(argv) {
41
+ const absBotpressHome = utils.path.absoluteFrom(utils.path.cwd(), argv.botpressHome);
42
+ super({
43
+ cliRootDir: argv.cliRootDir,
44
+ botpressHomeDir: absBotpressHome,
45
+ ...import_lodash.default.mapValues(consts.fromHomeDir, (p) => utils.path.absoluteFrom(absBotpressHome, p)),
46
+ ...import_lodash.default.mapValues(consts.fromCliRootDir, (p) => utils.path.absoluteFrom(argv.cliRootDir, p))
47
+ });
48
+ }
49
+ }
50
+ const UPDATE_MSG = (props) => `${import_chalk.default.bold("Update available")} ${import_chalk.default.dim(props.version)} \u2192 ${import_chalk.default.green(props.latest)}
51
+
52
+ To update, run:
53
+ for npm ${import_chalk.default.cyan(`npm i -g ${props.name}`)}
54
+ for yarn ${import_chalk.default.cyan(`yarn global add ${props.name}`)}
55
+ for pnpm ${import_chalk.default.cyan(`pnpm i -g ${props.name}`)}`;
56
+ class GlobalCommand extends import_base_command.BaseCommand {
57
+ api;
58
+ prompt;
59
+ constructor(api, prompt, ...args) {
60
+ super(...args);
61
+ this.api = api;
62
+ this.prompt = prompt;
63
+ }
64
+ get globalPaths() {
65
+ return new GlobalPaths(this.argv);
66
+ }
67
+ get globalCache() {
68
+ return new utils.cache.FSKeyValueCache(this.globalPaths.abs.globalCacheFile);
69
+ }
70
+ bootstrap = async () => {
71
+ const pkgJson = await this._readPackageJson();
72
+ const versionText = import_chalk.default.bold(`v${pkgJson.version}`);
73
+ this.logger.log(`Botpress CLI ${versionText}`, { prefix: "\u{1F916}" });
74
+ await this._notifyUpdate(pkgJson);
75
+ const paths = this.globalPaths;
76
+ if (paths.abs.botpressHomeDir !== consts.defaultBotpressHome) {
77
+ this.logger.log(`Using custom botpress home: ${paths.abs.botpressHomeDir}`, { prefix: "\u{1F3E0}" });
78
+ }
79
+ };
80
+ async ensureLoginAndCreateClient(credentials) {
81
+ const cache = this.globalCache;
82
+ const token = await cache.get("token");
83
+ const workspaceId = credentials.workspaceId ?? await cache.get("workspaceId");
84
+ const host = credentials.host ?? await cache.get("host");
85
+ if (!(token && workspaceId && host)) {
86
+ throw new errors.NotLoggedInError();
87
+ }
88
+ return this.api.newClient({ host, token, workspaceId }, this.logger);
89
+ }
90
+ _notifyUpdate = async (pkgJson) => {
91
+ try {
92
+ const latest = await (0, import_latest_version.default)(pkgJson.name);
93
+ if (latest !== pkgJson.version) {
94
+ this.logger.box(UPDATE_MSG({ ...pkgJson, latest }));
95
+ }
96
+ } catch (thrown) {
97
+ const err = errors.BotpressCLIError.map(thrown);
98
+ this.logger.debug(`Failed to check for updates: ${err.message}`);
99
+ }
100
+ };
101
+ _readPackageJson = async () => {
102
+ const path = pathlib.join(this.globalPaths.abs.cliRootDir, "package.json");
103
+ const strContent = await import_fs.default.promises.readFile(path, "utf8");
104
+ const jsonContent = JSON.parse(strContent);
105
+ return jsonContent;
106
+ };
107
+ }
108
+ // Annotate the CommonJS export names for ESM import in node:
109
+ 0 && (module.exports = {
110
+ GlobalCommand
111
+ });
@@ -0,0 +1,78 @@
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 command_implementations_exports = {};
26
+ __export(command_implementations_exports, {
27
+ default: () => command_implementations_default
28
+ });
29
+ module.exports = __toCommonJS(command_implementations_exports);
30
+ var import_api_client = require("../api-client");
31
+ var import_logger = require("../logger");
32
+ var utils = __toESM(require("../utils"));
33
+ var import_add_command = require("./add-command");
34
+ var bots = __toESM(require("./bot-commands"));
35
+ var import_build_command = require("./build-command");
36
+ var import_bundle_command = require("./bundle-command");
37
+ var import_deploy_command = require("./deploy-command");
38
+ var import_dev_command = require("./dev-command");
39
+ var import_gen_command = require("./gen-command");
40
+ var import_init_command = require("./init-command");
41
+ var integrations = __toESM(require("./integration-commands"));
42
+ var import_login_command = require("./login-command");
43
+ var import_logout_command = require("./logout-command");
44
+ var import_serve_command = require("./serve-command");
45
+ const getHandler = (cls) => async (argv) => {
46
+ const logger = new import_logger.Logger(argv);
47
+ const prompt = new utils.prompt.CLIPrompt(argv, logger);
48
+ return new cls(import_api_client.ApiClient, prompt, logger, argv).handler();
49
+ };
50
+ var command_implementations_default = {
51
+ login: getHandler(import_login_command.LoginCommand),
52
+ logout: getHandler(import_logout_command.LogoutCommand),
53
+ bots: {
54
+ subcommands: {
55
+ create: getHandler(bots.CreateBotCommand),
56
+ get: getHandler(bots.GetBotCommand),
57
+ delete: getHandler(bots.DeleteBotCommand),
58
+ list: getHandler(bots.ListBotsCommand)
59
+ }
60
+ },
61
+ integrations: {
62
+ subcommands: {
63
+ get: getHandler(integrations.GetIntegrationCommand),
64
+ list: getHandler(integrations.ListIntegrationsCommand),
65
+ delete: getHandler(integrations.DeleteIntegrationCommand)
66
+ }
67
+ },
68
+ init: getHandler(import_init_command.InitCommand),
69
+ generate: getHandler(import_gen_command.GenerateCommand),
70
+ bundle: getHandler(import_bundle_command.BundleCommand),
71
+ build: getHandler(import_build_command.BuildCommand),
72
+ serve: getHandler(import_serve_command.ServeCommand),
73
+ deploy: getHandler(import_deploy_command.DeployCommand),
74
+ add: getHandler(import_add_command.AddCommand),
75
+ dev: getHandler(import_dev_command.DevCommand)
76
+ };
77
+ // Annotate the CommonJS export names for ESM import in node:
78
+ 0 && (module.exports = {});
@@ -0,0 +1,85 @@
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 init_command_exports = {};
26
+ __export(init_command_exports, {
27
+ InitCommand: () => InitCommand
28
+ });
29
+ module.exports = __toCommonJS(init_command_exports);
30
+ var import_chalk = __toESM(require("chalk"));
31
+ var fs = __toESM(require("fs"));
32
+ var pathlib = __toESM(require("path"));
33
+ var consts = __toESM(require("../consts"));
34
+ var errors = __toESM(require("../errors"));
35
+ var utils = __toESM(require("../utils"));
36
+ var import_global_command = require("./global-command");
37
+ class InitCommand extends import_global_command.GlobalCommand {
38
+ async run() {
39
+ let { type: projectType } = this.argv;
40
+ if (!projectType) {
41
+ const promptedType = await this.prompt.select("What type of project do you wish to initialize?", {
42
+ choices: ["bot", "integration"].map((t) => ({ title: t, value: t }))
43
+ });
44
+ if (!promptedType) {
45
+ throw new errors.ParamRequiredError("Project Type");
46
+ }
47
+ projectType = promptedType;
48
+ }
49
+ const workDir = utils.path.absoluteFrom(utils.path.cwd(), this.argv.workDir);
50
+ if (projectType === "bot") {
51
+ const destination2 = pathlib.join(workDir, this.argv.name ?? consts.echoBotName);
52
+ const exist2 = await this._checkIfDestinationExists(destination2);
53
+ if (exist2) {
54
+ return;
55
+ }
56
+ await fs.promises.cp(this.globalPaths.abs.echoBotTemplate, destination2, { recursive: true });
57
+ this.logger.success(`Bot project initialized in ${import_chalk.default.bold(workDir)}`);
58
+ return;
59
+ }
60
+ const destination = pathlib.join(workDir, this.argv.name ?? consts.emptyIntegrationName);
61
+ const exist = await this._checkIfDestinationExists(destination);
62
+ if (exist) {
63
+ return;
64
+ }
65
+ await fs.promises.cp(this.globalPaths.abs.emptyIntegrationTemplate, destination, { recursive: true });
66
+ this.logger.success(`Integration project initialized in ${import_chalk.default.bold(this.argv.workDir)}`);
67
+ return;
68
+ }
69
+ _checkIfDestinationExists = async (destination) => {
70
+ if (fs.existsSync(destination)) {
71
+ const override = await this.prompt.confirm(
72
+ `Directory ${import_chalk.default.bold(destination)} already exists. Do you want to overwrite it?`
73
+ );
74
+ if (!override) {
75
+ this.logger.log("Aborting");
76
+ return true;
77
+ }
78
+ }
79
+ return false;
80
+ };
81
+ }
82
+ // Annotate the CommonJS export names for ESM import in node:
83
+ 0 && (module.exports = {
84
+ InitCommand
85
+ });
@@ -0,0 +1,107 @@
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 integration_commands_exports = {};
26
+ __export(integration_commands_exports, {
27
+ DeleteIntegrationCommand: () => DeleteIntegrationCommand,
28
+ GetIntegrationCommand: () => GetIntegrationCommand,
29
+ ListIntegrationsCommand: () => ListIntegrationsCommand
30
+ });
31
+ module.exports = __toCommonJS(integration_commands_exports);
32
+ var import_chalk = __toESM(require("chalk"));
33
+ var import_lodash = __toESM(require("lodash"));
34
+ var errors = __toESM(require("../errors"));
35
+ var import_integration_ref = require("../integration-ref");
36
+ var import_global_command = require("./global-command");
37
+ class GetIntegrationCommand extends import_global_command.GlobalCommand {
38
+ async run() {
39
+ const api = await this.ensureLoginAndCreateClient(this.argv);
40
+ const parsedRef = (0, import_integration_ref.parseIntegrationRef)(this.argv.integrationRef);
41
+ if (!parsedRef) {
42
+ throw new errors.InvalidIntegrationReferenceError(this.argv.integrationRef);
43
+ }
44
+ try {
45
+ const integration = await api.findIntegration(parsedRef);
46
+ if (integration) {
47
+ this.logger.success(`Integration ${import_chalk.default.bold(this.argv.integrationRef)}:`);
48
+ this.logger.json(integration);
49
+ return;
50
+ }
51
+ } catch (thrown) {
52
+ throw errors.BotpressCLIError.wrap(thrown, `Could not get integration ${this.argv.integrationRef}`);
53
+ }
54
+ throw new errors.BotpressCLIError(`Integration ${this.argv.integrationRef} not found`);
55
+ }
56
+ }
57
+ class ListIntegrationsCommand extends import_global_command.GlobalCommand {
58
+ async run() {
59
+ const api = await this.ensureLoginAndCreateClient(this.argv);
60
+ const privateLister = (req) => api.client.listIntegrations({ nextToken: req.nextToken, name: this.argv.name, version: this.argv.version });
61
+ const publicLister = (req) => api.client.listPublicIntegrations({ nextToken: req.nextToken, name: this.argv.name, version: this.argv.version });
62
+ try {
63
+ const privateIntegrations = await api.listAllPages(privateLister, (r) => r.integrations);
64
+ const publicIntegrations = await api.listAllPages(publicLister, (r) => r.integrations);
65
+ const integrations = import_lodash.default.uniqBy([...privateIntegrations, ...publicIntegrations], (i) => i.id);
66
+ this.logger.success("Integrations:");
67
+ this.logger.json(integrations);
68
+ } catch (thrown) {
69
+ throw errors.BotpressCLIError.wrap(thrown, "Could not list integrations");
70
+ }
71
+ }
72
+ }
73
+ class DeleteIntegrationCommand extends import_global_command.GlobalCommand {
74
+ async run() {
75
+ const api = await this.ensureLoginAndCreateClient(this.argv);
76
+ const parsedRef = (0, import_integration_ref.parseIntegrationRef)(this.argv.integrationRef);
77
+ if (!parsedRef) {
78
+ throw new errors.InvalidIntegrationReferenceError(this.argv.integrationRef);
79
+ }
80
+ let integration;
81
+ try {
82
+ integration = await api.findPrivateIntegration(parsedRef);
83
+ } catch (thrown) {
84
+ throw errors.BotpressCLIError.wrap(thrown, `Could not get integration ${this.argv.integrationRef}`);
85
+ }
86
+ if (!integration) {
87
+ const publicIntegration = await api.findPublicIntegration(parsedRef);
88
+ if (publicIntegration) {
89
+ throw new errors.BotpressCLIError(`Integration ${this.argv.integrationRef} does not belong to your workspace`);
90
+ }
91
+ throw new errors.BotpressCLIError(`Integration ${this.argv.integrationRef} not found`);
92
+ }
93
+ try {
94
+ await api.client.deleteIntegration({ id: integration.id });
95
+ } catch (thrown) {
96
+ throw errors.BotpressCLIError.wrap(thrown, `Could not delete integration ${this.argv.integrationRef}`);
97
+ }
98
+ this.logger.success(`Integration ${import_chalk.default.bold(this.argv.integrationRef)} deleted`);
99
+ return;
100
+ }
101
+ }
102
+ // Annotate the CommonJS export names for ESM import in node:
103
+ 0 && (module.exports = {
104
+ DeleteIntegrationCommand,
105
+ GetIntegrationCommand,
106
+ ListIntegrationsCommand
107
+ });
@@ -0,0 +1,75 @@
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 login_command_exports = {};
26
+ __export(login_command_exports, {
27
+ LoginCommand: () => LoginCommand
28
+ });
29
+ module.exports = __toCommonJS(login_command_exports);
30
+ var errors = __toESM(require("../errors"));
31
+ var import_global_command = require("./global-command");
32
+ class LoginCommand extends import_global_command.GlobalCommand {
33
+ async run() {
34
+ const promptedToken = await this.globalCache.sync("token", this.argv.token, async (previousToken) => {
35
+ const prompted = await this.prompt.password("Enter your Personal Access Token", {
36
+ initial: previousToken
37
+ });
38
+ if (!prompted) {
39
+ throw new errors.ParamRequiredError("Personal Access Token");
40
+ }
41
+ return prompted;
42
+ });
43
+ const promptedWorkspaceId = await this.globalCache.sync("workspaceId", this.argv.workspaceId, async (defaultId) => {
44
+ const tmpApi = this.api.newClient({ host: this.argv.host, token: promptedToken }, this.logger);
45
+ const userWorkspaces = await tmpApi.listAllPages(tmpApi.client.listWorkspaces, (r) => r.workspaces).catch((thrown) => {
46
+ throw errors.BotpressCLIError.wrap(thrown, "Could not list workspaces");
47
+ });
48
+ if (userWorkspaces.length === 0) {
49
+ throw new errors.NoWorkspacesFoundError();
50
+ }
51
+ const initial = userWorkspaces.find((ws) => ws.id === defaultId);
52
+ const prompted = await this.prompt.select("Which workspace do you want to login to?", {
53
+ initial: initial && { title: initial.name, value: initial.id },
54
+ choices: userWorkspaces.map((ws) => ({ title: ws.name, value: ws.id }))
55
+ });
56
+ if (!prompted) {
57
+ throw new errors.ParamRequiredError("Workspace Id");
58
+ }
59
+ return prompted;
60
+ });
61
+ await this.globalCache.set("host", this.argv.host);
62
+ const api = this.api.newClient(
63
+ { host: this.argv.host, token: promptedToken, workspaceId: promptedWorkspaceId },
64
+ this.logger
65
+ );
66
+ await api.testLogin().catch((thrown) => {
67
+ throw errors.BotpressCLIError.wrap(thrown, "Login failed. Please check your credentials");
68
+ });
69
+ this.logger.success("Logged In");
70
+ }
71
+ }
72
+ // Annotate the CommonJS export names for ESM import in node:
73
+ 0 && (module.exports = {
74
+ LoginCommand
75
+ });
@@ -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
+ });