@botpress/cli 2.1.1 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +22 -0
- package/dist/api/bot-body.js +89 -0
- package/dist/api/bot-body.js.map +7 -0
- package/dist/api/client.js +169 -0
- package/dist/api/client.js.map +7 -0
- package/dist/api/find-previous-version.js +66 -0
- package/dist/api/find-previous-version.js.map +7 -0
- package/dist/api/find-previous-version.test.js +76 -0
- package/dist/api/find-previous-version.test.js.map +7 -0
- package/dist/api/index.js +23 -0
- package/dist/api/index.js.map +7 -0
- package/dist/api/integration-body.js +146 -0
- package/dist/api/integration-body.js.map +7 -0
- package/dist/api/interface-body.js +95 -0
- package/dist/api/interface-body.js.map +7 -0
- package/dist/api/paging.js +42 -0
- package/dist/api/paging.js.map +7 -0
- package/dist/api/plugin-body.js +84 -0
- package/dist/api/plugin-body.js.map +7 -0
- package/dist/api/types.js +17 -0
- package/dist/api/types.js.map +7 -0
- package/dist/chat/index.js +211 -0
- package/dist/chat/index.js.map +7 -0
- package/dist/code-generation/bot-implementation/bot-implementation.js +116 -0
- package/dist/code-generation/bot-implementation/bot-implementation.js.map +7 -0
- package/dist/code-generation/bot-implementation/bot-plugins/index.js +80 -0
- package/dist/code-generation/bot-implementation/bot-plugins/index.js.map +7 -0
- package/dist/code-generation/bot-implementation/bot-plugins/plugin-module.js +129 -0
- package/dist/code-generation/bot-implementation/bot-plugins/plugin-module.js.map +7 -0
- package/dist/code-generation/bot-implementation/bot-typings/actions-module.js +88 -0
- package/dist/code-generation/bot-implementation/bot-typings/actions-module.js.map +7 -0
- package/dist/code-generation/bot-implementation/bot-typings/events-module.js +63 -0
- package/dist/code-generation/bot-implementation/bot-typings/events-module.js.map +7 -0
- package/dist/code-generation/bot-implementation/bot-typings/index.js +109 -0
- package/dist/code-generation/bot-implementation/bot-typings/index.js.map +7 -0
- package/dist/code-generation/bot-implementation/bot-typings/states-module.js +64 -0
- package/dist/code-generation/bot-implementation/bot-typings/states-module.js.map +7 -0
- package/dist/code-generation/bot-implementation/index.js +66 -0
- package/dist/code-generation/bot-implementation/index.js.map +7 -0
- package/dist/code-generation/consts.js +45 -0
- package/dist/code-generation/consts.js.map +7 -0
- package/dist/code-generation/generators.js +81 -0
- package/dist/code-generation/generators.js.map +7 -0
- package/dist/code-generation/index.js +49 -0
- package/dist/code-generation/index.js.map +7 -0
- package/dist/code-generation/integration-implementation/index.js +70 -0
- package/dist/code-generation/integration-implementation/index.js.map +7 -0
- package/dist/code-generation/integration-implementation/integration-implementation.js +114 -0
- package/dist/code-generation/integration-implementation/integration-implementation.js.map +7 -0
- package/dist/code-generation/integration-implementation/integration-secret.js +78 -0
- package/dist/code-generation/integration-implementation/integration-secret.js.map +7 -0
- package/dist/code-generation/integration-implementation/integration-typings/actions-module.js +88 -0
- package/dist/code-generation/integration-implementation/integration-typings/actions-module.js.map +7 -0
- package/dist/code-generation/integration-implementation/integration-typings/channels-module.js +107 -0
- package/dist/code-generation/integration-implementation/integration-typings/channels-module.js.map +7 -0
- package/dist/code-generation/integration-implementation/integration-typings/configuration-module.js +62 -0
- package/dist/code-generation/integration-implementation/integration-typings/configuration-module.js.map +7 -0
- package/dist/code-generation/integration-implementation/integration-typings/configurations-module.js +70 -0
- package/dist/code-generation/integration-implementation/integration-typings/configurations-module.js.map +7 -0
- package/dist/code-generation/integration-implementation/integration-typings/entities-module.js +63 -0
- package/dist/code-generation/integration-implementation/integration-typings/entities-module.js.map +7 -0
- package/dist/code-generation/integration-implementation/integration-typings/events-module.js +63 -0
- package/dist/code-generation/integration-implementation/integration-typings/events-module.js.map +7 -0
- package/dist/code-generation/integration-implementation/integration-typings/index.js +128 -0
- package/dist/code-generation/integration-implementation/integration-typings/index.js.map +7 -0
- package/dist/code-generation/integration-implementation/integration-typings/states-module.js +64 -0
- package/dist/code-generation/integration-implementation/integration-typings/states-module.js.map +7 -0
- package/dist/code-generation/integration-package/index.js +94 -0
- package/dist/code-generation/integration-package/index.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/actions-module.js +88 -0
- package/dist/code-generation/integration-package/integration-package-definition/actions-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/channels-module.js +107 -0
- package/dist/code-generation/integration-package/integration-package-definition/channels-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/configuration-module.js +63 -0
- package/dist/code-generation/integration-package/integration-package-definition/configuration-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/configurations-module.js +70 -0
- package/dist/code-generation/integration-package/integration-package-definition/configurations-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/entities-module.js +63 -0
- package/dist/code-generation/integration-package/integration-package-definition/entities-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/events-module.js +66 -0
- package/dist/code-generation/integration-package/integration-package-definition/events-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/index.js +140 -0
- package/dist/code-generation/integration-package/integration-package-definition/index.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/states-module.js +66 -0
- package/dist/code-generation/integration-package/integration-package-definition/states-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/typings.js +17 -0
- package/dist/code-generation/integration-package/integration-package-definition/typings.js.map +7 -0
- package/dist/code-generation/interface-implementation/index.js +29 -0
- package/dist/code-generation/interface-implementation/index.js.map +7 -0
- package/dist/code-generation/interface-implementation/integration-typings/actions-module.js +88 -0
- package/dist/code-generation/interface-implementation/integration-typings/actions-module.js.map +7 -0
- package/dist/code-generation/interface-implementation/integration-typings/channels-module.js +107 -0
- package/dist/code-generation/interface-implementation/integration-typings/channels-module.js.map +7 -0
- package/dist/code-generation/interface-implementation/integration-typings/entities-module.js +63 -0
- package/dist/code-generation/interface-implementation/integration-typings/entities-module.js.map +7 -0
- package/dist/code-generation/interface-implementation/integration-typings/events-module.js +63 -0
- package/dist/code-generation/interface-implementation/integration-typings/events-module.js.map +7 -0
- package/dist/code-generation/interface-implementation/integration-typings/index.js +121 -0
- package/dist/code-generation/interface-implementation/integration-typings/index.js.map +7 -0
- package/dist/code-generation/interface-package/index.js +94 -0
- package/dist/code-generation/interface-package/index.js.map +7 -0
- package/dist/code-generation/interface-package/interface-package-definition/actions-module.js +88 -0
- package/dist/code-generation/interface-package/interface-package-definition/actions-module.js.map +7 -0
- package/dist/code-generation/interface-package/interface-package-definition/channels-module.js +98 -0
- package/dist/code-generation/interface-package/interface-package-definition/channels-module.js.map +7 -0
- package/dist/code-generation/interface-package/interface-package-definition/entities-module.js +63 -0
- package/dist/code-generation/interface-package/interface-package-definition/entities-module.js.map +7 -0
- package/dist/code-generation/interface-package/interface-package-definition/events-module.js +66 -0
- package/dist/code-generation/interface-package/interface-package-definition/events-module.js.map +7 -0
- package/dist/code-generation/interface-package/interface-package-definition/index.js +104 -0
- package/dist/code-generation/interface-package/interface-package-definition/index.js.map +7 -0
- package/dist/code-generation/interface-package/interface-package-definition/typings.js +17 -0
- package/dist/code-generation/interface-package/interface-package-definition/typings.js.map +7 -0
- package/dist/code-generation/module.js +183 -0
- package/dist/code-generation/module.js.map +7 -0
- package/dist/code-generation/plugin-implementation/index.js +60 -0
- package/dist/code-generation/plugin-implementation/index.js.map +7 -0
- package/dist/code-generation/plugin-implementation/plugin-implementation.js +90 -0
- package/dist/code-generation/plugin-implementation/plugin-implementation.js.map +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/actions-module.js +88 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/actions-module.js.map +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/configuration-module.js +61 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/configuration-module.js.map +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/events-module.js +63 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/events-module.js.map +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/index.js +150 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/index.js.map +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/states-module.js +64 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/states-module.js.map +7 -0
- package/dist/code-generation/plugin-package/index.js +151 -0
- package/dist/code-generation/plugin-package/index.js.map +7 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/actions-module.js +88 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/actions-module.js.map +7 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/configuration-module.js +56 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/configuration-module.js.map +7 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/events-module.js +66 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/events-module.js.map +7 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/index.js +107 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/index.js.map +7 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/states-module.js +66 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/states-module.js.map +7 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/typings.js +17 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/typings.js.map +7 -0
- package/dist/code-generation/strings.js +115 -0
- package/dist/code-generation/strings.js.map +7 -0
- package/dist/code-generation/typings.js +17 -0
- package/dist/code-generation/typings.js.map +7 -0
- package/dist/command-definitions.js +85 -0
- package/dist/command-definitions.js.map +7 -0
- package/dist/command-implementations/add-command.js +262 -0
- package/dist/command-implementations/add-command.js.map +7 -0
- package/dist/command-implementations/base-command.js +69 -0
- package/dist/command-implementations/base-command.js.map +7 -0
- package/dist/command-implementations/bot-commands.js +117 -0
- package/dist/command-implementations/bot-commands.js.map +7 -0
- package/dist/command-implementations/build-command.js +53 -0
- package/dist/command-implementations/build-command.js.map +7 -0
- package/dist/command-implementations/bundle-command.js +87 -0
- package/dist/command-implementations/bundle-command.js.map +7 -0
- package/dist/command-implementations/chat-command.js +152 -0
- package/dist/command-implementations/chat-command.js.map +7 -0
- package/dist/command-implementations/deploy-command.js +503 -0
- package/dist/command-implementations/deploy-command.js.map +7 -0
- package/dist/command-implementations/dev-command.js +345 -0
- package/dist/command-implementations/dev-command.js.map +7 -0
- package/dist/command-implementations/gen-command.js +110 -0
- package/dist/command-implementations/gen-command.js.map +7 -0
- package/dist/command-implementations/global-command.js +137 -0
- package/dist/command-implementations/global-command.js.map +7 -0
- package/dist/command-implementations/index.js +105 -0
- package/dist/command-implementations/index.js.map +7 -0
- package/dist/command-implementations/init-command.js +162 -0
- package/dist/command-implementations/init-command.js.map +7 -0
- package/dist/command-implementations/integration-commands.js +130 -0
- package/dist/command-implementations/integration-commands.js.map +7 -0
- package/dist/command-implementations/interface-commands.js +110 -0
- package/dist/command-implementations/interface-commands.js.map +7 -0
- package/dist/command-implementations/lint-command.js +151 -0
- package/dist/command-implementations/lint-command.js.map +7 -0
- package/dist/command-implementations/login-command.js +82 -0
- package/dist/command-implementations/login-command.js.map +7 -0
- package/dist/command-implementations/logout-command.js +35 -0
- package/dist/command-implementations/logout-command.js.map +7 -0
- package/dist/command-implementations/plugin-commands.js +111 -0
- package/dist/command-implementations/plugin-commands.js.map +7 -0
- package/dist/command-implementations/project-command.js +383 -0
- package/dist/command-implementations/project-command.js.map +7 -0
- package/dist/command-implementations/read-command.js +70 -0
- package/dist/command-implementations/read-command.js.map +7 -0
- package/dist/command-implementations/serve-command.js +68 -0
- package/dist/command-implementations/serve-command.js.map +7 -0
- package/dist/command-tree.js +60 -0
- package/dist/command-tree.js.map +7 -0
- package/dist/config.js +352 -0
- package/dist/config.js.map +7 -0
- package/dist/consts.js +127 -0
- package/dist/consts.js.map +7 -0
- package/dist/errors.js +202 -0
- package/dist/errors.js.map +7 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +7 -0
- package/dist/init.js +50 -0
- package/dist/init.js.map +7 -0
- package/dist/linter/base-linter.js +75 -0
- package/dist/linter/base-linter.js.map +7 -0
- package/dist/linter/base-linter.test.js +187 -0
- package/dist/linter/base-linter.test.js.map +7 -0
- package/dist/linter/bot-linter.js +35 -0
- package/dist/linter/bot-linter.js.map +7 -0
- package/dist/linter/integration-linter.js +35 -0
- package/dist/linter/integration-linter.js.map +7 -0
- package/dist/linter/interface-linter.js +35 -0
- package/dist/linter/interface-linter.js.map +7 -0
- package/dist/linter/ruleset-tests/bot.ruleset.test.js +358 -0
- package/dist/linter/ruleset-tests/bot.ruleset.test.js.map +7 -0
- package/dist/linter/ruleset-tests/common.js +37 -0
- package/dist/linter/ruleset-tests/common.js.map +7 -0
- package/dist/linter/ruleset-tests/integration.ruleset.test.js +887 -0
- package/dist/linter/ruleset-tests/integration.ruleset.test.js.map +7 -0
- package/dist/linter/ruleset-tests/interface.ruleset.test.js +383 -0
- package/dist/linter/ruleset-tests/interface.ruleset.test.js.map +7 -0
- package/dist/linter/rulesets/bot.ruleset.js +191 -0
- package/dist/linter/rulesets/bot.ruleset.js.map +7 -0
- package/dist/linter/rulesets/integration.ruleset.js +378 -0
- package/dist/linter/rulesets/integration.ruleset.js.map +7 -0
- package/dist/linter/rulesets/interface.ruleset.js +157 -0
- package/dist/linter/rulesets/interface.ruleset.js.map +7 -0
- package/dist/linter/spectral-functions.js +36 -0
- package/dist/linter/spectral-functions.js.map +7 -0
- package/dist/logger/base-logger.js +170 -0
- package/dist/logger/base-logger.js.map +7 -0
- package/dist/logger/index.js +86 -0
- package/dist/logger/index.js.map +7 -0
- package/dist/package-ref.js +107 -0
- package/dist/package-ref.js.map +7 -0
- package/dist/package-ref.test.js +109 -0
- package/dist/package-ref.test.js.map +7 -0
- package/dist/register-yargs.js +91 -0
- package/dist/register-yargs.js.map +7 -0
- package/dist/root.js +41 -0
- package/dist/root.js.map +7 -0
- package/dist/sdk/index.js +22 -0
- package/dist/sdk/index.js.map +7 -0
- package/dist/sdk/resolve-bot-interfaces.js +43 -0
- package/dist/sdk/resolve-bot-interfaces.js.map +7 -0
- package/dist/sdk/resolve-integration-interfaces.js +161 -0
- package/dist/sdk/resolve-integration-interfaces.js.map +7 -0
- package/dist/sdk/validate-bot.js +88 -0
- package/dist/sdk/validate-bot.js.map +7 -0
- package/dist/sdk/validate-integration.js +72 -0
- package/dist/sdk/validate-integration.js.map +7 -0
- package/dist/typings.js +17 -0
- package/dist/typings.js.map +7 -0
- package/dist/utils/cache-utils.js +104 -0
- package/dist/utils/cache-utils.js.map +7 -0
- package/dist/utils/case-utils.js +84 -0
- package/dist/utils/case-utils.js.map +7 -0
- package/dist/utils/case-utils.test.js +75 -0
- package/dist/utils/case-utils.test.js.map +7 -0
- package/dist/utils/esbuild-utils.js +92 -0
- package/dist/utils/esbuild-utils.js.map +7 -0
- package/dist/utils/event-emitter.js +63 -0
- package/dist/utils/event-emitter.js.map +7 -0
- package/dist/utils/file-watcher.js +73 -0
- package/dist/utils/file-watcher.js.map +7 -0
- package/dist/utils/guard-utils.js +32 -0
- package/dist/utils/guard-utils.js.map +7 -0
- package/dist/utils/id-utils.js +59 -0
- package/dist/utils/id-utils.js.map +7 -0
- package/dist/utils/index.js +99 -0
- package/dist/utils/index.js.map +7 -0
- package/dist/utils/object-utils.js +32 -0
- package/dist/utils/object-utils.js.map +7 -0
- package/dist/utils/path-utils.js +106 -0
- package/dist/utils/path-utils.js.map +7 -0
- package/dist/utils/path-utils.test.js +72 -0
- package/dist/utils/path-utils.test.js.map +7 -0
- package/dist/utils/pkgjson-utils.js +57 -0
- package/dist/utils/pkgjson-utils.js.map +7 -0
- package/dist/utils/promise-utils.js +36 -0
- package/dist/utils/promise-utils.js.map +7 -0
- package/dist/utils/promise-utils.test.js +14 -0
- package/dist/utils/promise-utils.test.js.map +7 -0
- package/dist/utils/prompt-utils.js +105 -0
- package/dist/utils/prompt-utils.js.map +7 -0
- package/dist/utils/record-utils.js +118 -0
- package/dist/utils/record-utils.js.map +7 -0
- package/dist/utils/record-utils.test.js +38 -0
- package/dist/utils/record-utils.test.js.map +7 -0
- package/dist/utils/require-utils.js +90 -0
- package/dist/utils/require-utils.js.map +7 -0
- package/dist/utils/require-utils.test.js +54 -0
- package/dist/utils/require-utils.test.js.map +7 -0
- package/dist/utils/schema-utils.js +64 -0
- package/dist/utils/schema-utils.js.map +7 -0
- package/dist/utils/schema-utils.test.js +50 -0
- package/dist/utils/schema-utils.test.js.map +7 -0
- package/dist/utils/semver-utils.js +45 -0
- package/dist/utils/semver-utils.js.map +7 -0
- package/dist/utils/string-utils.js +42 -0
- package/dist/utils/string-utils.js.map +7 -0
- package/dist/utils/template-utils.js +51 -0
- package/dist/utils/template-utils.js.map +7 -0
- package/dist/utils/tunnel-utils.js +129 -0
- package/dist/utils/tunnel-utils.js.map +7 -0
- package/dist/utils/type-utils.js +17 -0
- package/dist/utils/type-utils.js.map +7 -0
- package/dist/utils/url-utils.js +67 -0
- package/dist/utils/url-utils.js.map +7 -0
- package/dist/worker/child-entrypoint.js +58 -0
- package/dist/worker/child-entrypoint.js.map +7 -0
- package/dist/worker/child-wrapper.js +119 -0
- package/dist/worker/child-wrapper.js.map +7 -0
- package/dist/worker/config.js +44 -0
- package/dist/worker/config.js.map +7 -0
- package/dist/worker/index.js +32 -0
- package/dist/worker/index.js.map +7 -0
- package/dist/worker/is-child.js +55 -0
- package/dist/worker/is-child.js.map +7 -0
- package/dist/worker/worker-state.js +71 -0
- package/dist/worker/worker-state.js.map +7 -0
- package/dist/worker/worker.js +91 -0
- package/dist/worker/worker.js.map +7 -0
- package/package.json +1 -1
- package/templates/empty-bot/.botpress/implementation/index.ts +50 -0
- package/templates/empty-bot/.botpress/implementation/plugins/index.ts +11 -0
- package/templates/empty-bot/.botpress/implementation/typings/actions/index.ts +6 -0
- package/templates/empty-bot/.botpress/implementation/typings/events/index.ts +6 -0
- package/templates/empty-bot/.botpress/implementation/typings/index.ts +20 -0
- package/templates/empty-bot/.botpress/implementation/typings/integrations/index.ts +6 -0
- package/templates/empty-bot/.botpress/implementation/typings/states/index.ts +6 -0
- package/templates/empty-bot/.botpress/index.ts +5 -0
- package/templates/empty-integration/.botpress/implementation/index.ts +57 -0
- package/templates/empty-integration/.botpress/implementation/typings/actions/index.ts +6 -0
- package/templates/empty-integration/.botpress/implementation/typings/channels/index.ts +6 -0
- package/templates/empty-integration/.botpress/implementation/typings/configuration/index.ts +2 -0
- package/templates/empty-integration/.botpress/implementation/typings/configurations/index.ts +6 -0
- package/templates/empty-integration/.botpress/implementation/typings/entities/index.ts +6 -0
- package/templates/empty-integration/.botpress/implementation/typings/events/index.ts +6 -0
- package/templates/empty-integration/.botpress/implementation/typings/index.ts +31 -0
- package/templates/empty-integration/.botpress/implementation/typings/states/index.ts +6 -0
- package/templates/empty-integration/.botpress/index.ts +2 -0
- package/templates/empty-integration/.botpress/secrets/index.ts +6 -0
- package/templates/empty-plugin/.botpress/implementation/index.ts +35 -0
- package/templates/empty-plugin/.botpress/implementation/typings/actions/index.ts +6 -0
- package/templates/empty-plugin/.botpress/implementation/typings/configuration/index.ts +2 -0
- package/templates/empty-plugin/.botpress/implementation/typings/events/index.ts +6 -0
- package/templates/empty-plugin/.botpress/implementation/typings/index.ts +26 -0
- package/templates/empty-plugin/.botpress/implementation/typings/integrations/index.ts +6 -0
- package/templates/empty-plugin/.botpress/implementation/typings/interfaces/index.ts +6 -0
- package/templates/empty-plugin/.botpress/implementation/typings/states/index.ts +6 -0
- package/templates/empty-plugin/.botpress/index.ts +1 -0
- package/templates/hello-world/.botpress/implementation/index.ts +57 -0
- package/templates/hello-world/.botpress/implementation/typings/actions/helloWorld/index.ts +12 -0
- package/templates/hello-world/.botpress/implementation/typings/actions/helloWorld/input.ts +5 -0
- package/templates/hello-world/.botpress/implementation/typings/actions/helloWorld/output.ts +5 -0
- package/templates/hello-world/.botpress/implementation/typings/actions/index.ts +9 -0
- package/templates/hello-world/.botpress/implementation/typings/channels/index.ts +6 -0
- package/templates/hello-world/.botpress/implementation/typings/configuration/index.ts +2 -0
- package/templates/hello-world/.botpress/implementation/typings/configurations/index.ts +6 -0
- package/templates/hello-world/.botpress/implementation/typings/entities/index.ts +6 -0
- package/templates/hello-world/.botpress/implementation/typings/events/index.ts +6 -0
- package/templates/hello-world/.botpress/implementation/typings/index.ts +31 -0
- package/templates/hello-world/.botpress/implementation/typings/states/index.ts +6 -0
- package/templates/hello-world/.botpress/index.ts +2 -0
- package/templates/hello-world/.botpress/secrets/index.ts +6 -0
- package/templates/webhook-message/.botpress/implementation/index.ts +57 -0
- package/templates/webhook-message/.botpress/implementation/typings/actions/index.ts +6 -0
- package/templates/webhook-message/.botpress/implementation/typings/channels/index.ts +9 -0
- package/templates/webhook-message/.botpress/implementation/typings/channels/webhook/index.ts +12 -0
- package/templates/webhook-message/.botpress/implementation/typings/channels/webhook/messages/index.ts +9 -0
- package/templates/webhook-message/.botpress/implementation/typings/channels/webhook/messages/text.ts +5 -0
- package/templates/webhook-message/.botpress/implementation/typings/configuration/index.ts +8 -0
- package/templates/webhook-message/.botpress/implementation/typings/configurations/index.ts +6 -0
- package/templates/webhook-message/.botpress/implementation/typings/entities/index.ts +6 -0
- package/templates/webhook-message/.botpress/implementation/typings/events/index.ts +6 -0
- package/templates/webhook-message/.botpress/implementation/typings/index.ts +31 -0
- package/templates/webhook-message/.botpress/implementation/typings/states/index.ts +6 -0
- package/templates/webhook-message/.botpress/index.ts +2 -0
- package/templates/webhook-message/.botpress/secrets/index.ts +6 -0
|
@@ -0,0 +1,345 @@
|
|
|
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
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var dev_command_exports = {};
|
|
30
|
+
__export(dev_command_exports, {
|
|
31
|
+
DevCommand: () => DevCommand
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(dev_command_exports);
|
|
34
|
+
var import_axios = __toESM(require("axios"));
|
|
35
|
+
var import_chalk = __toESM(require("chalk"));
|
|
36
|
+
var pathlib = __toESM(require("path"));
|
|
37
|
+
var uuid = __toESM(require("uuid"));
|
|
38
|
+
var import_bot_body = require("../api/bot-body");
|
|
39
|
+
var import_integration_body = require("../api/integration-body");
|
|
40
|
+
var errors = __toESM(require("../errors"));
|
|
41
|
+
var utils = __toESM(require("../utils"));
|
|
42
|
+
var import_worker = require("../worker");
|
|
43
|
+
var import_build_command = require("./build-command");
|
|
44
|
+
var import_project_command = require("./project-command");
|
|
45
|
+
const DEFAULT_BOT_PORT = 8075;
|
|
46
|
+
const DEFAULT_INTEGRATION_PORT = 8076;
|
|
47
|
+
const TUNNEL_HELLO_INTERVAL = 5e3;
|
|
48
|
+
class DevCommand extends import_project_command.ProjectCommand {
|
|
49
|
+
_initialDef = void 0;
|
|
50
|
+
async run() {
|
|
51
|
+
this.logger.warn("This command is experimental and subject to breaking changes without notice.");
|
|
52
|
+
const api = await this.ensureLoginAndCreateClient(this.argv);
|
|
53
|
+
const projectDef = await this.readProjectDefinitionFromFS();
|
|
54
|
+
if (projectDef.type === "interface") {
|
|
55
|
+
throw new errors.BotpressCLIError("This feature is not available for interfaces.");
|
|
56
|
+
}
|
|
57
|
+
this._initialDef = projectDef;
|
|
58
|
+
let env = {
|
|
59
|
+
...process.env,
|
|
60
|
+
BP_API_URL: api.url,
|
|
61
|
+
BP_TOKEN: api.token
|
|
62
|
+
};
|
|
63
|
+
let defaultPort = DEFAULT_BOT_PORT;
|
|
64
|
+
if (this._initialDef.type === "integration") {
|
|
65
|
+
defaultPort = DEFAULT_INTEGRATION_PORT;
|
|
66
|
+
const secretEnvVariables = await this.promptSecrets(this._initialDef.definition, this.argv, { formatEnv: true });
|
|
67
|
+
const nonNullSecretEnvVariables = utils.records.filterValues(secretEnvVariables, utils.guards.is.notNull);
|
|
68
|
+
env = { ...env, ...nonNullSecretEnvVariables };
|
|
69
|
+
}
|
|
70
|
+
const port = this.argv.port ?? defaultPort;
|
|
71
|
+
const urlParseResult = utils.url.parse(this.argv.tunnelUrl);
|
|
72
|
+
if (urlParseResult.status === "error") {
|
|
73
|
+
throw new errors.BotpressCLIError(`Invalid tunnel URL: ${urlParseResult.error}`);
|
|
74
|
+
}
|
|
75
|
+
const tunnelId = uuid.v4();
|
|
76
|
+
const { url: parsedTunnelUrl } = urlParseResult;
|
|
77
|
+
const isSecured = parsedTunnelUrl.protocol === "https" || parsedTunnelUrl.protocol === "wss";
|
|
78
|
+
const wsTunnelUrl = utils.url.format({ ...parsedTunnelUrl, protocol: isSecured ? "wss" : "ws" });
|
|
79
|
+
const httpTunnelUrl = utils.url.format({
|
|
80
|
+
...parsedTunnelUrl,
|
|
81
|
+
protocol: isSecured ? "https" : "http",
|
|
82
|
+
path: `/${tunnelId}`
|
|
83
|
+
});
|
|
84
|
+
let worker = void 0;
|
|
85
|
+
const supervisor = new utils.tunnel.TunnelSupervisor(wsTunnelUrl, tunnelId, this.logger);
|
|
86
|
+
supervisor.events.on("connected", ({ tunnel }) => {
|
|
87
|
+
const timer = setInterval(() => {
|
|
88
|
+
if (tunnel.closed) {
|
|
89
|
+
return handleClose();
|
|
90
|
+
}
|
|
91
|
+
tunnel.hello();
|
|
92
|
+
}, TUNNEL_HELLO_INTERVAL);
|
|
93
|
+
const handleClose = () => clearInterval(timer);
|
|
94
|
+
tunnel.events.on("close", handleClose);
|
|
95
|
+
tunnel.events.on("request", (req) => {
|
|
96
|
+
if (!worker) {
|
|
97
|
+
this.logger.debug("Worker not ready yet, ignoring request");
|
|
98
|
+
tunnel.send({ requestId: req.id, status: 503, body: "Worker not ready yet" });
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
void this._forwardTunnelRequest(`http://localhost:${port}`, req).then((res) => {
|
|
102
|
+
tunnel.send(res);
|
|
103
|
+
}).catch((thrown) => {
|
|
104
|
+
const err = errors.BotpressCLIError.wrap(thrown, "An error occurred while handling request");
|
|
105
|
+
this.logger.error(err.message);
|
|
106
|
+
tunnel.send({
|
|
107
|
+
requestId: req.id,
|
|
108
|
+
status: 500,
|
|
109
|
+
body: err.message
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
supervisor.events.on("manuallyClosed", () => {
|
|
115
|
+
this.logger.debug("Tunnel manually closed");
|
|
116
|
+
});
|
|
117
|
+
await supervisor.start();
|
|
118
|
+
await this._runBuild();
|
|
119
|
+
await this._deploy(api, httpTunnelUrl);
|
|
120
|
+
worker = await this._spawnWorker(env, port);
|
|
121
|
+
try {
|
|
122
|
+
const watcher = await utils.filewatcher.FileWatcher.watch(
|
|
123
|
+
this.argv.workDir,
|
|
124
|
+
async (events) => {
|
|
125
|
+
if (!worker) {
|
|
126
|
+
this.logger.debug("Worker not ready yet, ignoring file change event");
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const typescriptEvents = events.filter((e) => pathlib.extname(e.path) === ".ts");
|
|
130
|
+
if (typescriptEvents.length === 0) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
this.logger.log("Changes detected, rebuilding");
|
|
134
|
+
await this._restart(api, worker, httpTunnelUrl);
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
ignore: [this.projectPaths.abs.outDir]
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
await Promise.race([worker.wait(), watcher.wait(), supervisor.wait()]);
|
|
141
|
+
if (worker.running) {
|
|
142
|
+
await worker.kill();
|
|
143
|
+
}
|
|
144
|
+
await watcher.close();
|
|
145
|
+
supervisor.close();
|
|
146
|
+
} catch (thrown) {
|
|
147
|
+
throw errors.BotpressCLIError.wrap(thrown, "An error occurred while running the dev server");
|
|
148
|
+
} finally {
|
|
149
|
+
if (worker.running) {
|
|
150
|
+
await worker.kill();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
_restart = async (api, worker, tunnelUrl) => {
|
|
155
|
+
try {
|
|
156
|
+
await this._runBuild();
|
|
157
|
+
} catch (thrown) {
|
|
158
|
+
const error = errors.BotpressCLIError.wrap(thrown, "Build failed");
|
|
159
|
+
this.logger.error(error.message);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
await this._deploy(api, tunnelUrl);
|
|
163
|
+
await worker.reload();
|
|
164
|
+
};
|
|
165
|
+
_deploy = async (api, tunnelUrl) => {
|
|
166
|
+
const projectDef = await this.readProjectDefinitionFromFS();
|
|
167
|
+
if (projectDef.type === "interface") {
|
|
168
|
+
throw new errors.BotpressCLIError("This feature is not available for interfaces.");
|
|
169
|
+
}
|
|
170
|
+
if (projectDef.type === "integration") {
|
|
171
|
+
this._checkSecrets(projectDef.definition);
|
|
172
|
+
return await this._deployDevIntegration(api, tunnelUrl, projectDef.definition);
|
|
173
|
+
}
|
|
174
|
+
if (projectDef.type === "bot") {
|
|
175
|
+
return await this._deployDevBot(api, tunnelUrl, projectDef.definition);
|
|
176
|
+
}
|
|
177
|
+
throw new errors.UnsupportedProjectType();
|
|
178
|
+
};
|
|
179
|
+
_checkSecrets(integrationDef) {
|
|
180
|
+
if (this._initialDef?.type !== "integration") {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const initialSecrets = this._initialDef?.definition.secrets ?? {};
|
|
184
|
+
const currentSecrets = integrationDef.secrets ?? {};
|
|
185
|
+
const newSecrets = Object.keys(currentSecrets).filter((s) => !initialSecrets[s]);
|
|
186
|
+
if (newSecrets.length > 0) {
|
|
187
|
+
throw new errors.BotpressCLIError("Secrets were added while the server was running. A restart is required.");
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
_spawnWorker = async (env, port) => {
|
|
191
|
+
const outfile = this.projectPaths.abs.outFile;
|
|
192
|
+
const importPath = utils.path.toUnix(outfile);
|
|
193
|
+
const requireFrom = utils.path.rmExtension(importPath);
|
|
194
|
+
const code = `require('${requireFrom}').default.start(${port})`;
|
|
195
|
+
const worker = await import_worker.Worker.spawn(
|
|
196
|
+
{
|
|
197
|
+
type: "code",
|
|
198
|
+
code,
|
|
199
|
+
env
|
|
200
|
+
},
|
|
201
|
+
this.logger
|
|
202
|
+
).catch((thrown) => {
|
|
203
|
+
throw errors.BotpressCLIError.wrap(thrown, "Could not start dev worker");
|
|
204
|
+
});
|
|
205
|
+
return worker;
|
|
206
|
+
};
|
|
207
|
+
_runBuild() {
|
|
208
|
+
return new import_build_command.BuildCommand(this.api, this.prompt, this.logger, this.argv).run();
|
|
209
|
+
}
|
|
210
|
+
async _deployDevIntegration(api, externalUrl, integrationDef) {
|
|
211
|
+
const devId = await this.projectCache.get("devId");
|
|
212
|
+
let integration = void 0;
|
|
213
|
+
if (devId) {
|
|
214
|
+
const resp = await api.client.getIntegration({ id: devId }).catch(async (thrown) => {
|
|
215
|
+
const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev integration with id "${devId}"`);
|
|
216
|
+
this.logger.warn(err.message);
|
|
217
|
+
return { integration: void 0 };
|
|
218
|
+
});
|
|
219
|
+
if (resp.integration?.dev) {
|
|
220
|
+
integration = resp.integration;
|
|
221
|
+
} else {
|
|
222
|
+
await this.projectCache.rm("devId");
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const line = this.logger.line();
|
|
226
|
+
line.started(`Deploying dev integration ${import_chalk.default.bold(integrationDef.name)}...`);
|
|
227
|
+
let createIntegrationBody = await (0, import_integration_body.prepareCreateIntegrationBody)(integrationDef);
|
|
228
|
+
createIntegrationBody = {
|
|
229
|
+
...createIntegrationBody,
|
|
230
|
+
url: externalUrl,
|
|
231
|
+
configuration: await this.readIntegrationConfigDefinition(createIntegrationBody.configuration),
|
|
232
|
+
configurations: await utils.promises.awaitRecord(
|
|
233
|
+
utils.records.mapValues(
|
|
234
|
+
createIntegrationBody.configurations ?? {},
|
|
235
|
+
this.readIntegrationConfigDefinition.bind(this)
|
|
236
|
+
)
|
|
237
|
+
)
|
|
238
|
+
};
|
|
239
|
+
if (integration) {
|
|
240
|
+
const updateIntegrationBody = (0, import_integration_body.prepareUpdateIntegrationBody)(
|
|
241
|
+
{ ...createIntegrationBody, id: integration.id },
|
|
242
|
+
integration
|
|
243
|
+
);
|
|
244
|
+
const resp = await api.client.updateIntegration(updateIntegrationBody).catch((thrown) => {
|
|
245
|
+
throw errors.BotpressCLIError.wrap(thrown, `Could not update dev integration "${integrationDef.name}"`);
|
|
246
|
+
});
|
|
247
|
+
integration = resp.integration;
|
|
248
|
+
} else {
|
|
249
|
+
const resp = await api.client.createIntegration({ ...createIntegrationBody, dev: true }).catch((thrown) => {
|
|
250
|
+
throw errors.BotpressCLIError.wrap(thrown, `Could not deploy dev integration "${integrationDef.name}"`);
|
|
251
|
+
});
|
|
252
|
+
integration = resp.integration;
|
|
253
|
+
}
|
|
254
|
+
line.success(`Dev Integration deployed with id "${integration.id}" at "${externalUrl}"`);
|
|
255
|
+
line.commit();
|
|
256
|
+
await this.projectCache.set("devId", integration.id);
|
|
257
|
+
}
|
|
258
|
+
async _deployDevBot(api, externalUrl, botDef) {
|
|
259
|
+
const devId = await this.projectCache.get("devId");
|
|
260
|
+
let bot = void 0;
|
|
261
|
+
if (devId) {
|
|
262
|
+
const resp = await api.client.getBot({ id: devId }).catch(async (thrown) => {
|
|
263
|
+
const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev bot with id "${devId}"`);
|
|
264
|
+
this.logger.warn(err.message);
|
|
265
|
+
return { bot: void 0 };
|
|
266
|
+
});
|
|
267
|
+
if (resp.bot?.dev) {
|
|
268
|
+
bot = resp.bot;
|
|
269
|
+
} else {
|
|
270
|
+
await this.projectCache.rm("devId");
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (!bot) {
|
|
274
|
+
const createLine = this.logger.line();
|
|
275
|
+
createLine.started("Creating dev bot...");
|
|
276
|
+
const resp = await api.client.createBot({
|
|
277
|
+
dev: true,
|
|
278
|
+
url: externalUrl
|
|
279
|
+
}).catch((thrown) => {
|
|
280
|
+
throw errors.BotpressCLIError.wrap(thrown, "Could not deploy dev bot");
|
|
281
|
+
});
|
|
282
|
+
bot = resp.bot;
|
|
283
|
+
createLine.log("Dev Bot created");
|
|
284
|
+
createLine.commit();
|
|
285
|
+
await this.projectCache.set("devId", bot.id);
|
|
286
|
+
}
|
|
287
|
+
const updateLine = this.logger.line();
|
|
288
|
+
updateLine.started("Deploying dev bot...");
|
|
289
|
+
const integrationInstances = await this.fetchBotIntegrationInstances(botDef, api);
|
|
290
|
+
const updateBotBody = (0, import_bot_body.prepareUpdateBotBody)(
|
|
291
|
+
{
|
|
292
|
+
...await (0, import_bot_body.prepareCreateBotBody)(botDef),
|
|
293
|
+
id: bot.id,
|
|
294
|
+
url: externalUrl,
|
|
295
|
+
integrations: integrationInstances
|
|
296
|
+
},
|
|
297
|
+
bot
|
|
298
|
+
);
|
|
299
|
+
const { bot: updatedBot } = await api.client.updateBot(updateBotBody).catch((thrown) => {
|
|
300
|
+
throw errors.BotpressCLIError.wrap(thrown, "Could not deploy dev bot");
|
|
301
|
+
});
|
|
302
|
+
updateLine.success(`Dev Bot deployed with id "${updatedBot.id}" at "${externalUrl}"`);
|
|
303
|
+
updateLine.commit();
|
|
304
|
+
this.displayWebhookUrls(updatedBot);
|
|
305
|
+
}
|
|
306
|
+
_forwardTunnelRequest = async (baseUrl, request) => {
|
|
307
|
+
const axiosConfig = {
|
|
308
|
+
method: request.method,
|
|
309
|
+
url: this._formatLocalUrl(baseUrl, request),
|
|
310
|
+
headers: request.headers,
|
|
311
|
+
data: request.body,
|
|
312
|
+
responseType: "text",
|
|
313
|
+
validateStatus: () => true
|
|
314
|
+
};
|
|
315
|
+
this.logger.debug(`Forwarding request to ${axiosConfig.url}`);
|
|
316
|
+
const response = await (0, import_axios.default)(axiosConfig);
|
|
317
|
+
this.logger.debug("Sending back response up the tunnel");
|
|
318
|
+
return {
|
|
319
|
+
requestId: request.id,
|
|
320
|
+
status: response.status,
|
|
321
|
+
headers: this._getHeaders(response.headers),
|
|
322
|
+
body: response.data
|
|
323
|
+
};
|
|
324
|
+
};
|
|
325
|
+
_formatLocalUrl = (baseUrl, req) => {
|
|
326
|
+
if (req.query) {
|
|
327
|
+
return `${baseUrl}${req.path}?${req.query}`;
|
|
328
|
+
}
|
|
329
|
+
return `${baseUrl}${req.path}`;
|
|
330
|
+
};
|
|
331
|
+
_getHeaders = (res) => {
|
|
332
|
+
const headers = {};
|
|
333
|
+
for (const key in res) {
|
|
334
|
+
if (typeof res[key] === "string" || typeof res[key] === "number") {
|
|
335
|
+
headers[key] = String(res[key]);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return headers;
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
342
|
+
0 && (module.exports = {
|
|
343
|
+
DevCommand
|
|
344
|
+
});
|
|
345
|
+
//# sourceMappingURL=dev-command.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/command-implementations/dev-command.ts"],
|
|
4
|
+
"sourcesContent": ["import type * as client from '@botpress/client'\nimport type * as sdk from '@botpress/sdk'\nimport { TunnelRequest, TunnelResponse } from '@bpinternal/tunnel'\nimport axios, { AxiosRequestConfig, AxiosResponse } from 'axios'\nimport chalk from 'chalk'\nimport * as pathlib from 'path'\nimport * as uuid from 'uuid'\nimport { prepareCreateBotBody, prepareUpdateBotBody } from '../api/bot-body'\nimport type { ApiClient } from '../api/client'\nimport {\n prepareUpdateIntegrationBody,\n CreateIntegrationBody,\n prepareCreateIntegrationBody,\n} from '../api/integration-body'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport * as utils from '../utils'\nimport { Worker } from '../worker'\nimport { BuildCommand } from './build-command'\nimport { ProjectCommand, ProjectDefinition } from './project-command'\n\nconst DEFAULT_BOT_PORT = 8075\nconst DEFAULT_INTEGRATION_PORT = 8076\nconst TUNNEL_HELLO_INTERVAL = 5000\n\nexport type DevCommandDefinition = typeof commandDefinitions.dev\nexport class DevCommand extends ProjectCommand<DevCommandDefinition> {\n private _initialDef: ProjectDefinition | undefined = undefined\n\n public async run(): Promise<void> {\n this.logger.warn('This command is experimental and subject to breaking changes without notice.')\n\n const api = await this.ensureLoginAndCreateClient(this.argv)\n\n const projectDef = await this.readProjectDefinitionFromFS()\n if (projectDef.type === 'interface') {\n throw new errors.BotpressCLIError('This feature is not available for interfaces.')\n }\n this._initialDef = projectDef\n\n let env: Record<string, string> = {\n ...process.env,\n BP_API_URL: api.url,\n BP_TOKEN: api.token,\n }\n\n let defaultPort = DEFAULT_BOT_PORT\n if (this._initialDef.type === 'integration') {\n defaultPort = DEFAULT_INTEGRATION_PORT\n // TODO: store secrets in local cache to avoid prompting every time\n const secretEnvVariables = await this.promptSecrets(this._initialDef.definition, this.argv, { formatEnv: true })\n const nonNullSecretEnvVariables = utils.records.filterValues(secretEnvVariables, utils.guards.is.notNull)\n env = { ...env, ...nonNullSecretEnvVariables }\n }\n\n const port = this.argv.port ?? defaultPort\n\n const urlParseResult = utils.url.parse(this.argv.tunnelUrl)\n if (urlParseResult.status === 'error') {\n throw new errors.BotpressCLIError(`Invalid tunnel URL: ${urlParseResult.error}`)\n }\n\n const tunnelId = uuid.v4()\n\n const { url: parsedTunnelUrl } = urlParseResult\n const isSecured = parsedTunnelUrl.protocol === 'https' || parsedTunnelUrl.protocol === 'wss'\n\n const wsTunnelUrl: string = utils.url.format({ ...parsedTunnelUrl, protocol: isSecured ? 'wss' : 'ws' })\n const httpTunnelUrl: string = utils.url.format({\n ...parsedTunnelUrl,\n protocol: isSecured ? 'https' : 'http',\n path: `/${tunnelId}`,\n })\n\n let worker: Worker | undefined = undefined\n\n const supervisor = new utils.tunnel.TunnelSupervisor(wsTunnelUrl, tunnelId, this.logger)\n supervisor.events.on('connected', ({ tunnel }) => {\n // prevents the tunnel from closing due to inactivity\n const timer = setInterval(() => {\n if (tunnel.closed) {\n return handleClose()\n }\n tunnel.hello()\n }, TUNNEL_HELLO_INTERVAL)\n const handleClose = (): void => clearInterval(timer)\n tunnel.events.on('close', handleClose)\n\n tunnel.events.on('request', (req) => {\n if (!worker) {\n this.logger.debug('Worker not ready yet, ignoring request')\n tunnel.send({ requestId: req.id, status: 503, body: 'Worker not ready yet' })\n return\n }\n\n void this._forwardTunnelRequest(`http://localhost:${port}`, req)\n .then((res) => {\n tunnel.send(res)\n })\n .catch((thrown) => {\n const err = errors.BotpressCLIError.wrap(thrown, 'An error occurred while handling request')\n this.logger.error(err.message)\n tunnel.send({\n requestId: req.id,\n status: 500,\n body: err.message,\n })\n })\n })\n })\n\n supervisor.events.on('manuallyClosed', () => {\n this.logger.debug('Tunnel manually closed')\n })\n\n await supervisor.start()\n\n await this._runBuild()\n await this._deploy(api, httpTunnelUrl)\n worker = await this._spawnWorker(env, port)\n\n try {\n const watcher = await utils.filewatcher.FileWatcher.watch(\n this.argv.workDir,\n async (events) => {\n if (!worker) {\n this.logger.debug('Worker not ready yet, ignoring file change event')\n return\n }\n\n const typescriptEvents = events.filter((e) => pathlib.extname(e.path) === '.ts')\n if (typescriptEvents.length === 0) {\n return\n }\n\n this.logger.log('Changes detected, rebuilding')\n await this._restart(api, worker, httpTunnelUrl)\n },\n {\n ignore: [this.projectPaths.abs.outDir],\n }\n )\n\n await Promise.race([worker.wait(), watcher.wait(), supervisor.wait()])\n\n if (worker.running) {\n await worker.kill()\n }\n await watcher.close()\n supervisor.close()\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, 'An error occurred while running the dev server')\n } finally {\n if (worker.running) {\n await worker.kill()\n }\n }\n }\n\n private _restart = async (api: ApiClient, worker: Worker, tunnelUrl: string) => {\n try {\n await this._runBuild()\n } catch (thrown) {\n const error = errors.BotpressCLIError.wrap(thrown, 'Build failed')\n this.logger.error(error.message)\n return\n }\n\n await this._deploy(api, tunnelUrl)\n await worker.reload()\n }\n\n private _deploy = async (api: ApiClient, tunnelUrl: string) => {\n const projectDef = await this.readProjectDefinitionFromFS()\n\n if (projectDef.type === 'interface') {\n throw new errors.BotpressCLIError('This feature is not available for interfaces.')\n }\n if (projectDef.type === 'integration') {\n this._checkSecrets(projectDef.definition)\n return await this._deployDevIntegration(api, tunnelUrl, projectDef.definition)\n }\n if (projectDef.type === 'bot') {\n return await this._deployDevBot(api, tunnelUrl, projectDef.definition)\n }\n throw new errors.UnsupportedProjectType()\n }\n\n private _checkSecrets(integrationDef: sdk.IntegrationDefinition) {\n if (this._initialDef?.type !== 'integration') {\n return\n }\n const initialSecrets = this._initialDef?.definition.secrets ?? {}\n const currentSecrets = integrationDef.secrets ?? {}\n const newSecrets = Object.keys(currentSecrets).filter((s) => !initialSecrets[s])\n if (newSecrets.length > 0) {\n throw new errors.BotpressCLIError('Secrets were added while the server was running. A restart is required.')\n }\n }\n\n private _spawnWorker = async (env: Record<string, string>, port: number) => {\n const outfile = this.projectPaths.abs.outFile\n const importPath = utils.path.toUnix(outfile)\n const requireFrom = utils.path.rmExtension(importPath)\n const code = `require('${requireFrom}').default.start(${port})`\n const worker = await Worker.spawn(\n {\n type: 'code',\n code,\n env,\n },\n this.logger\n ).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not start dev worker')\n })\n\n return worker\n }\n\n private _runBuild() {\n return new BuildCommand(this.api, this.prompt, this.logger, this.argv).run()\n }\n\n private async _deployDevIntegration(\n api: ApiClient,\n externalUrl: string,\n integrationDef: sdk.IntegrationDefinition\n ): Promise<void> {\n const devId = await this.projectCache.get('devId')\n\n let integration: client.Integration | undefined = undefined\n\n if (devId) {\n const resp = await api.client.getIntegration({ id: devId }).catch(async (thrown) => {\n const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev integration with id \"${devId}\"`)\n this.logger.warn(err.message)\n return { integration: undefined }\n })\n\n if (resp.integration?.dev) {\n integration = resp.integration\n } else {\n await this.projectCache.rm('devId')\n }\n }\n\n const line = this.logger.line()\n line.started(`Deploying dev integration ${chalk.bold(integrationDef.name)}...`)\n\n let createIntegrationBody: CreateIntegrationBody = await prepareCreateIntegrationBody(integrationDef)\n createIntegrationBody = {\n ...createIntegrationBody,\n url: externalUrl,\n configuration: await this.readIntegrationConfigDefinition(createIntegrationBody.configuration),\n configurations: await utils.promises.awaitRecord(\n utils.records.mapValues(\n createIntegrationBody.configurations ?? {},\n this.readIntegrationConfigDefinition.bind(this)\n )\n ),\n }\n\n if (integration) {\n const updateIntegrationBody = prepareUpdateIntegrationBody(\n { ...createIntegrationBody, id: integration.id },\n integration\n )\n\n const resp = await api.client.updateIntegration(updateIntegrationBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update dev integration \"${integrationDef.name}\"`)\n })\n integration = resp.integration\n } else {\n const resp = await api.client.createIntegration({ ...createIntegrationBody, dev: true }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not deploy dev integration \"${integrationDef.name}\"`)\n })\n integration = resp.integration\n }\n\n line.success(`Dev Integration deployed with id \"${integration.id}\" at \"${externalUrl}\"`)\n line.commit()\n\n await this.projectCache.set('devId', integration.id)\n }\n\n private async _deployDevBot(api: ApiClient, externalUrl: string, botDef: sdk.BotDefinition): Promise<void> {\n const devId = await this.projectCache.get('devId')\n\n let bot: client.Bot | undefined = undefined\n\n if (devId) {\n const resp = await api.client.getBot({ id: devId }).catch(async (thrown) => {\n const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev bot with id \"${devId}\"`)\n this.logger.warn(err.message)\n return { bot: undefined }\n })\n\n if (resp.bot?.dev) {\n bot = resp.bot\n } else {\n await this.projectCache.rm('devId')\n }\n }\n\n if (!bot) {\n const createLine = this.logger.line()\n createLine.started('Creating dev bot...')\n const resp = await api.client\n .createBot({\n dev: true,\n url: externalUrl,\n })\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not deploy dev bot')\n })\n\n bot = resp.bot\n createLine.log('Dev Bot created')\n createLine.commit()\n await this.projectCache.set('devId', bot.id)\n }\n\n const updateLine = this.logger.line()\n updateLine.started('Deploying dev bot...')\n\n const integrationInstances = await this.fetchBotIntegrationInstances(botDef, api)\n const updateBotBody = prepareUpdateBotBody(\n {\n ...(await prepareCreateBotBody(botDef)),\n id: bot.id,\n url: externalUrl,\n integrations: integrationInstances,\n },\n bot\n )\n\n const { bot: updatedBot } = await api.client.updateBot(updateBotBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not deploy dev bot')\n })\n updateLine.success(`Dev Bot deployed with id \"${updatedBot.id}\" at \"${externalUrl}\"`)\n updateLine.commit()\n\n this.displayWebhookUrls(updatedBot)\n }\n\n private _forwardTunnelRequest = async (baseUrl: string, request: TunnelRequest): Promise<TunnelResponse> => {\n const axiosConfig = {\n method: request.method,\n url: this._formatLocalUrl(baseUrl, request),\n headers: request.headers,\n data: request.body,\n responseType: 'text',\n validateStatus: () => true,\n } satisfies AxiosRequestConfig\n\n this.logger.debug(`Forwarding request to ${axiosConfig.url}`)\n const response = await axios(axiosConfig)\n this.logger.debug('Sending back response up the tunnel')\n\n return {\n requestId: request.id,\n status: response.status,\n headers: this._getHeaders(response.headers),\n body: response.data,\n }\n }\n\n private _formatLocalUrl = (baseUrl: string, req: TunnelRequest): string => {\n if (req.query) {\n return `${baseUrl}${req.path}?${req.query}`\n }\n return `${baseUrl}${req.path}`\n }\n\n private _getHeaders = (res: AxiosResponse['headers']): TunnelResponse['headers'] => {\n const headers: TunnelResponse['headers'] = {}\n for (const key in res) {\n if (typeof res[key] === 'string' || typeof res[key] === 'number') {\n headers[key] = String(res[key])\n }\n }\n return headers\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAyD;AACzD,mBAAkB;AAClB,cAAyB;AACzB,WAAsB;AACtB,sBAA2D;AAE3D,8BAIO;AAEP,aAAwB;AACxB,YAAuB;AACvB,oBAAuB;AACvB,2BAA6B;AAC7B,6BAAkD;AAElD,MAAM,mBAAmB;AACzB,MAAM,2BAA2B;AACjC,MAAM,wBAAwB;AAGvB,MAAM,mBAAmB,sCAAqC;AAAA,EAC3D,cAA6C;AAAA,EAErD,MAAa,MAAqB;AAChC,SAAK,OAAO,KAAK,8EAA8E;AAE/F,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAE3D,UAAM,aAAa,MAAM,KAAK,4BAA4B;AAC1D,QAAI,WAAW,SAAS,aAAa;AACnC,YAAM,IAAI,OAAO,iBAAiB,+CAA+C;AAAA,IACnF;AACA,SAAK,cAAc;AAEnB,QAAI,MAA8B;AAAA,MAChC,GAAG,QAAQ;AAAA,MACX,YAAY,IAAI;AAAA,MAChB,UAAU,IAAI;AAAA,IAChB;AA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B,UAAU;AAAA,EACpC;AAAA,EAEQ,wBAAwB,OAAO,SAAiB,YAAoD;AAC1G,UAAM,cAAc;AAAA,MAClB,QAAQ,QAAQ;AAAA,MAChB,KAAK,KAAK,gBAAgB,SAAS,OAAO;AAAA,MAC1C,SAAS,QAAQ;AAAA,MACjB,MAAM,QAAQ;AAAA,MACd,cAAc;AAAA,MACd,gBAAgB,MAAM;AAAA,IACxB;AAEA,SAAK,OAAO,MAAM,yBAAyB,YAAY,KAAK;AAC5D,UAAM,WAAW,UAAM,aAAAC,SAAM,WAAW;AACxC,SAAK,OAAO,MAAM,qCAAqC;AAEvD,WAAO;AAAA,MACL,WAAW,QAAQ;AAAA,MACnB,QAAQ,SAAS;AAAA,MACjB,SAAS,KAAK,YAAY,SAAS,OAAO;AAAA,MAC1C,MAAM,SAAS;AAAA,IACjB;AAAA,EACF;AAAA,EAEQ,kBAAkB,CAAC,SAAiB,QAA+B;AACzE,QAAI,IAAI,OAAO;AACb,aAAO,GAAG,UAAU,IAAI,QAAQ,IAAI;AAAA,IACtC;AACA,WAAO,GAAG,UAAU,IAAI;AAAA,EAC1B;AAAA,EAEQ,cAAc,CAAC,QAA6D;AAClF,UAAM,UAAqC,CAAC;AAC5C,eAAW,OAAO,KAAK;AACrB,UAAI,OAAO,IAAI,GAAG,MAAM,YAAY,OAAO,IAAI,GAAG,MAAM,UAAU;AAChE,gBAAQ,GAAG,IAAI,OAAO,IAAI,GAAG,CAAC;AAAA,MAChC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;",
|
|
6
|
+
"names": ["chalk", "axios"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
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
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var gen_command_exports = {};
|
|
30
|
+
__export(gen_command_exports, {
|
|
31
|
+
GenerateCommand: () => GenerateCommand
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(gen_command_exports);
|
|
34
|
+
var import_chalk = __toESM(require("chalk"));
|
|
35
|
+
var import_fs = __toESM(require("fs"));
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
var codegen = __toESM(require("../code-generation"));
|
|
38
|
+
var errors = __toESM(require("../errors"));
|
|
39
|
+
var utils = __toESM(require("../utils"));
|
|
40
|
+
var import_project_command = require("./project-command");
|
|
41
|
+
class GenerateCommand extends import_project_command.ProjectCommand {
|
|
42
|
+
async run() {
|
|
43
|
+
const projectDef = await this.readProjectDefinitionFromFS();
|
|
44
|
+
if (projectDef.type === "interface") {
|
|
45
|
+
this.logger.success("Interface projects have no code to generate since they have no implementation.");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (projectDef.type === "integration") {
|
|
49
|
+
return await this._generateIntegration(projectDef.definition);
|
|
50
|
+
}
|
|
51
|
+
if (projectDef.type === "bot") {
|
|
52
|
+
return await this._generateBot(projectDef.definition);
|
|
53
|
+
}
|
|
54
|
+
if (projectDef.type === "plugin") {
|
|
55
|
+
return await this._generatePlugin(projectDef.definition);
|
|
56
|
+
}
|
|
57
|
+
throw new errors.UnsupportedProjectType();
|
|
58
|
+
}
|
|
59
|
+
async _generateIntegration(integrationDef) {
|
|
60
|
+
this._validateSecrets(integrationDef);
|
|
61
|
+
const line = this.logger.line();
|
|
62
|
+
const { name } = integrationDef;
|
|
63
|
+
line.started(`Generating typings for integration ${import_chalk.default.bold(name)}...`);
|
|
64
|
+
const fromWorkDir = this.projectPaths.rel("workDir");
|
|
65
|
+
const generatedFiles = await codegen.generateIntegrationImplementation(integrationDef);
|
|
66
|
+
await this._writeGeneratedFilesToOutFolder(generatedFiles);
|
|
67
|
+
line.success(`Typings available at ${import_chalk.default.grey(fromWorkDir.outDir)}`);
|
|
68
|
+
}
|
|
69
|
+
async _generateBot(botDefinition) {
|
|
70
|
+
const line = this.logger.line();
|
|
71
|
+
line.started("Generating typings for bot...");
|
|
72
|
+
const fromWorkDir = this.projectPaths.rel("workDir");
|
|
73
|
+
const generatedFiles = await codegen.generateBotImplementation(botDefinition);
|
|
74
|
+
await this._writeGeneratedFilesToOutFolder(generatedFiles);
|
|
75
|
+
line.success(`Typings available at ${import_chalk.default.grey(fromWorkDir.outDir)}`);
|
|
76
|
+
}
|
|
77
|
+
async _generatePlugin(pluginDefinition) {
|
|
78
|
+
const line = this.logger.line();
|
|
79
|
+
const { name } = pluginDefinition;
|
|
80
|
+
line.started(`Generating typings for plugin ${import_chalk.default.bold(name)}...`);
|
|
81
|
+
const fromWorkDir = this.projectPaths.rel("workDir");
|
|
82
|
+
const generatedFiles = await codegen.generatePluginImplementation(pluginDefinition);
|
|
83
|
+
await this._writeGeneratedFilesToOutFolder(generatedFiles);
|
|
84
|
+
line.success(`Typings available at ${import_chalk.default.grey(fromWorkDir.outDir)}`);
|
|
85
|
+
}
|
|
86
|
+
async _writeGeneratedFilesToOutFolder(files) {
|
|
87
|
+
for (const file of files) {
|
|
88
|
+
const filePath = utils.path.absoluteFrom(this.projectPaths.abs.outDir, file.path);
|
|
89
|
+
const dirPath = import_path.default.dirname(filePath);
|
|
90
|
+
await import_fs.default.promises.mkdir(dirPath, { recursive: true });
|
|
91
|
+
await import_fs.default.promises.writeFile(filePath, file.content);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
_validateSecrets(integrationDef) {
|
|
95
|
+
const { secrets } = integrationDef;
|
|
96
|
+
if (!secrets) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
for (const secretName in secrets) {
|
|
100
|
+
if (!utils.casing.is.screamingSnakeCase(secretName)) {
|
|
101
|
+
throw new errors.BotpressCLIError(`Secret ${secretName} should be in SCREAMING_SNAKE_CASE`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
+
0 && (module.exports = {
|
|
108
|
+
GenerateCommand
|
|
109
|
+
});
|
|
110
|
+
//# sourceMappingURL=gen-command.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/command-implementations/gen-command.ts"],
|
|
4
|
+
"sourcesContent": ["import * as sdk from '@botpress/sdk'\nimport chalk from 'chalk'\nimport fslib from 'fs'\nimport pathlib from 'path'\nimport * as codegen from '../code-generation'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport * as utils from '../utils'\nimport { ProjectCommand } from './project-command'\n\nexport type GenerateCommandDefinition = typeof commandDefinitions.generate\nexport class GenerateCommand extends ProjectCommand<GenerateCommandDefinition> {\n public async run(): Promise<void> {\n const projectDef = await this.readProjectDefinitionFromFS()\n if (projectDef.type === 'interface') {\n this.logger.success('Interface projects have no code to generate since they have no implementation.')\n return\n }\n if (projectDef.type === 'integration') {\n return await this._generateIntegration(projectDef.definition)\n }\n if (projectDef.type === 'bot') {\n return await this._generateBot(projectDef.definition)\n }\n if (projectDef.type === 'plugin') {\n return await this._generatePlugin(projectDef.definition)\n }\n throw new errors.UnsupportedProjectType()\n }\n\n private async _generateIntegration(integrationDef: sdk.IntegrationDefinition): Promise<void> {\n this._validateSecrets(integrationDef)\n\n const line = this.logger.line()\n\n const { name } = integrationDef\n line.started(`Generating typings for integration ${chalk.bold(name)}...`)\n\n const fromWorkDir = this.projectPaths.rel('workDir')\n\n const generatedFiles = await codegen.generateIntegrationImplementation(integrationDef)\n\n await this._writeGeneratedFilesToOutFolder(generatedFiles)\n\n line.success(`Typings available at ${chalk.grey(fromWorkDir.outDir)}`)\n }\n\n private async _generateBot(botDefinition: sdk.BotDefinition): Promise<void> {\n const line = this.logger.line()\n\n line.started('Generating typings for bot...')\n\n const fromWorkDir = this.projectPaths.rel('workDir')\n\n const generatedFiles = await codegen.generateBotImplementation(botDefinition)\n\n await this._writeGeneratedFilesToOutFolder(generatedFiles)\n\n line.success(`Typings available at ${chalk.grey(fromWorkDir.outDir)}`)\n }\n\n private async _generatePlugin(pluginDefinition: sdk.PluginDefinition): Promise<void> {\n const line = this.logger.line()\n\n const { name } = pluginDefinition\n line.started(`Generating typings for plugin ${chalk.bold(name)}...`)\n\n const fromWorkDir = this.projectPaths.rel('workDir')\n\n const generatedFiles = await codegen.generatePluginImplementation(pluginDefinition)\n\n await this._writeGeneratedFilesToOutFolder(generatedFiles)\n\n line.success(`Typings available at ${chalk.grey(fromWorkDir.outDir)}`)\n }\n\n private async _writeGeneratedFilesToOutFolder(files: codegen.File[]) {\n for (const file of files) {\n const filePath = utils.path.absoluteFrom(this.projectPaths.abs.outDir, file.path)\n const dirPath = pathlib.dirname(filePath)\n await fslib.promises.mkdir(dirPath, { recursive: true })\n await fslib.promises.writeFile(filePath, file.content)\n }\n }\n\n private _validateSecrets(integrationDef: sdk.IntegrationDefinition): void {\n const { secrets } = integrationDef\n if (!secrets) {\n return\n }\n\n for (const secretName in secrets) {\n if (!utils.casing.is.screamingSnakeCase(secretName)) {\n throw new errors.BotpressCLIError(`Secret ${secretName} should be in SCREAMING_SNAKE_CASE`)\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAClB,gBAAkB;AAClB,kBAAoB;AACpB,cAAyB;AAEzB,aAAwB;AACxB,YAAuB;AACvB,6BAA+B;AAGxB,MAAM,wBAAwB,sCAA0C;AAAA,EAC7E,MAAa,MAAqB;AAChC,UAAM,aAAa,MAAM,KAAK,4BAA4B;AAC1D,QAAI,WAAW,SAAS,aAAa;AACnC,WAAK,OAAO,QAAQ,gFAAgF;AACpG;AAAA,IACF;AACA,QAAI,WAAW,SAAS,eAAe;AACrC,aAAO,MAAM,KAAK,qBAAqB,WAAW,UAAU;AAAA,IAC9D;AACA,QAAI,WAAW,SAAS,OAAO;AAC7B,aAAO,MAAM,KAAK,aAAa,WAAW,UAAU;AAAA,IACtD;AACA,QAAI,WAAW,SAAS,UAAU;AAChC,aAAO,MAAM,KAAK,gBAAgB,WAAW,UAAU;AAAA,IACzD;AACA,UAAM,IAAI,OAAO,uBAAuB;AAAA,EAC1C;AAAA,EAEA,MAAc,qBAAqB,gBAA0D;AAC3F,SAAK,iBAAiB,cAAc;AAEpC,UAAM,OAAO,KAAK,OAAO,KAAK;AAE9B,UAAM,EAAE,KAAK,IAAI;AACjB,SAAK,QAAQ,sCAAsC,aAAAA,QA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BAAiB,gBAAiD;AACxE,UAAM,EAAE,QAAQ,IAAI;AACpB,QAAI,CAAC,SAAS;AACZ;AAAA,IACF;AAEA,eAAW,cAAc,SAAS;AAChC,UAAI,CAAC,MAAM,OAAO,GAAG,mBAAmB,UAAU,GAAG;AACnD,cAAM,IAAI,OAAO,iBAAiB,UAAU,8CAA8C;AAAA,MAC5F;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["chalk", "pathlib", "fslib"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
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
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var global_command_exports = {};
|
|
30
|
+
__export(global_command_exports, {
|
|
31
|
+
GlobalCommand: () => GlobalCommand
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(global_command_exports);
|
|
34
|
+
var import_chalk = __toESM(require("chalk"));
|
|
35
|
+
var import_latest_version = __toESM(require("latest-version"));
|
|
36
|
+
var import_lodash = __toESM(require("lodash"));
|
|
37
|
+
var import_semver = __toESM(require("semver"));
|
|
38
|
+
var consts = __toESM(require("../consts"));
|
|
39
|
+
var errors = __toESM(require("../errors"));
|
|
40
|
+
var utils = __toESM(require("../utils"));
|
|
41
|
+
var import_base_command = require("./base-command");
|
|
42
|
+
class GlobalPaths extends utils.path.PathStore {
|
|
43
|
+
constructor(argv) {
|
|
44
|
+
const absBotpressHome = utils.path.absoluteFrom(utils.path.cwd(), argv.botpressHome);
|
|
45
|
+
super({
|
|
46
|
+
cliRootDir: consts.cliRootDir,
|
|
47
|
+
botpressHomeDir: absBotpressHome,
|
|
48
|
+
...import_lodash.default.mapValues(consts.fromHomeDir, (p) => utils.path.absoluteFrom(absBotpressHome, p)),
|
|
49
|
+
...import_lodash.default.mapValues(consts.fromCliRootDir, (p) => utils.path.absoluteFrom(consts.cliRootDir, p))
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
class GlobalCommand extends import_base_command.BaseCommand {
|
|
54
|
+
api;
|
|
55
|
+
prompt;
|
|
56
|
+
_pkgJson;
|
|
57
|
+
constructor(api, prompt, ...args) {
|
|
58
|
+
super(...args);
|
|
59
|
+
this.api = api;
|
|
60
|
+
this.prompt = prompt;
|
|
61
|
+
}
|
|
62
|
+
get globalPaths() {
|
|
63
|
+
return new GlobalPaths(this.argv);
|
|
64
|
+
}
|
|
65
|
+
get globalCache() {
|
|
66
|
+
return new utils.cache.FSKeyValueCache(this.globalPaths.abs.globalCacheFile);
|
|
67
|
+
}
|
|
68
|
+
async bootstrap() {
|
|
69
|
+
const pkgJson = await this.readPkgJson();
|
|
70
|
+
const versionText = import_chalk.default.bold(`v${pkgJson.version}`);
|
|
71
|
+
this.logger.log(`Botpress CLI ${versionText}`, { prefix: "\u{1F916}" });
|
|
72
|
+
await this._notifyUpdateCli();
|
|
73
|
+
const paths = this.globalPaths;
|
|
74
|
+
if (paths.abs.botpressHomeDir !== consts.defaultBotpressHome) {
|
|
75
|
+
this.logger.log(`Using custom botpress home: ${paths.abs.botpressHomeDir}`, { prefix: "\u{1F3E0}" });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
teardown = async () => {
|
|
79
|
+
this.logger.cleanup();
|
|
80
|
+
};
|
|
81
|
+
async ensureLoginAndCreateClient(credentials) {
|
|
82
|
+
const cache = this.globalCache;
|
|
83
|
+
const token = await cache.get("token");
|
|
84
|
+
const workspaceId = credentials.workspaceId ?? await cache.get("workspaceId");
|
|
85
|
+
const apiUrl = credentials.apiUrl ?? await cache.get("apiUrl");
|
|
86
|
+
if (!(token && workspaceId && apiUrl)) {
|
|
87
|
+
throw new errors.NotLoggedInError();
|
|
88
|
+
}
|
|
89
|
+
if (apiUrl !== consts.defaultBotpressApiUrl) {
|
|
90
|
+
this.logger.log(`Using custom url ${apiUrl}`, { prefix: "\u{1F517}" });
|
|
91
|
+
}
|
|
92
|
+
return this.api.newClient({ apiUrl, token, workspaceId }, this.logger);
|
|
93
|
+
}
|
|
94
|
+
_notifyUpdateCli = async () => {
|
|
95
|
+
try {
|
|
96
|
+
this.logger.debug("Checking if cli is up to date");
|
|
97
|
+
const pkgJson = await this.readPkgJson();
|
|
98
|
+
if (!pkgJson.version) {
|
|
99
|
+
throw new errors.BotpressCLIError("Could not find version in package.json");
|
|
100
|
+
}
|
|
101
|
+
const latest = await (0, import_latest_version.default)(pkgJson.name);
|
|
102
|
+
const isOutdated = import_semver.default.lt(pkgJson.version, latest);
|
|
103
|
+
if (isOutdated) {
|
|
104
|
+
this.logger.box(
|
|
105
|
+
[
|
|
106
|
+
`${import_chalk.default.bold("Update available")} ${import_chalk.default.dim(pkgJson.version)} \u2192 ${import_chalk.default.green(latest)}`,
|
|
107
|
+
"",
|
|
108
|
+
"To update, run:",
|
|
109
|
+
` for npm ${import_chalk.default.cyan(`npm i -g ${pkgJson.name}`)}`,
|
|
110
|
+
` for yarn ${import_chalk.default.cyan(`yarn global add ${pkgJson.name}`)}`,
|
|
111
|
+
` for pnpm ${import_chalk.default.cyan(`pnpm i -g ${pkgJson.name}`)}`
|
|
112
|
+
].join("\n")
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
} catch (thrown) {
|
|
116
|
+
const err = errors.BotpressCLIError.map(thrown);
|
|
117
|
+
this.logger.debug(`Failed to check if cli is up to date: ${err.message}`);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
async readPkgJson() {
|
|
121
|
+
if (this._pkgJson) {
|
|
122
|
+
return this._pkgJson;
|
|
123
|
+
}
|
|
124
|
+
const { cliRootDir } = this.globalPaths.abs;
|
|
125
|
+
const pkgJson = await utils.pkgJson.readPackageJson(cliRootDir);
|
|
126
|
+
if (!pkgJson) {
|
|
127
|
+
throw new errors.BotpressCLIError(`Could not find package.json at "${cliRootDir}"`);
|
|
128
|
+
}
|
|
129
|
+
this._pkgJson = pkgJson;
|
|
130
|
+
return pkgJson;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
134
|
+
0 && (module.exports = {
|
|
135
|
+
GlobalCommand
|
|
136
|
+
});
|
|
137
|
+
//# sourceMappingURL=global-command.js.map
|