@botpress/cli 2.2.5 → 3.0.0
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 +8 -8
- package/dist/api/bot-body.js.map +2 -2
- package/dist/api/client.js +10 -2
- package/dist/api/client.js.map +2 -2
- package/dist/api/find-previous-version.test.js +1 -1
- package/dist/api/find-previous-version.test.js.map +2 -2
- package/dist/api/index.js +1 -0
- package/dist/api/index.js.map +2 -2
- package/dist/api/integration-body.js +6 -19
- package/dist/api/integration-body.js.map +2 -2
- package/dist/api/interface-body.js +1 -5
- package/dist/api/interface-body.js.map +2 -2
- package/dist/api/plugin-body.js +3 -0
- package/dist/api/plugin-body.js.map +2 -2
- package/dist/api/types.js.map +1 -1
- package/dist/code-generation/bot-implementation/bot-implementation.js +5 -2
- package/dist/code-generation/bot-implementation/bot-implementation.js.map +2 -2
- package/dist/code-generation/bot-implementation/bot-plugins/plugin-module.js +3 -0
- package/dist/code-generation/bot-implementation/bot-plugins/plugin-module.js.map +2 -2
- package/dist/code-generation/bot-implementation/bot-typings/index.js +11 -2
- package/dist/code-generation/bot-implementation/bot-typings/index.js.map +2 -2
- package/dist/code-generation/bot-implementation/bot-typings/tables-module.js +64 -0
- package/dist/code-generation/bot-implementation/bot-typings/tables-module.js.map +7 -0
- package/dist/code-generation/generators.js +11 -2
- package/dist/code-generation/generators.js.map +3 -3
- package/dist/code-generation/integration-package/index.js +4 -21
- package/dist/code-generation/integration-package/index.js.map +2 -2
- package/dist/code-generation/integration-package/integration-package-definition/actions-module.js +10 -1
- package/dist/code-generation/integration-package/integration-package-definition/actions-module.js.map +2 -2
- package/dist/code-generation/integration-package/integration-package-definition/channels-module.js +11 -1
- package/dist/code-generation/integration-package/integration-package-definition/channels-module.js.map +2 -2
- package/dist/code-generation/integration-package/integration-package-definition/configuration-module.js +10 -8
- package/dist/code-generation/integration-package/integration-package-definition/configuration-module.js.map +2 -2
- package/dist/code-generation/integration-package/integration-package-definition/configurations-module.js +10 -5
- package/dist/code-generation/integration-package/integration-package-definition/configurations-module.js.map +2 -2
- package/dist/code-generation/integration-package/integration-package-definition/entities-module.js +9 -1
- package/dist/code-generation/integration-package/integration-package-definition/entities-module.js.map +2 -2
- package/dist/code-generation/integration-package/integration-package-definition/events-module.js +9 -4
- package/dist/code-generation/integration-package/integration-package-definition/events-module.js.map +2 -2
- package/dist/code-generation/integration-package/integration-package-definition/index.js +12 -3
- package/dist/code-generation/integration-package/integration-package-definition/index.js.map +2 -2
- package/dist/code-generation/integration-package/integration-package-definition/interfaces-module.js +61 -0
- package/dist/code-generation/integration-package/integration-package-definition/interfaces-module.js.map +7 -0
- package/dist/code-generation/integration-package/integration-package-definition/states-module.js +6 -1
- package/dist/code-generation/integration-package/integration-package-definition/states-module.js.map +2 -2
- package/dist/code-generation/integration-package/integration-package-definition/typings.js.map +1 -1
- package/dist/code-generation/interface-package/index.js +4 -21
- package/dist/code-generation/interface-package/index.js.map +2 -2
- package/dist/code-generation/interface-package/interface-package-definition/actions-module.js +10 -1
- package/dist/code-generation/interface-package/interface-package-definition/actions-module.js.map +2 -2
- package/dist/code-generation/interface-package/interface-package-definition/channels-module.js +9 -1
- package/dist/code-generation/interface-package/interface-package-definition/channels-module.js.map +2 -2
- package/dist/code-generation/interface-package/interface-package-definition/entities-module.js +9 -1
- package/dist/code-generation/interface-package/interface-package-definition/entities-module.js.map +2 -2
- package/dist/code-generation/interface-package/interface-package-definition/events-module.js +9 -1
- package/dist/code-generation/interface-package/interface-package-definition/events-module.js.map +2 -2
- package/dist/code-generation/interface-package/interface-package-definition/index.js +0 -2
- package/dist/code-generation/interface-package/interface-package-definition/index.js.map +2 -2
- package/dist/code-generation/interface-package/interface-package-definition/typings.js.map +1 -1
- package/dist/code-generation/module.js +13 -7
- package/dist/code-generation/module.js.map +2 -2
- package/dist/code-generation/plugin-implementation/plugin-implementation.js +27 -4
- package/dist/code-generation/plugin-implementation/plugin-implementation.js.map +2 -2
- package/dist/code-generation/plugin-implementation/plugin-typings/index.js +19 -2
- package/dist/code-generation/plugin-implementation/plugin-typings/index.js.map +2 -2
- package/dist/code-generation/plugin-implementation/plugin-typings/tables-module.js +64 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/tables-module.js.map +7 -0
- package/dist/code-generation/plugin-package/index.js +4 -46
- package/dist/code-generation/plugin-package/index.js.map +2 -2
- package/dist/code-generation/plugin-package/plugin-package-definition/actions-module.js +8 -1
- package/dist/code-generation/plugin-package/plugin-package-definition/actions-module.js.map +2 -2
- package/dist/code-generation/plugin-package/plugin-package-definition/configuration-module.js +10 -1
- package/dist/code-generation/plugin-package/plugin-package-definition/configuration-module.js.map +2 -2
- package/dist/code-generation/plugin-package/plugin-package-definition/events-module.js +9 -4
- package/dist/code-generation/plugin-package/plugin-package-definition/events-module.js.map +2 -2
- package/dist/code-generation/plugin-package/plugin-package-definition/index.js +15 -3
- package/dist/code-generation/plugin-package/plugin-package-definition/index.js.map +2 -2
- package/dist/code-generation/plugin-package/plugin-package-definition/interfaces-module.js +58 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/interfaces-module.js.map +7 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/states-module.js +6 -1
- package/dist/code-generation/plugin-package/plugin-package-definition/states-module.js.map +2 -2
- package/dist/code-generation/plugin-package/plugin-package-definition/typings.js.map +1 -1
- package/dist/code-generation/strings.js +10 -5
- package/dist/code-generation/strings.js.map +2 -2
- package/dist/code-generation/typings.js.map +1 -1
- package/dist/code-generation/typings.test.js +15 -0
- package/dist/code-generation/typings.test.js.map +7 -0
- package/dist/command-implementations/add-command.js +70 -25
- package/dist/command-implementations/add-command.js.map +2 -2
- package/dist/command-implementations/bundle-command.js +34 -27
- package/dist/command-implementations/bundle-command.js.map +2 -2
- package/dist/command-implementations/deploy-command.js +26 -68
- package/dist/command-implementations/deploy-command.js.map +2 -2
- package/dist/command-implementations/dev-command.js +13 -17
- package/dist/command-implementations/dev-command.js.map +2 -2
- package/dist/command-implementations/lint-command.js +5 -8
- package/dist/command-implementations/lint-command.js.map +3 -3
- package/dist/command-implementations/plugin-commands.js +1 -2
- package/dist/command-implementations/plugin-commands.js.map +2 -2
- package/dist/command-implementations/project-command.js +82 -34
- package/dist/command-implementations/project-command.js.map +2 -2
- package/dist/command-implementations/read-command.js +23 -8
- package/dist/command-implementations/read-command.js.map +2 -2
- package/dist/command-implementations/serve-command.js +1 -1
- package/dist/command-implementations/serve-command.js.map +1 -1
- package/dist/consts.js +4 -2
- package/dist/consts.js.map +2 -2
- package/dist/errors.js +3 -3
- package/dist/errors.js.map +2 -2
- package/dist/linter/base-linter.test.js +6 -1
- package/dist/linter/base-linter.test.js.map +2 -2
- package/dist/linter/bot-linter.js.map +2 -2
- package/dist/linter/integration-linter.js.map +1 -1
- package/dist/linter/interface-linter.js.map +2 -2
- package/dist/linter/ruleset-tests/bot.ruleset.test.js.map +2 -2
- package/dist/linter/ruleset-tests/interface.ruleset.test.js.map +2 -2
- package/dist/sdk/index.js +0 -2
- package/dist/sdk/index.js.map +2 -2
- package/dist/{sdk/resolve-bot-interfaces.js → tables/index.js} +7 -21
- package/dist/tables/index.js.map +7 -0
- package/dist/tables/schemas.js +106 -0
- package/dist/tables/schemas.js.map +7 -0
- package/dist/tables/tables-publisher.js +157 -0
- package/dist/tables/tables-publisher.js.map +7 -0
- package/dist/utils/esbuild-utils.js +15 -13
- package/dist/utils/esbuild-utils.js.map +2 -2
- package/dist/utils/type-utils.js.map +1 -1
- package/package.json +2 -2
- package/templates/empty-bot/.botpress/implementation/index.ts +5 -2
- package/templates/empty-bot/.botpress/implementation/typings/index.ts +3 -0
- package/templates/empty-bot/.botpress/implementation/typings/tables/index.ts +6 -0
- package/templates/empty-bot/package.json +1 -1
- package/templates/empty-integration/package.json +1 -1
- package/templates/empty-plugin/.botpress/implementation/index.ts +27 -4
- package/templates/empty-plugin/.botpress/implementation/typings/index.ts +3 -0
- package/templates/empty-plugin/.botpress/implementation/typings/tables/index.ts +6 -0
- package/templates/empty-plugin/package.json +1 -1
- package/templates/hello-world/package.json +1 -1
- package/templates/webhook-message/package.json +1 -1
- package/dist/sdk/resolve-bot-interfaces.js.map +0 -7
- package/dist/sdk/resolve-integration-interfaces.js +0 -161
- package/dist/sdk/resolve-integration-interfaces.js.map +0 -7
|
@@ -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 * 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,
|
|
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 * as apiUtils from '../api'\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'\nimport * as tables from '../tables'\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: 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()\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 let createIntegrationBody = await this.prepareCreateIntegrationBody(integrationDef)\n createIntegrationBody = {\n ...createIntegrationBody,\n interfaces: await this.fetchIntegrationInterfaceInstances(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 updateLine = this.logger.line()\n updateLine.started('Deploying dev bot...')\n\n const integrationInstances = await this.fetchBotIntegrationInstances(botDef, api)\n const createBotBody = await apiUtils.prepareCreateBotBody(botDef)\n const updateBotBody = apiUtils.prepareUpdateBotBody(\n {\n ...createBotBody,\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 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 _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,eAA0B;AAE1B,aAAwB;AACxB,YAAuB;AACvB,oBAAuB;AACvB,2B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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
|
}
|
|
@@ -32,14 +32,11 @@ __export(lint_command_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(lint_command_exports);
|
|
34
34
|
var import_sdk = require("@botpress/sdk");
|
|
35
|
-
var
|
|
36
|
-
var import_integration_body = require("../api/integration-body");
|
|
37
|
-
var import_interface_body = require("../api/interface-body");
|
|
35
|
+
var apiUtils = __toESM(require("../api"));
|
|
38
36
|
var errors = __toESM(require("../errors"));
|
|
39
37
|
var import_bot_linter = require("../linter/bot-linter");
|
|
40
38
|
var import_integration_linter = require("../linter/integration-linter");
|
|
41
39
|
var import_interface_linter = require("../linter/interface-linter");
|
|
42
|
-
var import_sdk2 = require("../sdk");
|
|
43
40
|
var import_project_command = require("./project-command");
|
|
44
41
|
class LintCommand extends import_project_command.ProjectCommand {
|
|
45
42
|
async run() {
|
|
@@ -68,7 +65,7 @@ class LintCommand extends import_project_command.ProjectCommand {
|
|
|
68
65
|
for (const [eventName, eventDef] of Object.entries(definition.events)) {
|
|
69
66
|
definition.events[eventName] = this._dereferenceEventDefinition(eventDef);
|
|
70
67
|
}
|
|
71
|
-
const parsedInterfaceDefinition = await
|
|
68
|
+
const parsedInterfaceDefinition = await apiUtils.prepareCreateInterfaceBody(definition);
|
|
72
69
|
const linter = new import_interface_linter.InterfaceLinter(parsedInterfaceDefinition);
|
|
73
70
|
await linter.lint();
|
|
74
71
|
linter.logResults(this.logger);
|
|
@@ -79,7 +76,7 @@ class LintCommand extends import_project_command.ProjectCommand {
|
|
|
79
76
|
}
|
|
80
77
|
async _runLintForBot(definition) {
|
|
81
78
|
const strippedDefinition = this._stripAutoGeneratedContentFromBot(definition);
|
|
82
|
-
const parsedBotDefinition = await
|
|
79
|
+
const parsedBotDefinition = await apiUtils.prepareCreateBotBody(strippedDefinition);
|
|
83
80
|
const linter = new import_bot_linter.BotLinter(parsedBotDefinition);
|
|
84
81
|
await linter.lint();
|
|
85
82
|
linter.logResults(this.logger);
|
|
@@ -96,7 +93,7 @@ class LintCommand extends import_project_command.ProjectCommand {
|
|
|
96
93
|
}
|
|
97
94
|
async _runLintForIntegration(definition) {
|
|
98
95
|
const strippedDefinition = this._stripAutoGeneratedContentFromIntegration(definition);
|
|
99
|
-
const parsedIntegrationDefinition = await
|
|
96
|
+
const parsedIntegrationDefinition = await this.prepareCreateIntegrationBody(strippedDefinition);
|
|
100
97
|
const linter = new import_integration_linter.IntegrationLinter({ ...parsedIntegrationDefinition, secrets: strippedDefinition.secrets });
|
|
101
98
|
await linter.lint();
|
|
102
99
|
linter.logResults(this.logger);
|
|
@@ -116,7 +113,7 @@ class LintCommand extends import_project_command.ProjectCommand {
|
|
|
116
113
|
_getAutoGeneratedContentOfIntegration(definition) {
|
|
117
114
|
const actionNames = /* @__PURE__ */ new Set();
|
|
118
115
|
const eventNames = /* @__PURE__ */ new Set();
|
|
119
|
-
const interfacesStatements =
|
|
116
|
+
const interfacesStatements = definition.interfaces ?? {};
|
|
120
117
|
for (const iface of Object.values(interfacesStatements)) {
|
|
121
118
|
for (const actionDefinition of Object.values(iface.actions)) {
|
|
122
119
|
actionNames.add(actionDefinition.name);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/command-implementations/lint-command.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type IntegrationDefinition,\n type BotDefinition,\n type InterfaceDefinition,\n ActionDefinition,\n z,\n EventDefinition,\n} from '@botpress/sdk'\nimport
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAOO;AACP,
|
|
6
|
-
"names": [
|
|
4
|
+
"sourcesContent": ["import {\n type IntegrationDefinition,\n type BotDefinition,\n type InterfaceDefinition,\n ActionDefinition,\n z,\n EventDefinition,\n} from '@botpress/sdk'\nimport * as apiUtils from '../api'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport { BotLinter } from '../linter/bot-linter'\nimport { IntegrationLinter } from '../linter/integration-linter'\nimport { InterfaceLinter } from '../linter/interface-linter'\nimport { ProjectCommand } from './project-command'\n\nexport type LintCommandDefinition = typeof commandDefinitions.lint\nexport class LintCommand extends ProjectCommand<LintCommandDefinition> {\n public async run(): Promise<void> {\n const projectDef = await this.readProjectDefinitionFromFS()\n if (projectDef.bpLintDisabled) {\n this.logger.warn(\n 'Linting is disabled for this project because of a bplint directive. To enable linting, remove the \"bplint-disable\" directive from the project definition file'\n )\n return\n }\n\n switch (projectDef.type) {\n case 'integration':\n return this._runLintForIntegration(projectDef.definition)\n case 'bot':\n return this._runLintForBot(projectDef.definition)\n case 'interface':\n return this._runLintForInterface(projectDef.definition)\n default:\n throw new errors.UnsupportedProjectType()\n }\n }\n\n private async _runLintForInterface(definition: InterfaceDefinition): Promise<void> {\n for (const [actionName, actionDef] of Object.entries(definition.actions)) {\n definition.actions[actionName] = this._dereferenceActionDefinition(actionDef)\n }\n\n for (const [eventName, eventDef] of Object.entries(definition.events)) {\n definition.events[eventName] = this._dereferenceEventDefinition(eventDef)\n }\n\n const parsedInterfaceDefinition = await apiUtils.prepareCreateInterfaceBody(definition)\n const linter = new InterfaceLinter(parsedInterfaceDefinition)\n\n await linter.lint()\n linter.logResults(this.logger)\n\n if (linter.hasErrors()) {\n throw new errors.BotpressCLIError('Interface definition contains linting errors')\n }\n\n this.logger.success('Interface definition is valid')\n }\n\n private async _runLintForBot(definition: BotDefinition): Promise<void> {\n const strippedDefinition = this._stripAutoGeneratedContentFromBot(definition)\n const parsedBotDefinition = await apiUtils.prepareCreateBotBody(strippedDefinition)\n const linter = new BotLinter(parsedBotDefinition)\n\n await linter.lint()\n linter.logResults(this.logger)\n\n if (linter.hasErrors()) {\n throw new errors.BotpressCLIError('Bot definition contains linting errors')\n }\n\n this.logger.success('Bot definition is valid')\n }\n\n private _stripAutoGeneratedContentFromBot(definition: BotDefinition) {\n return {\n ...definition,\n integrations: {},\n } as BotDefinition\n }\n\n private async _runLintForIntegration(definition: IntegrationDefinition): Promise<void> {\n const strippedDefinition = this._stripAutoGeneratedContentFromIntegration(definition)\n const parsedIntegrationDefinition = await this.prepareCreateIntegrationBody(strippedDefinition)\n const linter = new IntegrationLinter({ ...parsedIntegrationDefinition, secrets: strippedDefinition.secrets })\n\n await linter.lint()\n linter.logResults(this.logger)\n\n if (linter.hasErrors()) {\n throw new errors.BotpressCLIError('Integration definition contains linting errors')\n }\n\n this.logger.success('Integration definition is valid')\n }\n\n private _stripAutoGeneratedContentFromIntegration(definition: IntegrationDefinition) {\n const { actionNames, eventNames } = this._getAutoGeneratedContentOfIntegration(definition)\n\n return {\n ...definition,\n actions: Object.fromEntries(Object.entries(definition.actions ?? {}).filter(([key]) => !actionNames.has(key))),\n events: Object.fromEntries(Object.entries(definition.events ?? {}).filter(([key]) => !eventNames.has(key))),\n } as IntegrationDefinition\n }\n\n private _getAutoGeneratedContentOfIntegration(definition: IntegrationDefinition) {\n const actionNames = new Set<string>()\n const eventNames = new Set<string>()\n\n const interfacesStatements = definition.interfaces ?? {}\n for (const iface of Object.values(interfacesStatements)) {\n for (const actionDefinition of Object.values(iface.actions)) {\n actionNames.add(actionDefinition.name)\n }\n for (const eventDefinition of Object.values(iface.events)) {\n eventNames.add(eventDefinition.name)\n }\n }\n\n return { actionNames, eventNames } as const\n }\n\n private _dereferenceActionDefinition = (actionDef: ActionDefinition): ActionDefinition => {\n const inputRefs = actionDef.input.schema.getReferences()\n const outputRefs = actionDef.output.schema.getReferences()\n\n const inputRefSchemas = Object.fromEntries(inputRefs.map((ref) => [ref, this._replaceRef(ref)]))\n const outputRefSchemas = Object.fromEntries(outputRefs.map((ref) => [ref, this._replaceRef(ref)]))\n\n actionDef.input.schema = actionDef.input.schema.dereference(inputRefSchemas) as z.ZodObject\n actionDef.output.schema = actionDef.output.schema.dereference(outputRefSchemas) as z.ZodObject\n\n return actionDef\n }\n\n private _dereferenceEventDefinition = (eventDef: EventDefinition): EventDefinition => {\n const refs = eventDef.schema.getReferences()\n\n const refSchemas = Object.fromEntries(refs.map((ref) => [ref, this._replaceRef(ref)]))\n\n eventDef.schema = eventDef.schema.dereference(refSchemas) as z.ZodObject\n\n return eventDef\n }\n\n private _replaceRef = (refUri: string): z.ZodObject => z.object({}).title(refUri).describe(refUri)\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAOO;AACP,eAA0B;AAE1B,aAAwB;AACxB,wBAA0B;AAC1B,gCAAkC;AAClC,8BAAgC;AAChC,6BAA+B;AAGxB,MAAM,oBAAoB,sCAAsC;AAAA,EACrE,MAAa,MAAqB;AAChC,UAAM,aAAa,MAAM,KAAK,4BAA4B;AAC1D,QAAI,WAAW,gBAAgB;AAC7B,WAAK,OAAO;AAAA,QACV;AAAA,MACF;AACA;AAAA,IACF;AAEA,YAAQ,WAAW,MAAM;AAAA,MACvB,KAAK;AACH,eAAO,KAAK,uBAAuB,WAAW,UAAU;AAAA,MAC1D,KAAK;AACH,eAAO,KAAK,eAAe,WAAW,UAAU;AAAA,MAClD,KAAK;AACH,eAAO,KAAK,qBAAqB,WAAW,UAAU;AAAA,MACxD;AACE,cAAM,IAAI,OAAO,uBAAuB;AAAA,IAC5C;AAAA,EACF;AAAA,EAEA,MAAc,qBAAqB,YAAgD;AACjF,eAAW,CAAC,YAAY,SAAS,KAAK,OAAO,QAAQ,WAAW,OAAO,GAAG;AACxE,iBAAW,QAAQ,UAAU,IAAI,KAAK,6B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AAU,MAAM,SAAS,UAAU,MAAM,OAAO,YAAY,eAAe;AAC3E,cAAU,OAAO,SAAS,UAAU,OAAO,OAAO,YAAY,gBAAgB;AAE9E,WAAO;AAAA,EACT;AAAA,EAEQ,8BAA8B,CAAC,aAA+C;AACpF,UAAM,OAAO,SAAS,OAAO,cAAc;AAE3C,UAAM,aAAa,OAAO,YAAY,KAAK,IAAI,CAAC,QAAQ,CAAC,KAAK,KAAK,YAAY,GAAG,CAAC,CAAC,CAAC;AAErF,aAAS,SAAS,SAAS,OAAO,YAAY,UAAU;AAExD,WAAO;AAAA,EACT;AAAA,EAEQ,cAAc,CAAC,WAAgC,aAAE,OAAO,CAAC,CAAC,EAAE,MAAM,MAAM,EAAE,SAAS,MAAM;AACnG;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -36,7 +36,6 @@ module.exports = __toCommonJS(plugin_commands_exports);
|
|
|
36
36
|
var import_chalk = __toESM(require("chalk"));
|
|
37
37
|
var errors = __toESM(require("../errors"));
|
|
38
38
|
var import_package_ref = require("../package-ref");
|
|
39
|
-
var utils = __toESM(require("../utils"));
|
|
40
39
|
var import_global_command = require("./global-command");
|
|
41
40
|
class GetPluginCommand extends import_global_command.GlobalCommand {
|
|
42
41
|
async run() {
|
|
@@ -52,7 +51,7 @@ class GetPluginCommand extends import_global_command.GlobalCommand {
|
|
|
52
51
|
const plugin = await api.findPublicPlugin(parsedRef);
|
|
53
52
|
if (plugin) {
|
|
54
53
|
this.logger.success(`Plugin ${import_chalk.default.bold(this.argv.pluginRef)}:`);
|
|
55
|
-
this.logger.json(
|
|
54
|
+
this.logger.json(plugin);
|
|
56
55
|
return;
|
|
57
56
|
}
|
|
58
57
|
} catch (thrown) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/command-implementations/plugin-commands.ts"],
|
|
4
|
-
"sourcesContent": ["import type * as client from '@botpress/client'\nimport chalk from 'chalk'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport { parsePackageRef } from '../package-ref'\nimport
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAElB,aAAwB;AACxB,yBAAgC;AAChC,
|
|
4
|
+
"sourcesContent": ["import type * as client from '@botpress/client'\nimport chalk from 'chalk'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport { parsePackageRef } from '../package-ref'\nimport { GlobalCommand } from './global-command'\n\nexport type GetPluginCommandDefinition = typeof commandDefinitions.plugins.subcommands.get\nexport class GetPluginCommand extends GlobalCommand<GetPluginCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n const parsedRef = parsePackageRef(this.argv.pluginRef)\n if (!parsedRef) {\n throw new errors.InvalidPackageReferenceError(this.argv.pluginRef)\n }\n if (parsedRef.type === 'path') {\n throw new errors.BotpressCLIError('Cannot get local plugin')\n }\n\n try {\n const plugin = await api.findPublicPlugin(parsedRef)\n if (plugin) {\n this.logger.success(`Plugin ${chalk.bold(this.argv.pluginRef)}:`)\n this.logger.json(plugin)\n return\n }\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, `Could not get plugin ${this.argv.pluginRef}`)\n }\n\n throw new errors.BotpressCLIError(`Plugin ${this.argv.pluginRef} not found`)\n }\n}\n\nexport type ListPluginsCommandDefinition = typeof commandDefinitions.plugins.subcommands.list\nexport class ListPluginsCommand extends GlobalCommand<ListPluginsCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n\n const lister = (req: { nextToken?: string }) => api.client.listPlugins({ nextToken: req.nextToken })\n\n try {\n const plugins = await api.listAllPages(lister, (r) => r.plugins)\n\n this.logger.success('Plugins:')\n this.logger.json(plugins)\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not list plugins')\n }\n }\n}\n\nexport type DeletePluginCommandDefinition = typeof commandDefinitions.plugins.subcommands.delete\nexport class DeletePluginCommand extends GlobalCommand<DeletePluginCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n const parsedRef = parsePackageRef(this.argv.pluginRef)\n if (!parsedRef) {\n throw new errors.InvalidPackageReferenceError(this.argv.pluginRef)\n }\n if (parsedRef.type === 'path') {\n throw new errors.BotpressCLIError('Cannot delete local plugin')\n }\n\n let plugin: client.Plugin | undefined\n try {\n plugin = await api.findPublicPlugin(parsedRef)\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, `Could not get plugin ${this.argv.pluginRef}`)\n }\n\n if (!plugin) {\n throw new errors.BotpressCLIError(`Plugin ${this.argv.pluginRef} not found`)\n }\n\n try {\n await api.client.deletePlugin({ id: plugin.id })\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, `Could not delete plugin ${this.argv.pluginRef}`)\n }\n\n this.logger.success(`Plugin ${chalk.bold(this.argv.pluginRef)} deleted`)\n return\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAElB,aAAwB;AACxB,yBAAgC;AAChC,4BAA8B;AAGvB,MAAM,yBAAyB,oCAA0C;AAAA,EAC9E,MAAa,MAAqB;AAChC,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAC3D,UAAM,gBAAY,oCAAgB,KAAK,KAAK,SAAS;AACrD,QAAI,CAAC,WAAW;AACd,YAAM,IAAI,OAAO,6BAA6B,KAAK,KAAK,SAAS;AAAA,IACnE;AACA,QAAI,UAAU,SAAS,QAAQ;AAC7B,YAAM,IAAI,OAAO,iBAAiB,yBAAyB;AAAA,IAC7D;AAEA,QAAI;AACF,YAAM,SAAS,MAAM,IAAI,iBAAiB,SAAS;AACnD,UAAI,QAAQ;A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AQ;AACX,YAAM,IAAI,OAAO,iBAAiB,UAAU,KAAK,KAAK,qBAAqB;AAAA,IAC7E;AAEA,QAAI;AACF,YAAM,IAAI,OAAO,aAAa,EAAE,IAAI,OAAO,GAAG,CAAC;AAAA,IACjD,SAAS,QAAP;AACA,YAAM,OAAO,iBAAiB,KAAK,QAAQ,2BAA2B,KAAK,KAAK,WAAW;AAAA,IAC7F;AAEA,SAAK,OAAO,QAAQ,UAAU,aAAAA,QAAM,KAAK,KAAK,KAAK,SAAS,WAAW;AACvE;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["chalk"]
|
|
7
7
|
}
|
|
@@ -36,6 +36,7 @@ var import_chalk = __toESM(require("chalk"));
|
|
|
36
36
|
var import_fs = __toESM(require("fs"));
|
|
37
37
|
var import_lodash = __toESM(require("lodash"));
|
|
38
38
|
var import_semver = __toESM(require("semver"));
|
|
39
|
+
var apiUtils = __toESM(require("../api"));
|
|
39
40
|
var codegen = __toESM(require("../code-generation"));
|
|
40
41
|
var consts = __toESM(require("../consts"));
|
|
41
42
|
var errors = __toESM(require("../errors"));
|
|
@@ -66,21 +67,41 @@ class ProjectCommand extends import_global_command.GlobalCommand {
|
|
|
66
67
|
async fetchBotIntegrationInstances(botDefinition, api) {
|
|
67
68
|
const integrationList = (0, import_lodash.default)(botDefinition.integrations).values().filter(utils.guards.is.defined).value();
|
|
68
69
|
const { remoteInstances, localInstances } = this._splitApiAndLocalIntegrationInstances(integrationList);
|
|
69
|
-
const fetchedInstances = await import_bluebird.default.map(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
70
|
+
const fetchedInstances = await import_bluebird.default.map(
|
|
71
|
+
localInstances,
|
|
72
|
+
async (instance) => {
|
|
73
|
+
const ref = { type: "name", name: instance.name, version: instance.version };
|
|
74
|
+
const integration = await api.findIntegration(ref);
|
|
75
|
+
if (!integration) {
|
|
76
|
+
const formattedRef = (0, import_package_ref.formatPackageRef)(ref);
|
|
77
|
+
throw new errors.BotpressCLIError(`Integration "${formattedRef}" not found`);
|
|
78
|
+
}
|
|
79
|
+
return { ...instance, id: integration.id };
|
|
75
80
|
}
|
|
76
|
-
|
|
77
|
-
});
|
|
81
|
+
);
|
|
78
82
|
return (0, import_lodash.default)([...fetchedInstances, ...remoteInstances]).keyBy((i) => i.id).mapValues(({ enabled, configurationType, configuration }) => ({
|
|
79
83
|
enabled,
|
|
80
84
|
configurationType: configurationType ?? null,
|
|
81
85
|
configuration
|
|
82
86
|
})).value();
|
|
83
87
|
}
|
|
88
|
+
async fetchIntegrationInterfaceInstances(integrationDefinition, api) {
|
|
89
|
+
const interfaceList = (0, import_lodash.default)(integrationDefinition.interfaces).values().filter(utils.guards.is.defined).value();
|
|
90
|
+
const { remoteInstances, localInstances } = this._splitApiAndLocalInterfaceInstances(interfaceList);
|
|
91
|
+
const fetchedInstances = await import_bluebird.default.map(
|
|
92
|
+
localInstances,
|
|
93
|
+
async (instance) => {
|
|
94
|
+
const ref = { type: "name", name: instance.name, version: instance.version };
|
|
95
|
+
const interfaceInstance = await api.findPublicInterface(ref);
|
|
96
|
+
if (!interfaceInstance) {
|
|
97
|
+
const formattedRef = (0, import_package_ref.formatPackageRef)(ref);
|
|
98
|
+
throw new errors.BotpressCLIError(`Interface "${formattedRef}" not found`);
|
|
99
|
+
}
|
|
100
|
+
return { ...instance, id: interfaceInstance.id };
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
return (0, import_lodash.default)([...fetchedInstances, ...remoteInstances]).keyBy((i) => i.id).value();
|
|
104
|
+
}
|
|
84
105
|
_splitApiAndLocalIntegrationInstances(instances) {
|
|
85
106
|
const remoteInstances = [];
|
|
86
107
|
const localInstances = [];
|
|
@@ -94,6 +115,19 @@ class ProjectCommand extends import_global_command.GlobalCommand {
|
|
|
94
115
|
}
|
|
95
116
|
return { remoteInstances, localInstances };
|
|
96
117
|
}
|
|
118
|
+
_splitApiAndLocalInterfaceInstances(instances) {
|
|
119
|
+
const remoteInstances = [];
|
|
120
|
+
const localInstances = [];
|
|
121
|
+
for (const instance of instances) {
|
|
122
|
+
const { id } = instance;
|
|
123
|
+
if (id) {
|
|
124
|
+
remoteInstances.push({ ...instance, id });
|
|
125
|
+
} else {
|
|
126
|
+
localInstances.push(instance);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return { remoteInstances, localInstances };
|
|
130
|
+
}
|
|
97
131
|
async readProjectDefinitionFromFS() {
|
|
98
132
|
const projectPaths = this.projectPaths;
|
|
99
133
|
try {
|
|
@@ -127,16 +161,13 @@ class ProjectCommand extends import_global_command.GlobalCommand {
|
|
|
127
161
|
const bpLintDisabled = await this._isBpLintDisabled(abs.integrationDefinition);
|
|
128
162
|
const { outputFiles } = await utils.esbuild.buildEntrypoint({
|
|
129
163
|
absWorkingDir: abs.workDir,
|
|
130
|
-
entrypoint: rel.integrationDefinition
|
|
131
|
-
write: false,
|
|
132
|
-
minify: false
|
|
164
|
+
entrypoint: rel.integrationDefinition
|
|
133
165
|
});
|
|
134
166
|
const artifact = outputFiles[0];
|
|
135
167
|
if (!artifact) {
|
|
136
168
|
throw new errors.BotpressCLIError("Could not read integration definition");
|
|
137
169
|
}
|
|
138
|
-
|
|
139
|
-
definition = (0, import_sdk.resolveInterfaces)(definition);
|
|
170
|
+
const { default: definition } = utils.require.requireJsCode(artifact.text);
|
|
140
171
|
(0, import_sdk.validateIntegrationDefinition)(definition);
|
|
141
172
|
return { definition, bpLintDisabled };
|
|
142
173
|
}
|
|
@@ -149,9 +180,7 @@ class ProjectCommand extends import_global_command.GlobalCommand {
|
|
|
149
180
|
const bpLintDisabled = await this._isBpLintDisabled(abs.interfaceDefinition);
|
|
150
181
|
const { outputFiles } = await utils.esbuild.buildEntrypoint({
|
|
151
182
|
absWorkingDir: abs.workDir,
|
|
152
|
-
entrypoint: rel.interfaceDefinition
|
|
153
|
-
write: false,
|
|
154
|
-
minify: false
|
|
183
|
+
entrypoint: rel.interfaceDefinition
|
|
155
184
|
});
|
|
156
185
|
const artifact = outputFiles[0];
|
|
157
186
|
if (!artifact) {
|
|
@@ -169,16 +198,13 @@ class ProjectCommand extends import_global_command.GlobalCommand {
|
|
|
169
198
|
const bpLintDisabled = await this._isBpLintDisabled(abs.botDefinition);
|
|
170
199
|
const { outputFiles } = await utils.esbuild.buildEntrypoint({
|
|
171
200
|
absWorkingDir: abs.workDir,
|
|
172
|
-
entrypoint: rel.botDefinition
|
|
173
|
-
write: false,
|
|
174
|
-
minify: false
|
|
201
|
+
entrypoint: rel.botDefinition
|
|
175
202
|
});
|
|
176
203
|
const artifact = outputFiles[0];
|
|
177
204
|
if (!artifact) {
|
|
178
205
|
throw new errors.BotpressCLIError("Could not read bot definition");
|
|
179
206
|
}
|
|
180
|
-
|
|
181
|
-
definition = (0, import_sdk.resolveBotInterfaces)(definition);
|
|
207
|
+
const { default: definition } = utils.require.requireJsCode(artifact.text);
|
|
182
208
|
(0, import_sdk.validateBotDefinition)(definition);
|
|
183
209
|
return { definition, bpLintDisabled };
|
|
184
210
|
}
|
|
@@ -191,9 +217,7 @@ class ProjectCommand extends import_global_command.GlobalCommand {
|
|
|
191
217
|
const bpLintDisabled = await this._isBpLintDisabled(abs.pluginDefinition);
|
|
192
218
|
const { outputFiles } = await utils.esbuild.buildEntrypoint({
|
|
193
219
|
absWorkingDir: abs.workDir,
|
|
194
|
-
entrypoint: rel.pluginDefinition
|
|
195
|
-
write: false,
|
|
196
|
-
minify: false
|
|
220
|
+
entrypoint: rel.pluginDefinition
|
|
197
221
|
});
|
|
198
222
|
const artifact = outputFiles[0];
|
|
199
223
|
if (!artifact) {
|
|
@@ -284,24 +308,48 @@ class ProjectCommand extends import_global_command.GlobalCommand {
|
|
|
284
308
|
const envVariables = import_lodash.default.mapKeys(values, (_v, k) => codegen.secretEnvVariableName(k));
|
|
285
309
|
return envVariables;
|
|
286
310
|
}
|
|
287
|
-
async
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
311
|
+
async prepareCreateIntegrationBody(integrationDef) {
|
|
312
|
+
const partialBody = await apiUtils.prepareCreateIntegrationBody(integrationDef);
|
|
313
|
+
const code = await this.readProjectFile(this.projectPaths.abs.outFileCJS);
|
|
314
|
+
const icon = await this.readProjectFile(integrationDef.icon, "base64");
|
|
315
|
+
const readme = await this.readProjectFile(integrationDef.readme, "base64");
|
|
316
|
+
const extractScript = await this.readProjectFile(integrationDef.identifier?.extractScript);
|
|
317
|
+
const fallbackHandlerScript = await this.readProjectFile(integrationDef.identifier?.fallbackHandlerScript);
|
|
291
318
|
return {
|
|
292
|
-
...
|
|
319
|
+
...partialBody,
|
|
320
|
+
code,
|
|
321
|
+
icon,
|
|
322
|
+
readme,
|
|
293
323
|
identifier: {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
324
|
+
extractScript,
|
|
325
|
+
fallbackHandlerScript
|
|
326
|
+
},
|
|
327
|
+
configuration: integrationDef.configuration ? {
|
|
328
|
+
schema: await utils.schema.mapZodToJsonSchema(integrationDef.configuration),
|
|
329
|
+
identifier: {
|
|
330
|
+
required: integrationDef.configuration.identifier?.required,
|
|
331
|
+
linkTemplateScript: await this.readProjectFile(
|
|
332
|
+
integrationDef.configuration.identifier?.linkTemplateScript
|
|
333
|
+
)
|
|
334
|
+
}
|
|
335
|
+
} : void 0,
|
|
336
|
+
configurations: integrationDef.configurations ? await utils.records.mapValuesAsync(integrationDef.configurations, async (configuration) => ({
|
|
337
|
+
title: configuration.title,
|
|
338
|
+
description: configuration.description,
|
|
339
|
+
schema: await utils.schema.mapZodToJsonSchema(configuration),
|
|
340
|
+
identifier: {
|
|
341
|
+
required: configuration.identifier?.required,
|
|
342
|
+
linkTemplateScript: await this.readProjectFile(configuration.identifier?.linkTemplateScript)
|
|
343
|
+
}
|
|
344
|
+
})) : void 0
|
|
297
345
|
};
|
|
298
346
|
}
|
|
299
|
-
readProjectFile = async (filePath) => {
|
|
347
|
+
readProjectFile = async (filePath, encoding = "utf-8") => {
|
|
300
348
|
if (!filePath) {
|
|
301
349
|
return void 0;
|
|
302
350
|
}
|
|
303
351
|
const absoluteFilePath = utils.path.absoluteFrom(this.projectPaths.abs.workDir, filePath);
|
|
304
|
-
return import_fs.default.promises.readFile(absoluteFilePath,
|
|
352
|
+
return import_fs.default.promises.readFile(absoluteFilePath, encoding).catch((thrown) => {
|
|
305
353
|
throw errors.BotpressCLIError.wrap(thrown, `Could not read file "${absoluteFilePath}"`);
|
|
306
354
|
});
|
|
307
355
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/command-implementations/project-command.ts"],
|
|
4
|
-
"sourcesContent": ["import type * as client from '@botpress/client'\nimport type * as sdk from '@botpress/sdk'\nimport type { YargsConfig } from '@bpinternal/yargs-extra'\nimport bluebird from 'bluebird'\nimport chalk from 'chalk'\nimport fs from 'fs'\nimport _ from 'lodash'\nimport semver from 'semver'\nimport { ApiClient } from '../api/client'\nimport * as codegen from '../code-generation'\nimport type * as config from '../config'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport { formatPackageRef, PackageRef } from '../package-ref'\nimport { validateIntegrationDefinition, resolveInterfaces, resolveBotInterfaces, validateBotDefinition } from '../sdk'\nimport type { CommandArgv, CommandDefinition } from '../typings'\nimport * as utils from '../utils'\nimport { GlobalCommand } from './global-command'\n\nexport type ProjectCommandDefinition = CommandDefinition<typeof config.schemas.project>\nexport type ProjectCache = { botId: string; devId: string }\n\ntype ConfigurableProjectPaths = { workDir: string }\ntype ConstantProjectPaths = typeof consts.fromWorkDir\ntype AllProjectPaths = ConfigurableProjectPaths & ConstantProjectPaths\n\ntype IntegrationInstance = NonNullable<sdk.BotDefinition['integrations']>[string]\ntype RemoteIntegrationInstance = utils.types.Merge<IntegrationInstance, { id: string }>\ntype LocalIntegrationInstance = utils.types.Merge<IntegrationInstance, { uri?: string }>\ntype BotIntegrationRequest = NonNullable<NonNullable<client.ClientInputs['updateBot']['integrations']>[string]>\n\ntype LintIgnoredConfig = { bpLintDisabled?: boolean }\n\nexport type ProjectType = ProjectDefinition['type']\nexport type ProjectDefinition = LintIgnoredConfig &\n (\n | { type: 'integration'; definition: sdk.IntegrationDefinition }\n | { type: 'interface'; definition: sdk.InterfaceDefinition }\n | { type: 'bot'; definition: sdk.BotDefinition }\n | { type: 'plugin'; definition: sdk.PluginDefinition }\n )\n\nclass ProjectPaths extends utils.path.PathStore<keyof AllProjectPaths> {\n public constructor(argv: CommandArgv<ProjectCommandDefinition>) {\n const absWorkDir = utils.path.absoluteFrom(utils.path.cwd(), argv.workDir)\n super({\n workDir: absWorkDir,\n ..._.mapValues(consts.fromWorkDir, (p) => utils.path.absoluteFrom(absWorkDir, p)),\n })\n }\n}\n\nexport abstract class ProjectCommand<C extends ProjectCommandDefinition> extends GlobalCommand<C> {\n protected override async bootstrap() {\n await super.bootstrap()\n await this._notifyUpdateSdk()\n }\n\n protected get projectPaths() {\n return new ProjectPaths(this.argv)\n }\n\n protected get projectCache() {\n return new utils.cache.FSKeyValueCache<ProjectCache>(this.projectPaths.abs.projectCacheFile)\n }\n\n protected async fetchBotIntegrationInstances(\n botDefinition: sdk.BotDefinition,\n api: ApiClient\n ): Promise<Record<string, BotIntegrationRequest>> {\n const integrationList = _(botDefinition.integrations).values().filter(utils.guards.is.defined).value()\n\n const { remoteInstances, localInstances } = this._splitApiAndLocalIntegrationInstances(integrationList)\n\n const fetchedInstances: RemoteIntegrationInstance[] = await bluebird.map(localInstances, async (instance) => {\n const ref: PackageRef = { type: 'name', name: instance.name, version: instance.version }\n const integration = await api.findIntegration(ref)\n if (!integration) {\n const formattedRef = formatPackageRef(ref)\n throw new errors.BotpressCLIError(`Integration \"${formattedRef}\" not found`)\n }\n return { ...instance, id: integration.id }\n })\n\n return _([...fetchedInstances, ...remoteInstances])\n .keyBy((i) => i.id)\n .mapValues(({ enabled, configurationType, configuration }) => ({\n enabled,\n configurationType: configurationType ?? null,\n configuration,\n }))\n .value()\n }\n\n private _splitApiAndLocalIntegrationInstances(instances: IntegrationInstance[]): {\n remoteInstances: RemoteIntegrationInstance[]\n localInstances: LocalIntegrationInstance[]\n } {\n const remoteInstances: RemoteIntegrationInstance[] = []\n const localInstances: LocalIntegrationInstance[] = []\n for (const instance of instances) {\n const { id } = instance\n if (id) {\n remoteInstances.push({ ...instance, id })\n } else {\n localInstances.push(instance)\n }\n }\n\n return { remoteInstances, localInstances }\n }\n\n protected async readProjectDefinitionFromFS(): Promise<ProjectDefinition> {\n const projectPaths = this.projectPaths\n try {\n const integrationDefinition = await this._readIntegrationDefinitionFromFS(projectPaths)\n if (integrationDefinition) {\n return { type: 'integration', ...integrationDefinition }\n }\n const interfaceDefinition = await this._readInterfaceDefinitionFromFS(projectPaths)\n if (interfaceDefinition) {\n return { type: 'interface', ...interfaceDefinition }\n }\n const botDefinition = await this._readBotDefinitionFromFS(projectPaths)\n if (botDefinition) {\n return { type: 'bot', ...botDefinition }\n }\n const pluginDefinition = await this._readPluginDefinitionFromFS(projectPaths)\n if (pluginDefinition) {\n return { type: 'plugin', ...pluginDefinition }\n }\n } catch (thrown: unknown) {\n throw errors.BotpressCLIError.wrap(thrown, 'Error while reading project definition')\n }\n\n throw new errors.ProjectDefinitionNotFoundError(this.projectPaths.abs.workDir)\n }\n\n private async _readIntegrationDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'integrationDefinition'>\n ): Promise<({ definition: sdk.IntegrationDefinition } & LintIgnoredConfig) | undefined> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.integrationDefinition)) {\n return\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.integrationDefinition)\n\n const { outputFiles } = await utils.esbuild.buildEntrypoint({\n absWorkingDir: abs.workDir,\n entrypoint: rel.integrationDefinition,\n write: false,\n minify: false,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read integration definition')\n }\n\n let { default: definition } = utils.require.requireJsCode<{ default: sdk.IntegrationDefinition }>(artifact.text)\n definition = resolveInterfaces(definition)\n validateIntegrationDefinition(definition)\n return { definition, bpLintDisabled }\n }\n\n private async _readInterfaceDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'interfaceDefinition'>\n ): Promise<({ definition: sdk.InterfaceDefinition } & LintIgnoredConfig) | undefined> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.interfaceDefinition)) {\n return\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.interfaceDefinition)\n\n const { outputFiles } = await utils.esbuild.buildEntrypoint({\n absWorkingDir: abs.workDir,\n entrypoint: rel.interfaceDefinition,\n write: false,\n minify: false,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read interface definition')\n }\n\n const { default: definition } = utils.require.requireJsCode<{ default: sdk.InterfaceDefinition }>(artifact.text)\n\n return { definition, bpLintDisabled }\n }\n\n private async _readBotDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'botDefinition'>\n ): Promise<({ definition: sdk.BotDefinition } & LintIgnoredConfig) | undefined> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.botDefinition)) {\n return\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.botDefinition)\n\n const { outputFiles } = await utils.esbuild.buildEntrypoint({\n absWorkingDir: abs.workDir,\n entrypoint: rel.botDefinition,\n write: false,\n minify: false,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read bot definition')\n }\n\n let { default: definition } = utils.require.requireJsCode<{ default: sdk.BotDefinition }>(artifact.text)\n definition = resolveBotInterfaces(definition)\n validateBotDefinition(definition)\n return { definition, bpLintDisabled }\n }\n\n private async _readPluginDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'pluginDefinition'>\n ): Promise<({ definition: sdk.PluginDefinition } & LintIgnoredConfig) | undefined> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.pluginDefinition)) {\n return\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.pluginDefinition)\n\n const { outputFiles } = await utils.esbuild.buildEntrypoint({\n absWorkingDir: abs.workDir,\n entrypoint: rel.pluginDefinition,\n write: false,\n minify: false,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read plugin definition')\n }\n\n const { default: definition } = utils.require.requireJsCode<{ default: sdk.PluginDefinition }>(artifact.text)\n // TODO: validate plugin definition\n return { definition, bpLintDisabled }\n }\n\n private async _isBpLintDisabled(definitionPath: string): Promise<boolean> {\n const tsContent = await fs.promises.readFile(definitionPath, 'utf-8')\n const regex = /\\/\\* bplint-disable \\*\\//\n return regex.test(tsContent)\n }\n\n protected displayWebhookUrls(bot: client.Bot) {\n if (!_.keys(bot.integrations).length) {\n this.logger.debug('No integrations in bot')\n return\n }\n\n this.logger.log('Integrations:')\n for (const integration of Object.values(bot.integrations).filter(utils.guards.is.defined)) {\n if (!integration.enabled) {\n this.logger.log(`${chalk.grey(integration.name)} ${chalk.italic('(disabled)')}: ${integration.webhookUrl}`, {\n prefix: { symbol: '\u25CB', indent: 2 },\n })\n } else {\n this.logger.log(`${chalk.bold(integration.name)} : ${integration.webhookUrl}`, {\n prefix: { symbol: '\u25CF', indent: 2 },\n })\n }\n }\n }\n\n protected async promptSecrets(\n integrationDef: sdk.IntegrationDefinition,\n argv: YargsConfig<typeof config.schemas.secrets>,\n opts: { formatEnv?: boolean; knownSecrets?: string[] } = {}\n ): Promise<Record<string, string | null>> {\n const formatEnv = opts.formatEnv ?? false\n const knownSecrets = opts.knownSecrets ?? []\n\n const { secrets: secretDefinitions } = integrationDef\n if (!secretDefinitions) {\n return {}\n }\n\n const secretArgv = this._parseArgvSecrets(argv.secrets)\n const invalidSecret = Object.keys(secretArgv).find((s) => !secretDefinitions[s])\n if (invalidSecret) {\n throw new errors.BotpressCLIError(`Secret ${invalidSecret} is not defined in integration definition`)\n }\n\n const values: Record<string, string | null> = {}\n for (const [secretName, { optional }] of Object.entries(secretDefinitions)) {\n const argvSecret = secretArgv[secretName]\n if (argvSecret) {\n this.logger.debug(`Using secret \"${secretName}\" from argv`)\n values[secretName] = argvSecret\n continue\n }\n\n const alreadyKnown = knownSecrets.includes(secretName)\n let mode: string\n if (alreadyKnown) {\n mode = 'already set'\n } else if (optional) {\n mode = 'optional'\n } else {\n mode = 'required'\n }\n\n const prompted = await this.prompt.text(`Enter value for secret \"${secretName}\" (${mode})`)\n if (prompted) {\n values[secretName] = prompted\n continue\n }\n\n if (alreadyKnown) {\n this.logger.log(`Secret \"${secretName}\" is unchanged`)\n } else if (optional) {\n this.logger.warn(`Secret \"${secretName}\" is unassigned`)\n } else {\n throw new errors.BotpressCLIError(`Secret \"${secretName}\" is required`)\n }\n }\n\n for (const secretName of knownSecrets) {\n const isDefined = secretName in secretDefinitions\n if (isDefined) {\n continue\n }\n const prompted = await this.prompt.confirm(`Secret \"${secretName}\" was removed. Do you wish to delete it?`)\n if (prompted) {\n this.logger.log(`Deleting secret \"${secretName}\"`, { prefix: { symbol: '\u00D7', fg: 'red' } })\n values[secretName] = null\n }\n }\n\n if (!formatEnv) {\n return values\n }\n\n const envVariables = _.mapKeys(values, (_v, k) => codegen.secretEnvVariableName(k))\n return envVariables\n }\n\n protected async readIntegrationConfigDefinition<C extends client.ClientInputs['createIntegration']['configuration']>(\n config: C\n ): Promise<C> {\n if (!config?.identifier) {\n return config\n }\n return {\n ...config,\n identifier: {\n ...config.identifier,\n linkTemplateScript: await this.readProjectFile(config.identifier.linkTemplateScript),\n },\n }\n }\n\n protected readProjectFile = async (filePath: string | undefined): Promise<string | undefined> => {\n if (!filePath) {\n return undefined\n }\n const absoluteFilePath = utils.path.absoluteFrom(this.projectPaths.abs.workDir, filePath)\n return fs.promises.readFile(absoluteFilePath, 'utf-8').catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not read file \"${absoluteFilePath}\"`)\n })\n }\n\n private _parseArgvSecrets(argvSecrets: string[]): Record<string, string> {\n const parsed: Record<string, string> = {}\n for (const secret of argvSecrets) {\n const [key, value] = utils.string.splitOnce(secret, '=')\n if (!value) {\n throw new errors.BotpressCLIError(\n `Secret \"${key}\" is missing a value. Expected format: \"SECRET_NAME=secretValue\"`\n )\n }\n parsed[key!] = value\n }\n\n return parsed\n }\n\n private _notifyUpdateSdk = async (): Promise<void> => {\n try {\n this.logger.debug('Checking if sdk is up to date')\n\n const { workDir } = this.projectPaths.abs\n const projectPkgJson = await utils.pkgJson.readPackageJson(workDir)\n if (!projectPkgJson) {\n this.logger.debug(`Could not find package.json at \"${workDir}\"`)\n return\n }\n\n const sdkPackageName = '@botpress/sdk'\n const actualSdkVersion = utils.pkgJson.findDependency(projectPkgJson, sdkPackageName)\n if (!actualSdkVersion) {\n this.logger.debug(`Could not find dependency \"${sdkPackageName}\" in project package.json`)\n return\n }\n\n if (actualSdkVersion.startsWith('workspace:')) {\n return\n }\n\n const actualCleanedSdkVersion = semver.valid(semver.coerce(actualSdkVersion))\n if (!actualCleanedSdkVersion) {\n this.logger.debug(`Invalid sdk version \"${actualSdkVersion}\" in project package.json`)\n return\n }\n\n const cliPkgJson = await this.readPkgJson()\n const expectedSdkVersion = utils.pkgJson.findDependency(cliPkgJson, sdkPackageName)\n if (!expectedSdkVersion) {\n this.logger.debug(`Could not find dependency \"${sdkPackageName}\" in cli package.json`)\n return\n }\n\n const expectedCleanedSdkVersion = semver.valid(semver.coerce(expectedSdkVersion))\n if (!expectedCleanedSdkVersion) {\n this.logger.debug(`Invalid sdk version \"${expectedSdkVersion}\" in cli package.json`)\n return\n }\n\n if (semver.eq(actualCleanedSdkVersion, expectedCleanedSdkVersion)) {\n return\n }\n\n const diff = semver.diff(actualCleanedSdkVersion, expectedCleanedSdkVersion)\n if (!diff) {\n this.logger.debug(`Could not compare versions \"${actualCleanedSdkVersion}\" and \"${expectedCleanedSdkVersion}\"`)\n return\n }\n\n const errorMsg = `Project SDK version is \"${actualCleanedSdkVersion}\", but expected \"${expectedCleanedSdkVersion}\"`\n if (utils.semver.releases.lt(diff, 'minor')) {\n this.logger.debug(`${errorMsg}. This may cause compatibility issues.`)\n return\n }\n\n this.logger.warn(chalk.bold(`${errorMsg}. This will cause compatibility issues.`))\n } catch (thrown) {\n const err = errors.BotpressCLIError.map(thrown)\n this.logger.debug(`Failed to check if sdk is up to date: ${err.message}`)\n }\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAAqB;AACrB,mBAAkB;AAClB,gBAAe;AACf,oBAAc;AACd,oBAAmB;
|
|
4
|
+
"sourcesContent": ["import type * as client from '@botpress/client'\nimport type * as sdk from '@botpress/sdk'\nimport type { YargsConfig } from '@bpinternal/yargs-extra'\nimport bluebird from 'bluebird'\nimport chalk from 'chalk'\nimport fs from 'fs'\nimport _ from 'lodash'\nimport semver from 'semver'\nimport * as apiUtils from '../api'\nimport * as codegen from '../code-generation'\nimport type * as config from '../config'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport { formatPackageRef, PackageRef } from '../package-ref'\nimport { validateIntegrationDefinition, validateBotDefinition } from '../sdk'\nimport type { CommandArgv, CommandDefinition } from '../typings'\nimport * as utils from '../utils'\nimport { GlobalCommand } from './global-command'\n\nexport type ProjectCommandDefinition = CommandDefinition<typeof config.schemas.project>\nexport type ProjectCache = { botId: string; devId: string }\n\ntype ConfigurableProjectPaths = { workDir: string }\ntype ConstantProjectPaths = typeof consts.fromWorkDir\ntype AllProjectPaths = ConfigurableProjectPaths & ConstantProjectPaths\n\ntype IntegrationInstance = NonNullable<sdk.BotDefinition['integrations']>[string]\ntype RemoteIntegrationInstance = utils.types.Merge<IntegrationInstance, { id: string }>\ntype LocalIntegrationInstance = utils.types.Merge<IntegrationInstance, { uri?: string }>\ntype BotIntegrationRequest = NonNullable<NonNullable<apiUtils.UpdateBotRequestBody['integrations']>[string]>\n\ntype InterfaceExtension = NonNullable<sdk.IntegrationDefinition['interfaces']>[string]\ntype RemoteInterfaceExtension = utils.types.Merge<InterfaceExtension, { id: string }>\ntype LocalInterfaceExtension = utils.types.Merge<InterfaceExtension, { uri?: string }>\ntype IntegrationInterfaceRequest = NonNullable<NonNullable<apiUtils.UpdateIntegrationRequestBody['interfaces']>[string]>\n\ntype LintIgnoredConfig = { bpLintDisabled?: boolean }\n\nexport type ProjectType = ProjectDefinition['type']\nexport type ProjectDefinition = LintIgnoredConfig &\n (\n | { type: 'integration'; definition: sdk.IntegrationDefinition }\n | { type: 'interface'; definition: sdk.InterfaceDefinition }\n | { type: 'bot'; definition: sdk.BotDefinition }\n | { type: 'plugin'; definition: sdk.PluginDefinition }\n )\n\nclass ProjectPaths extends utils.path.PathStore<keyof AllProjectPaths> {\n public constructor(argv: CommandArgv<ProjectCommandDefinition>) {\n const absWorkDir = utils.path.absoluteFrom(utils.path.cwd(), argv.workDir)\n super({\n workDir: absWorkDir,\n ..._.mapValues(consts.fromWorkDir, (p) => utils.path.absoluteFrom(absWorkDir, p)),\n })\n }\n}\n\nexport abstract class ProjectCommand<C extends ProjectCommandDefinition> extends GlobalCommand<C> {\n protected override async bootstrap() {\n await super.bootstrap()\n await this._notifyUpdateSdk()\n }\n\n protected get projectPaths() {\n return new ProjectPaths(this.argv)\n }\n\n protected get projectCache() {\n return new utils.cache.FSKeyValueCache<ProjectCache>(this.projectPaths.abs.projectCacheFile)\n }\n\n protected async fetchBotIntegrationInstances(\n botDefinition: sdk.BotDefinition,\n api: apiUtils.ApiClient\n ): Promise<Record<string, BotIntegrationRequest>> {\n const integrationList = _(botDefinition.integrations).values().filter(utils.guards.is.defined).value()\n\n const { remoteInstances, localInstances } = this._splitApiAndLocalIntegrationInstances(integrationList)\n\n const fetchedInstances: RemoteIntegrationInstance[] = await bluebird.map(\n localInstances,\n async (instance): Promise<RemoteIntegrationInstance> => {\n const ref: PackageRef = { type: 'name', name: instance.name, version: instance.version }\n const integration = await api.findIntegration(ref)\n if (!integration) {\n const formattedRef = formatPackageRef(ref)\n throw new errors.BotpressCLIError(`Integration \"${formattedRef}\" not found`)\n }\n return { ...instance, id: integration.id }\n }\n )\n\n return _([...fetchedInstances, ...remoteInstances])\n .keyBy((i) => i.id)\n .mapValues(({ enabled, configurationType, configuration }) => ({\n enabled,\n configurationType: configurationType ?? null,\n configuration,\n }))\n .value()\n }\n\n protected async fetchIntegrationInterfaceInstances(\n integrationDefinition: sdk.IntegrationDefinition,\n api: apiUtils.ApiClient\n ): Promise<Record<string, IntegrationInterfaceRequest>> {\n const interfaceList = _(integrationDefinition.interfaces).values().filter(utils.guards.is.defined).value()\n\n const { remoteInstances, localInstances } = this._splitApiAndLocalInterfaceInstances(interfaceList)\n\n const fetchedInstances: RemoteInterfaceExtension[] = await bluebird.map(\n localInstances,\n async (instance): Promise<RemoteInterfaceExtension> => {\n const ref: PackageRef = { type: 'name', name: instance.name, version: instance.version }\n const interfaceInstance = await api.findPublicInterface(ref)\n if (!interfaceInstance) {\n const formattedRef = formatPackageRef(ref)\n throw new errors.BotpressCLIError(`Interface \"${formattedRef}\" not found`)\n }\n return { ...instance, id: interfaceInstance.id }\n }\n )\n\n return _([...fetchedInstances, ...remoteInstances])\n .keyBy((i) => i.id)\n .value()\n }\n\n private _splitApiAndLocalIntegrationInstances(instances: IntegrationInstance[]): {\n remoteInstances: RemoteIntegrationInstance[]\n localInstances: LocalIntegrationInstance[]\n } {\n const remoteInstances: RemoteIntegrationInstance[] = []\n const localInstances: LocalIntegrationInstance[] = []\n for (const instance of instances) {\n const { id } = instance\n if (id) {\n remoteInstances.push({ ...instance, id })\n } else {\n localInstances.push(instance)\n }\n }\n\n return { remoteInstances, localInstances }\n }\n\n private _splitApiAndLocalInterfaceInstances(instances: InterfaceExtension[]): {\n remoteInstances: RemoteInterfaceExtension[]\n localInstances: LocalInterfaceExtension[]\n } {\n const remoteInstances: RemoteInterfaceExtension[] = []\n const localInstances: LocalInterfaceExtension[] = []\n for (const instance of instances) {\n const { id } = instance\n if (id) {\n remoteInstances.push({ ...instance, id })\n } else {\n localInstances.push(instance)\n }\n }\n\n return { remoteInstances, localInstances }\n }\n\n protected async readProjectDefinitionFromFS(): Promise<ProjectDefinition> {\n const projectPaths = this.projectPaths\n try {\n const integrationDefinition = await this._readIntegrationDefinitionFromFS(projectPaths)\n if (integrationDefinition) {\n return { type: 'integration', ...integrationDefinition }\n }\n const interfaceDefinition = await this._readInterfaceDefinitionFromFS(projectPaths)\n if (interfaceDefinition) {\n return { type: 'interface', ...interfaceDefinition }\n }\n const botDefinition = await this._readBotDefinitionFromFS(projectPaths)\n if (botDefinition) {\n return { type: 'bot', ...botDefinition }\n }\n const pluginDefinition = await this._readPluginDefinitionFromFS(projectPaths)\n if (pluginDefinition) {\n return { type: 'plugin', ...pluginDefinition }\n }\n } catch (thrown: unknown) {\n throw errors.BotpressCLIError.wrap(thrown, 'Error while reading project definition')\n }\n\n throw new errors.ProjectDefinitionNotFoundError(this.projectPaths.abs.workDir)\n }\n\n private async _readIntegrationDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'integrationDefinition'>\n ): Promise<({ definition: sdk.IntegrationDefinition } & LintIgnoredConfig) | undefined> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.integrationDefinition)) {\n return\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.integrationDefinition)\n\n const { outputFiles } = await utils.esbuild.buildEntrypoint({\n absWorkingDir: abs.workDir,\n entrypoint: rel.integrationDefinition,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read integration definition')\n }\n\n const { default: definition } = utils.require.requireJsCode<{ default: sdk.IntegrationDefinition }>(artifact.text)\n validateIntegrationDefinition(definition)\n return { definition, bpLintDisabled }\n }\n\n private async _readInterfaceDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'interfaceDefinition'>\n ): Promise<({ definition: sdk.InterfaceDefinition } & LintIgnoredConfig) | undefined> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.interfaceDefinition)) {\n return\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.interfaceDefinition)\n\n const { outputFiles } = await utils.esbuild.buildEntrypoint({\n absWorkingDir: abs.workDir,\n entrypoint: rel.interfaceDefinition,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read interface definition')\n }\n\n const { default: definition } = utils.require.requireJsCode<{ default: sdk.InterfaceDefinition }>(artifact.text)\n\n return { definition, bpLintDisabled }\n }\n\n private async _readBotDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'botDefinition'>\n ): Promise<({ definition: sdk.BotDefinition } & LintIgnoredConfig) | undefined> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.botDefinition)) {\n return\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.botDefinition)\n\n const { outputFiles } = await utils.esbuild.buildEntrypoint({\n absWorkingDir: abs.workDir,\n entrypoint: rel.botDefinition,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read bot definition')\n }\n\n const { default: definition } = utils.require.requireJsCode<{ default: sdk.BotDefinition }>(artifact.text)\n validateBotDefinition(definition)\n return { definition, bpLintDisabled }\n }\n\n private async _readPluginDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'pluginDefinition'>\n ): Promise<({ definition: sdk.PluginDefinition } & LintIgnoredConfig) | undefined> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.pluginDefinition)) {\n return\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.pluginDefinition)\n\n const { outputFiles } = await utils.esbuild.buildEntrypoint({\n absWorkingDir: abs.workDir,\n entrypoint: rel.pluginDefinition,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read plugin definition')\n }\n\n const { default: definition } = utils.require.requireJsCode<{ default: sdk.PluginDefinition }>(artifact.text)\n // TODO: validate plugin definition\n return { definition, bpLintDisabled }\n }\n\n private async _isBpLintDisabled(definitionPath: string): Promise<boolean> {\n const tsContent = await fs.promises.readFile(definitionPath, 'utf-8')\n const regex = /\\/\\* bplint-disable \\*\\//\n return regex.test(tsContent)\n }\n\n protected displayWebhookUrls(bot: client.Bot) {\n if (!_.keys(bot.integrations).length) {\n this.logger.debug('No integrations in bot')\n return\n }\n\n this.logger.log('Integrations:')\n for (const integration of Object.values(bot.integrations).filter(utils.guards.is.defined)) {\n if (!integration.enabled) {\n this.logger.log(`${chalk.grey(integration.name)} ${chalk.italic('(disabled)')}: ${integration.webhookUrl}`, {\n prefix: { symbol: '\u25CB', indent: 2 },\n })\n } else {\n this.logger.log(`${chalk.bold(integration.name)} : ${integration.webhookUrl}`, {\n prefix: { symbol: '\u25CF', indent: 2 },\n })\n }\n }\n }\n\n protected async promptSecrets(\n integrationDef: sdk.IntegrationDefinition,\n argv: YargsConfig<typeof config.schemas.secrets>,\n opts: { formatEnv?: boolean; knownSecrets?: string[] } = {}\n ): Promise<Record<string, string | null>> {\n const formatEnv = opts.formatEnv ?? false\n const knownSecrets = opts.knownSecrets ?? []\n\n const { secrets: secretDefinitions } = integrationDef\n if (!secretDefinitions) {\n return {}\n }\n\n const secretArgv = this._parseArgvSecrets(argv.secrets)\n const invalidSecret = Object.keys(secretArgv).find((s) => !secretDefinitions[s])\n if (invalidSecret) {\n throw new errors.BotpressCLIError(`Secret ${invalidSecret} is not defined in integration definition`)\n }\n\n const values: Record<string, string | null> = {}\n for (const [secretName, { optional }] of Object.entries(secretDefinitions)) {\n const argvSecret = secretArgv[secretName]\n if (argvSecret) {\n this.logger.debug(`Using secret \"${secretName}\" from argv`)\n values[secretName] = argvSecret\n continue\n }\n\n const alreadyKnown = knownSecrets.includes(secretName)\n let mode: string\n if (alreadyKnown) {\n mode = 'already set'\n } else if (optional) {\n mode = 'optional'\n } else {\n mode = 'required'\n }\n\n const prompted = await this.prompt.text(`Enter value for secret \"${secretName}\" (${mode})`)\n if (prompted) {\n values[secretName] = prompted\n continue\n }\n\n if (alreadyKnown) {\n this.logger.log(`Secret \"${secretName}\" is unchanged`)\n } else if (optional) {\n this.logger.warn(`Secret \"${secretName}\" is unassigned`)\n } else {\n throw new errors.BotpressCLIError(`Secret \"${secretName}\" is required`)\n }\n }\n\n for (const secretName of knownSecrets) {\n const isDefined = secretName in secretDefinitions\n if (isDefined) {\n continue\n }\n const prompted = await this.prompt.confirm(`Secret \"${secretName}\" was removed. Do you wish to delete it?`)\n if (prompted) {\n this.logger.log(`Deleting secret \"${secretName}\"`, { prefix: { symbol: '\u00D7', fg: 'red' } })\n values[secretName] = null\n }\n }\n\n if (!formatEnv) {\n return values\n }\n\n const envVariables = _.mapKeys(values, (_v, k) => codegen.secretEnvVariableName(k))\n return envVariables\n }\n\n protected async prepareCreateIntegrationBody(\n integrationDef: sdk.IntegrationDefinition\n ): Promise<apiUtils.CreateIntegrationRequestBody> {\n const partialBody = await apiUtils.prepareCreateIntegrationBody(integrationDef)\n const code = await this.readProjectFile(this.projectPaths.abs.outFileCJS)\n const icon = await this.readProjectFile(integrationDef.icon, 'base64')\n const readme = await this.readProjectFile(integrationDef.readme, 'base64')\n const extractScript = await this.readProjectFile(integrationDef.identifier?.extractScript)\n const fallbackHandlerScript = await this.readProjectFile(integrationDef.identifier?.fallbackHandlerScript)\n return {\n ...partialBody,\n code,\n icon,\n readme,\n identifier: {\n extractScript,\n fallbackHandlerScript,\n },\n configuration: integrationDef.configuration\n ? {\n schema: await utils.schema.mapZodToJsonSchema(integrationDef.configuration),\n identifier: {\n required: integrationDef.configuration.identifier?.required,\n linkTemplateScript: await this.readProjectFile(\n integrationDef.configuration.identifier?.linkTemplateScript\n ),\n },\n }\n : undefined,\n configurations: integrationDef.configurations\n ? await utils.records.mapValuesAsync(integrationDef.configurations, async (configuration) => ({\n title: configuration.title,\n description: configuration.description,\n schema: await utils.schema.mapZodToJsonSchema(configuration),\n identifier: {\n required: configuration.identifier?.required,\n linkTemplateScript: await this.readProjectFile(configuration.identifier?.linkTemplateScript),\n },\n }))\n : undefined,\n }\n }\n\n protected readProjectFile = async (\n filePath: string | undefined,\n encoding: BufferEncoding = 'utf-8'\n ): Promise<string | undefined> => {\n if (!filePath) {\n return undefined\n }\n const absoluteFilePath = utils.path.absoluteFrom(this.projectPaths.abs.workDir, filePath)\n return fs.promises.readFile(absoluteFilePath, encoding).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not read file \"${absoluteFilePath}\"`)\n })\n }\n\n private _parseArgvSecrets(argvSecrets: string[]): Record<string, string> {\n const parsed: Record<string, string> = {}\n for (const secret of argvSecrets) {\n const [key, value] = utils.string.splitOnce(secret, '=')\n if (!value) {\n throw new errors.BotpressCLIError(\n `Secret \"${key}\" is missing a value. Expected format: \"SECRET_NAME=secretValue\"`\n )\n }\n parsed[key!] = value\n }\n\n return parsed\n }\n\n private _notifyUpdateSdk = async (): Promise<void> => {\n try {\n this.logger.debug('Checking if sdk is up to date')\n\n const { workDir } = this.projectPaths.abs\n const projectPkgJson = await utils.pkgJson.readPackageJson(workDir)\n if (!projectPkgJson) {\n this.logger.debug(`Could not find package.json at \"${workDir}\"`)\n return\n }\n\n const sdkPackageName = '@botpress/sdk'\n const actualSdkVersion = utils.pkgJson.findDependency(projectPkgJson, sdkPackageName)\n if (!actualSdkVersion) {\n this.logger.debug(`Could not find dependency \"${sdkPackageName}\" in project package.json`)\n return\n }\n\n if (actualSdkVersion.startsWith('workspace:')) {\n return\n }\n\n const actualCleanedSdkVersion = semver.valid(semver.coerce(actualSdkVersion))\n if (!actualCleanedSdkVersion) {\n this.logger.debug(`Invalid sdk version \"${actualSdkVersion}\" in project package.json`)\n return\n }\n\n const cliPkgJson = await this.readPkgJson()\n const expectedSdkVersion = utils.pkgJson.findDependency(cliPkgJson, sdkPackageName)\n if (!expectedSdkVersion) {\n this.logger.debug(`Could not find dependency \"${sdkPackageName}\" in cli package.json`)\n return\n }\n\n const expectedCleanedSdkVersion = semver.valid(semver.coerce(expectedSdkVersion))\n if (!expectedCleanedSdkVersion) {\n this.logger.debug(`Invalid sdk version \"${expectedSdkVersion}\" in cli package.json`)\n return\n }\n\n if (semver.eq(actualCleanedSdkVersion, expectedCleanedSdkVersion)) {\n return\n }\n\n const diff = semver.diff(actualCleanedSdkVersion, expectedCleanedSdkVersion)\n if (!diff) {\n this.logger.debug(`Could not compare versions \"${actualCleanedSdkVersion}\" and \"${expectedCleanedSdkVersion}\"`)\n return\n }\n\n const errorMsg = `Project SDK version is \"${actualCleanedSdkVersion}\", but expected \"${expectedCleanedSdkVersion}\"`\n if (utils.semver.releases.lt(diff, 'minor')) {\n this.logger.debug(`${errorMsg}. This may cause compatibility issues.`)\n return\n }\n\n this.logger.warn(chalk.bold(`${errorMsg}. This will cause compatibility issues.`))\n } catch (thrown) {\n const err = errors.BotpressCLIError.map(thrown)\n this.logger.debug(`Failed to check if sdk is up to date: ${err.message}`)\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAAqB;AACrB,mBAAkB;AAClB,gBAAe;AACf,oBAAc;AACd,oBAAmB;AACnB,eAA0B;AAC1B,cAAyB;AAEzB,aAAwB;AACxB,aAAwB;AACxB,yBAA6C;AAC7C,iBAAqE;AAErE,YAAuB;AACvB,4BAA8B;AA8B9B,MAAM,qBAAqB,MAAM,KAAK,UAAiC;AAAA,EAC9D,YAAY,MAA6C;AAC9D,UAAM,aAAa,MAAM,KAAK,aAAa,MAAM,KAAK,IAAI,GAAG,KAAK,OAAO;AACzE,UAAM;AAAA,MACJ,S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