@botpress/cli 0.2.2 → 0.2.4

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.
@@ -55,7 +55,7 @@ class BaseCommand {
55
55
  await this.teardown();
56
56
  }
57
57
  }
58
- process.exit(exitCode);
58
+ return { exitCode };
59
59
  }
60
60
  }
61
61
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/command-implementations/base-command.ts"],
4
- "sourcesContent": ["import * as errors from '../errors'\nimport type { Logger } from '../logger'\nimport type { CommandArgv, CommandDefinition } from '../typings'\n\nexport abstract class BaseCommand<C extends CommandDefinition> {\n public constructor(protected readonly logger: Logger, protected readonly argv: CommandArgv<C>) {}\n\n protected abstract run(): Promise<void>\n protected abstract bootstrap?: () => Promise<void>\n protected abstract teardown?: () => Promise<void>\n\n public async handler(): Promise<never> {\n let exitCode = 0\n try {\n if (this.bootstrap) {\n await this.bootstrap()\n }\n await this.run()\n } catch (thrown) {\n const error = errors.BotpressCLIError.map(thrown)\n\n if (error.debug) {\n const msg = error.message + ' (Run with verbose flag (-v) to see more details)'\n this.logger.error(msg)\n this.logger.debug(error.debug)\n } else {\n this.logger.error(error.message)\n }\n\n exitCode = 1\n } finally {\n if (this.teardown) {\n await this.teardown()\n }\n }\n\n process.exit(exitCode)\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,aAAwB;AAIjB,MAAe,YAAyC;AAAA,EACtD,YAA+B,QAAmC,MAAsB;AAAzD;AAAmC;AAAA,EAAuB;AAAA,EAMhG,MAAa,UAA0B;AACrC,QAAI,WAAW;AACf,QAAI;AACF,UAAI,KAAK,WAAW;AAClB,cAAM,KAAK,UAAU;AAAA,MACvB;AACA,YAAM,KAAK,IAAI;AAAA,IACjB,SAAS,QAAP;AACA,YAAM,QAAQ,OAAO,iBAAiB,IAAI,MAAM;AAEhD,UAAI,MAAM,OAAO;AACf,cAAM,MAAM,MAAM,UAAU;AAC5B,aAAK,OAAO,MAAM,GAAG;AACrB,aAAK,OAAO,MAAM,MAAM,KAAK;AAAA,MAC/B,OAAO;AACL,aAAK,OAAO,MAAM,MAAM,OAAO;AAAA,MACjC;AAEA,iBAAW;AAAA,IACb,UAAE;AACA,UAAI,KAAK,UAAU;AACjB,cAAM,KAAK,SAAS;AAAA,MACtB;AAAA,IACF;AAEA,YAAQ,KAAK,QAAQ;AAAA,EACvB;AACF;",
4
+ "sourcesContent": ["import * as errors from '../errors'\nimport type { Logger } from '../logger'\nimport type { CommandArgv, CommandDefinition } from '../typings'\n\nexport abstract class BaseCommand<C extends CommandDefinition> {\n public constructor(protected readonly logger: Logger, protected readonly argv: CommandArgv<C>) {}\n\n protected abstract run(): Promise<void>\n protected abstract bootstrap?: () => Promise<void>\n protected abstract teardown?: () => Promise<void>\n\n public async handler(): Promise<{ exitCode: number }> {\n let exitCode = 0\n try {\n if (this.bootstrap) {\n await this.bootstrap()\n }\n await this.run()\n } catch (thrown) {\n const error = errors.BotpressCLIError.map(thrown)\n\n if (error.debug) {\n const msg = error.message + ' (Run with verbose flag (-v) to see more details)'\n this.logger.error(msg)\n this.logger.debug(error.debug)\n } else {\n this.logger.error(error.message)\n }\n\n exitCode = 1\n } finally {\n if (this.teardown) {\n await this.teardown()\n }\n }\n\n return { exitCode }\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,aAAwB;AAIjB,MAAe,YAAyC;AAAA,EACtD,YAA+B,QAAmC,MAAsB;AAAzD;AAAmC;AAAA,EAAuB;AAAA,EAMhG,MAAa,UAAyC;AACpD,QAAI,WAAW;AACf,QAAI;AACF,UAAI,KAAK,WAAW;AAClB,cAAM,KAAK,UAAU;AAAA,MACvB;AACA,YAAM,KAAK,IAAI;AAAA,IACjB,SAAS,QAAP;AACA,YAAM,QAAQ,OAAO,iBAAiB,IAAI,MAAM;AAEhD,UAAI,MAAM,OAAO;AACf,cAAM,MAAM,MAAM,UAAU;AAC5B,aAAK,OAAO,MAAM,GAAG;AACrB,aAAK,OAAO,MAAM,MAAM,KAAK;AAAA,MAC/B,OAAO;AACL,aAAK,OAAO,MAAM,MAAM,OAAO;AAAA,MACjC;AAEA,iBAAW;AAAA,IACb,UAAE;AACA,UAAI,KAAK,UAAU;AACjB,cAAM,KAAK,SAAS;AAAA,MACtB;AAAA,IACF;AAEA,WAAO,EAAE,SAAS;AAAA,EACpB;AACF;",
6
6
  "names": []
7
7
  }
@@ -38,6 +38,7 @@ var import_build_command = require("./build-command");
38
38
  var import_project_command = require("./project-command");
39
39
  const DEFAULT_BOT_PORT = 8075;
40
40
  const DEFAULT_INTEGRATION_PORT = 8076;
41
+ const TUNNEL_HELLO_INTERVAL = 5e3;
41
42
  class DevCommand extends import_project_command.ProjectCommand {
42
43
  _initialDef = void 0;
43
44
  async run() {
@@ -71,6 +72,8 @@ class DevCommand extends import_project_command.ProjectCommand {
71
72
  });
72
73
  const supervisor = new utils.tunnel.TunnelSupervisor(wsTunnelUrl, tunnelId, this.logger);
73
74
  supervisor.events.on("connected", ({ tunnel }) => {
75
+ const timer = setInterval(() => tunnel.hello(), TUNNEL_HELLO_INTERVAL);
76
+ tunnel.events.on("close", () => clearInterval(timer));
74
77
  tunnel.events.on(
75
78
  "request",
76
79
  (req) => void this._forwardTunnelRequest(`http://localhost:${port}`, req).then((res) => {
@@ -87,8 +90,8 @@ class DevCommand extends import_project_command.ProjectCommand {
87
90
  );
88
91
  });
89
92
  await supervisor.start();
90
- await this._deploy(api, httpTunnelUrl);
91
93
  await this._runBuild();
94
+ await this._deploy(api, httpTunnelUrl);
92
95
  const worker = await this._spawnWorker(env, port);
93
96
  try {
94
97
  const watcher = await utils.filewatcher.FileWatcher.watch(
@@ -120,7 +123,6 @@ class DevCommand extends import_project_command.ProjectCommand {
120
123
  }
121
124
  }
122
125
  _restart = async (api, worker, tunnelUrl) => {
123
- await this._deploy(api, tunnelUrl);
124
126
  try {
125
127
  await this._runBuild();
126
128
  } catch (thrown) {
@@ -128,6 +130,7 @@ class DevCommand extends import_project_command.ProjectCommand {
128
130
  this.logger.error(error.message);
129
131
  return;
130
132
  }
133
+ await this._deploy(api, tunnelUrl);
131
134
  await worker.reload();
132
135
  };
133
136
  _deploy = async (api, tunnelUrl) => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/command-implementations/dev-command.ts"],
4
- "sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport type { Bot as BotImpl, IntegrationDefinition } 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 type { ApiClient } from '../api-client'\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 } from './project-command'\n\nconst DEFAULT_BOT_PORT = 8075\nconst DEFAULT_INTEGRATION_PORT = 8076\n\nexport type DevCommandDefinition = typeof commandDefinitions.dev\nexport class DevCommand extends ProjectCommand<DevCommandDefinition> {\n private _initialDef: IntegrationDefinition | 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 this._initialDef = await this.readIntegrationDefinitionFromFS()\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) {\n defaultPort = DEFAULT_INTEGRATION_PORT\n const secrets = await this.promptSecrets(this._initialDef, this.argv)\n env = { ...env, ...secrets }\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 const supervisor = new utils.tunnel.TunnelSupervisor(wsTunnelUrl, tunnelId, this.logger)\n supervisor.events.on('connected', ({ tunnel }) => {\n tunnel.events.on(\n 'request',\n (req) =>\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 await supervisor.start()\n\n await this._deploy(api, httpTunnelUrl)\n await this._runBuild()\n const 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 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 await this._deploy(api, tunnelUrl)\n\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 worker.reload()\n }\n\n private _deploy = async (api: ApiClient, tunnelUrl: string) => {\n const integrationDef = await this.readIntegrationDefinitionFromFS()\n if (integrationDef) {\n this._checkSecrets(integrationDef)\n await this._deployDevIntegration(api, tunnelUrl, integrationDef)\n } else {\n await this._deployDevBot(api, tunnelUrl)\n }\n }\n\n private _checkSecrets(integrationDef: IntegrationDefinition) {\n const initialSecrets = this._initialDef?.secrets ?? []\n const currentSecrets = integrationDef.secrets ?? []\n const newSecrets = currentSecrets.filter((s) => !initialSecrets.includes(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: IntegrationDefinition\n ): Promise<void> {\n const devId = await this.projectCache.get('devId')\n\n let integration: bpclient.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 if (integration) {\n const resp = await api.client\n .updateIntegration({ ...integrationDef, id: integration.id, url: externalUrl })\n .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\n .createIntegration({ ...integrationDef, dev: true, url: externalUrl })\n .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}\"`)\n await this.projectCache.set('devId', integration.id)\n }\n\n private async _deployDevBot(api: ApiClient, externalUrl: string): Promise<void> {\n const devId = await this.projectCache.get('devId')\n\n let bot: bpclient.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.success(`Dev Bot created with id \"${bot.id}\"`)\n await this.projectCache.set('devId', bot.id)\n }\n\n const outfile = this.projectPaths.abs.outFile\n const { default: botImpl } = utils.require.requireJsFile<{ default: BotImpl }>(outfile)\n\n const integrations = this.prepareIntegrations(botImpl, bot)\n\n const updateLine = this.logger.line()\n updateLine.started('Deploying dev bot...')\n\n const { bot: updatedBot } = await api.client\n .updateBot({\n ...botImpl.definition,\n id: bot.id,\n integrations,\n url: externalUrl,\n })\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not deploy dev bot')\n })\n updateLine.success(`Dev Bot deployed with id \"${updatedBot.id}\"`)\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] = 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;AAGtB,aAAwB;AACxB,YAAuB;AACvB,oBAAuB;AACvB,2BAA6B;AAC7B,6BAA+B;AAE/B,MAAM,mBAAmB;AACzB,MAAM,2BAA2B;AAG1B,MAAM,mBAAmB,sCAAqC;AAAA,EAC3D,cAAiD;AAAA,EAEzD,MAAa,MAAqB;AAChC,SAAK,OAAO,KAAK,8EAA8E;AAE/F,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAE3D,SAAK,cAAc,MAAM,KAAK,gCAAgC;AAE9D,QAAI,MAA8B;AAAA,MAChC,GAAG,QAAQ;AAAA,MACX,YAAY,IAAI;AAAA,MAChB,UAAU,IAAI;AAAA,IAChB;AAEA,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;AAAA,MAClB,QAAQ,QAAQ;AAAA,MAChB,KAAK,KAAK,gBAAgB,SAAS,OAAO;AAAA,MAC1C,SAAS,QAAQ;AAAA,MACjB,MAAM,QAAQ;AAAA,MACd,cAAc;AAAA,MACd,gBAAgB,MAAM;AAAA,IACxB;AAEA,SAAK,OAAO,MAAM,yBAAyB,YAAY,KAAK;AAC5D,UAAM,WAAW,UAAM,aAAAC,SAAM,WAAW;AACxC,SAAK,OAAO,MAAM,qCAAqC;AAEvD,WAAO;AAAA,MACL,WAAW,QAAQ;AAAA,MACnB,QAAQ,SAAS;AAAA,MACjB,SAAS,KAAK,YAAY,SAAS,OAAO;AAAA,MAC1C,MAAM,SAAS;AAAA,IACjB;AAAA,EACF;AAAA,EAEQ,kBAAkB,CAAC,SAAiB,QAA+B;AACzE,QAAI,IAAI,OAAO;AACb,aAAO,GAAG,UAAU,IAAI,QAAQ,IAAI;AAAA,IACtC;AACA,WAAO,GAAG,UAAU,IAAI;AAAA,EAC1B;AAAA,EAEQ,cAAc,CAAC,QAA6D;AAClF,UAAM,UAAqC,CAAC;AAC5C,eAAW,OAAO,KAAK;AACrB,UAAI,OAAO,IAAI,SAAS,YAAY,OAAO,IAAI,SAAS,UAAU;AAChE,gBAAQ,OAAO,IAAI;AAAA,MACrB;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;",
4
+ "sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport type { Bot as BotImpl, IntegrationDefinition } 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 type { ApiClient } from '../api-client'\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 } 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: IntegrationDefinition | 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 this._initialDef = await this.readIntegrationDefinitionFromFS()\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) {\n defaultPort = DEFAULT_INTEGRATION_PORT\n const secrets = await this.promptSecrets(this._initialDef, this.argv)\n env = { ...env, ...secrets }\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 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(() => tunnel.hello(), TUNNEL_HELLO_INTERVAL)\n tunnel.events.on('close', () => clearInterval(timer))\n\n tunnel.events.on(\n 'request',\n (req) =>\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 await supervisor.start()\n\n await this._runBuild()\n await this._deploy(api, httpTunnelUrl)\n const 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 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 integrationDef = await this.readIntegrationDefinitionFromFS()\n if (integrationDef) {\n this._checkSecrets(integrationDef)\n await this._deployDevIntegration(api, tunnelUrl, integrationDef)\n } else {\n await this._deployDevBot(api, tunnelUrl)\n }\n }\n\n private _checkSecrets(integrationDef: IntegrationDefinition) {\n const initialSecrets = this._initialDef?.secrets ?? []\n const currentSecrets = integrationDef.secrets ?? []\n const newSecrets = currentSecrets.filter((s) => !initialSecrets.includes(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: IntegrationDefinition\n ): Promise<void> {\n const devId = await this.projectCache.get('devId')\n\n let integration: bpclient.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 if (integration) {\n const resp = await api.client\n .updateIntegration({ ...integrationDef, id: integration.id, url: externalUrl })\n .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\n .createIntegration({ ...integrationDef, dev: true, url: externalUrl })\n .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}\"`)\n await this.projectCache.set('devId', integration.id)\n }\n\n private async _deployDevBot(api: ApiClient, externalUrl: string): Promise<void> {\n const devId = await this.projectCache.get('devId')\n\n let bot: bpclient.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.success(`Dev Bot created with id \"${bot.id}\"`)\n await this.projectCache.set('devId', bot.id)\n }\n\n const outfile = this.projectPaths.abs.outFile\n const { default: botImpl } = utils.require.requireJsFile<{ default: BotImpl }>(outfile)\n\n const integrations = this.prepareIntegrations(botImpl, bot)\n\n const updateLine = this.logger.line()\n updateLine.started('Deploying dev bot...')\n\n const { bot: updatedBot } = await api.client\n .updateBot({\n ...botImpl.definition,\n id: bot.id,\n integrations,\n url: externalUrl,\n })\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not deploy dev bot')\n })\n updateLine.success(`Dev Bot deployed with id \"${updatedBot.id}\"`)\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 (type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AC,SAAiB,QAA+B;AACzE,QAAI,IAAI,OAAO;AACb,aAAO,GAAG,UAAU,IAAI,QAAQ,IAAI;AAAA,IACtC;AACA,WAAO,GAAG,UAAU,IAAI;AAAA,EAC1B;AAAA,EAEQ,cAAc,CAAC,QAA6D;AAClF,UAAM,UAAqC,CAAC;AAC5C,eAAW,OAAO,KAAK;AACrB,UAAI,OAAO,IAAI,SAAS,YAAY,OAAO,IAAI,SAAS,UAAU;AAChE,gBAAQ,OAAO,IAAI;AAAA,MACrB;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;",
6
6
  "names": ["chalk", "axios"]
7
7
  }
@@ -41,10 +41,10 @@ class GlobalPaths extends utils.path.PathStore {
41
41
  constructor(argv) {
42
42
  const absBotpressHome = utils.path.absoluteFrom(utils.path.cwd(), argv.botpressHome);
43
43
  super({
44
- cliRootDir: argv.cliRootDir,
44
+ cliRootDir: consts.cliRootDir,
45
45
  botpressHomeDir: absBotpressHome,
46
46
  ...import_lodash.default.mapValues(consts.fromHomeDir, (p) => utils.path.absoluteFrom(absBotpressHome, p)),
47
- ...import_lodash.default.mapValues(consts.fromCliRootDir, (p) => utils.path.absoluteFrom(argv.cliRootDir, p))
47
+ ...import_lodash.default.mapValues(consts.fromCliRootDir, (p) => utils.path.absoluteFrom(consts.cliRootDir, p))
48
48
  });
49
49
  }
50
50
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/command-implementations/global-command.ts"],
4
- "sourcesContent": ["import type { YargsConfig } from '@bpinternal/yargs-extra'\nimport chalk from 'chalk'\nimport fs from 'fs'\nimport latestVersion from 'latest-version'\nimport _ from 'lodash'\nimport * as pathlib from 'path'\nimport semver from 'semver'\nimport type { ApiClientFactory } from '../api-client'\nimport type * as config from '../config'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport type { CommandArgv, CommandDefinition } from '../typings'\nimport * as utils from '../utils'\nimport { BaseCommand } from './base-command'\n\nexport type GlobalCommandDefinition = CommandDefinition<typeof config.schemas.global>\nexport type GlobalCache = { apiUrl: string; token: string; workspaceId: string }\n\nexport type ConfigurableGlobalPaths = { botpressHomeDir: string; cliRootDir: utils.path.AbsolutePath }\nexport type ConstantGlobalPaths = typeof consts.fromHomeDir & typeof consts.fromCliRootDir\nexport type AllGlobalPaths = ConfigurableGlobalPaths & ConstantGlobalPaths\n\nclass GlobalPaths extends utils.path.PathStore<keyof AllGlobalPaths> {\n public constructor(argv: CommandArgv<GlobalCommandDefinition>) {\n const absBotpressHome = utils.path.absoluteFrom(utils.path.cwd(), argv.botpressHome)\n super({\n cliRootDir: argv.cliRootDir,\n botpressHomeDir: absBotpressHome,\n ..._.mapValues(consts.fromHomeDir, (p) => utils.path.absoluteFrom(absBotpressHome, p)),\n ..._.mapValues(consts.fromCliRootDir, (p) => utils.path.absoluteFrom(argv.cliRootDir, p)),\n })\n }\n}\n\ntype PackageJson = { name: string; version: string }\n\nconst UPDATE_MSG = (props: PackageJson & { latest: string }) =>\n `${chalk.bold('Update available')} ${chalk.dim(props.version)} \u2192 ${chalk.green(props.latest)}\n\nTo update, run:\n for npm ${chalk.cyan(`npm i -g ${props.name}`)}\n for yarn ${chalk.cyan(`yarn global add ${props.name}`)}\n for pnpm ${chalk.cyan(`pnpm i -g ${props.name}`)}`\n\nexport abstract class GlobalCommand<C extends GlobalCommandDefinition> extends BaseCommand<C> {\n protected api: ApiClientFactory\n protected prompt: utils.prompt.CLIPrompt\n\n public constructor(\n api: ApiClientFactory,\n prompt: utils.prompt.CLIPrompt,\n ...args: ConstructorParameters<typeof BaseCommand<C>>\n ) {\n super(...args)\n this.api = api\n this.prompt = prompt\n }\n\n protected get globalPaths() {\n return new GlobalPaths(this.argv)\n }\n\n protected get globalCache() {\n return new utils.cache.FSKeyValueCache<GlobalCache>(this.globalPaths.abs.globalCacheFile)\n }\n\n protected override bootstrap = async () => {\n const pkgJson = await this._readPackageJson()\n\n const versionText = chalk.bold(`v${pkgJson.version}`)\n this.logger.log(`Botpress CLI ${versionText}`, { prefix: '\uD83E\uDD16' })\n\n await this._notifyUpdate(pkgJson)\n\n const paths = this.globalPaths\n if (paths.abs.botpressHomeDir !== consts.defaultBotpressHome) {\n this.logger.log(`Using custom botpress home: ${paths.abs.botpressHomeDir}`, { prefix: '\uD83C\uDFE0' })\n }\n }\n\n protected override teardown = async () => {\n this.logger.cleanup()\n }\n\n protected async ensureLoginAndCreateClient(credentials: YargsConfig<typeof config.schemas.credentials>) {\n const cache = this.globalCache\n const token = await cache.get('token')\n const workspaceId = credentials.workspaceId ?? (await cache.get('workspaceId'))\n const apiUrl = credentials.apiUrl ?? (await cache.get('apiUrl'))\n\n if (!(token && workspaceId && apiUrl)) {\n throw new errors.NotLoggedInError()\n }\n\n return this.api.newClient({ apiUrl, token, workspaceId }, this.logger)\n }\n\n private _notifyUpdate = async (pkgJson: PackageJson): Promise<void> => {\n try {\n const latest = await latestVersion(pkgJson.name)\n const isOutdated = semver.lt(pkgJson.version, latest)\n if (isOutdated) {\n this.logger.box(UPDATE_MSG({ ...pkgJson, latest }))\n }\n } catch (thrown) {\n const err = errors.BotpressCLIError.map(thrown)\n this.logger.debug(`Failed to check for updates: ${err.message}`)\n }\n }\n\n private _readPackageJson = async (): Promise<PackageJson> => {\n const path = pathlib.join(this.globalPaths.abs.cliRootDir, 'package.json')\n const strContent = await fs.promises.readFile(path, 'utf8')\n const jsonContent = JSON.parse(strContent)\n return jsonContent\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAClB,gBAAe;AACf,4BAA0B;AAC1B,oBAAc;AACd,cAAyB;AACzB,oBAAmB;AAGnB,aAAwB;AACxB,aAAwB;AAExB,YAAuB;AACvB,0BAA4B;AAS5B,MAAM,oBAAoB,MAAM,KAAK,UAAgC;AAAA,EAC5D,YAAY,MAA4C;AAC7D,UAAM,kBAAkB,MAAM,KAAK,aAAa,MAAM,KAAK,I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s from 'fs'\nimport latestVersion from 'latest-version'\nimport _ from 'lodash'\nimport * as pathlib from 'path'\nimport semver from 'semver'\nimport type { ApiClientFactory } from '../api-client'\nimport type * as config from '../config'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport type { CommandArgv, CommandDefinition } from '../typings'\nimport * as utils from '../utils'\nimport { BaseCommand } from './base-command'\n\nexport type GlobalCommandDefinition = CommandDefinition<typeof config.schemas.global>\nexport type GlobalCache = { apiUrl: string; token: string; workspaceId: string }\n\nexport type ConfigurableGlobalPaths = { botpressHomeDir: string; cliRootDir: utils.path.AbsolutePath }\nexport type ConstantGlobalPaths = typeof consts.fromHomeDir & typeof consts.fromCliRootDir\nexport type AllGlobalPaths = ConfigurableGlobalPaths & ConstantGlobalPaths\n\nclass GlobalPaths extends utils.path.PathStore<keyof AllGlobalPaths> {\n public constructor(argv: CommandArgv<GlobalCommandDefinition>) {\n const absBotpressHome = utils.path.absoluteFrom(utils.path.cwd(), argv.botpressHome)\n super({\n cliRootDir: consts.cliRootDir,\n botpressHomeDir: absBotpressHome,\n ..._.mapValues(consts.fromHomeDir, (p) => utils.path.absoluteFrom(absBotpressHome, p)),\n ..._.mapValues(consts.fromCliRootDir, (p) => utils.path.absoluteFrom(consts.cliRootDir, p)),\n })\n }\n}\n\ntype PackageJson = { name: string; version: string }\n\nconst UPDATE_MSG = (props: PackageJson & { latest: string }) =>\n `${chalk.bold('Update available')} ${chalk.dim(props.version)} \u2192 ${chalk.green(props.latest)}\n\nTo update, run:\n for npm ${chalk.cyan(`npm i -g ${props.name}`)}\n for yarn ${chalk.cyan(`yarn global add ${props.name}`)}\n for pnpm ${chalk.cyan(`pnpm i -g ${props.name}`)}`\n\nexport abstract class GlobalCommand<C extends GlobalCommandDefinition> extends BaseCommand<C> {\n protected api: ApiClientFactory\n protected prompt: utils.prompt.CLIPrompt\n\n public constructor(\n api: ApiClientFactory,\n prompt: utils.prompt.CLIPrompt,\n ...args: ConstructorParameters<typeof BaseCommand<C>>\n ) {\n super(...args)\n this.api = api\n this.prompt = prompt\n }\n\n protected get globalPaths() {\n return new GlobalPaths(this.argv)\n }\n\n protected get globalCache() {\n return new utils.cache.FSKeyValueCache<GlobalCache>(this.globalPaths.abs.globalCacheFile)\n }\n\n protected override bootstrap = async () => {\n const pkgJson = await this._readPackageJson()\n\n const versionText = chalk.bold(`v${pkgJson.version}`)\n this.logger.log(`Botpress CLI ${versionText}`, { prefix: '\uD83E\uDD16' })\n\n await this._notifyUpdate(pkgJson)\n\n const paths = this.globalPaths\n if (paths.abs.botpressHomeDir !== consts.defaultBotpressHome) {\n this.logger.log(`Using custom botpress home: ${paths.abs.botpressHomeDir}`, { prefix: '\uD83C\uDFE0' })\n }\n }\n\n protected override teardown = async () => {\n this.logger.cleanup()\n }\n\n protected async ensureLoginAndCreateClient(credentials: YargsConfig<typeof config.schemas.credentials>) {\n const cache = this.globalCache\n const token = await cache.get('token')\n const workspaceId = credentials.workspaceId ?? (await cache.get('workspaceId'))\n const apiUrl = credentials.apiUrl ?? (await cache.get('apiUrl'))\n\n if (!(token && workspaceId && apiUrl)) {\n throw new errors.NotLoggedInError()\n }\n\n return this.api.newClient({ apiUrl, token, workspaceId }, this.logger)\n }\n\n private _notifyUpdate = async (pkgJson: PackageJson): Promise<void> => {\n try {\n const latest = await latestVersion(pkgJson.name)\n const isOutdated = semver.lt(pkgJson.version, latest)\n if (isOutdated) {\n this.logger.box(UPDATE_MSG({ ...pkgJson, latest }))\n }\n } catch (thrown) {\n const err = errors.BotpressCLIError.map(thrown)\n this.logger.debug(`Failed to check for updates: ${err.message}`)\n }\n }\n\n private _readPackageJson = async (): Promise<PackageJson> => {\n const path = pathlib.join(this.globalPaths.abs.cliRootDir, 'package.json')\n const strContent = await fs.promises.readFile(path, 'utf8')\n const jsonContent = JSON.parse(strContent)\n return jsonContent\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;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QAAQ,KAAK,KAAK,YAAY,IAAI,YAAY,cAAc;AACzE,UAAM,aAAa,MAAM,UAAAC,QAAG,SAAS,SAAS,MAAM,MAAM;AAC1D,UAAM,cAAc,KAAK,MAAM,UAAU;AACzC,WAAO;AAAA,EACT;AACF;",
6
6
  "names": ["_", "chalk", "latestVersion", "semver", "fs"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/command-implementations/integration-commands.ts"],
4
- "sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport chalk from 'chalk'\nimport _ from 'lodash'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport { parseIntegrationRef } from '../integration-ref'\nimport { GlobalCommand } from './global-command'\n\nexport type GetIntegrationCommandDefinition = typeof commandDefinitions.integrations.subcommands.get\nexport class GetIntegrationCommand extends GlobalCommand<GetIntegrationCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n const parsedRef = parseIntegrationRef(this.argv.integrationRef)\n if (!parsedRef) {\n throw new errors.InvalidIntegrationReferenceError(this.argv.integrationRef)\n }\n\n try {\n const integration = await api.findIntegration(parsedRef)\n if (integration) {\n this.logger.success(`Integration ${chalk.bold(this.argv.integrationRef)}:`)\n this.logger.json(integration)\n return\n }\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, `Could not get integration ${this.argv.integrationRef}`)\n }\n\n throw new errors.BotpressCLIError(`Integration ${this.argv.integrationRef} not found`)\n }\n}\n\nexport type ListIntegrationCommandDefinition = typeof commandDefinitions.integrations.subcommands.list\nexport class ListIntegrationsCommand extends GlobalCommand<ListIntegrationCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n\n const privateLister = (req: { nextToken?: string }) =>\n api.client.listIntegrations({ nextToken: req.nextToken, name: this.argv.name, version: this.argv.version })\n\n const publicLister = (req: { nextToken?: string }) =>\n api.client.listPublicIntegrations({ nextToken: req.nextToken, name: this.argv.name, version: this.argv.version })\n\n try {\n const privateIntegrations = await api.listAllPages(privateLister, (r) => r.integrations)\n const publicIntegrations = await api.listAllPages(publicLister, (r) => r.integrations)\n const integrations = _.uniqBy([...privateIntegrations, ...publicIntegrations], (i) => i.id)\n\n this.logger.success('Integrations:')\n this.logger.json(integrations)\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not list integrations')\n }\n }\n}\n\nexport type DeleteIntegrationCommandDefinition = typeof commandDefinitions.integrations.subcommands.delete\nexport class DeleteIntegrationCommand extends GlobalCommand<DeleteIntegrationCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n const parsedRef = parseIntegrationRef(this.argv.integrationRef)\n if (!parsedRef) {\n throw new errors.InvalidIntegrationReferenceError(this.argv.integrationRef)\n }\n\n let integration: bpclient.Integration | undefined\n try {\n integration = await api.findPrivateIntegration(parsedRef)\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, `Could not get integration ${this.argv.integrationRef}`)\n }\n\n if (!integration) {\n const publicIntegration = await api.findPublicIntegration(parsedRef)\n if (publicIntegration) {\n throw new errors.BotpressCLIError(`Integration ${this.argv.integrationRef} does not belong to your workspace`)\n }\n\n throw new errors.BotpressCLIError(`Integration ${this.argv.integrationRef} not found`)\n }\n\n try {\n await api.client.deleteIntegration({ id: integration.id })\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, `Could not delete integration ${this.argv.integrationRef}`)\n }\n\n this.logger.success(`Integration ${chalk.bold(this.argv.integrationRef)} deleted`)\n return\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAClB,oBAAc;AAEd,aAAwB;AACxB,6BAAoC;AACpC,4BAA8B;AAGvB,MAAM,8BAA8B,oCAA+C;AAAA,EACxF,MAAa,MAAqB;AAChC,UAAM,MAAM,M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C/B,SAAS,QAAP;AACA,YAAM,OAAO,iBAAiB,KAAK,QAAQ,6BAA6B;AAAA,IAC1E;AAAA,EACF;AACF;AAGO,MAAM,iCAAiC,oCAAkD;AAAA,EAC9F,MAAa,MAAqB;AAChC,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAC3D,UAAM,gBAAY,4CAAoB,KAAK,KAAK,cAAc;AAC9D,QAAI,CAAC,WAAW;AACd,YAAM,IAAI,OAAO,iCAAiC,KAAK,KAAK,cAAc;AAAA,IAC5E;AAEA,QAAI;AACJ,QAAI;AACF,oBAAc,MAAM,IAAI,uBAAuB,SAAS;AAAA,IAC1D,SAAS,QAAP;AACA,YAAM,OAAO,iBAAiB,KAAK,QAAQ,6BAA6B,KAAK,KAAK,gBAAgB;AAAA,IACpG;AAEA,QAAI,CAAC,aAAa;AAChB,YAAM,oBAAoB,MAAM,IAAI,sBAAsB,SAAS;AACnE,UAAI,mBAAmB;AACrB,cAAM,IAAI,OAAO,iBAAiB,eAAe,KAAK,KAAK,kDAAkD;AAAA,MAC/G;AAEA,YAAM,IAAI,OAAO,iBAAiB,eAAe,KAAK,KAAK,0BAA0B;AAAA,IACvF;AAEA,QAAI;AACF,YAAM,IAAI,OAAO,kBAAkB,EAAE,IAAI,YAAY,GAAG,CAAC;AAAA,IAC3D,SAAS,QAAP;AACA,YAAM,OAAO,iBAAiB,KAAK,QAAQ,gCAAgC,KAAK,KAAK,gBAAgB;AAAA,IACvG;AAEA,SAAK,OAAO,QAAQ,eAAe,aAAAD,QAAM,KAAK,KAAK,KAAK,cAAc,WAAW;AACjF;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport chalk from 'chalk'\nimport _ from 'lodash'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport { parseIntegrationRef } from '../integration-ref'\nimport { GlobalCommand } from './global-command'\n\nexport type GetIntegrationCommandDefinition = typeof commandDefinitions.integrations.subcommands.get\nexport class GetIntegrationCommand extends GlobalCommand<GetIntegrationCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n const parsedRef = parseIntegrationRef(this.argv.integrationRef)\n if (!parsedRef) {\n throw new errors.InvalidIntegrationReferenceError(this.argv.integrationRef)\n }\n\n try {\n const integration = await api.findIntegration(parsedRef)\n if (integration) {\n this.logger.success(`Integration ${chalk.bold(this.argv.integrationRef)}:`)\n this.logger.json(integration)\n return\n }\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, `Could not get integration ${this.argv.integrationRef}`)\n }\n\n throw new errors.BotpressCLIError(`Integration ${this.argv.integrationRef} not found`)\n }\n}\n\nexport type ListIntegrationsCommandDefinition = typeof commandDefinitions.integrations.subcommands.list\nexport class ListIntegrationsCommand extends GlobalCommand<ListIntegrationsCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n\n const privateLister = (req: { nextToken?: string }) =>\n api.client.listIntegrations({ nextToken: req.nextToken, name: this.argv.name, version: this.argv.version })\n\n const publicLister = (req: { nextToken?: string }) =>\n api.client.listPublicIntegrations({ nextToken: req.nextToken, name: this.argv.name, version: this.argv.version })\n\n try {\n const privateIntegrations = await api.listAllPages(privateLister, (r) => r.integrations)\n const publicIntegrations = await api.listAllPages(publicLister, (r) => r.integrations)\n const integrations = _.uniqBy([...privateIntegrations, ...publicIntegrations], (i) => i.id)\n\n this.logger.success('Integrations:')\n this.logger.json(integrations)\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not list integrations')\n }\n }\n}\n\nexport type DeleteIntegrationCommandDefinition = typeof commandDefinitions.integrations.subcommands.delete\nexport class DeleteIntegrationCommand extends GlobalCommand<DeleteIntegrationCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n const parsedRef = parseIntegrationRef(this.argv.integrationRef)\n if (!parsedRef) {\n throw new errors.InvalidIntegrationReferenceError(this.argv.integrationRef)\n }\n\n let integration: bpclient.Integration | undefined\n try {\n integration = await api.findPrivateIntegration(parsedRef)\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, `Could not get integration ${this.argv.integrationRef}`)\n }\n\n if (!integration) {\n const publicIntegration = await api.findPublicIntegration(parsedRef)\n if (publicIntegration) {\n throw new errors.BotpressCLIError(`Integration ${this.argv.integrationRef} does not belong to your workspace`)\n }\n\n throw new errors.BotpressCLIError(`Integration ${this.argv.integrationRef} not found`)\n }\n\n try {\n await api.client.deleteIntegration({ id: integration.id })\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, `Could not delete integration ${this.argv.integrationRef}`)\n }\n\n this.logger.success(`Integration ${chalk.bold(this.argv.integrationRef)} deleted`)\n return\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAClB,oBAAc;AAEd,aAAwB;AACxB,6BAAoC;AACpC,4BAA8B;AAGvB,MAAM,8BAA8B,oCAA+C;AAAA,EACxF,MAAa,MAAqB;AAChC,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAC3D,UAAM,gBAAY,4CAAoB,KAAK,KAAK,cAAc;AAC9D,QAAI,CAAC,WAAW;AACd,YAAM,IAAI,OAAO,iCAAiC,KAAK,KAAK,cAAc;AAAA,IAC5E;AAEA,QAAI;AACF,YAAM,cAAc,MAAM,IAAI,gBAAgB,SAAS;AACvD,UAAI,aAAa;AACf,aAAK,OAAO,QAAQ,eAAe,aAAAA,QAAM,KAAK,KAAK,KAAK,cAAc,IAAI;AAC1E,aAAK,OAAO,KAAK,WAAW;AAC5B;AAAA,MACF;AAAA,IACF,SAAS,QAAP;AACA,YAAM,OAAO,iBAAiB,KAAK,QAAQ,6BAA6B,KAAK,KAAK,gBAAgB;AAAA,IACpG;AAEA,UAAM,IAAI,OAAO,iBAAiB,eAAe,KAAK,KAAK,0B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,aAAa;AAChB,YAAM,oBAAoB,MAAM,IAAI,sBAAsB,SAAS;AACnE,UAAI,mBAAmB;AACrB,cAAM,IAAI,OAAO,iBAAiB,eAAe,KAAK,KAAK,kDAAkD;AAAA,MAC/G;AAEA,YAAM,IAAI,OAAO,iBAAiB,eAAe,KAAK,KAAK,0BAA0B;AAAA,IACvF;AAEA,QAAI;AACF,YAAM,IAAI,OAAO,kBAAkB,EAAE,IAAI,YAAY,GAAG,CAAC;AAAA,IAC3D,SAAS,QAAP;AACA,YAAM,OAAO,iBAAiB,KAAK,QAAQ,gCAAgC,KAAK,KAAK,gBAAgB;AAAA,IACvG;AAEA,SAAK,OAAO,QAAQ,eAAe,aAAAD,QAAM,KAAK,KAAK,KAAK,cAAc,WAAW;AACjF;AAAA,EACF;AACF;",
6
6
  "names": ["chalk", "_"]
7
7
  }
package/dist/consts.js CHANGED
@@ -24,6 +24,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
25
  var consts_exports = {};
26
26
  __export(consts_exports, {
27
+ cliRootDir: () => cliRootDir,
27
28
  defaultBotpressApiUrl: () => defaultBotpressApiUrl,
28
29
  defaultBotpressAppUrl: () => defaultBotpressAppUrl,
29
30
  defaultBotpressHome: () => defaultBotpressHome,
@@ -40,12 +41,14 @@ __export(consts_exports, {
40
41
  module.exports = __toCommonJS(consts_exports);
41
42
  var import_os = __toESM(require("os"));
42
43
  var import_path = __toESM(require("path"));
44
+ var import_root = require("./root");
43
45
  const defaultBotpressHome = import_path.default.join(import_os.default.homedir(), ".botpress");
44
46
  const defaultOutputFolder = ".botpress";
45
47
  const defaultEntrypoint = import_path.default.join("src", "index.ts");
46
48
  const defaultBotpressApiUrl = "https://api.botpress.cloud";
47
49
  const defaultBotpressAppUrl = "https://app.botpress.cloud";
48
50
  const defaultTunnelUrl = "https://tunnel.botpress.cloud";
51
+ const cliRootDir = import_root.CLI_ROOT_DIR;
49
52
  const echoBotDirName = "echo-bot";
50
53
  const emptyIntegrationDirName = "empty-integration";
51
54
  const fromCliRootDir = {
@@ -69,6 +72,7 @@ const fromOutDir = {
69
72
  };
70
73
  // Annotate the CommonJS export names for ESM import in node:
71
74
  0 && (module.exports = {
75
+ cliRootDir,
72
76
  defaultBotpressApiUrl,
73
77
  defaultBotpressAppUrl,
74
78
  defaultBotpressHome,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/consts.ts"],
4
- "sourcesContent": ["import os from 'os'\nimport pathlib from 'path'\n\n// configurable\n\nexport const defaultBotpressHome = pathlib.join(os.homedir(), '.botpress')\n\nexport const defaultOutputFolder = '.botpress'\nexport const defaultEntrypoint = pathlib.join('src', 'index.ts')\nexport const defaultBotpressApiUrl = 'https://api.botpress.cloud'\nexport const defaultBotpressAppUrl = 'https://app.botpress.cloud'\nexport const defaultTunnelUrl = 'https://tunnel.botpress.cloud'\n\n// not configurable\n\nexport const echoBotDirName = 'echo-bot'\nexport const emptyIntegrationDirName = 'empty-integration'\n\nexport const fromCliRootDir = {\n packageJson: 'package.json',\n echoBotTemplate: pathlib.join('templates', echoBotDirName),\n emptyIntegrationTemplate: pathlib.join('templates', emptyIntegrationDirName),\n}\n\nexport const fromHomeDir = {\n globalCacheFile: 'global.cache.json',\n}\n\nexport const fromWorkDir = {\n definition: 'integration.definition.ts',\n}\n\nexport const fromOutDir = {\n distDir: 'dist',\n outFile: pathlib.join('dist', 'index.js'),\n installDir: 'installations',\n implementationDir: 'implementation',\n secretsDir: 'secrets',\n projectCacheFile: 'project.cache.json',\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AACf,kBAAoB;AAIb,MAAM,sBAAsB,YAAAA,QAAQ,KAAK,UAAAC,QAAG,QAAQ,GAAG,WAAW;AAElE,MAAM,sBAAsB;AAC5B,MAAM,oBAAoB,YAAAD,QAAQ,KAAK,OAAO,UAAU;AACxD,MAAM,wBAAwB;AAC9B,MAAM,wBAAwB;AAC9B,MAAM,mBAAmB;AAIzB,MAAM,iBAAiB;AACvB,MAAM,0BAA0B;AAEhC,MAAM,iBAAiB;AAAA,EAC5B,aAAa;AAAA,EACb,iBAAiB,YAAAA,QAAQ,KAAK,aAAa,cAAc;AAAA,EACzD,0BAA0B,YAAAA,QAAQ,KAAK,aAAa,uBAAuB;AAC7E;AAEO,MAAM,cAAc;AAAA,EACzB,iBAAiB;AACnB;AAEO,MAAM,cAAc;AAAA,EACzB,YAAY;AACd;AAEO,MAAM,aAAa;AAAA,EACxB,SAAS;AAAA,EACT,SAAS,YAAAA,QAAQ,KAAK,QAAQ,UAAU;AAAA,EACxC,YAAY;AAAA,EACZ,mBAAmB;AAAA,EACnB,YAAY;AAAA,EACZ,kBAAkB;AACpB;",
4
+ "sourcesContent": ["import os from 'os'\nimport pathlib from 'path'\nimport { CLI_ROOT_DIR } from './root'\n\n// configurable\n\nexport const defaultBotpressHome = pathlib.join(os.homedir(), '.botpress')\n\nexport const defaultOutputFolder = '.botpress'\nexport const defaultEntrypoint = pathlib.join('src', 'index.ts')\nexport const defaultBotpressApiUrl = 'https://api.botpress.cloud'\nexport const defaultBotpressAppUrl = 'https://app.botpress.cloud'\nexport const defaultTunnelUrl = 'https://tunnel.botpress.cloud'\n\n// not configurable\n\nexport const cliRootDir = CLI_ROOT_DIR\n\nexport const echoBotDirName = 'echo-bot'\nexport const emptyIntegrationDirName = 'empty-integration'\n\nexport const fromCliRootDir = {\n packageJson: 'package.json',\n echoBotTemplate: pathlib.join('templates', echoBotDirName),\n emptyIntegrationTemplate: pathlib.join('templates', emptyIntegrationDirName),\n}\n\nexport const fromHomeDir = {\n globalCacheFile: 'global.cache.json',\n}\n\nexport const fromWorkDir = {\n definition: 'integration.definition.ts',\n}\n\nexport const fromOutDir = {\n distDir: 'dist',\n outFile: pathlib.join('dist', 'index.js'),\n installDir: 'installations',\n implementationDir: 'implementation',\n secretsDir: 'secrets',\n projectCacheFile: 'project.cache.json',\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AACf,kBAAoB;AACpB,kBAA6B;AAItB,MAAM,sBAAsB,YAAAA,QAAQ,KAAK,UAAAC,QAAG,QAAQ,GAAG,WAAW;AAElE,MAAM,sBAAsB;AAC5B,MAAM,oBAAoB,YAAAD,QAAQ,KAAK,OAAO,UAAU;AACxD,MAAM,wBAAwB;AAC9B,MAAM,wBAAwB;AAC9B,MAAM,mBAAmB;AAIzB,MAAM,aAAa;AAEnB,MAAM,iBAAiB;AACvB,MAAM,0BAA0B;AAEhC,MAAM,iBAAiB;AAAA,EAC5B,aAAa;AAAA,EACb,iBAAiB,YAAAA,QAAQ,KAAK,aAAa,cAAc;AAAA,EACzD,0BAA0B,YAAAA,QAAQ,KAAK,aAAa,uBAAuB;AAC7E;AAEO,MAAM,cAAc;AAAA,EACzB,iBAAiB;AACnB;AAEO,MAAM,cAAc;AAAA,EACzB,YAAY;AACd;AAEO,MAAM,aAAa;AAAA,EACxB,SAAS;AAAA,EACT,SAAS,YAAAA,QAAQ,KAAK,QAAQ,UAAU;AAAA,EACxC,YAAY;AAAA,EACZ,mBAAmB;AAAA,EACnB,YAAY;AAAA,EACZ,kBAAkB;AACpB;",
6
6
  "names": ["pathlib", "os"]
7
7
  }
package/dist/index.js CHANGED
@@ -24,8 +24,6 @@ var tree = __toESM(require("./command-tree"));
24
24
  var errors = __toESM(require("./errors"));
25
25
  var import_logger = require("./logger");
26
26
  var import_register_yargs = require("./register-yargs");
27
- var utils = __toESM(require("./utils"));
28
- const CLI_ROOT_DIR = utils.path.join(__dirname, "..");
29
27
  const logError = (thrown) => {
30
28
  const error = errors.BotpressCLIError.map(thrown);
31
29
  new import_logger.Logger().error(error.message);
@@ -43,6 +41,6 @@ const yargsFail = (msg) => {
43
41
  process.on("uncaughtException", (thrown) => onError(thrown));
44
42
  process.on("unhandledRejection", (thrown) => onError(thrown));
45
43
  const commands = tree.zipTree(import_command_definitions.default, import_command_implementations.default);
46
- (0, import_register_yargs.registerYargs)(import_yargs_extra.default, commands, { cliRootDir: CLI_ROOT_DIR });
44
+ (0, import_register_yargs.registerYargs)(import_yargs_extra.default, commands);
47
45
  void import_yargs_extra.default.version().scriptName("bp").demandCommand(1, "You didn't provide any command. Use the --help flag to see the list of available commands.").recommendCommands().strict().help().fail(yargsFail).parse();
48
46
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["import yargs from '@bpinternal/yargs-extra'\nimport commandDefinitions from './command-definitions'\nimport commandImplementations from './command-implementations'\nimport * as tree from './command-tree'\nimport * as errors from './errors'\nimport { Logger } from './logger'\nimport { registerYargs } from './register-yargs'\nimport * as utils from './utils'\n\nconst CLI_ROOT_DIR = utils.path.join(__dirname as utils.path.AbsolutePath, '..')\n\nconst logError = (thrown: unknown) => {\n const error = errors.BotpressCLIError.map(thrown)\n new Logger().error(error.message)\n}\n\nconst onError = (thrown: unknown) => {\n logError(thrown)\n process.exit(1)\n}\n\nconst yargsFail = (msg: string) => {\n logError(`${msg}\\n`)\n yargs.showHelp()\n process.exit(1)\n}\n\nprocess.on('uncaughtException', (thrown: unknown) => onError(thrown))\nprocess.on('unhandledRejection', (thrown: unknown) => onError(thrown))\n\nconst commands = tree.zipTree(commandDefinitions, commandImplementations)\n\nregisterYargs(yargs, commands, { cliRootDir: CLI_ROOT_DIR })\n\nvoid yargs\n .version()\n .scriptName('bp')\n .demandCommand(1, \"You didn't provide any command. Use the --help flag to see the list of available commands.\")\n .recommendCommands()\n .strict()\n .help()\n .fail(yargsFail)\n .parse()\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA,yBAAkB;AAClB,iCAA+B;AAC/B,qCAAmC;AACnC,WAAsB;AACtB,aAAwB;AACxB,oBAAuB;AACvB,4BAA8B;AAC9B,YAAuB;AAEvB,MAAM,eAAe,MAAM,KAAK,KAAK,WAAsC,IAAI;AAE/E,MAAM,WAAW,CAAC,WAAoB;AACpC,QAAM,QAAQ,OAAO,iBAAiB,IAAI,MAAM;AAChD,MAAI,qBAAO,EAAE,MAAM,MAAM,OAAO;AAClC;AAEA,MAAM,UAAU,CAAC,WAAoB;AACnC,WAAS,MAAM;AACf,UAAQ,KAAK,CAAC;AAChB;AAEA,MAAM,YAAY,CAAC,QAAgB;AACjC,WAAS,GAAG;AAAA,CAAO;AACnB,qBAAAA,QAAM,SAAS;AACf,UAAQ,KAAK,CAAC;AAChB;AAEA,QAAQ,GAAG,qBAAqB,CAAC,WAAoB,QAAQ,MAAM,CAAC;AACpE,QAAQ,GAAG,sBAAsB,CAAC,WAAoB,QAAQ,MAAM,CAAC;AAErE,MAAM,WAAW,KAAK,QAAQ,2BAAAC,SAAoB,+BAAAC,OAAsB;AAAA,IAExE,qCAAc,mBAAAF,SAAO,UAAU,EAAE,YAAY,aAAa,CAAC;AAE3D,KAAK,mBAAAA,QACF,QAAQ,EACR,WAAW,IAAI,EACf,cAAc,GAAG,4FAA4F,EAC7G,kBAAkB,EAClB,OAAO,EACP,KAAK,EACL,KAAK,SAAS,EACd,MAAM;",
4
+ "sourcesContent": ["import yargs from '@bpinternal/yargs-extra'\nimport commandDefinitions from './command-definitions'\nimport commandImplementations from './command-implementations'\nimport * as tree from './command-tree'\nimport * as errors from './errors'\nimport { Logger } from './logger'\nimport { registerYargs } from './register-yargs'\n\nconst logError = (thrown: unknown) => {\n const error = errors.BotpressCLIError.map(thrown)\n new Logger().error(error.message)\n}\n\nconst onError = (thrown: unknown) => {\n logError(thrown)\n process.exit(1)\n}\n\nconst yargsFail = (msg: string) => {\n logError(`${msg}\\n`)\n yargs.showHelp()\n process.exit(1)\n}\n\nprocess.on('uncaughtException', (thrown: unknown) => onError(thrown))\nprocess.on('unhandledRejection', (thrown: unknown) => onError(thrown))\n\nconst commands = tree.zipTree(commandDefinitions, commandImplementations)\n\nregisterYargs(yargs, commands)\n\nvoid yargs\n .version()\n .scriptName('bp')\n .demandCommand(1, \"You didn't provide any command. Use the --help flag to see the list of available commands.\")\n .recommendCommands()\n .strict()\n .help()\n .fail(yargsFail)\n .parse()\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA,yBAAkB;AAClB,iCAA+B;AAC/B,qCAAmC;AACnC,WAAsB;AACtB,aAAwB;AACxB,oBAAuB;AACvB,4BAA8B;AAE9B,MAAM,WAAW,CAAC,WAAoB;AACpC,QAAM,QAAQ,OAAO,iBAAiB,IAAI,MAAM;AAChD,MAAI,qBAAO,EAAE,MAAM,MAAM,OAAO;AAClC;AAEA,MAAM,UAAU,CAAC,WAAoB;AACnC,WAAS,MAAM;AACf,UAAQ,KAAK,CAAC;AAChB;AAEA,MAAM,YAAY,CAAC,QAAgB;AACjC,WAAS,GAAG;AAAA,CAAO;AACnB,qBAAAA,QAAM,SAAS;AACf,UAAQ,KAAK,CAAC;AAChB;AAEA,QAAQ,GAAG,qBAAqB,CAAC,WAAoB,QAAQ,MAAM,CAAC;AACpE,QAAQ,GAAG,sBAAsB,CAAC,WAAoB,QAAQ,MAAM,CAAC;AAErE,MAAM,WAAW,KAAK,QAAQ,2BAAAC,SAAoB,+BAAAC,OAAsB;AAAA,IAExE,qCAAc,mBAAAF,SAAO,QAAQ;AAE7B,KAAK,mBAAAA,QACF,QAAQ,EACR,WAAW,IAAI,EACf,cAAc,GAAG,4FAA4F,EAC7G,kBAAkB,EAClB,OAAO,EACP,KAAK,EACL,KAAK,SAAS,EACd,MAAM;",
6
6
  "names": ["yargs", "commandDefinitions", "commandImplementations"]
7
7
  }
package/dist/init.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/init.ts"],
4
- "sourcesContent": ["import Module from 'module'\nimport pathlib from 'path'\n\nconst DEFAULT_DIRNAME = '.botpress'\n\nconst getOutDir = () => {\n const { BP_OUTDIR } = process.env\n if (!BP_OUTDIR) {\n return pathlib.join(process.cwd(), DEFAULT_DIRNAME)\n }\n if (pathlib.isAbsolute(BP_OUTDIR)) {\n return BP_OUTDIR\n }\n return pathlib.join(process.cwd(), BP_OUTDIR)\n}\n\nconst outDirPath = getOutDir()\nconst outDirName = pathlib.basename(outDirPath)\nconst originalRequire = Module.prototype.require\n\nconst rewire = function (this: NodeRequire, mod: string) {\n const importParts = mod.split('/')\n\n if (importParts[0] === outDirName) {\n const newMod = importParts.slice(1).join('/')\n const fullpath = pathlib.join(outDirPath, newMod)\n return originalRequire.apply(this, [fullpath])\n }\n\n return originalRequire.apply(this, [mod])\n} as NodeRequire\n\nModule.prototype.require = rewire\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA,oBAAmB;AACnB,kBAAoB;AAEpB,MAAM,kBAAkB;AAExB,MAAM,YAAY,MAAM;AACtB,QAAM,EAAE,UAAU,IAAI,QAAQ;AAC9B,MAAI,CAAC,WAAW;AACd,WAAO,YAAAA,QAAQ,KAAK,QAAQ,IAAI,GAAG,eAAe;AAAA,EACpD;AACA,MAAI,YAAAA,QAAQ,WAAW,SAAS,GAAG;AACjC,WAAO;AAAA,EACT;AACA,SAAO,YAAAA,QAAQ,KAAK,QAAQ,IAAI,GAAG,SAAS;AAC9C;AAEA,MAAM,aAAa,UAAU;AAC7B,MAAM,aAAa,YAAAA,QAAQ,SAAS,UAAU;AAC9C,MAAM,kBAAkB,cAAAC,QAAO,UAAU;AAEzC,MAAM,SAAS,SAA6B,KAAa;AACvD,QAAM,cAAc,IAAI,MAAM,GAAG;AAEjC,MAAI,YAAY,OAAO,YAAY;AACjC,UAAM,SAAS,YAAY,MAAM,CAAC,EAAE,KAAK,GAAG;AAC5C,UAAM,WAAW,YAAAD,QAAQ,KAAK,YAAY,MAAM;AAChD,WAAO,gBAAgB,MAAM,MAAM,CAAC,QAAQ,CAAC;AAAA,EAC/C;AAEA,SAAO,gBAAgB,MAAM,MAAM,CAAC,GAAG,CAAC;AAC1C;AAEA,cAAAC,QAAO,UAAU,UAAU;",
4
+ "sourcesContent": ["/**\n * Important:\n *\n * This file must be kept at the root of the src directory (and dist directory when built)\n */\nimport Module from 'module'\nimport pathlib from 'path'\n\nconst DEFAULT_DIRNAME = '.botpress'\n\nconst getOutDir = () => {\n const { BP_OUTDIR } = process.env\n if (!BP_OUTDIR) {\n return pathlib.join(process.cwd(), DEFAULT_DIRNAME)\n }\n if (pathlib.isAbsolute(BP_OUTDIR)) {\n return BP_OUTDIR\n }\n return pathlib.join(process.cwd(), BP_OUTDIR)\n}\n\nconst outDirPath = getOutDir()\nconst outDirName = pathlib.basename(outDirPath)\nconst originalRequire = Module.prototype.require\n\nconst rewire = function (this: NodeRequire, mod: string) {\n const importParts = mod.split('/')\n\n if (importParts[0] === outDirName) {\n const newMod = importParts.slice(1).join('/')\n const fullpath = pathlib.join(outDirPath, newMod)\n return originalRequire.apply(this, [fullpath])\n }\n\n return originalRequire.apply(this, [mod])\n} as NodeRequire\n\nModule.prototype.require = rewire\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAKA,oBAAmB;AACnB,kBAAoB;AAEpB,MAAM,kBAAkB;AAExB,MAAM,YAAY,MAAM;AACtB,QAAM,EAAE,UAAU,IAAI,QAAQ;AAC9B,MAAI,CAAC,WAAW;AACd,WAAO,YAAAA,QAAQ,KAAK,QAAQ,IAAI,GAAG,eAAe;AAAA,EACpD;AACA,MAAI,YAAAA,QAAQ,WAAW,SAAS,GAAG;AACjC,WAAO;AAAA,EACT;AACA,SAAO,YAAAA,QAAQ,KAAK,QAAQ,IAAI,GAAG,SAAS;AAC9C;AAEA,MAAM,aAAa,UAAU;AAC7B,MAAM,aAAa,YAAAA,QAAQ,SAAS,UAAU;AAC9C,MAAM,kBAAkB,cAAAC,QAAO,UAAU;AAEzC,MAAM,SAAS,SAA6B,KAAa;AACvD,QAAM,cAAc,IAAI,MAAM,GAAG;AAEjC,MAAI,YAAY,OAAO,YAAY;AACjC,UAAM,SAAS,YAAY,MAAM,CAAC,EAAE,KAAK,GAAG;AAC5C,UAAM,WAAW,YAAAD,QAAQ,KAAK,YAAY,MAAM;AAChD,WAAO,gBAAgB,MAAM,MAAM,CAAC,QAAQ,CAAC;AAAA,EAC/C;AAEA,SAAO,gBAAgB,MAAM,MAAM,CAAC,GAAG,CAAC;AAC1C;AAEA,cAAAC,QAAO,UAAU,UAAU;",
6
6
  "names": ["pathlib", "Module"]
7
7
  }
@@ -34,12 +34,12 @@ const parseArguments = (schema, argv) => {
34
34
  const yargsEnv = (0, import_yargs_extra.parseEnv)(schema, "BP");
35
35
  return (0, import_yargs_extra.cleanupConfig)(schema, { ...argv, ...yargsEnv });
36
36
  };
37
- const registerYargs = (yargz, commands, props) => {
37
+ const registerYargs = (yargz, commands) => {
38
38
  for (const cmdName in commands) {
39
39
  const command = commands[cmdName];
40
40
  if (tree.guards.command.isSubTree(command)) {
41
41
  yargz.command(cmdName, command.description ?? cmdName, (y) => {
42
- registerYargs(y, command.subcommands, props);
42
+ registerYargs(y, command.subcommands);
43
43
  return y;
44
44
  });
45
45
  continue;
@@ -74,7 +74,8 @@ const registerYargs = (yargz, commands, props) => {
74
74
  },
75
75
  async (argv) => {
76
76
  const parsed = parseArguments(schema, argv);
77
- await command.handler({ ...parsed, ...props });
77
+ const { exitCode } = await command.handler({ ...parsed });
78
+ process.exit(exitCode);
78
79
  }
79
80
  );
80
81
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/register-yargs.ts"],
4
- "sourcesContent": ["import yargs, { YargsArgv, YargsConfig, cleanupConfig, parseEnv } from '@bpinternal/yargs-extra'\nimport _ from 'lodash'\nimport * as tree from './command-tree'\nimport type * as typings from './typings'\nimport type * as utils from './utils'\n\nexport type YargsInstance = typeof yargs\n\nexport type RegisterProps = {\n cliRootDir: utils.path.AbsolutePath\n}\n\nconst parseArguments = <S extends typings.CommandSchema>(schema: S, argv: YargsArgv<S>): YargsConfig<S> => {\n const yargsEnv = parseEnv(schema, 'BP')\n return cleanupConfig(schema, { ...argv, ...yargsEnv })\n}\n\nexport const registerYargs = (yargz: YargsInstance, commands: tree.CommandTree, props: RegisterProps) => {\n for (const cmdName in commands) {\n const command = commands[cmdName] as tree.CommandTreeNode\n\n if (tree.guards.command.isSubTree(command)) {\n yargz.command(cmdName, command.description ?? cmdName, (y) => {\n registerYargs(y, command.subcommands, props)\n return y\n })\n continue\n }\n\n const { schema, description, alias } = command\n const aliases = alias ? [cmdName, alias] : [cmdName]\n\n const options = Object.entries(schema)\n let positionals = options.filter(\n (value): value is [string, typings.CommandPositionalOption] => !!value[1].positional\n )\n\n let usage = aliases\n if (positionals.length) {\n positionals = _.sortBy(positionals, ([, option]) => option.idx)\n const positionalArgs = positionals.map(([optName, option]) =>\n option.demandOption ? `<${optName}>` : `[${optName}]`\n )\n const positionalStr = positionalArgs.join(' ')\n usage = aliases.map((optAlias) => `${optAlias} ${positionalStr}`)\n }\n\n yargz.command(\n usage,\n description ?? cmdName,\n (y) => {\n for (const [key, option] of Object.entries(schema)) {\n if (option.positional) {\n y = y.positional(key, option)\n } else {\n y = y.option(key, option)\n }\n }\n return y\n },\n async (argv) => {\n const parsed = parseArguments(schema, argv)\n await command.handler({ ...parsed, ...props })\n }\n )\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAuE;AACvE,oBAAc;AACd,WAAsB;AAUtB,MAAM,iBAAiB,CAAkC,QAAW,SAAuC;AACzG,QAAM,eAAW,6BAAS,QAAQ,IAAI;AACtC,aAAO,kCAAc,QAAQ,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AAS,eAAe,QAAQ,IAAI;AAC1C,cAAM,QAAQ,QAAQ,EAAE,GAAG,QAAQ,GAAG,MAAM,CAAC;AAAA,MAC/C;AAAA,IACF;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import yargs, { YargsArgv, YargsConfig, cleanupConfig, parseEnv } from '@bpinternal/yargs-extra'\nimport _ from 'lodash'\nimport * as tree from './command-tree'\nimport type * as typings from './typings'\n\nexport type YargsInstance = typeof yargs\n\nconst parseArguments = <S extends typings.CommandSchema>(schema: S, argv: YargsArgv<S>): YargsConfig<S> => {\n const yargsEnv = parseEnv(schema, 'BP')\n return cleanupConfig(schema, { ...argv, ...yargsEnv })\n}\n\nexport const registerYargs = (yargz: YargsInstance, commands: tree.CommandTree) => {\n for (const cmdName in commands) {\n const command = commands[cmdName] as tree.CommandTreeNode\n\n if (tree.guards.command.isSubTree(command)) {\n yargz.command(cmdName, command.description ?? cmdName, (y) => {\n registerYargs(y, command.subcommands)\n return y\n })\n continue\n }\n\n const { schema, description, alias } = command\n const aliases = alias ? [cmdName, alias] : [cmdName]\n\n const options = Object.entries(schema)\n let positionals = options.filter(\n (value): value is [string, typings.CommandPositionalOption] => !!value[1].positional\n )\n\n let usage = aliases\n if (positionals.length) {\n positionals = _.sortBy(positionals, ([, option]) => option.idx)\n const positionalArgs = positionals.map(([optName, option]) =>\n option.demandOption ? `<${optName}>` : `[${optName}]`\n )\n const positionalStr = positionalArgs.join(' ')\n usage = aliases.map((optAlias) => `${optAlias} ${positionalStr}`)\n }\n\n yargz.command(\n usage,\n description ?? cmdName,\n (y) => {\n for (const [key, option] of Object.entries(schema)) {\n if (option.positional) {\n y = y.positional(key, option)\n } else {\n y = y.option(key, option)\n }\n }\n return y\n },\n async (argv) => {\n const parsed = parseArguments(schema, argv)\n const { exitCode } = await command.handler({ ...parsed })\n process.exit(exitCode)\n }\n )\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAA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AAA,UAC9B,OAAO;AACL,gBAAI,EAAE,OAAO,KAAK,MAAM;AAAA,UAC1B;AAAA,QACF;AACA,eAAO;AAAA,MACT;AAAA,MACA,OAAO,SAAS;AACd,cAAM,SAAS,eAAe,QAAQ,IAAI;AAC1C,cAAM,EAAE,SAAS,IAAI,MAAM,QAAQ,QAAQ,EAAE,GAAG,OAAO,CAAC;AACxD,gBAAQ,KAAK,QAAQ;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AACF;",
6
6
  "names": ["_"]
7
7
  }
package/dist/root.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var root_exports = {};
26
+ __export(root_exports, {
27
+ CLI_ROOT_DIR: () => CLI_ROOT_DIR
28
+ });
29
+ module.exports = __toCommonJS(root_exports);
30
+ var utils = __toESM(require("./utils"));
31
+ const CLI_ROOT_DIR = utils.path.join(__dirname, "..");
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ CLI_ROOT_DIR
35
+ });
36
+ //# sourceMappingURL=root.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/root.ts"],
4
+ "sourcesContent": ["/**\n * Important:\n *\n * This file must be kept at the root of the src directory (and dist directory when built)\n */\nimport * as utils from './utils'\n\nexport const CLI_ROOT_DIR = utils.path.join(__dirname as utils.path.AbsolutePath, '..')\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,YAAuB;AAEhB,MAAM,eAAe,MAAM,KAAK,KAAK,WAAsC,IAAI;",
6
+ "names": []
7
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/typings.ts"],
4
- "sourcesContent": ["import type yargs from '@bpinternal/yargs-extra'\n// eslint-disable-next-line no-duplicate-imports\nimport type { YargsConfig, YargsSchema } from '@bpinternal/yargs-extra'\nimport type * as utils from './utils'\n\nexport type CommandPositionalOption = yargs.PositionalOptions & { positional: true; idx: number }\nexport type CommandNamedOption = YargsSchema[string] & { positional?: false }\nexport type CommandOption = CommandPositionalOption | CommandNamedOption\nexport type CommandSchema = Record<string, CommandOption>\n\nexport type CommandArgv<C extends CommandDefinition = CommandDefinition> = YargsConfig<C['schema']> & {\n cliRootDir: utils.path.AbsolutePath\n}\n\nexport type CommandDefinition<S extends CommandSchema = CommandSchema> = {\n schema: S\n description?: string\n alias?: string\n}\n\nexport type CommandImplementation<C extends CommandDefinition = CommandDefinition> = (\n argv: CommandArgv<C>\n) => Promise<never>\n\nexport type CommandLeaf<C extends CommandDefinition = CommandDefinition> = C & {\n handler: CommandImplementation<C>\n}\n"],
4
+ "sourcesContent": ["import type yargs from '@bpinternal/yargs-extra'\n// eslint-disable-next-line no-duplicate-imports\nimport type { YargsConfig, YargsSchema } from '@bpinternal/yargs-extra'\n\nexport type CommandPositionalOption = yargs.PositionalOptions & { positional: true; idx: number }\nexport type CommandNamedOption = YargsSchema[string] & { positional?: false }\nexport type CommandOption = CommandPositionalOption | CommandNamedOption\nexport type CommandSchema = Record<string, CommandOption>\n\nexport type CommandArgv<C extends CommandDefinition = CommandDefinition> = YargsConfig<C['schema']> & {\n /**\n * Ignored: fixes weird typing issue\n */\n _?: string\n}\n\nexport type CommandDefinition<S extends CommandSchema = CommandSchema> = {\n schema: S\n description?: string\n alias?: string\n}\n\nexport type CommandImplementation<C extends CommandDefinition = CommandDefinition> = (\n argv: CommandArgv<C>\n) => Promise<{ exitCode: number }>\n\nexport type CommandLeaf<C extends CommandDefinition = CommandDefinition> = C & {\n handler: CommandImplementation<C>\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
18
+ mod
19
+ ));
20
+ var import_vitest = require("vitest");
21
+ var caseUtils = __toESM(require("./case-utils"));
22
+ const pascalCase = "HelloWorld";
23
+ const kebabCase = "hello-world";
24
+ const snakeCase = "hello_world";
25
+ const screamingSnakeCase = "HELLO_WORLD";
26
+ const camelCase = "helloWorld";
27
+ (0, import_vitest.test)("case utils should convert from pascal case to all other cases", () => {
28
+ (0, import_vitest.expect)(caseUtils.to.kebabCase(pascalCase)).toBe(kebabCase);
29
+ (0, import_vitest.expect)(caseUtils.to.snakeCase(pascalCase)).toBe(snakeCase);
30
+ (0, import_vitest.expect)(caseUtils.to.screamingSnakeCase(pascalCase)).toBe(screamingSnakeCase);
31
+ (0, import_vitest.expect)(caseUtils.to.camelCase(pascalCase)).toBe(camelCase);
32
+ });
33
+ (0, import_vitest.test)("case utils should convert from kebab case to all other cases", () => {
34
+ (0, import_vitest.expect)(caseUtils.to.pascalCase(kebabCase)).toBe(pascalCase);
35
+ (0, import_vitest.expect)(caseUtils.to.snakeCase(kebabCase)).toBe(snakeCase);
36
+ (0, import_vitest.expect)(caseUtils.to.screamingSnakeCase(kebabCase)).toBe(screamingSnakeCase);
37
+ (0, import_vitest.expect)(caseUtils.to.camelCase(kebabCase)).toBe(camelCase);
38
+ });
39
+ (0, import_vitest.test)("case utils should convert from snake case to all other cases", () => {
40
+ (0, import_vitest.expect)(caseUtils.to.pascalCase(snakeCase)).toBe(pascalCase);
41
+ (0, import_vitest.expect)(caseUtils.to.kebabCase(snakeCase)).toBe(kebabCase);
42
+ (0, import_vitest.expect)(caseUtils.to.screamingSnakeCase(snakeCase)).toBe(screamingSnakeCase);
43
+ (0, import_vitest.expect)(caseUtils.to.camelCase(snakeCase)).toBe(camelCase);
44
+ });
45
+ (0, import_vitest.test)("case utils should convert from screaming snake case to all other cases", () => {
46
+ (0, import_vitest.expect)(caseUtils.to.pascalCase(screamingSnakeCase)).toBe(pascalCase);
47
+ (0, import_vitest.expect)(caseUtils.to.kebabCase(screamingSnakeCase)).toBe(kebabCase);
48
+ (0, import_vitest.expect)(caseUtils.to.snakeCase(screamingSnakeCase)).toBe(snakeCase);
49
+ (0, import_vitest.expect)(caseUtils.to.camelCase(screamingSnakeCase)).toBe(camelCase);
50
+ });
51
+ (0, import_vitest.test)("case utils should convert from camel case to all other cases", () => {
52
+ (0, import_vitest.expect)(caseUtils.to.pascalCase(camelCase)).toBe(pascalCase);
53
+ (0, import_vitest.expect)(caseUtils.to.kebabCase(camelCase)).toBe(kebabCase);
54
+ (0, import_vitest.expect)(caseUtils.to.snakeCase(camelCase)).toBe(snakeCase);
55
+ (0, import_vitest.expect)(caseUtils.to.screamingSnakeCase(camelCase)).toBe(screamingSnakeCase);
56
+ });
57
+ //# sourceMappingURL=case-utils.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/case-utils.test.ts"],
4
+ "sourcesContent": ["import { test, expect } from 'vitest'\nimport * as caseUtils from './case-utils'\n\nconst pascalCase = 'HelloWorld'\nconst kebabCase = 'hello-world'\nconst snakeCase = 'hello_world'\nconst screamingSnakeCase = 'HELLO_WORLD'\nconst camelCase = 'helloWorld'\n\ntest('case utils should convert from pascal case to all other cases', () => {\n expect(caseUtils.to.kebabCase(pascalCase)).toBe(kebabCase)\n expect(caseUtils.to.snakeCase(pascalCase)).toBe(snakeCase)\n expect(caseUtils.to.screamingSnakeCase(pascalCase)).toBe(screamingSnakeCase)\n expect(caseUtils.to.camelCase(pascalCase)).toBe(camelCase)\n})\n\ntest('case utils should convert from kebab case to all other cases', () => {\n expect(caseUtils.to.pascalCase(kebabCase)).toBe(pascalCase)\n expect(caseUtils.to.snakeCase(kebabCase)).toBe(snakeCase)\n expect(caseUtils.to.screamingSnakeCase(kebabCase)).toBe(screamingSnakeCase)\n expect(caseUtils.to.camelCase(kebabCase)).toBe(camelCase)\n})\n\ntest('case utils should convert from snake case to all other cases', () => {\n expect(caseUtils.to.pascalCase(snakeCase)).toBe(pascalCase)\n expect(caseUtils.to.kebabCase(snakeCase)).toBe(kebabCase)\n expect(caseUtils.to.screamingSnakeCase(snakeCase)).toBe(screamingSnakeCase)\n expect(caseUtils.to.camelCase(snakeCase)).toBe(camelCase)\n})\n\ntest('case utils should convert from screaming snake case to all other cases', () => {\n expect(caseUtils.to.pascalCase(screamingSnakeCase)).toBe(pascalCase)\n expect(caseUtils.to.kebabCase(screamingSnakeCase)).toBe(kebabCase)\n expect(caseUtils.to.snakeCase(screamingSnakeCase)).toBe(snakeCase)\n expect(caseUtils.to.camelCase(screamingSnakeCase)).toBe(camelCase)\n})\n\ntest('case utils should convert from camel case to all other cases', () => {\n expect(caseUtils.to.pascalCase(camelCase)).toBe(pascalCase)\n expect(caseUtils.to.kebabCase(camelCase)).toBe(kebabCase)\n expect(caseUtils.to.snakeCase(camelCase)).toBe(snakeCase)\n expect(caseUtils.to.screamingSnakeCase(camelCase)).toBe(screamingSnakeCase)\n})\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA,oBAA6B;AAC7B,gBAA2B;AAE3B,MAAM,aAAa;AACnB,MAAM,YAAY;AAClB,MAAM,YAAY;AAClB,MAAM,qBAAqB;AAC3B,MAAM,YAAY;AAAA,IAElB,oBAAK,iEAAiE,MAAM;AAC1E,4BAAO,UAAU,GAAG,UAAU,UAAU,CAAC,EAAE,KAAK,SAAS;AACzD,4BAAO,UAAU,GAAG,UAAU,UAAU,CAAC,EAAE,KAAK,SAAS;AACzD,4BAAO,UAAU,GAAG,mBAAmB,UAAU,CAAC,EAAE,KAAK,kBAAkB;AAC3E,4BAAO,UAAU,GAAG,UAAU,UAAU,CAAC,EAAE,KAAK,SAAS;AAC3D,CAAC;AAAA,IAED,oBAAK,gEAAgE,MAAM;AACzE,4BAAO,UAAU,GAAG,WAAW,SAAS,CAAC,EAAE,KAAK,UAAU;AAC1D,4BAAO,UAAU,GAAG,UAAU,SAAS,CAAC,EAAE,KAAK,SAAS;AACxD,4BAAO,UAAU,GAAG,mBAAmB,SAAS,CAAC,EAAE,KAAK,kBAAkB;AAC1E,4BAAO,UAAU,GAAG,UAAU,SAAS,CAAC,EAAE,KAAK,SAAS;AAC1D,CAAC;AAAA,IAED,oBAAK,gEAAgE,MAAM;AACzE,4BAAO,UAAU,GAAG,WAAW,SAAS,CAAC,EAAE,KAAK,UAAU;AAC1D,4BAAO,UAAU,GAAG,UAAU,SAAS,CAAC,EAAE,KAAK,SAAS;AACxD,4BAAO,UAAU,GAAG,mBAAmB,SAAS,CAAC,EAAE,KAAK,kBAAkB;AAC1E,4BAAO,UAAU,GAAG,UAAU,SAAS,CAAC,EAAE,KAAK,SAAS;AAC1D,CAAC;AAAA,IAED,oBAAK,0EAA0E,MAAM;AACnF,4BAAO,UAAU,GAAG,WAAW,kBAAkB,CAAC,EAAE,KAAK,UAAU;AACnE,4BAAO,UAAU,GAAG,UAAU,kBAAkB,CAAC,EAAE,KAAK,SAAS;AACjE,4BAAO,UAAU,GAAG,UAAU,kBAAkB,CAAC,EAAE,KAAK,SAAS;AACjE,4BAAO,UAAU,GAAG,UAAU,kBAAkB,CAAC,EAAE,KAAK,SAAS;AACnE,CAAC;AAAA,IAED,oBAAK,gEAAgE,MAAM;AACzE,4BAAO,UAAU,GAAG,WAAW,SAAS,CAAC,EAAE,KAAK,UAAU;AAC1D,4BAAO,UAAU,GAAG,UAAU,SAAS,CAAC,EAAE,KAAK,SAAS;AACxD,4BAAO,UAAU,GAAG,UAAU,SAAS,CAAC,EAAE,KAAK,SAAS;AACxD,4BAAO,UAAU,GAAG,mBAAmB,SAAS,CAAC,EAAE,KAAK,kBAAkB;AAC5E,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
18
+ mod
19
+ ));
20
+ var import_vitest = require("vitest");
21
+ var requireUtils = __toESM(require("./require-utils"));
22
+ (0, import_vitest.test)("require js code should do as its name suggests", () => {
23
+ const code = `
24
+ module.exports = {
25
+ foo: 'bar'
26
+ }
27
+ `;
28
+ const result = requireUtils.requireJsCode(code);
29
+ (0, import_vitest.expect)(result.foo).toBe("bar");
30
+ });
31
+ //# sourceMappingURL=require-utils.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/require-utils.test.ts"],
4
+ "sourcesContent": ["import { test, expect } from 'vitest'\nimport * as requireUtils from './require-utils'\n\ntest('require js code should do as its name suggests', () => {\n const code = `\n module.exports = {\n foo: 'bar'\n }\n `\n\n const result = requireUtils.requireJsCode<{ foo: string }>(code)\n\n expect(result.foo).toBe('bar')\n})\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA,oBAA6B;AAC7B,mBAA8B;AAAA,IAE9B,oBAAK,kDAAkD,MAAM;AAC3D,QAAM,OAAO;AAAA;AAAA;AAAA;AAAA;AAMb,QAAM,SAAS,aAAa,cAA+B,IAAI;AAE/D,4BAAO,OAAO,GAAG,EAAE,KAAK,KAAK;AAC/B,CAAC;",
6
+ "names": []
7
+ }
package/e2e/api.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { Client } from '@botpress/client'
2
+
3
+ export type ApiBot = Awaited<ReturnType<Client['listBots']>>['bots'][0]
4
+ export const fetchAllBots = async (client: Client): Promise<ApiBot[]> => {
5
+ let allBots: ApiBot[] = []
6
+ let nextToken: string | undefined = undefined
7
+ do {
8
+ const { bots, meta } = await client.listBots({ nextToken })
9
+ allBots = allBots.concat(bots)
10
+ nextToken = meta.nextToken
11
+ } while (nextToken)
12
+ return allBots
13
+ }
14
+
15
+ export type ApiIntegration = Awaited<ReturnType<Client['listIntegrations']>>['integrations'][0]
16
+ export const fetchAllIntegrations = async (client: Client): Promise<ApiIntegration[]> => {
17
+ let allIntegrations: ApiIntegration[] = []
18
+ let nextToken: string | undefined = undefined
19
+ do {
20
+ const { integrations, meta } = await client.listIntegrations({ nextToken })
21
+ allIntegrations = allIntegrations.concat(integrations)
22
+ nextToken = meta.nextToken
23
+ } while (nextToken)
24
+ return allIntegrations
25
+ }
@@ -0,0 +1,20 @@
1
+ import * as consts from '../src/consts'
2
+
3
+ const noBuild = false
4
+ const secrets = [] satisfies string[]
5
+ const sourceMap = false
6
+ const verbose = false
7
+ const confirm = true
8
+ const json = false
9
+ const entryPoint = consts.defaultEntrypoint
10
+ const outDir = consts.defaultOutputFolder
11
+ export default {
12
+ noBuild,
13
+ secrets,
14
+ sourceMap,
15
+ verbose,
16
+ confirm,
17
+ json,
18
+ entryPoint,
19
+ outDir,
20
+ }
package/e2e/index.ts ADDED
@@ -0,0 +1,83 @@
1
+ import { Logger } from '@bpinternal/log4bot'
2
+ import yargs, { YargsConfig, YargsSchema } from '@bpinternal/yargs-extra'
3
+ import * as consts from '../src/consts'
4
+ import { createDeployBot } from './tests/create-deploy-bot'
5
+ import { createDeployIntegration } from './tests/create-deploy-integration'
6
+ import { devBot } from './tests/dev-bot'
7
+ import { Test } from './typings'
8
+ import { sleep, TmpDirectory } from './utils'
9
+
10
+ const tests: Test[] = [createDeployBot, createDeployIntegration, devBot]
11
+
12
+ const timeout = (ms: number) =>
13
+ sleep(ms).then(() => {
14
+ throw new Error(`Timeout after ${ms}ms`)
15
+ })
16
+
17
+ const TIMEOUT = 20_000
18
+
19
+ const configSchema = {
20
+ timeout: {
21
+ type: 'number',
22
+ default: TIMEOUT,
23
+ },
24
+ verbose: {
25
+ type: 'boolean',
26
+ default: false,
27
+ alias: 'v',
28
+ },
29
+ filter: {
30
+ type: 'string',
31
+ },
32
+ workspaceId: {
33
+ type: 'string',
34
+ demandOption: true,
35
+ },
36
+ token: {
37
+ type: 'string',
38
+ demandOption: true,
39
+ },
40
+ apiUrl: {
41
+ type: 'string',
42
+ default: consts.defaultBotpressApiUrl,
43
+ },
44
+ tunnelUrl: {
45
+ type: 'string',
46
+ default: consts.defaultTunnelUrl,
47
+ },
48
+ } satisfies YargsSchema
49
+
50
+ const main = async (argv: YargsConfig<typeof configSchema>): Promise<never> => {
51
+ const logger = new Logger('e2e', { level: argv.verbose ? 'debug' : 'info' })
52
+
53
+ const filterRegex = argv.filter ? new RegExp(argv.filter) : null
54
+ const filteredTests = tests.filter(({ name }) => (filterRegex ? filterRegex.test(name) : true))
55
+ logger.info(`Running ${filteredTests.length} / ${tests.length} tests`)
56
+
57
+ for (const { name, handler } of filteredTests) {
58
+ const logLine = `### Running test: "${name}" ###`
59
+ const logPad = '#'.repeat(logLine.length)
60
+ logger.info(logPad)
61
+ logger.info(logLine)
62
+ logger.info(logPad + '\n')
63
+
64
+ const tmpDir = TmpDirectory.create()
65
+ try {
66
+ const t0 = Date.now()
67
+ await Promise.race([handler({ tmpDir: tmpDir.path, ...argv }), timeout(argv.timeout)])
68
+ const t1 = Date.now()
69
+ logger.info(`SUCCESS: "${name}" (${t1 - t0}ms)`)
70
+ } catch (thrown) {
71
+ const err = thrown instanceof Error ? thrown : new Error(`${thrown}`)
72
+ logger.attachError(err).error(`FAILURE: "${name}"`)
73
+ process.exit(1)
74
+ } finally {
75
+ tmpDir.cleanup()
76
+ }
77
+ }
78
+
79
+ logger.info('All tests passed')
80
+ process.exit(0)
81
+ }
82
+
83
+ void yargs.command('$0', 'Run E2E Tests', configSchema, main).parse()
@@ -0,0 +1,50 @@
1
+ import { Client } from '@botpress/client'
2
+ import pathlib from 'path'
3
+ import * as uuid from 'uuid'
4
+ import impl from '../../src/command-implementations'
5
+ import { ApiBot, fetchAllBots } from '../api'
6
+ import defaults from '../defaults'
7
+ import { Test } from '../typings'
8
+ import * as utils from '../utils'
9
+
10
+ const fetchBot = async (client: Client, botName: string): Promise<ApiBot | undefined> => {
11
+ const bots = await fetchAllBots(client)
12
+ return bots.find(({ name }) => name === botName)
13
+ }
14
+
15
+ export const createDeployBot: Test = {
16
+ name: 'cli should allow creating, building, deploying and mannaging a bot',
17
+ handler: async ({ tmpDir, ...creds }) => {
18
+ const botpressHomeDir = pathlib.join(tmpDir, '.botpresshome')
19
+ const baseDir = pathlib.join(tmpDir, 'bots')
20
+ const botName = uuid.v4()
21
+ const botDir = pathlib.join(baseDir, botName)
22
+
23
+ const argv = {
24
+ ...defaults,
25
+ botpressHome: botpressHomeDir,
26
+ confirm: true,
27
+ ...creds,
28
+ }
29
+
30
+ const client = new Client({ host: creds.apiUrl, token: creds.token, workspaceId: creds.workspaceId })
31
+
32
+ await impl.init({ ...argv, workDir: baseDir, name: botName, type: 'bot' }).then(utils.handleExitCode)
33
+ await utils.npmInstall({ workDir: botDir }).then(utils.handleExitCode)
34
+ await impl.build({ ...argv, workDir: botDir }).then(utils.handleExitCode)
35
+ await impl.login({ ...argv }).then(utils.handleExitCode)
36
+ await impl.bots.subcommands.create({ ...argv, name: botName }).then(utils.handleExitCode)
37
+
38
+ const bot = await fetchBot(client, botName)
39
+ if (!bot) {
40
+ throw new Error(`Bot ${botName} should have been created`)
41
+ }
42
+
43
+ await impl.deploy({ ...argv, workDir: botDir, createNewBot: false, botId: bot.id }).then(utils.handleExitCode)
44
+ await impl.bots.subcommands.delete({ ...argv, botRef: bot.id }).then(utils.handleExitCode)
45
+
46
+ if (await fetchBot(client, botName)) {
47
+ throw new Error(`Bot ${botName} should have been deleted`)
48
+ }
49
+ },
50
+ }
@@ -0,0 +1,55 @@
1
+ import { Client } from '@botpress/client'
2
+
3
+ import pathlib from 'path'
4
+ import * as uuid from 'uuid'
5
+ import impl from '../../src/command-implementations'
6
+ import { ApiIntegration, fetchAllIntegrations } from '../api'
7
+ import defaults from '../defaults'
8
+ import { Test } from '../typings'
9
+ import * as utils from '../utils'
10
+
11
+ const fetchIntegration = async (client: Client, integrationName: string): Promise<ApiIntegration | undefined> => {
12
+ const integrations = await fetchAllIntegrations(client)
13
+ return integrations.find(({ name }) => name === integrationName)
14
+ }
15
+
16
+ export const createDeployIntegration: Test = {
17
+ name: 'cli should allow creating, building, deploying and mannaging an integration',
18
+ handler: async ({ tmpDir, ...creds }) => {
19
+ const botpressHomeDir = pathlib.join(tmpDir, '.botpresshome')
20
+ const baseDir = pathlib.join(tmpDir, 'integrations')
21
+ const integrationName = `myintegration-${uuid.v4()}`.replace(/-/g, '')
22
+ const integrationDir = pathlib.join(baseDir, integrationName)
23
+
24
+ const argv = {
25
+ ...defaults,
26
+ botpressHome: botpressHomeDir,
27
+ confirm: true,
28
+ ...creds,
29
+ }
30
+
31
+ const client = new Client({ host: creds.apiUrl, token: creds.token, workspaceId: creds.workspaceId })
32
+
33
+ await impl
34
+ .init({ ...argv, workDir: baseDir, name: integrationName, type: 'integration' })
35
+ .then(utils.handleExitCode)
36
+ await utils.npmInstall({ workDir: integrationDir }).then(utils.handleExitCode)
37
+ await impl.build({ ...argv, workDir: integrationDir }).then(utils.handleExitCode)
38
+ await impl.login({ ...argv }).then(utils.handleExitCode)
39
+
40
+ await impl
41
+ .deploy({ ...argv, createNewBot: undefined, botId: undefined, workDir: integrationDir })
42
+ .then(utils.handleExitCode)
43
+
44
+ const integration = await fetchIntegration(client, integrationName)
45
+ if (!integration) {
46
+ throw new Error(`Integration ${integrationName} should have been created`)
47
+ }
48
+
49
+ await impl.integrations.subcommands.delete({ ...argv, integrationRef: integration.id }).then(utils.handleExitCode)
50
+
51
+ if (await fetchIntegration(client, integrationName)) {
52
+ throw new Error(`Integration ${integrationName} should have been deleted`)
53
+ }
54
+ },
55
+ }
@@ -0,0 +1,57 @@
1
+ import findProcess from 'find-process'
2
+ import pathlib from 'path'
3
+ import * as uuid from 'uuid'
4
+ import impl from '../../src/command-implementations'
5
+ import defaults from '../defaults'
6
+ import { Test } from '../typings'
7
+ import * as utils from '../utils'
8
+
9
+ const handleExitCode = ({ exitCode }: { exitCode: number }) => {
10
+ if (exitCode !== 0) {
11
+ throw new Error(`Command exited with code ${exitCode}`)
12
+ }
13
+ }
14
+
15
+ const PORT = 8075
16
+
17
+ export const devBot: Test = {
18
+ name: 'cli should allow creating and running a bot locally',
19
+ handler: async ({ tmpDir, tunnelUrl, ...creds }) => {
20
+ const botpressHomeDir = pathlib.join(tmpDir, '.botpresshome')
21
+ const baseDir = pathlib.join(tmpDir, 'bots')
22
+ const botName = uuid.v4()
23
+ const botDir = pathlib.join(baseDir, botName)
24
+
25
+ const argv = {
26
+ ...defaults,
27
+ botpressHome: botpressHomeDir,
28
+ confirm: true,
29
+ ...creds,
30
+ }
31
+
32
+ await impl.init({ ...argv, workDir: baseDir, name: botName, type: 'bot' }).then(handleExitCode)
33
+ await utils.npmInstall({ workDir: botDir }).then(handleExitCode)
34
+ await impl.login({ ...argv }).then(handleExitCode)
35
+
36
+ const cmdPromise = impl.dev({ ...argv, workDir: botDir, port: PORT, tunnelUrl }).then(handleExitCode)
37
+ await utils.sleep(5000)
38
+
39
+ const allProcess = await findProcess('port', PORT)
40
+ if (allProcess.length === 0) {
41
+ throw new Error(`Expected to find a process listening on port ${PORT}`)
42
+ }
43
+ if (allProcess.length > 1) {
44
+ throw new Error(`Expected to find only one process listening on port ${PORT}`)
45
+ }
46
+ const botProcess = allProcess[0]
47
+
48
+ /**
49
+ * TODO:
50
+ * - try calling the Bot locally to see if it works
51
+ * - allow listing dev bots in API and find the one we just created (by name)
52
+ */
53
+
54
+ process.kill(botProcess.pid)
55
+ await cmdPromise
56
+ },
57
+ }
package/e2e/typings.ts ADDED
@@ -0,0 +1,12 @@
1
+ export type TestProps = {
2
+ tmpDir: string
3
+ workspaceId: string
4
+ token: string
5
+ apiUrl: string
6
+ tunnelUrl: string
7
+ }
8
+
9
+ export type Test = {
10
+ name: string
11
+ handler: (props: TestProps) => Promise<void>
12
+ }
package/e2e/utils.ts ADDED
@@ -0,0 +1,42 @@
1
+ import childprocess from 'child_process'
2
+ import tmp from 'tmp'
3
+
4
+ export const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms))
5
+
6
+ export class TmpDirectory {
7
+ private _closed = false
8
+
9
+ public static create() {
10
+ return new TmpDirectory(tmp.dirSync({ unsafeCleanup: true }))
11
+ }
12
+
13
+ private constructor(private _res: tmp.DirResult) {}
14
+
15
+ public get path() {
16
+ if (this._closed) {
17
+ throw new Error('Cannot access tmp directory after cleanup')
18
+ }
19
+ return this._res.name
20
+ }
21
+
22
+ public cleanup() {
23
+ if (this._closed) {
24
+ return
25
+ }
26
+ this._res.removeCallback()
27
+ }
28
+ }
29
+
30
+ export const npmInstall = async ({ workDir }: { workDir: string }) => {
31
+ const { status } = childprocess.spawnSync('pnpm', ['install'], {
32
+ cwd: workDir,
33
+ stdio: 'inherit',
34
+ })
35
+ return { exitCode: status ?? 0 }
36
+ }
37
+
38
+ export const handleExitCode = ({ exitCode }: { exitCode: number }) => {
39
+ if (exitCode !== 0) {
40
+ throw new Error(`Command exited with code ${exitCode}`)
41
+ }
42
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botpress/cli",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Botpress CLI",
5
5
  "scripts": {
6
6
  "build": "pnpm run bundle && pnpm run template:gen",
@@ -8,7 +8,9 @@
8
8
  "start": "node dist/index.js",
9
9
  "type:check": "tsc --noEmit",
10
10
  "bundle": "ts-node -T build.ts",
11
- "template:gen": "pnpm -r --stream -F echo-bot -F empty-integration exec bp gen"
11
+ "template:gen": "pnpm -r --stream -F echo-bot -F empty-integration exec bp gen",
12
+ "e2e:test": "ts-node -T ./e2e",
13
+ "unit:test": "pnpm vitest --run"
12
14
  },
13
15
  "keywords": [],
14
16
  "author": "",
@@ -18,8 +20,8 @@
18
20
  },
19
21
  "main": "dist/index.js",
20
22
  "dependencies": {
21
- "@botpress/client": "0.1.2",
22
- "@bpinternal/tunnel": "^0.0.2",
23
+ "@botpress/client": "0.1.3",
24
+ "@bpinternal/tunnel": "^0.1.0",
23
25
  "@bpinternal/yargs-extra": "^0.0.3",
24
26
  "@parcel/watcher": "^2.1.0",
25
27
  "@types/lodash": "^4.14.191",
@@ -45,12 +47,16 @@
45
47
  "zod-to-json-schema": "^3.20.1"
46
48
  },
47
49
  "devDependencies": {
48
- "@botpress/sdk": "0.1.4",
50
+ "@botpress/sdk": "0.1.5",
51
+ "@bpinternal/log4bot": "^0.0.4",
49
52
  "@types/bluebird": "^3.5.38",
50
53
  "@types/prompts": "^2.0.14",
51
54
  "@types/semver": "^7.3.11",
55
+ "@types/tmp": "^0.2.3",
52
56
  "@types/uuid": "^9.0.1",
57
+ "find-process": "^1.4.7",
53
58
  "glob": "^9.3.4",
59
+ "tmp": "^0.2.1",
54
60
  "ts-node": "^10.9.1"
55
61
  },
56
62
  "engines": {
@@ -8,14 +8,13 @@
8
8
  "author": "",
9
9
  "license": "MIT",
10
10
  "dependencies": {
11
- "@botpress/client": "0.1.2",
12
- "@botpress/sdk": "0.1.4",
11
+ "@botpress/client": "0.1.3",
12
+ "@botpress/sdk": "0.1.5",
13
13
  "zod": "^3.20.6"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@types/node": "^18.11.17",
17
17
  "ts-node": "^10.9.1",
18
- "typescript": "^4.9.4",
19
- "@tsconfig/node18-strictest": "^1.0.0"
18
+ "typescript": "^4.9.4"
20
19
  }
21
20
  }
@@ -1,6 +1,19 @@
1
1
  {
2
- "extends": "@tsconfig/node18-strictest/tsconfig.json",
3
2
  "compilerOptions": {
3
+ "lib": ["es2022"],
4
+ "module": "commonjs",
5
+ "strict": true,
6
+ "esModuleInterop": true,
7
+ "skipLibCheck": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "moduleResolution": "node",
10
+ "allowUnusedLabels": false,
11
+ "allowUnreachableCode": false,
12
+ "noFallthroughCasesInSwitch": true,
13
+ "noImplicitOverride": true,
14
+ "noImplicitReturns": true,
15
+ "noUncheckedIndexedAccess": true,
16
+ "noUnusedParameters": true,
4
17
  "target": "es2017",
5
18
  "baseUrl": ".",
6
19
  "outDir": "dist",
@@ -8,14 +8,13 @@
8
8
  "author": "",
9
9
  "license": "MIT",
10
10
  "dependencies": {
11
- "@botpress/client": "0.1.2",
12
- "@botpress/sdk": "0.1.4",
11
+ "@botpress/client": "0.1.3",
12
+ "@botpress/sdk": "0.1.5",
13
13
  "zod": "^3.20.6"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@types/node": "^18.11.17",
17
17
  "ts-node": "^10.9.1",
18
- "typescript": "^4.9.4",
19
- "@tsconfig/node18-strictest": "^1.0.0"
18
+ "typescript": "^4.9.4"
20
19
  }
21
20
  }
@@ -1,6 +1,19 @@
1
1
  {
2
- "extends": "@tsconfig/node18-strictest/tsconfig.json",
3
2
  "compilerOptions": {
3
+ "lib": ["es2022"],
4
+ "module": "commonjs",
5
+ "strict": true,
6
+ "esModuleInterop": true,
7
+ "skipLibCheck": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "moduleResolution": "node",
10
+ "allowUnusedLabels": false,
11
+ "allowUnreachableCode": false,
12
+ "noFallthroughCasesInSwitch": true,
13
+ "noImplicitOverride": true,
14
+ "noImplicitReturns": true,
15
+ "noUncheckedIndexedAccess": true,
16
+ "noUnusedParameters": true,
4
17
  "target": "es2017",
5
18
  "baseUrl": ".",
6
19
  "outDir": "dist",