@botpress/cli 4.17.14 → 4.17.16
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 +16 -12
- package/bin.js +1 -1
- package/dist/api/bot-body.d.ts +5 -0
- package/dist/api/client.d.ts +50 -0
- package/dist/api/index.d.ts +6 -0
- package/dist/api/integration-body.d.ts +5 -0
- package/dist/api/interface-body.d.ts +7 -0
- package/dist/api/paging.d.ts +9 -0
- package/dist/api/plugin-body.d.ts +5 -0
- package/dist/api/retry.d.ts +2 -0
- package/dist/api/types.d.ts +62 -0
- package/dist/chat/index.d.ts +25 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +51 -0
- package/dist/cli.js.map +7 -0
- package/dist/code-generation/bot-implementation/bot-implementation.d.ts +8 -0
- package/dist/code-generation/bot-implementation/bot-plugins/index.d.ts +7 -0
- package/dist/code-generation/bot-implementation/bot-plugins/plugin-module.d.ts +13 -0
- package/dist/code-generation/bot-implementation/bot-typings/actions-module.d.ts +21 -0
- package/dist/code-generation/bot-implementation/bot-typings/events-module.d.ts +10 -0
- package/dist/code-generation/bot-implementation/bot-typings/index.d.ts +7 -0
- package/dist/code-generation/bot-implementation/bot-typings/states-module.d.ts +17 -0
- package/dist/code-generation/bot-implementation/bot-typings/tables-module.d.ts +10 -0
- package/dist/code-generation/bot-implementation/bot-typings/workflows-module.d.ts +27 -0
- package/dist/code-generation/bot-implementation/index.d.ts +3 -0
- package/dist/code-generation/consts.d.ts +5 -0
- package/dist/code-generation/generators.d.ts +10 -0
- package/dist/code-generation/index.d.ts +8 -0
- package/dist/code-generation/integration-implementation/index.d.ts +3 -0
- package/dist/code-generation/integration-implementation/integration-implementation.d.ts +7 -0
- package/dist/code-generation/integration-implementation/integration-secret.d.ts +8 -0
- package/dist/code-generation/integration-implementation/integration-typings/actions-module.d.ts +21 -0
- package/dist/code-generation/integration-implementation/integration-typings/channels-module.d.ts +5 -0
- package/dist/code-generation/integration-implementation/integration-typings/configuration-module.d.ts +7 -0
- package/dist/code-generation/integration-implementation/integration-typings/configurations-module.d.ts +10 -0
- package/dist/code-generation/integration-implementation/integration-typings/entities-module.d.ts +10 -0
- package/dist/code-generation/integration-implementation/integration-typings/events-module.d.ts +10 -0
- package/dist/code-generation/integration-implementation/integration-typings/index.d.ts +8 -0
- package/dist/code-generation/integration-implementation/integration-typings/states-module.d.ts +17 -0
- package/dist/code-generation/integration-package/index.d.ts +2 -0
- package/dist/code-generation/integration-package/integration-package-definition/actions-module.d.ts +21 -0
- package/dist/code-generation/integration-package/integration-package-definition/channels-module.d.ts +5 -0
- package/dist/code-generation/integration-package/integration-package-definition/configuration-module.d.ts +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/configurations-module.d.ts +10 -0
- package/dist/code-generation/integration-package/integration-package-definition/entities-module.d.ts +10 -0
- package/dist/code-generation/integration-package/integration-package-definition/events-module.d.ts +10 -0
- package/dist/code-generation/integration-package/integration-package-definition/index.d.ts +8 -0
- package/dist/code-generation/integration-package/integration-package-definition/interfaces-module.d.ts +10 -0
- package/dist/code-generation/integration-package/integration-package-definition/states-module.d.ts +10 -0
- package/dist/code-generation/integration-package/integration-package-definition/typings.d.ts +10 -0
- package/dist/code-generation/interface-implementation/index.d.ts +4 -0
- package/dist/code-generation/interface-implementation/integration-typings/actions-module.d.ts +21 -0
- package/dist/code-generation/interface-implementation/integration-typings/channels-module.d.ts +5 -0
- package/dist/code-generation/interface-implementation/integration-typings/entities-module.d.ts +10 -0
- package/dist/code-generation/interface-implementation/integration-typings/events-module.d.ts +10 -0
- package/dist/code-generation/interface-implementation/integration-typings/index.d.ts +8 -0
- package/dist/code-generation/interface-package/index.d.ts +2 -0
- package/dist/code-generation/interface-package/interface-package-definition/actions-module.d.ts +21 -0
- package/dist/code-generation/interface-package/interface-package-definition/channels-module.d.ts +5 -0
- package/dist/code-generation/interface-package/interface-package-definition/entities-module.d.ts +10 -0
- package/dist/code-generation/interface-package/interface-package-definition/events-module.d.ts +10 -0
- package/dist/code-generation/interface-package/interface-package-definition/index.d.ts +8 -0
- package/dist/code-generation/interface-package/interface-package-definition/typings.d.ts +7 -0
- package/dist/code-generation/module.d.ts +49 -0
- package/dist/code-generation/plugin-implementation/index.d.ts +3 -0
- package/dist/code-generation/plugin-implementation/plugin-implementation.d.ts +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/actions-module.d.ts +21 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/configuration-module.d.ts +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/events-module.d.ts +10 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/index.d.ts +8 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/states-module.d.ts +17 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/tables-module.d.ts +10 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/workflows-module.d.ts +27 -0
- package/dist/code-generation/plugin-package/index.d.ts +2 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/actions-module.d.ts +21 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/configuration-module.d.ts +7 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/events-module.d.ts +10 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/index.d.ts +8 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/interfaces-module.d.ts +7 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/recurring-events-module.d.ts +5 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/states-module.d.ts +10 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/typings.d.ts +7 -0
- package/dist/code-generation/strings.d.ts +4 -0
- package/dist/code-generation/typings.d.ts +162 -0
- package/dist/code-generation/typings.test.d.ts +1 -0
- package/dist/command-definitions.d.ts +1480 -0
- package/dist/command-implementations/add-command.d.ts +15 -0
- package/dist/command-implementations/add-command.js +3 -2
- package/dist/command-implementations/add-command.js.map +2 -2
- package/dist/command-implementations/base-command.d.ts +13 -0
- package/dist/command-implementations/bot-commands.d.ts +20 -0
- package/dist/command-implementations/build-command.d.ts +9 -0
- package/dist/command-implementations/build-command.js +2 -4
- package/dist/command-implementations/build-command.js.map +2 -2
- package/dist/command-implementations/bundle-command.d.ts +10 -0
- package/dist/command-implementations/bundle-command.js +6 -5
- package/dist/command-implementations/bundle-command.js.map +2 -2
- package/dist/command-implementations/chat-command.d.ts +13 -0
- package/dist/command-implementations/deploy-command.d.ts +18 -0
- package/dist/command-implementations/deploy-command.js +9 -5
- package/dist/command-implementations/deploy-command.js.map +2 -2
- package/dist/command-implementations/dev-command.d.ts +21 -0
- package/dist/command-implementations/dev-command.js +9 -6
- package/dist/command-implementations/dev-command.js.map +2 -2
- package/dist/command-implementations/gen-command.d.ts +11 -0
- package/dist/command-implementations/gen-command.js +8 -5
- package/dist/command-implementations/gen-command.js.map +2 -2
- package/dist/command-implementations/global-command.d.ts +57 -0
- package/dist/command-implementations/index.d.ts +1534 -0
- package/dist/command-implementations/init-command.d.ts +17 -0
- package/dist/command-implementations/integration-commands.d.ts +15 -0
- package/dist/command-implementations/interface-commands.d.ts +14 -0
- package/dist/command-implementations/lint-command.d.ts +15 -0
- package/dist/command-implementations/lint-command.js +15 -8
- package/dist/command-implementations/lint-command.js.map +3 -3
- package/dist/command-implementations/login-command.d.ts +6 -0
- package/dist/command-implementations/logout-command.d.ts +6 -0
- package/dist/command-implementations/plugin-commands.d.ts +14 -0
- package/dist/command-implementations/profile-commands.d.ts +14 -0
- package/dist/command-implementations/project-command.d.ts +94 -0
- package/dist/command-implementations/project-command.js +54 -18
- package/dist/command-implementations/project-command.js.map +2 -2
- package/dist/command-implementations/read-command.d.ts +10 -0
- package/dist/command-implementations/read-command.js +9 -5
- package/dist/command-implementations/read-command.js.map +2 -2
- package/dist/command-implementations/serve-command.d.ts +6 -0
- package/dist/command-implementations/serve-command.js +5 -4
- package/dist/command-implementations/serve-command.js.map +2 -2
- package/dist/command-tree.d.ts +39 -0
- package/dist/config.d.ts +1441 -0
- package/dist/consts.d.ts +41 -0
- package/dist/errors.d.ts +56 -0
- package/dist/index.d.ts +1524 -0
- package/dist/index.js +50 -25
- package/dist/index.js.map +3 -3
- package/dist/init.d.ts +1 -0
- package/dist/linter/base-linter.d.ts +21 -0
- package/dist/linter/base-linter.test.d.ts +1 -0
- package/dist/linter/bot-linter.d.ts +5 -0
- package/dist/linter/integration-linter.d.ts +7 -0
- package/dist/linter/interface-linter.d.ts +5 -0
- package/dist/linter/ruleset-tests/bot.ruleset.test.d.ts +1 -0
- package/dist/linter/ruleset-tests/common.d.ts +9 -0
- package/dist/linter/ruleset-tests/integration.ruleset.test.d.ts +1 -0
- package/dist/linter/ruleset-tests/interface.ruleset.test.d.ts +1 -0
- package/dist/linter/rulesets/bot.ruleset.d.ts +165 -0
- package/dist/linter/rulesets/integration.ruleset.d.ts +390 -0
- package/dist/linter/rulesets/interface.ruleset.d.ts +141 -0
- package/dist/linter/spectral-functions.d.ts +11 -0
- package/dist/logger/base-logger.d.ts +43 -0
- package/dist/logger/index.d.ts +22 -0
- package/dist/logger/logger.test.d.ts +1 -0
- package/dist/package-ref.d.ts +22 -0
- package/dist/package-ref.test.d.ts +1 -0
- package/dist/project-templates.d.ts +42 -0
- package/dist/register-yargs.d.ts +4 -0
- package/dist/root.d.ts +7 -0
- package/dist/sdk/index.d.ts +2 -0
- package/dist/sdk/validate-bot.d.ts +2 -0
- package/dist/sdk/validate-bot.test.d.ts +1 -0
- package/dist/sdk/validate-integration.d.ts +2 -0
- package/dist/tables/index.d.ts +1 -0
- package/dist/tables/schemas.d.ts +1259 -0
- package/dist/tables/tables-publisher.d.ts +22 -0
- package/dist/typings.d.ts +27 -0
- package/dist/utils/attribute-utils.d.ts +10 -0
- package/dist/utils/cache-utils.d.ts +14 -0
- package/dist/utils/case-utils.d.ts +14 -0
- package/dist/utils/case-utils.test.d.ts +1 -0
- package/dist/utils/concurrency-utils.d.ts +1 -0
- package/dist/utils/concurrency-utils.test.d.ts +1 -0
- package/dist/utils/esbuild-utils.d.ts +29 -0
- package/dist/utils/event-emitter.d.ts +7 -0
- package/dist/utils/file-watcher.d.ts +17 -0
- package/dist/utils/guard-utils.d.ts +4 -0
- package/dist/utils/id-utils.d.ts +2 -0
- package/dist/utils/index.d.ts +22 -0
- package/dist/utils/object-utils.d.ts +1 -0
- package/dist/utils/path-utils.d.ts +28 -0
- package/dist/utils/path-utils.test.d.ts +1 -0
- package/dist/utils/pkgjson-utils.d.ts +17 -0
- package/dist/utils/promise-utils.d.ts +2 -0
- package/dist/utils/promise-utils.test.d.ts +1 -0
- package/dist/utils/prompt-utils.d.ts +33 -0
- package/dist/utils/record-utils.d.ts +8 -0
- package/dist/utils/record-utils.test.d.ts +1 -0
- package/dist/utils/require-utils.d.ts +2 -0
- package/dist/utils/require-utils.test.d.ts +1 -0
- package/dist/utils/schema-utils.d.ts +13 -0
- package/dist/utils/schema-utils.test.d.ts +1 -0
- package/dist/utils/semver-utils.d.ts +8 -0
- package/dist/utils/string-utils.d.ts +2 -0
- package/dist/utils/template-utils.d.ts +1 -0
- package/dist/utils/tunnel-utils.d.ts +49 -0
- package/dist/utils/type-utils.d.ts +19 -0
- package/dist/utils/url-utils.d.ts +19 -0
- package/dist/worker/child-entrypoint.d.ts +1 -0
- package/dist/worker/child-wrapper.d.ts +18 -0
- package/dist/worker/config.d.ts +28 -0
- package/dist/worker/index.d.ts +2 -0
- package/dist/worker/is-child.d.ts +14 -0
- package/dist/worker/worker-state.d.ts +30 -0
- package/dist/worker/worker.d.ts +20 -0
- package/package.json +6 -4
- package/tsconfig.build.json +14 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 { isEqual } from 'lodash'\nimport * as pathlib from 'path'\nimport * as uuid from 'uuid'\nimport * as apiUtils from '../api'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport * as tables from '../tables'\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\nconst FILEWATCHER_DEBOUNCE_MS = 2000\n\nexport type DevCommandDefinition = typeof commandDefinitions.dev\nexport class DevCommand extends ProjectCommand<DevCommandDefinition> {\n private _initialDef: ProjectDefinition | undefined = undefined\n private _cacheDevRequestBody: apiUtils.UpdateBotRequestBody | apiUtils.UpdateIntegrationRequestBody | undefined\n private _buildContext: utils.esbuild.IncrementalBuildContext\n\n public constructor(...args: ConstructorParameters<typeof ProjectCommand<DevCommandDefinition>>) {\n super(...args)\n this._buildContext = new utils.esbuild.IncrementalBuildContext()\n }\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 cachedTunnelId = await this.projectCache.get('tunnelId')\n\n let tunnelId: string\n if (this.argv.tunnelId) {\n tunnelId = this.argv.tunnelId\n } else if (cachedTunnelId) {\n tunnelId = cachedTunnelId\n } else {\n tunnelId = uuid.v4()\n }\n\n if (cachedTunnelId !== tunnelId) {\n await this.projectCache.set('tunnelId', tunnelId)\n }\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 debounceMs: FILEWATCHER_DEBOUNCE_MS,\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: apiUtils.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: apiUtils.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.outFileCJS\n const importPath = utils.path.toUnix(outfile)\n const code = `require('${importPath}').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(this._buildContext)\n }\n\n private async _deployDevIntegration(\n api: apiUtils.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 const createIntegrationBody = {\n ...(await this.prepareCreateIntegrationBody(integrationDef)),\n ...(await this.prepareIntegrationDependencies(integrationDef, api)),\n url: externalUrl,\n }\n\n if (integration) {\n const updateIntegrationBody = apiUtils.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: apiUtils.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 updateBotBody = apiUtils.prepareUpdateBotBody(\n {\n ...(await apiUtils.prepareCreateBotBody(botDef)),\n ...(await this.prepareBotDependencies(botDef, api)),\n id: bot.id,\n url: externalUrl,\n },\n bot\n )\n\n if (!(await this._didDefinitionChange(updateBotBody))) {\n this.logger.log('Skipping deployment step. No changes found in bot.definition.ts')\n return\n }\n const updateLine = this.logger.line()\n updateLine.started('Deploying dev bot...')\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\n this.validateIntegrationRegistration(updatedBot, (failedIntegrations) => {\n throw new errors.BotpressCLIError(\n `Some integrations failed to register:\\n${Object.entries(failedIntegrations)\n .map(([key, int]) => `\u2022 ${key}: ${int.statusReason}`)\n .join('\\n')}`\n )\n })\n\n updateLine.success(`Dev Bot deployed with id \"${updatedBot.id}\" at \"${externalUrl}\"`)\n updateLine.commit()\n\n const tablesPublisher = new tables.TablesPublisher({ api, logger: this.logger, prompt: this.prompt })\n await tablesPublisher.deployTables({ botId: updatedBot.id, botDefinition: botDef })\n\n this.displayWebhookUrls(updatedBot)\n }\n\n private async _didDefinitionChange(body: apiUtils.UpdateBotRequestBody | apiUtils.UpdateIntegrationRequestBody) {\n const didChange = !isEqual(body, this._cacheDevRequestBody)\n this._cacheDevRequestBody = { ...body }\n return didChange\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,oBAAwB;AACxB,cAAyB;AACzB,WAAsB;AACtB,eAA0B;AAE1B,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,oBAAuB;AACvB,2BAA6B;AAC7B,6BAAkD;AAElD,MAAM,mBAAmB;AACzB,MAAM,2BAA2B;AACjC,MAAM,wBAAwB;AAC9B,MAAM,0BAA0B;AAGzB,MAAM,mBAAmB,sCAAqC;AAAA,EAC3D,cAA6C;AAAA,EAC7C;AAAA,EACA;AAAA,EAED,eAAe,MAA0E;AAC9F,UAAM,GAAG,IAAI;AACb,SAAK,gBAAgB,IAAI,MAAM,QAAQ,wBAAwB;AAAA,EACjE;AAAA,EAEA,MAAa,MAAqB;AAChC,SAAK,OAAO,KAAK,8EAA8E;AAE/F,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAE3D,UAAM,aAAa,
|
|
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 { isEqual } from 'lodash'\nimport * as pathlib from 'path'\nimport * as uuid from 'uuid'\nimport * as apiUtils from '../api'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport * as tables from '../tables'\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\nconst FILEWATCHER_DEBOUNCE_MS = 2000\n\nexport type DevCommandDefinition = typeof commandDefinitions.dev\nexport class DevCommand extends ProjectCommand<DevCommandDefinition> {\n private _initialDef: ProjectDefinition | undefined = undefined\n private _cacheDevRequestBody: apiUtils.UpdateBotRequestBody | apiUtils.UpdateIntegrationRequestBody | undefined\n private _buildContext: utils.esbuild.IncrementalBuildContext\n\n public constructor(...args: ConstructorParameters<typeof ProjectCommand<DevCommandDefinition>>) {\n super(...args)\n this._buildContext = new utils.esbuild.IncrementalBuildContext()\n }\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 { projectType, resolveProjectDefinition } = this.readProjectDefinitionFromFS()\n if (projectType === 'interface') {\n throw new errors.BotpressCLIError('This feature is not available for interfaces.')\n }\n const projectDef = await resolveProjectDefinition()\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 cachedTunnelId = await this.projectCache.get('tunnelId')\n\n let tunnelId: string\n if (this.argv.tunnelId) {\n tunnelId = this.argv.tunnelId\n } else if (cachedTunnelId) {\n tunnelId = cachedTunnelId\n } else {\n tunnelId = uuid.v4()\n }\n\n if (cachedTunnelId !== tunnelId) {\n await this.projectCache.set('tunnelId', tunnelId)\n }\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 debounceMs: FILEWATCHER_DEBOUNCE_MS,\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: apiUtils.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: apiUtils.ApiClient, tunnelUrl: string) => {\n const { projectType, resolveProjectDefinition } = this.readProjectDefinitionFromFS()\n\n if (projectType === 'interface') {\n throw new errors.BotpressCLIError('This feature is not available for interfaces.')\n }\n if (projectType === 'integration') {\n const projectDef = await resolveProjectDefinition()\n this._checkSecrets(projectDef.definition)\n return await this._deployDevIntegration(api, tunnelUrl, projectDef.definition)\n }\n if (projectType === 'bot') {\n const projectDef = await resolveProjectDefinition()\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.outFileCJS\n const importPath = utils.path.toUnix(outfile)\n const code = `require('${importPath}').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(this._buildContext)\n }\n\n private async _deployDevIntegration(\n api: apiUtils.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 const createIntegrationBody = {\n ...(await this.prepareCreateIntegrationBody(integrationDef)),\n ...(await this.prepareIntegrationDependencies(integrationDef, api)),\n url: externalUrl,\n }\n\n if (integration) {\n const updateIntegrationBody = apiUtils.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: apiUtils.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 updateBotBody = apiUtils.prepareUpdateBotBody(\n {\n ...(await apiUtils.prepareCreateBotBody(botDef)),\n ...(await this.prepareBotDependencies(botDef, api)),\n id: bot.id,\n url: externalUrl,\n },\n bot\n )\n\n if (!(await this._didDefinitionChange(updateBotBody))) {\n this.logger.log('Skipping deployment step. No changes found in bot.definition.ts')\n return\n }\n const updateLine = this.logger.line()\n updateLine.started('Deploying dev bot...')\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\n this.validateIntegrationRegistration(updatedBot, (failedIntegrations) => {\n throw new errors.BotpressCLIError(\n `Some integrations failed to register:\\n${Object.entries(failedIntegrations)\n .map(([key, int]) => `\u2022 ${key}: ${int.statusReason}`)\n .join('\\n')}`\n )\n })\n\n updateLine.success(`Dev Bot deployed with id \"${updatedBot.id}\" at \"${externalUrl}\"`)\n updateLine.commit()\n\n const tablesPublisher = new tables.TablesPublisher({ api, logger: this.logger, prompt: this.prompt })\n await tablesPublisher.deployTables({ botId: updatedBot.id, botDefinition: botDef })\n\n this.displayWebhookUrls(updatedBot)\n }\n\n private async _didDefinitionChange(body: apiUtils.UpdateBotRequestBody | apiUtils.UpdateIntegrationRequestBody) {\n const didChange = !isEqual(body, this._cacheDevRequestBody)\n this._cacheDevRequestBody = { ...body }\n return didChange\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,oBAAwB;AACxB,cAAyB;AACzB,WAAsB;AACtB,eAA0B;AAE1B,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,oBAAuB;AACvB,2BAA6B;AAC7B,6BAAkD;AAElD,MAAM,mBAAmB;AACzB,MAAM,2BAA2B;AACjC,MAAM,wBAAwB;AAC9B,MAAM,0BAA0B;AAGzB,MAAM,mBAAmB,sCAAqC;AAAA,EAC3D,cAA6C;AAAA,EAC7C;AAAA,EACA;AAAA,EAED,eAAe,MAA0E;AAC9F,UAAM,GAAG,IAAI;AACb,SAAK,gBAAgB,IAAI,MAAM,QAAQ,wBAAwB;AAAA,EACjE;AAAA,EAEA,MAAa,MAAqB;AAChC,SAAK,OAAO,KAAK,8EAA8E;AAE/F,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAE3D,UAAM,EAAE,aAAa,yBAAyB,IAAI,KAAK,4BAA4B;AACnF,QAAI,gBAAgB,aAAa;AAC/B,YAAM,IAAI,OAAO,iBAAiB,+CAA+C;AAAA,IACnF;AACA,UAAM,aAAa,MAAM,yBAAyB;AAClD,SAAK,cAAc;AAEnB,QAAI,MAA8B;AAAA,MAChC,GAAG,QAAQ;AAAA,MACX,YAAY,IAAI;AAAA,MAChB,UAAU,IAAI;AAAA,IAChB;AAEA,QAAI,cAAc;AAClB,QAAI,KAAK,YAAY,SAAS,eAAe;AAC3C,oBAAc;AAEd,YA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,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,OAAO,GAAG,IAAI,IAAI,IAAI,IAAI,KAAK;AAAA,IAC3C;AACA,WAAO,GAAG,OAAO,GAAG,IAAI,IAAI;AAAA,EAC9B;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
6
|
"names": ["chalk", "axios"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type commandDefinitions from '../command-definitions';
|
|
2
|
+
import { ProjectCommand } from './project-command';
|
|
3
|
+
export type GenerateCommandDefinition = typeof commandDefinitions.generate;
|
|
4
|
+
export declare class GenerateCommand extends ProjectCommand<GenerateCommandDefinition> {
|
|
5
|
+
run(): Promise<void>;
|
|
6
|
+
private _generateIntegration;
|
|
7
|
+
private _generateBot;
|
|
8
|
+
private _generatePlugin;
|
|
9
|
+
private _writeGeneratedFilesToOutFolder;
|
|
10
|
+
private _validateSecrets;
|
|
11
|
+
}
|
|
@@ -40,18 +40,21 @@ var utils = __toESM(require("../utils"));
|
|
|
40
40
|
var import_project_command = require("./project-command");
|
|
41
41
|
class GenerateCommand extends import_project_command.ProjectCommand {
|
|
42
42
|
async run() {
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
43
|
+
const { projectType, resolveProjectDefinition } = this.readProjectDefinitionFromFS();
|
|
44
|
+
if (projectType === "interface") {
|
|
45
45
|
this.logger.success("Interface projects have no code to generate since they have no implementation.");
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
|
-
if (
|
|
48
|
+
if (projectType === "integration") {
|
|
49
|
+
const projectDef = await resolveProjectDefinition();
|
|
49
50
|
return await this._generateIntegration(projectDef.definition);
|
|
50
51
|
}
|
|
51
|
-
if (
|
|
52
|
+
if (projectType === "bot") {
|
|
53
|
+
const projectDef = await resolveProjectDefinition();
|
|
52
54
|
return await this._generateBot(projectDef.definition);
|
|
53
55
|
}
|
|
54
|
-
if (
|
|
56
|
+
if (projectType === "plugin") {
|
|
57
|
+
const projectDef = await resolveProjectDefinition();
|
|
55
58
|
return await this._generatePlugin(projectDef.definition);
|
|
56
59
|
}
|
|
57
60
|
throw new errors.UnsupportedProjectType();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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
|
|
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,
|
|
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 { projectType, resolveProjectDefinition } = this.readProjectDefinitionFromFS()\n if (projectType === 'interface') {\n this.logger.success('Interface projects have no code to generate since they have no implementation.')\n return\n }\n if (projectType === 'integration') {\n const projectDef = await resolveProjectDefinition()\n return await this._generateIntegration(projectDef.definition)\n }\n if (projectType === 'bot') {\n const projectDef = await resolveProjectDefinition()\n return await this._generateBot(projectDef.definition)\n }\n if (projectType === 'plugin') {\n const projectDef = await resolveProjectDefinition()\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.dereferencePluginEntities())\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.dereferenceEntities())\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,EAAE,aAAa,yBAAyB,IAAI,KAAK,4BAA4B;AACnF,QAAI,gBAAgB,aAAa;AAC/B,WAAK,OAAO,QAAQ,gFAAgF;AACpG;AAAA,IACF;AACA,QAAI,gBAAgB,eAAe;AACjC,YAAM,aAAa,MAAM,yBAAyB;AAClD,aAAO,MAAM,KAAK,qBAAqB,WAAW,UAAU;AAAA,IAC9D;AACA,QAAI,gBAAgB,OAAO;AACzB,YAAM,aAAa,MAAM,yBAAyB;AAClD,aAAO,MAAM,KAAK,aAAa,WAAW,UAAU;AAAA,IACtD;AACA,QAAI,gBAAgB,UAAU;AAC5B,YAAM,aAAa,MAAM,yBAAyB;AAClD,aAAO,M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,OAAuB;AACnE,eAAW,QAAQ,OAAO;AACxB,YAAM,WAAW,MAAM,KAAK,aAAa,KAAK,aAAa,IAAI,QAAQ,KAAK,IAAI;AAChF,YAAM,UAAU,YAAAC,QAAQ,QAAQ,QAAQ;AACxC,YAAM,UAAAC,QAAM,SAAS,MAAM,SAAS,EAAE,WAAW,KAAK,CAAC;AACvD,YAAM,UAAAA,QAAM,SAAS,UAAU,UAAU,KAAK,OAAO;AAAA,IACvD;AAAA,EACF;AAAA,EAEQ,iBAAiB,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,UAAU,oCAAoC;AAAA,MAC5F;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["chalk", "pathlib", "fslib"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { z } from '@botpress/sdk';
|
|
2
|
+
import type { YargsConfig } from '@bpinternal/yargs-extra';
|
|
3
|
+
import type { ApiClientFactory } from '../api/client';
|
|
4
|
+
import * as config from '../config';
|
|
5
|
+
import * as consts from '../consts';
|
|
6
|
+
import type { CommandArgv, CommandDefinition } from '../typings';
|
|
7
|
+
import * as utils from '../utils';
|
|
8
|
+
import { BaseCommand } from './base-command';
|
|
9
|
+
export type GlobalCommandDefinition = CommandDefinition<typeof config.schemas.global>;
|
|
10
|
+
export type GlobalCache = {
|
|
11
|
+
apiUrl: string;
|
|
12
|
+
token: string;
|
|
13
|
+
workspaceId: string;
|
|
14
|
+
activeProfile: string;
|
|
15
|
+
};
|
|
16
|
+
export type ConfigurableGlobalPaths = {
|
|
17
|
+
botpressHomeDir: string;
|
|
18
|
+
cliRootDir: utils.path.AbsolutePath;
|
|
19
|
+
profilesPath: string;
|
|
20
|
+
};
|
|
21
|
+
export type ConstantGlobalPaths = typeof consts.fromHomeDir & typeof consts.fromCliRootDir;
|
|
22
|
+
export type AllGlobalPaths = ConfigurableGlobalPaths & ConstantGlobalPaths;
|
|
23
|
+
declare const profileCredentialSchema: import("@botpress/sdk").ZodObject<{
|
|
24
|
+
apiUrl: import("@botpress/sdk").ZodString;
|
|
25
|
+
workspaceId: import("@botpress/sdk").ZodString;
|
|
26
|
+
token: import("@botpress/sdk").ZodString;
|
|
27
|
+
}, "strip", {
|
|
28
|
+
apiUrl: string;
|
|
29
|
+
workspaceId: string;
|
|
30
|
+
token: string;
|
|
31
|
+
}, {
|
|
32
|
+
apiUrl: string;
|
|
33
|
+
workspaceId: string;
|
|
34
|
+
token: string;
|
|
35
|
+
}>;
|
|
36
|
+
export type ProfileCredentials = z.infer<typeof profileCredentialSchema>;
|
|
37
|
+
declare class GlobalPaths extends utils.path.PathStore<keyof AllGlobalPaths> {
|
|
38
|
+
constructor(argv: CommandArgv<GlobalCommandDefinition>);
|
|
39
|
+
}
|
|
40
|
+
export declare abstract class GlobalCommand<C extends GlobalCommandDefinition> extends BaseCommand<C> {
|
|
41
|
+
protected api: ApiClientFactory;
|
|
42
|
+
protected prompt: utils.prompt.CLIPrompt;
|
|
43
|
+
private _pkgJson;
|
|
44
|
+
constructor(api: ApiClientFactory, prompt: utils.prompt.CLIPrompt, ...args: ConstructorParameters<typeof BaseCommand<C>>);
|
|
45
|
+
protected get globalPaths(): GlobalPaths;
|
|
46
|
+
protected get globalCache(): utils.cache.FSKeyValueCache<GlobalCache>;
|
|
47
|
+
protected bootstrap(): Promise<void>;
|
|
48
|
+
protected teardown: () => Promise<void>;
|
|
49
|
+
protected getAuthenticatedClient(credentials: Partial<YargsConfig<typeof config.schemas.credentials>>): Promise<import("../api/client").ApiClient | null>;
|
|
50
|
+
protected readProfileFromFS(profile: string): Promise<ProfileCredentials>;
|
|
51
|
+
protected readProfilesFromFS(): Promise<Record<string, ProfileCredentials>>;
|
|
52
|
+
protected writeProfileToFS(profileName: string, profile: ProfileCredentials): Promise<void>;
|
|
53
|
+
protected ensureLoginAndCreateClient(credentials: YargsConfig<typeof config.schemas.credentials>): Promise<import("../api/client").ApiClient>;
|
|
54
|
+
private readonly _notifyUpdateCli;
|
|
55
|
+
protected readPkgJson(): Promise<utils.pkgJson.PackageJson>;
|
|
56
|
+
}
|
|
57
|
+
export {};
|