@botpress/cli 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/code-generation/integration-instance.js +7 -10
- package/dist/code-generation/integration-instance.js.map +2 -2
- package/dist/command-implementations/deploy-command.js +5 -5
- package/dist/command-implementations/deploy-command.js.map +2 -2
- package/dist/command-implementations/dev-command.js +96 -14
- package/dist/command-implementations/dev-command.js.map +3 -3
- package/dist/command-implementations/project-command.js.map +2 -2
- package/dist/config.js +6 -6
- package/dist/config.js.map +2 -2
- package/dist/consts.js +3 -0
- package/dist/consts.js.map +2 -2
- package/dist/utils/index.js +8 -2
- package/dist/utils/index.js.map +2 -2
- package/dist/utils/tunnel-utils.js +126 -0
- package/dist/utils/tunnel-utils.js.map +7 -0
- package/dist/utils/url-utils.js +67 -0
- package/dist/utils/url-utils.js.map +7 -0
- package/dist/worker/child-wrapper.js +4 -0
- package/dist/worker/child-wrapper.js.map +2 -2
- package/package.json +5 -4
- package/templates/echo-bot/package.json +2 -2
- package/templates/empty-integration/package.json +2 -2
|
@@ -37,26 +37,23 @@ import type { Configuration } from './configuration'
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
export type ${propsName} = {
|
|
40
|
-
enabled
|
|
41
|
-
config: Configuration
|
|
42
|
-
} | {
|
|
43
|
-
enabled: false
|
|
40
|
+
enabled?: boolean
|
|
44
41
|
config?: Configuration
|
|
45
42
|
}
|
|
46
43
|
|
|
47
44
|
export class ${className} implements IntegrationInstance {
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
|
|
51
47
|
public readonly name = '${name}'
|
|
52
48
|
public readonly version = '${version}'
|
|
53
49
|
public readonly id = '${id}'
|
|
54
|
-
|
|
55
|
-
public readonly
|
|
50
|
+
|
|
51
|
+
public readonly enabled?: boolean
|
|
52
|
+
public readonly configuration?: Configuration
|
|
56
53
|
|
|
57
54
|
constructor(props?: ${propsName}) {
|
|
58
|
-
this.enabled = props?.enabled
|
|
59
|
-
this.configuration = props?.config
|
|
55
|
+
this.enabled = props?.enabled
|
|
56
|
+
this.configuration = props?.config
|
|
60
57
|
}
|
|
61
58
|
}
|
|
62
59
|
`;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/code-generation/integration-instance.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Integration } from '@botpress/client'\nimport { casing } from '../utils'\nimport { ConfigurationModule } from './configuration'\nimport { INDEX_FILE } from './const'\nimport { Module, ModuleDef } from './module'\n\nconst CONTENT = ({\n name,\n className,\n propsName,\n version,\n id,\n}: {\n name: string\n className: string\n propsName: string\n version: string\n id: string\n}) => `\nimport type { IntegrationInstance } from '@botpress/sdk'\nimport type { Configuration } from './configuration'\n\n\nexport type ${propsName} = {\n enabled
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAuB;AACvB,2BAAoC;AACpC,mBAA2B;AAC3B,oBAAkC;AAElC,MAAM,UAAU,CAAC;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAMM;AAAA;AAAA;AAAA;AAAA;AAAA,cAKQ;AAAA;AAAA;AAAA;AAAA;AAAA
|
|
4
|
+
"sourcesContent": ["import type { Integration } from '@botpress/client'\nimport { casing } from '../utils'\nimport { ConfigurationModule } from './configuration'\nimport { INDEX_FILE } from './const'\nimport { Module, ModuleDef } from './module'\n\nconst CONTENT = ({\n name,\n className,\n propsName,\n version,\n id,\n}: {\n name: string\n className: string\n propsName: string\n version: string\n id: string\n}) => `\nimport type { IntegrationInstance } from '@botpress/sdk'\nimport type { Configuration } from './configuration'\n\n\nexport type ${propsName} = {\n enabled?: boolean\n config?: Configuration\n}\n\nexport class ${className} implements IntegrationInstance {\n \n \n public readonly name = '${name}'\n public readonly version = '${version}'\n public readonly id = '${id}'\n \n public readonly enabled?: boolean\n public readonly configuration?: Configuration\n\n constructor(props?: ${propsName}) {\n this.enabled = props?.enabled\n this.configuration = props?.config\n }\n}\n`\n\nexport class IntegrationInstanceIndexModule extends Module {\n public static async create(integration: Integration): Promise<IntegrationInstanceIndexModule> {\n const { name, version, id } = integration\n\n const configModule = await ConfigurationModule.create(integration.configuration ?? { schema: {} })\n\n const exportName = casing.to.pascalCase(name)\n\n const content = CONTENT({ name, className: exportName, propsName: `${exportName}Props`, version, id })\n const inst = new IntegrationInstanceIndexModule({ path: INDEX_FILE, content, exportName })\n\n inst.pushDep(configModule)\n\n return inst\n }\n\n private constructor(def: ModuleDef) {\n super(def)\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAuB;AACvB,2BAAoC;AACpC,mBAA2B;AAC3B,oBAAkC;AAElC,MAAM,UAAU,CAAC;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAMM;AAAA;AAAA;AAAA;AAAA;AAAA,cAKQ;AAAA;AAAA;AAAA;AAAA;AAAA,eAKC;AAAA;AAAA;AAAA,4BAGa;AAAA,+BACG;AAAA,0BACL;AAAA;AAAA;AAAA;AAAA;AAAA,wBAKF;AAAA;AAAA;AAAA;AAAA;AAAA;AAOjB,MAAM,uCAAuC,qBAAO;AAAA,EACzD,aAAoB,OAAO,aAAmE;AAC5F,UAAM,EAAE,MAAM,SAAS,GAAG,IAAI;AAE9B,UAAM,eAAe,MAAM,yCAAoB,OAAO,YAAY,iBAAiB,EAAE,QAAQ,CAAC,EAAE,CAAC;AAEjG,UAAM,aAAa,oBAAO,GAAG,WAAW,IAAI;AAE5C,UAAM,UAAU,QAAQ,EAAE,MAAM,WAAW,YAAY,WAAW,GAAG,mBAAmB,SAAS,GAAG,CAAC;AACrG,UAAM,OAAO,IAAI,+BAA+B,EAAE,MAAM,yBAAY,SAAS,WAAW,CAAC;AAEzF,SAAK,QAAQ,YAAY;AAEzB,WAAO;AAAA,EACT;AAAA,EAEQ,YAAY,KAAgB;AAClC,UAAM,GAAG;AAAA,EACX;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -113,15 +113,15 @@ class DeployCommand extends import_project_command.ProjectCommand {
|
|
|
113
113
|
...acc,
|
|
114
114
|
[channelName]: {
|
|
115
115
|
...channelDef,
|
|
116
|
-
messages: utils.records.setOnNullMissingValues(channelDef
|
|
116
|
+
messages: utils.records.setOnNullMissingValues(channelDef?.messages, currentChannel?.messages),
|
|
117
117
|
message: {
|
|
118
|
-
...channelDef
|
|
119
|
-
tags: utils.records.setOnNullMissingValues(channelDef
|
|
118
|
+
...channelDef?.message,
|
|
119
|
+
tags: utils.records.setOnNullMissingValues(channelDef?.message?.tags, currentChannel?.message.tags)
|
|
120
120
|
},
|
|
121
121
|
conversation: {
|
|
122
|
-
...channelDef
|
|
122
|
+
...channelDef?.conversation,
|
|
123
123
|
tags: utils.records.setOnNullMissingValues(
|
|
124
|
-
channelDef
|
|
124
|
+
channelDef?.conversation?.tags,
|
|
125
125
|
currentChannel?.conversation.tags
|
|
126
126
|
)
|
|
127
127
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/command-implementations/deploy-command.ts"],
|
|
4
|
-
"sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport type { Bot as BotImpl, IntegrationDefinition } from '@botpress/sdk'\nimport chalk from 'chalk'\nimport * as fs from 'fs'\nimport type { ApiClient } from 'src/api-client'\nimport type commandDefinitions from '../command-definitions'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport * as utils from '../utils'\nimport { BuildCommand } from './build-command'\nimport { ProjectCommand } from './project-command'\n\ntype CreateIntegrationBody = Parameters<bpclient.Client['createIntegration']>[0]\ntype UpdateIntegrationBody = Parameters<bpclient.Client['updateIntegration']>[0]\ntype UpdateBotBody = Parameters<bpclient.Client['updateBot']>[0]\n\nexport type DeployCommandDefinition = typeof commandDefinitions.deploy\nexport class DeployCommand extends ProjectCommand<DeployCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n if (api.url !== consts.defaultBotpressApiUrl) {\n this.logger.log(`Using custom url ${api.url}`)\n }\n\n if (!this.argv.noBuild) {\n await this._runBuild() // This ensures the bundle is always synced with source code\n }\n\n const integrationDef = await this.readIntegrationDefinitionFromFS()\n if (integrationDef) {\n return this._deployIntegration(api, integrationDef)\n }\n return this._deployBot(api, this.argv.botId, this.argv.createNewBot)\n }\n\n private async _runBuild() {\n return new BuildCommand(this.api, this.prompt, this.logger, this.argv).run()\n }\n\n private async _deployIntegration(api: ApiClient, integrationDef: IntegrationDefinition) {\n const outfile = this.projectPaths.abs.outFile\n let code = await fs.promises.readFile(outfile, 'utf-8')\n\n const secrets = await this.promptSecrets(integrationDef, this.argv)\n // TODO: provide these secrets to the backend by API and remove this string replacement hack\n for (const [secretName, secretValue] of Object.entries(secrets)) {\n code = code.replace(new RegExp(`process\\\\.env\\\\.${secretName}`, 'g'), `\"${secretValue}\"`)\n }\n\n const { name, version, icon: iconRelativeFilePath, readme: readmeRelativeFilePath } = integrationDef\n\n const iconFileContent = await this._readMediaFile('icon', iconRelativeFilePath)\n const readmeFileContent = await this._readMediaFile('readme', readmeRelativeFilePath)\n\n const integration = await api.findIntegration({ type: 'name', name, version })\n\n let message: string\n if (integration) {\n this.logger.warn('Integration already exists. If you decide to deploy, it will overwrite the existing one.')\n message = `Are you sure you want to override integration ${integrationDef.name} v${integrationDef.version}?`\n } else {\n message = `Are you sure you want to deploy integration ${integrationDef.name} v${integrationDef.version}?`\n }\n\n const confirm = await this.prompt.confirm(message)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n const publishBody: CreateIntegrationBody = {\n ...integrationDef,\n icon: iconFileContent,\n readme: readmeFileContent,\n code,\n }\n\n const line = this.logger.line()\n line.started(`Deploying integration ${chalk.bold(integrationDef.name)} v${integrationDef.version}...`)\n if (integration) {\n const publishUpdateBody: UpdateIntegrationBody = this._prepareUpdateIntegrationBody(integration, {\n id: integration.id,\n ...publishBody,\n })\n\n await api.client.updateIntegration(publishUpdateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update integration \"${integrationDef.name}\"`)\n })\n } else {\n await api.client.createIntegration(publishBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not create integration \"${integrationDef.name}\"`)\n })\n }\n line.success('Integration deployed')\n }\n\n // all fields that were removed are replaced by null for the API to remove them\n private _prepareUpdateIntegrationBody = (\n integration: bpclient.Integration,\n body: UpdateIntegrationBody\n ): UpdateIntegrationBody => ({\n ...body,\n actions: utils.records.setOnNullMissingValues(body.actions, integration.actions),\n events: utils.records.setOnNullMissingValues(body.events, integration.events),\n states: utils.records.setOnNullMissingValues(body.states, integration.states),\n user: {\n ...body.user,\n tags: utils.records.setOnNullMissingValues(body.user?.tags, integration.user?.tags),\n },\n channels: Object.entries(body.channels ?? {}).reduce((acc, [channelName, channelDef]) => {\n const currentChannel = integration.channels[channelName]\n return {\n ...acc,\n [channelName]: {\n ...channelDef,\n messages: utils.records.setOnNullMissingValues(channelDef.messages, currentChannel?.messages),\n message: {\n ...channelDef.message,\n tags: utils.records.setOnNullMissingValues(channelDef.message?.tags, currentChannel?.message.tags),\n },\n conversation: {\n ...channelDef.conversation,\n tags: utils.records.setOnNullMissingValues(\n channelDef.conversation?.tags,\n currentChannel?.conversation.tags\n ),\n },\n },\n }\n }, {} as UpdateIntegrationBody['channels']),\n })\n\n private _readMediaFile = async (\n filePurpose: 'icon' | 'readme',\n filePath: string | undefined\n ): Promise<string | undefined> => {\n if (!filePath) {\n return undefined\n }\n\n const absoluteFilePath = utils.path.absoluteFrom(this.projectPaths.abs.workDir, filePath)\n return fs.promises.readFile(absoluteFilePath, 'base64').catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not read ${filePurpose} file \"${absoluteFilePath}\"`)\n })\n }\n\n private async _deployBot(api: ApiClient, argvBotId: string | undefined, argvCreateNew: boolean | undefined) {\n const outfile = this.projectPaths.abs.outFile\n const code = await fs.promises.readFile(outfile, 'utf-8')\n const { default: botImpl } = utils.require.requireJsFile<{ default: BotImpl }>(outfile)\n\n const {\n states,\n events,\n recurringEvents,\n configuration: botConfiguration,\n user,\n conversation,\n message,\n } = botImpl.definition\n\n let bot: bpclient.Bot\n if (argvBotId && argvCreateNew) {\n throw new errors.BotpressCLIError('Cannot specify both --botId and --createNew')\n } else if (argvCreateNew) {\n const confirm = await this.prompt.confirm('Are you sure you want to create a new bot ?')\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n bot = await this._createNewBot(api)\n } else {\n bot = await this._getExistingBot(api, argvBotId)\n\n const confirm = await this.prompt.confirm(`Are you sure you want to deploy the bot \"${bot.name}\"?`)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n }\n\n const integrations = this.prepareIntegrations(botImpl, bot)\n\n const line = this.logger.line()\n line.started(`Deploying bot ${chalk.bold(bot.name)}...`)\n\n const updateBotBody: UpdateBotBody = this._prepareUpdateBotBody(bot, {\n id: bot.id,\n code,\n states,\n recurringEvents,\n configuration: botConfiguration,\n events,\n user,\n conversation,\n message,\n integrations,\n })\n\n const { bot: updatedBot } = await api.client.updateBot(updateBotBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update bot \"${bot.name}\"`)\n })\n line.success('Bot deployed')\n this.displayWebhookUrls(updatedBot)\n }\n\n // all fields that were removed are replaced by null for the API to remove them\n private _prepareUpdateBotBody = (bot: bpclient.Bot, body: UpdateBotBody): UpdateBotBody => ({\n ...body,\n states: utils.records.setOnNullMissingValues(body.states, bot.states),\n recurringEvents: utils.records.setOnNullMissingValues(body.recurringEvents, bot.recurringEvents),\n events: utils.records.setOnNullMissingValues(body.events, bot.events),\n user: {\n ...body.user,\n tags: utils.records.setOnNullMissingValues(body.user?.tags, bot.user?.tags),\n },\n conversation: {\n ...body.conversation,\n tags: utils.records.setOnNullMissingValues(body.conversation?.tags, bot.conversation?.tags),\n },\n message: {\n ...body.message,\n tags: utils.records.setOnNullMissingValues(body.message?.tags, bot.message?.tags),\n },\n })\n\n private async _createNewBot(api: ApiClient): Promise<bpclient.Bot> {\n const line = this.logger.line()\n const { bot: createdBot } = await api.client.createBot({}).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not create bot')\n })\n line.success(`Bot created with ID \"${createdBot.id}\" and name \"${createdBot.name}\"`)\n await this.projectCache.set('botId', createdBot.id)\n return createdBot\n }\n\n private async _getExistingBot(api: ApiClient, botId: string | undefined): Promise<bpclient.Bot> {\n const promptedBotId = await this.projectCache.sync('botId', botId, async (defaultId) => {\n const userBots = await api\n .listAllPages(api.client.listBots, (r) => r.bots)\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not fetch existing bots')\n })\n\n if (!userBots.length) {\n throw new errors.NoBotsFoundError()\n }\n\n const initial = userBots.find((bot) => bot.id === defaultId)\n\n const prompted = await this.prompt.select('Which bot do you want to deploy?', {\n initial: initial && { title: initial.name, value: initial.id },\n choices: userBots.map((bot) => ({ title: bot.name, value: bot.id })),\n })\n\n if (!prompted) {\n throw new errors.ParamRequiredError('Bot Id')\n }\n\n return prompted\n })\n\n const { bot: fetchedBot } = await api.client.getBot({ id: promptedBotId }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not get bot info')\n })\n\n return fetchedBot\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAkB;AAClB,SAAoB;AAGpB,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,2BAA6B;AAC7B,6BAA+B;AAOxB,MAAM,sBAAsB,sCAAwC;AAAA,EACzE,MAAa,MAAqB;AAChC,UAAM,MAAM,MAAM,KAAK,2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UAAU,OAAO,QAAQ,KAAK,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,aAAa,UAAU,MAAM;AACvF,YAAM,iBAAiB,YAAY,SAAS;AAC5C,aAAO;AAAA,QACL,GAAG;AAAA,QACH,CAAC,cAAc;AAAA,UACb,GAAG;AAAA,UACH,UAAU,MAAM,QAAQ,uBAAuB,
|
|
4
|
+
"sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport type { Bot as BotImpl, IntegrationDefinition } from '@botpress/sdk'\nimport chalk from 'chalk'\nimport * as fs from 'fs'\nimport type { ApiClient } from 'src/api-client'\nimport type commandDefinitions from '../command-definitions'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport * as utils from '../utils'\nimport { BuildCommand } from './build-command'\nimport { ProjectCommand } from './project-command'\n\ntype CreateIntegrationBody = Parameters<bpclient.Client['createIntegration']>[0]\ntype UpdateIntegrationBody = Parameters<bpclient.Client['updateIntegration']>[0]\ntype UpdateBotBody = Parameters<bpclient.Client['updateBot']>[0]\n\nexport type DeployCommandDefinition = typeof commandDefinitions.deploy\nexport class DeployCommand extends ProjectCommand<DeployCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n if (api.url !== consts.defaultBotpressApiUrl) {\n this.logger.log(`Using custom url ${api.url}`)\n }\n\n if (!this.argv.noBuild) {\n await this._runBuild() // This ensures the bundle is always synced with source code\n }\n\n const integrationDef = await this.readIntegrationDefinitionFromFS()\n if (integrationDef) {\n return this._deployIntegration(api, integrationDef)\n }\n return this._deployBot(api, this.argv.botId, this.argv.createNewBot)\n }\n\n private async _runBuild() {\n return new BuildCommand(this.api, this.prompt, this.logger, this.argv).run()\n }\n\n private async _deployIntegration(api: ApiClient, integrationDef: IntegrationDefinition) {\n const outfile = this.projectPaths.abs.outFile\n let code = await fs.promises.readFile(outfile, 'utf-8')\n\n const secrets = await this.promptSecrets(integrationDef, this.argv)\n // TODO: provide these secrets to the backend by API and remove this string replacement hack\n for (const [secretName, secretValue] of Object.entries(secrets)) {\n code = code.replace(new RegExp(`process\\\\.env\\\\.${secretName}`, 'g'), `\"${secretValue}\"`)\n }\n\n const { name, version, icon: iconRelativeFilePath, readme: readmeRelativeFilePath } = integrationDef\n\n const iconFileContent = await this._readMediaFile('icon', iconRelativeFilePath)\n const readmeFileContent = await this._readMediaFile('readme', readmeRelativeFilePath)\n\n const integration = await api.findIntegration({ type: 'name', name, version })\n\n let message: string\n if (integration) {\n this.logger.warn('Integration already exists. If you decide to deploy, it will overwrite the existing one.')\n message = `Are you sure you want to override integration ${integrationDef.name} v${integrationDef.version}?`\n } else {\n message = `Are you sure you want to deploy integration ${integrationDef.name} v${integrationDef.version}?`\n }\n\n const confirm = await this.prompt.confirm(message)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n const publishBody: CreateIntegrationBody = {\n ...integrationDef,\n icon: iconFileContent,\n readme: readmeFileContent,\n code,\n }\n\n const line = this.logger.line()\n line.started(`Deploying integration ${chalk.bold(integrationDef.name)} v${integrationDef.version}...`)\n if (integration) {\n const publishUpdateBody: UpdateIntegrationBody = this._prepareUpdateIntegrationBody(integration, {\n id: integration.id,\n ...publishBody,\n })\n\n await api.client.updateIntegration(publishUpdateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update integration \"${integrationDef.name}\"`)\n })\n } else {\n await api.client.createIntegration(publishBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not create integration \"${integrationDef.name}\"`)\n })\n }\n line.success('Integration deployed')\n }\n\n // all fields that were removed are replaced by null for the API to remove them\n private _prepareUpdateIntegrationBody = (\n integration: bpclient.Integration,\n body: UpdateIntegrationBody\n ): UpdateIntegrationBody => ({\n ...body,\n actions: utils.records.setOnNullMissingValues(body.actions, integration.actions),\n events: utils.records.setOnNullMissingValues(body.events, integration.events),\n states: utils.records.setOnNullMissingValues(body.states, integration.states),\n user: {\n ...body.user,\n tags: utils.records.setOnNullMissingValues(body.user?.tags, integration.user?.tags),\n },\n channels: Object.entries(body.channels ?? {}).reduce((acc, [channelName, channelDef]) => {\n const currentChannel = integration.channels[channelName]\n return {\n ...acc,\n [channelName]: {\n ...channelDef,\n messages: utils.records.setOnNullMissingValues(channelDef?.messages, currentChannel?.messages),\n message: {\n ...channelDef?.message,\n tags: utils.records.setOnNullMissingValues(channelDef?.message?.tags, currentChannel?.message.tags),\n },\n conversation: {\n ...channelDef?.conversation,\n tags: utils.records.setOnNullMissingValues(\n channelDef?.conversation?.tags,\n currentChannel?.conversation.tags\n ),\n },\n },\n }\n }, {} as UpdateIntegrationBody['channels']),\n })\n\n private _readMediaFile = async (\n filePurpose: 'icon' | 'readme',\n filePath: string | undefined\n ): Promise<string | undefined> => {\n if (!filePath) {\n return undefined\n }\n\n const absoluteFilePath = utils.path.absoluteFrom(this.projectPaths.abs.workDir, filePath)\n return fs.promises.readFile(absoluteFilePath, 'base64').catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not read ${filePurpose} file \"${absoluteFilePath}\"`)\n })\n }\n\n private async _deployBot(api: ApiClient, argvBotId: string | undefined, argvCreateNew: boolean | undefined) {\n const outfile = this.projectPaths.abs.outFile\n const code = await fs.promises.readFile(outfile, 'utf-8')\n const { default: botImpl } = utils.require.requireJsFile<{ default: BotImpl }>(outfile)\n\n const {\n states,\n events,\n recurringEvents,\n configuration: botConfiguration,\n user,\n conversation,\n message,\n } = botImpl.definition\n\n let bot: bpclient.Bot\n if (argvBotId && argvCreateNew) {\n throw new errors.BotpressCLIError('Cannot specify both --botId and --createNew')\n } else if (argvCreateNew) {\n const confirm = await this.prompt.confirm('Are you sure you want to create a new bot ?')\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n bot = await this._createNewBot(api)\n } else {\n bot = await this._getExistingBot(api, argvBotId)\n\n const confirm = await this.prompt.confirm(`Are you sure you want to deploy the bot \"${bot.name}\"?`)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n }\n\n const integrations = this.prepareIntegrations(botImpl, bot)\n\n const line = this.logger.line()\n line.started(`Deploying bot ${chalk.bold(bot.name)}...`)\n\n const updateBotBody: UpdateBotBody = this._prepareUpdateBotBody(bot, {\n id: bot.id,\n code,\n states,\n recurringEvents,\n configuration: botConfiguration,\n events,\n user,\n conversation,\n message,\n integrations,\n })\n\n const { bot: updatedBot } = await api.client.updateBot(updateBotBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update bot \"${bot.name}\"`)\n })\n line.success('Bot deployed')\n this.displayWebhookUrls(updatedBot)\n }\n\n // all fields that were removed are replaced by null for the API to remove them\n private _prepareUpdateBotBody = (bot: bpclient.Bot, body: UpdateBotBody): UpdateBotBody => ({\n ...body,\n states: utils.records.setOnNullMissingValues(body.states, bot.states),\n recurringEvents: utils.records.setOnNullMissingValues(body.recurringEvents, bot.recurringEvents),\n events: utils.records.setOnNullMissingValues(body.events, bot.events),\n user: {\n ...body.user,\n tags: utils.records.setOnNullMissingValues(body.user?.tags, bot.user?.tags),\n },\n conversation: {\n ...body.conversation,\n tags: utils.records.setOnNullMissingValues(body.conversation?.tags, bot.conversation?.tags),\n },\n message: {\n ...body.message,\n tags: utils.records.setOnNullMissingValues(body.message?.tags, bot.message?.tags),\n },\n })\n\n private async _createNewBot(api: ApiClient): Promise<bpclient.Bot> {\n const line = this.logger.line()\n const { bot: createdBot } = await api.client.createBot({}).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not create bot')\n })\n line.success(`Bot created with ID \"${createdBot.id}\" and name \"${createdBot.name}\"`)\n await this.projectCache.set('botId', createdBot.id)\n return createdBot\n }\n\n private async _getExistingBot(api: ApiClient, botId: string | undefined): Promise<bpclient.Bot> {\n const promptedBotId = await this.projectCache.sync('botId', botId, async (defaultId) => {\n const userBots = await api\n .listAllPages(api.client.listBots, (r) => r.bots)\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not fetch existing bots')\n })\n\n if (!userBots.length) {\n throw new errors.NoBotsFoundError()\n }\n\n const initial = userBots.find((bot) => bot.id === defaultId)\n\n const prompted = await this.prompt.select('Which bot do you want to deploy?', {\n initial: initial && { title: initial.name, value: initial.id },\n choices: userBots.map((bot) => ({ title: bot.name, value: bot.id })),\n })\n\n if (!prompted) {\n throw new errors.ParamRequiredError('Bot Id')\n }\n\n return prompted\n })\n\n const { bot: fetchedBot } = await api.client.getBot({ id: promptedBotId }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not get bot info')\n })\n\n return fetchedBot\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAkB;AAClB,SAAoB;AAGpB,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,2BAA6B;AAC7B,6BAA+B;AAOxB,MAAM,sBAAsB,sCAAwC;AAAA,EACzE,MAAa,MAAqB;AAChC,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAC3D,QAAI,IAAI,QAAQ,OAAO,uBAAuB;AAC5C,WAAK,OAAO,IAAI,oBAAoB,IAAI,KAAK;AAAA,IAC/C;AAEA,QAAI,CAAC,KAAK,KAAK,SAAS;AACtB,YAAM,KAAK,UAAU;AAAA,IACvB;AAEA,UAAM,iBAAiB,MAAM,KAAK,gCAAgC;AAClE,QAAI,gBAAgB;AAClB,aAAO,KAAK,mBAAmB,KAAK,cAAc;AAAA,IACpD;AACA,WAAO,KAAK,WAAW,KAAK,KAAK,KAAK,OAAO,KAAK,KAAK,YAAY;AAAA,EACrE;AAAA,EAEA,MAAc,YAAY;AACxB,WAAO,IAAI,kCAAa,KAAK,KAAK,KAAK,QAAQ,KAAK,QAAQ,KAAK,IAAI,EAAE,IAAI;AAAA,EAC7E;AAAA,EAEA,MAAc,mBAAmB,KAAgB,gBAAuC;AACtF,UAAM,UAAU,KAAK,aAAa,IAAI;AACtC,QAAI,OAAO,MAAM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13 +27,17 @@ __export(dev_command_exports, {
|
|
|
27
27
|
DevCommand: () => DevCommand
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(dev_command_exports);
|
|
30
|
+
var import_axios = __toESM(require("axios"));
|
|
30
31
|
var import_chalk = __toESM(require("chalk"));
|
|
31
32
|
var pathlib = __toESM(require("path"));
|
|
33
|
+
var uuid = __toESM(require("uuid"));
|
|
32
34
|
var errors = __toESM(require("../errors"));
|
|
33
35
|
var utils = __toESM(require("../utils"));
|
|
34
36
|
var import_worker = require("../worker");
|
|
35
37
|
var import_build_command = require("./build-command");
|
|
36
38
|
var import_project_command = require("./project-command");
|
|
39
|
+
const DEFAULT_BOT_PORT = 8075;
|
|
40
|
+
const DEFAULT_INTEGRATION_PORT = 8076;
|
|
37
41
|
class DevCommand extends import_project_command.ProjectCommand {
|
|
38
42
|
_initialDef = void 0;
|
|
39
43
|
async run() {
|
|
@@ -41,16 +45,51 @@ class DevCommand extends import_project_command.ProjectCommand {
|
|
|
41
45
|
const api = await this.ensureLoginAndCreateClient(this.argv);
|
|
42
46
|
this._initialDef = await this.readIntegrationDefinitionFromFS();
|
|
43
47
|
let env = {
|
|
48
|
+
...process.env,
|
|
44
49
|
BP_API_URL: api.url,
|
|
45
50
|
BP_TOKEN: api.token
|
|
46
51
|
};
|
|
52
|
+
let defaultPort = DEFAULT_BOT_PORT;
|
|
47
53
|
if (this._initialDef) {
|
|
54
|
+
defaultPort = DEFAULT_INTEGRATION_PORT;
|
|
48
55
|
const secrets = await this.promptSecrets(this._initialDef, this.argv);
|
|
49
56
|
env = { ...env, ...secrets };
|
|
50
57
|
}
|
|
51
|
-
|
|
58
|
+
const port = this.argv.port ?? defaultPort;
|
|
59
|
+
const urlParseResult = utils.url.parse(this.argv.tunnelUrl);
|
|
60
|
+
if (urlParseResult.status === "error") {
|
|
61
|
+
throw new errors.BotpressCLIError(`Invalid tunnel URL: ${urlParseResult.error}`);
|
|
62
|
+
}
|
|
63
|
+
const tunnelId = uuid.v4();
|
|
64
|
+
const { url: parsedTunnelUrl } = urlParseResult;
|
|
65
|
+
const isSecured = parsedTunnelUrl.protocol === "https" || parsedTunnelUrl.protocol === "wss";
|
|
66
|
+
const wsTunnelUrl = utils.url.format({ ...parsedTunnelUrl, protocol: isSecured ? "wss" : "ws" });
|
|
67
|
+
const httpTunnelUrl = utils.url.format({
|
|
68
|
+
...parsedTunnelUrl,
|
|
69
|
+
protocol: isSecured ? "https" : "http",
|
|
70
|
+
path: `/${tunnelId}`
|
|
71
|
+
});
|
|
72
|
+
const supervisor = new utils.tunnel.TunnelSupervisor(wsTunnelUrl, tunnelId, this.logger);
|
|
73
|
+
supervisor.events.on("connected", ({ tunnel }) => {
|
|
74
|
+
tunnel.events.on(
|
|
75
|
+
"request",
|
|
76
|
+
(req) => void this._forwardTunnelRequest(`http://localhost:${port}`, req).then((res) => {
|
|
77
|
+
tunnel.send(res);
|
|
78
|
+
}).catch((thrown) => {
|
|
79
|
+
const err = errors.BotpressCLIError.wrap(thrown, "An error occurred while handling request");
|
|
80
|
+
this.logger.error(err.message);
|
|
81
|
+
tunnel.send({
|
|
82
|
+
requestId: req.id,
|
|
83
|
+
status: 500,
|
|
84
|
+
body: err.message
|
|
85
|
+
});
|
|
86
|
+
})
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
await supervisor.start();
|
|
90
|
+
await this._deploy(api, httpTunnelUrl);
|
|
52
91
|
await this._runBuild();
|
|
53
|
-
const worker = await this._spawnWorker(env);
|
|
92
|
+
const worker = await this._spawnWorker(env, port);
|
|
54
93
|
try {
|
|
55
94
|
const watcher = await utils.filewatcher.FileWatcher.watch(
|
|
56
95
|
this.argv.workDir,
|
|
@@ -60,24 +99,28 @@ class DevCommand extends import_project_command.ProjectCommand {
|
|
|
60
99
|
return;
|
|
61
100
|
}
|
|
62
101
|
this.logger.log("Changes detected, rebuilding");
|
|
63
|
-
await this._restart(api, worker);
|
|
102
|
+
await this._restart(api, worker, httpTunnelUrl);
|
|
64
103
|
},
|
|
65
104
|
{
|
|
66
105
|
ignore: [this.projectPaths.abs.outDir]
|
|
67
106
|
}
|
|
68
107
|
);
|
|
69
|
-
await Promise.race([worker.wait(), watcher.wait()]);
|
|
108
|
+
await Promise.race([worker.wait(), watcher.wait(), supervisor.wait()]);
|
|
109
|
+
if (worker.running) {
|
|
110
|
+
await worker.kill();
|
|
111
|
+
}
|
|
70
112
|
await watcher.close();
|
|
113
|
+
supervisor.close();
|
|
71
114
|
} catch (thrown) {
|
|
72
|
-
throw errors.BotpressCLIError.wrap(thrown, "An error occurred while running the dev
|
|
115
|
+
throw errors.BotpressCLIError.wrap(thrown, "An error occurred while running the dev server");
|
|
73
116
|
} finally {
|
|
74
117
|
if (worker.running) {
|
|
75
118
|
await worker.kill();
|
|
76
119
|
}
|
|
77
120
|
}
|
|
78
121
|
}
|
|
79
|
-
_restart = async (api, worker) => {
|
|
80
|
-
await this._deploy(api);
|
|
122
|
+
_restart = async (api, worker, tunnelUrl) => {
|
|
123
|
+
await this._deploy(api, tunnelUrl);
|
|
81
124
|
try {
|
|
82
125
|
await this._runBuild();
|
|
83
126
|
} catch (thrown) {
|
|
@@ -87,13 +130,13 @@ class DevCommand extends import_project_command.ProjectCommand {
|
|
|
87
130
|
}
|
|
88
131
|
await worker.reload();
|
|
89
132
|
};
|
|
90
|
-
_deploy = async (api) => {
|
|
133
|
+
_deploy = async (api, tunnelUrl) => {
|
|
91
134
|
const integrationDef = await this.readIntegrationDefinitionFromFS();
|
|
92
135
|
if (integrationDef) {
|
|
93
136
|
this._checkSecrets(integrationDef);
|
|
94
|
-
await this._deployDevIntegration(api,
|
|
137
|
+
await this._deployDevIntegration(api, tunnelUrl, integrationDef);
|
|
95
138
|
} else {
|
|
96
|
-
await this._deployDevBot(api,
|
|
139
|
+
await this._deployDevBot(api, tunnelUrl);
|
|
97
140
|
}
|
|
98
141
|
};
|
|
99
142
|
_checkSecrets(integrationDef) {
|
|
@@ -104,11 +147,11 @@ class DevCommand extends import_project_command.ProjectCommand {
|
|
|
104
147
|
throw new errors.BotpressCLIError("Secrets were added while the server was running. A restart is required.");
|
|
105
148
|
}
|
|
106
149
|
}
|
|
107
|
-
_spawnWorker = async (env) => {
|
|
150
|
+
_spawnWorker = async (env, port) => {
|
|
108
151
|
const outfile = this.projectPaths.abs.outFile;
|
|
109
152
|
const importPath = utils.path.toUnix(outfile);
|
|
110
153
|
const requireFrom = utils.path.rmExtension(importPath);
|
|
111
|
-
const code = `require('${requireFrom}').default.start(${
|
|
154
|
+
const code = `require('${requireFrom}').default.start(${port})`;
|
|
112
155
|
const worker = await import_worker.Worker.spawn(
|
|
113
156
|
{
|
|
114
157
|
type: "code",
|
|
@@ -188,12 +231,51 @@ class DevCommand extends import_project_command.ProjectCommand {
|
|
|
188
231
|
const integrations = this.prepareIntegrations(botImpl, bot);
|
|
189
232
|
const updateLine = this.logger.line();
|
|
190
233
|
updateLine.started("Deploying dev bot...");
|
|
191
|
-
const { bot: updatedBot } = await api.client.updateBot({
|
|
234
|
+
const { bot: updatedBot } = await api.client.updateBot({
|
|
235
|
+
...botImpl.definition,
|
|
236
|
+
id: bot.id,
|
|
237
|
+
integrations,
|
|
238
|
+
url: externalUrl
|
|
239
|
+
}).catch((thrown) => {
|
|
192
240
|
throw errors.BotpressCLIError.wrap(thrown, "Could not deploy dev bot");
|
|
193
241
|
});
|
|
194
|
-
updateLine.success(
|
|
242
|
+
updateLine.success(`Dev Bot deployed with id "${updatedBot.id}"`);
|
|
195
243
|
this.displayWebhookUrls(updatedBot);
|
|
196
244
|
}
|
|
245
|
+
_forwardTunnelRequest = async (baseUrl, request) => {
|
|
246
|
+
const axiosConfig = {
|
|
247
|
+
method: request.method,
|
|
248
|
+
url: this._formatLocalUrl(baseUrl, request),
|
|
249
|
+
headers: request.headers,
|
|
250
|
+
data: request.body,
|
|
251
|
+
responseType: "text",
|
|
252
|
+
validateStatus: () => true
|
|
253
|
+
};
|
|
254
|
+
this.logger.debug(`Forwarding request to ${axiosConfig.url}`);
|
|
255
|
+
const response = await (0, import_axios.default)(axiosConfig);
|
|
256
|
+
this.logger.debug("Sending back response up the tunnel");
|
|
257
|
+
return {
|
|
258
|
+
requestId: request.id,
|
|
259
|
+
status: response.status,
|
|
260
|
+
headers: this._getHeaders(response.headers),
|
|
261
|
+
body: response.data
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
_formatLocalUrl = (baseUrl, req) => {
|
|
265
|
+
if (req.query) {
|
|
266
|
+
return `${baseUrl}${req.path}?${req.query}`;
|
|
267
|
+
}
|
|
268
|
+
return `${baseUrl}${req.path}`;
|
|
269
|
+
};
|
|
270
|
+
_getHeaders = (res) => {
|
|
271
|
+
const headers = {};
|
|
272
|
+
for (const key in res) {
|
|
273
|
+
if (typeof res[key] === "string" || typeof res[key] === "number") {
|
|
274
|
+
headers[key] = res[key];
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return headers;
|
|
278
|
+
};
|
|
197
279
|
}
|
|
198
280
|
// Annotate the CommonJS export names for ESM import in node:
|
|
199
281
|
0 && (module.exports = {
|
|
@@ -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 chalk from 'chalk'\nimport * as pathlib from 'path'\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'\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 BP_API_URL: api.url,\n BP_TOKEN: api.token,\n }\n\n if (this._initialDef) {\n const secrets = await this.promptSecrets(this._initialDef, this.argv)\n env = { ...env, ...secrets }\n }\n\n await this._deploy(api)\n await this._runBuild()\n const worker = await this._spawnWorker(env)\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)\n },\n {\n ignore: [this.projectPaths.abs.outDir],\n }\n )\n\n await Promise.race([worker.wait(), watcher.wait()])\n await watcher.close()\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, 'An error occurred while running the dev worker')\n } finally {\n if (worker.running) {\n await worker.kill()\n }\n }\n }\n\n private _restart = async (api: ApiClient, worker: Worker) => {\n await this._deploy(api)\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) => {\n const integrationDef = await this.readIntegrationDefinitionFromFS()\n if (integrationDef) {\n this._checkSecrets(integrationDef)\n await this._deployDevIntegration(api, this.argv.url, integrationDef)\n } else {\n await this._deployDevBot(api, this.argv.url)\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>) => {\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(${this.argv.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({ id: bot.id, integrations, url: externalUrl })\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not deploy dev bot')\n })\n updateLine.success('Dev Bot deployed')\n\n this.displayWebhookUrls(updatedBot)\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
6
|
-
"names": ["chalk"]
|
|
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,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
6
|
+
"names": ["chalk", "axios"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/command-implementations/project-command.ts"],
|
|
4
|
-
"sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport type { IntegrationDefinition, Bot as BotImpl } from '@botpress/sdk'\nimport type { YargsConfig } from '@bpinternal/yargs-extra'\nimport chalk from 'chalk'\nimport fs from 'fs'\nimport _ from 'lodash'\nimport pathlib from 'path'\nimport * as codegen from '../code-generation'\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 { GlobalCommand } from './global-command'\n\nexport type ProjectCommandDefinition = CommandDefinition<typeof config.schemas.project>\nexport type ProjectCache = { botId: string; devId: string }\n\ntype ConfigurableProjectPaths = { entryPoint: string; outDir: string; workDir: string }\ntype ConstantProjectPaths = typeof consts.fromOutDir & typeof consts.fromWorkDir\ntype AllProjectPaths = ConfigurableProjectPaths & ConstantProjectPaths\n\nclass ProjectPaths extends utils.path.PathStore<keyof AllProjectPaths> {\n public constructor(argv: CommandArgv<ProjectCommandDefinition>) {\n const absWorkDir = utils.path.absoluteFrom(utils.path.cwd(), argv.workDir)\n const absEntrypoint = utils.path.absoluteFrom(absWorkDir, argv.entryPoint)\n const absOutDir = utils.path.absoluteFrom(absWorkDir, argv.outDir)\n super({\n workDir: absWorkDir,\n entryPoint: absEntrypoint,\n outDir: absOutDir,\n ..._.mapValues(consts.fromOutDir, (p) => utils.path.absoluteFrom(absOutDir, p)),\n ..._.mapValues(consts.fromWorkDir, (p) => utils.path.absoluteFrom(absWorkDir, p)),\n })\n }\n}\n\nexport abstract class ProjectCommand<C extends ProjectCommandDefinition> extends GlobalCommand<C> {\n protected get projectPaths() {\n return new ProjectPaths(this.argv)\n }\n\n protected get projectCache() {\n return new utils.cache.FSKeyValueCache<ProjectCache>(this.projectPaths.abs.projectCacheFile)\n }\n\n protected async readIntegrationDefinitionFromFS(): Promise<IntegrationDefinition | undefined> {\n const abs = this.projectPaths.abs\n const rel = this.projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.definition)) {\n this.logger.debug(`Integration definition not found at ${rel.definition}`)\n return\n }\n\n const { outputFiles } = await utils.esbuild.buildEntrypoint({\n cwd: abs.workDir,\n outfile: '',\n entrypoint: rel.definition,\n write: false,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read integration definition')\n }\n\n const { default: definition } = utils.require.requireJsCode<{ default: IntegrationDefinition }>(artifact.text)\n return definition\n }\n\n protected async writeGeneratedFilesToOutFolder(files: codegen.File[]) {\n for (const file of files) {\n const filePath = utils.path.absoluteFrom(this.projectPaths.abs.outDir, file.path)\n const dirPath = pathlib.dirname(filePath)\n await fs.promises.mkdir(dirPath, { recursive: true })\n await fs.promises.writeFile(filePath, file.content)\n }\n }\n\n protected prepareIntegrations(
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAkB;AAClB,gBAAe;AACf,oBAAc;AACd,kBAAoB;AACpB,cAAyB;AAEzB,aAAwB;AACxB,aAAwB;AAExB,YAAuB;AACvB,4BAA8B;
|
|
4
|
+
"sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport type { IntegrationDefinition, Bot as BotImpl } from '@botpress/sdk'\nimport type { YargsConfig } from '@bpinternal/yargs-extra'\nimport chalk from 'chalk'\nimport fs from 'fs'\nimport _ from 'lodash'\nimport pathlib from 'path'\nimport * as codegen from '../code-generation'\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 { GlobalCommand } from './global-command'\n\ntype IntegrationInstances = Parameters<bpclient.Client['updateBot']>[0]['integrations']\n\nexport type ProjectCommandDefinition = CommandDefinition<typeof config.schemas.project>\nexport type ProjectCache = { botId: string; devId: string }\n\ntype ConfigurableProjectPaths = { entryPoint: string; outDir: string; workDir: string }\ntype ConstantProjectPaths = typeof consts.fromOutDir & typeof consts.fromWorkDir\ntype AllProjectPaths = ConfigurableProjectPaths & ConstantProjectPaths\n\nclass ProjectPaths extends utils.path.PathStore<keyof AllProjectPaths> {\n public constructor(argv: CommandArgv<ProjectCommandDefinition>) {\n const absWorkDir = utils.path.absoluteFrom(utils.path.cwd(), argv.workDir)\n const absEntrypoint = utils.path.absoluteFrom(absWorkDir, argv.entryPoint)\n const absOutDir = utils.path.absoluteFrom(absWorkDir, argv.outDir)\n super({\n workDir: absWorkDir,\n entryPoint: absEntrypoint,\n outDir: absOutDir,\n ..._.mapValues(consts.fromOutDir, (p) => utils.path.absoluteFrom(absOutDir, p)),\n ..._.mapValues(consts.fromWorkDir, (p) => utils.path.absoluteFrom(absWorkDir, p)),\n })\n }\n}\n\nexport abstract class ProjectCommand<C extends ProjectCommandDefinition> extends GlobalCommand<C> {\n protected get projectPaths() {\n return new ProjectPaths(this.argv)\n }\n\n protected get projectCache() {\n return new utils.cache.FSKeyValueCache<ProjectCache>(this.projectPaths.abs.projectCacheFile)\n }\n\n protected async readIntegrationDefinitionFromFS(): Promise<IntegrationDefinition | undefined> {\n const abs = this.projectPaths.abs\n const rel = this.projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.definition)) {\n this.logger.debug(`Integration definition not found at ${rel.definition}`)\n return\n }\n\n const { outputFiles } = await utils.esbuild.buildEntrypoint({\n cwd: abs.workDir,\n outfile: '',\n entrypoint: rel.definition,\n write: false,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read integration definition')\n }\n\n const { default: definition } = utils.require.requireJsCode<{ default: IntegrationDefinition }>(artifact.text)\n return definition\n }\n\n protected async writeGeneratedFilesToOutFolder(files: codegen.File[]) {\n for (const file of files) {\n const filePath = utils.path.absoluteFrom(this.projectPaths.abs.outDir, file.path)\n const dirPath = pathlib.dirname(filePath)\n await fs.promises.mkdir(dirPath, { recursive: true })\n await fs.promises.writeFile(filePath, file.content)\n }\n }\n\n protected prepareIntegrations(botImpl: BotImpl, botInfo: bpclient.Bot): IntegrationInstances {\n const { integrations: integrationList } = botImpl.definition\n\n const integrationsToUninstall: IntegrationInstances = _(botInfo.integrations)\n .keys()\n .filter((key) => !integrationList?.map((i) => i.id).includes(key))\n .zipObject()\n .mapValues(() => null)\n .value()\n\n const integrationsToInstall: IntegrationInstances = _(integrationList ?? [])\n .keyBy((i) => i.id)\n .mapValues(({ enabled, configuration }) => ({ enabled, configuration }))\n .value()\n\n return { ...integrationsToUninstall, ...integrationsToInstall }\n }\n\n protected displayWebhookUrls(bot: bpclient.Bot) {\n if (!_.keys(bot.integrations).length) {\n this.logger.debug('No integrations in bot')\n return\n }\n\n this.logger.log('Integrations:')\n for (const integration of Object.values(bot.integrations)) {\n if (!integration.enabled) {\n this.logger.log(`${chalk.grey(integration.name)} ${chalk.italic('(disabled)')}: ${integration.webhookUrl}`, {\n prefix: { symbol: '\u25CB', indent: 2 },\n })\n } else {\n this.logger.log(`${chalk.bold(integration.name)} : ${integration.webhookUrl}`, {\n prefix: { symbol: '\u25CF', indent: 2 },\n })\n }\n }\n }\n\n protected async promptSecrets(\n integrationDef: IntegrationDefinition,\n argv: YargsConfig<typeof config.schemas.secrets>\n ): Promise<Record<string, string>> {\n const { secrets: secretDefinitions } = integrationDef\n if (!secretDefinitions) {\n return {}\n }\n\n const secretArgv = this._parseArgvSecrets(argv.secrets)\n const invalidSecret = Object.keys(secretArgv).find((s) => !secretDefinitions.includes(s))\n if (invalidSecret) {\n throw new errors.BotpressCLIError(`Secret ${invalidSecret} is not defined in integration definition`)\n }\n\n const values: Record<string, string> = {}\n for (const secretDef of secretDefinitions) {\n const argvSecret = secretArgv[secretDef]\n if (argvSecret) {\n this.logger.debug(`Using secret \"${secretDef}\" from argv`)\n values[secretDef] = argvSecret\n continue\n }\n\n const prompted = await this.prompt.text(`Enter value for secret \"${secretDef}\"`)\n if (!prompted) {\n throw new errors.BotpressCLIError('Secret is required')\n }\n values[secretDef] = prompted\n }\n\n const envVariables = _.mapKeys(values, (_v, k) => codegen.secretEnvVariableName(k))\n return envVariables\n }\n\n private _parseArgvSecrets(argvSecrets: string[]): Record<string, string> {\n const parsed: Record<string, string> = {}\n for (const secret of argvSecrets) {\n const [key, value] = this._splitOnce(secret, '=')\n if (!value) {\n throw new errors.BotpressCLIError(\n `Secret \"${key}\" is missing a value. Expected format: \"SECRET_NAME=secretValue\"`\n )\n }\n parsed[key!] = value\n }\n\n return parsed\n }\n\n private _splitOnce = (text: string, separator: string): [string, string | undefined] => {\n const index = text.indexOf(separator)\n if (index === -1) {\n return [text, undefined]\n }\n return [text.slice(0, index), text.slice(index + 1)]\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAkB;AAClB,gBAAe;AACf,oBAAc;AACd,kBAAoB;AACpB,cAAyB;AAEzB,aAAwB;AACxB,aAAwB;AAExB,YAAuB;AACvB,4BAA8B;AAW9B,MAAM,qBAAqB,MAAM,KAAK,UAAiC;AAAA,EAC9D,YAAY,MAA6C;AAC9D,UAAM,aAAa,MAAM,KAAK,aAAa,MAAM,KAAK,IAAI,GAAG,KAAK,OAAO;AACzE,UAAM,gBAAgB,MAAM,KAAK,aAAa,YAAY,KAAK,UAAU;AACzE,UAAM,YAAY,MAAM,KAAK,aAAa,YAAY,KAAK,MAAM;AACjE,UAAM;AAAA,MACJ,SAAS;AAAA,MACT,YAAY;AAAA,MACZ,QAAQ;AAAA,MACR,GAAG,cAAAA,QAAE,UAAU,OAAO,YAAY,CAAC,MAAM,MAAM,KAAK,aAAa,WAAW,CAAC,CAAC;AAAA,MAC9E,GAAG,cAAAA,QAAE,UAAU,OAAO,aAAa,CAAC,MAAM,MAAM,KAAK,aAAa,YAA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 const devSchema = {
|
|
|
142
142
|
...projectSchema,
|
|
143
143
|
...credentialsSchema,
|
|
144
144
|
...secretsSchema,
|
|
145
|
-
|
|
146
|
-
type: "string",
|
|
147
|
-
description: "The publicly available URL of the bot or integration (often using ngrok)",
|
|
148
|
-
demandOption: true
|
|
149
|
-
},
|
|
145
|
+
sourceMap,
|
|
150
146
|
port,
|
|
151
|
-
|
|
147
|
+
tunnelUrl: {
|
|
148
|
+
type: "string",
|
|
149
|
+
description: "The tunnel HTTP URL to use",
|
|
150
|
+
default: consts.defaultTunnelUrl
|
|
151
|
+
}
|
|
152
152
|
};
|
|
153
153
|
const addSchema = {
|
|
154
154
|
...projectSchema,
|
package/dist/config.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/config.ts"],
|
|
4
|
-
"sourcesContent": ["import * as consts from './consts'\nimport type { CommandOption, CommandSchema } from './typings'\n\n// command options\n\nconst port = {\n type: 'number',\n description: 'The port to use',\n} satisfies CommandOption\n\nconst workDir = {\n type: 'string',\n description: 'The path to the project',\n default: process.cwd(),\n} satisfies CommandOption\n\nconst noBuild = {\n type: 'boolean',\n description: 'Skip the build step',\n default: false,\n} satisfies CommandOption\n\nconst apiUrl = {\n type: 'string',\n description: 'The URL of the Botpress server',\n} satisfies CommandOption\n\nconst token = {\n type: 'string',\n description: 'You Personal Access Token ',\n} satisfies CommandOption\n\nconst workspaceId = {\n type: 'string',\n description: 'The Workspace Id to deploy to',\n} satisfies CommandOption\n\nconst secrets = {\n type: 'string',\n description: 'Values for the integration secrets',\n array: true,\n default: [],\n} satisfies CommandOption\n\nconst botRef = {\n type: 'string',\n description: 'The bot ID. Bot Name is not supported.',\n demandOption: true,\n positional: true,\n idx: 0,\n} satisfies CommandOption\n\nconst integrationRef = {\n type: 'string',\n description: 'The integration ID or name with optionnal version. Ex: teams or teams@0.2.0',\n demandOption: true,\n positional: true,\n idx: 0,\n} satisfies CommandOption\n\nconst sourceMap = { type: 'boolean', description: 'Generate sourcemaps', default: false } satisfies CommandOption\n\n// base schemas\n\nconst globalSchema = {\n verbose: {\n type: 'boolean',\n description: 'Enable verbose logging',\n alias: 'v',\n default: false,\n },\n confirm: {\n type: 'boolean',\n description: 'Confirm all prompts',\n alias: 'y',\n default: false,\n },\n json: {\n type: 'boolean',\n description: 'Prevent logging anything else than raw json in stdout. Useful for piping output to other tools',\n default: false,\n },\n botpressHome: {\n type: 'string',\n description: 'The path to the Botpress home directory',\n default: consts.defaultBotpressHome,\n },\n} satisfies CommandSchema\n\nconst projectSchema = {\n ...globalSchema,\n entryPoint: { type: 'string', description: 'The entry point of the project', default: consts.defaultEntrypoint },\n outDir: { type: 'string', description: 'The output directory', default: consts.defaultOutputFolder },\n workDir,\n} satisfies CommandSchema\n\nconst credentialsSchema = {\n apiUrl,\n workspaceId,\n token,\n} satisfies CommandSchema\n\nconst secretsSchema = {\n secrets,\n} satisfies CommandSchema\n\n// command schemas\n\nconst generateSchema = {\n ...projectSchema,\n} satisfies CommandSchema\n\nconst bundleSchema = {\n ...projectSchema,\n sourceMap,\n} satisfies CommandSchema\n\nconst buildSchema = {\n ...projectSchema,\n sourceMap,\n} satisfies CommandSchema\n\nconst serveSchema = {\n ...projectSchema,\n ...secretsSchema,\n port,\n} satisfies CommandSchema\n\nconst deploySchema = {\n ...projectSchema,\n ...credentialsSchema,\n ...secretsSchema,\n botId: { type: 'string', description: 'The bot ID to deploy. Only used when deploying a bot' },\n noBuild,\n createNewBot: { type: 'boolean', description: 'Create a new bot when deploying. Only used when deploying a bot' },\n sourceMap,\n} satisfies CommandSchema\n\nconst devSchema = {\n ...projectSchema,\n ...credentialsSchema,\n ...secretsSchema,\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,aAAwB;AAKxB,MAAM,OAAO;AAAA,EACX,MAAM;AAAA,EACN,aAAa;AACf;AAEA,M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AU,aAAa,wBAAwB,SAAS,OAAO,oBAAoB;AAAA,EACnG;AACF;AAEA,MAAM,oBAAoB;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,gBAAgB;AAAA,EACpB;AACF;AAIA,MAAM,iBAAiB;AAAA,EACrB,GAAG;AACL;AAEA,MAAM,eAAe;AAAA,EACnB,GAAG;AAAA,EACH;AACF;AAEA,MAAM,cAAc;AAAA,EAClB,GAAG;AAAA,EACH;AACF;AAEA,MAAM,cAAc;AAAA,EAClB,GAAG;AAAA,EACH,GAAG;AAAA,EACH;AACF;AAEA,MAAM,eAAe;AAAA,EACnB,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AAAA,EACH,OAAO,EAAE,MAAM,UAAU,aAAa,uDAAuD;AAAA,EAC7F;AAAA,EACA,cAAc,EAAE,MAAM,WAAW,aAAa,kEAAkE;AAAA,EAChH;AACF;AAEA,MAAM,YAAY;AAAA,EAChB,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AAAA,EACH,
|
|
4
|
+
"sourcesContent": ["import * as consts from './consts'\nimport type { CommandOption, CommandSchema } from './typings'\n\n// command options\n\nconst port = {\n type: 'number',\n description: 'The port to use',\n} satisfies CommandOption\n\nconst workDir = {\n type: 'string',\n description: 'The path to the project',\n default: process.cwd(),\n} satisfies CommandOption\n\nconst noBuild = {\n type: 'boolean',\n description: 'Skip the build step',\n default: false,\n} satisfies CommandOption\n\nconst apiUrl = {\n type: 'string',\n description: 'The URL of the Botpress server',\n} satisfies CommandOption\n\nconst token = {\n type: 'string',\n description: 'You Personal Access Token ',\n} satisfies CommandOption\n\nconst workspaceId = {\n type: 'string',\n description: 'The Workspace Id to deploy to',\n} satisfies CommandOption\n\nconst secrets = {\n type: 'string',\n description: 'Values for the integration secrets',\n array: true,\n default: [],\n} satisfies CommandOption\n\nconst botRef = {\n type: 'string',\n description: 'The bot ID. Bot Name is not supported.',\n demandOption: true,\n positional: true,\n idx: 0,\n} satisfies CommandOption\n\nconst integrationRef = {\n type: 'string',\n description: 'The integration ID or name with optionnal version. Ex: teams or teams@0.2.0',\n demandOption: true,\n positional: true,\n idx: 0,\n} satisfies CommandOption\n\nconst sourceMap = { type: 'boolean', description: 'Generate sourcemaps', default: false } satisfies CommandOption\n\n// base schemas\n\nconst globalSchema = {\n verbose: {\n type: 'boolean',\n description: 'Enable verbose logging',\n alias: 'v',\n default: false,\n },\n confirm: {\n type: 'boolean',\n description: 'Confirm all prompts',\n alias: 'y',\n default: false,\n },\n json: {\n type: 'boolean',\n description: 'Prevent logging anything else than raw json in stdout. Useful for piping output to other tools',\n default: false,\n },\n botpressHome: {\n type: 'string',\n description: 'The path to the Botpress home directory',\n default: consts.defaultBotpressHome,\n },\n} satisfies CommandSchema\n\nconst projectSchema = {\n ...globalSchema,\n entryPoint: { type: 'string', description: 'The entry point of the project', default: consts.defaultEntrypoint },\n outDir: { type: 'string', description: 'The output directory', default: consts.defaultOutputFolder },\n workDir,\n} satisfies CommandSchema\n\nconst credentialsSchema = {\n apiUrl,\n workspaceId,\n token,\n} satisfies CommandSchema\n\nconst secretsSchema = {\n secrets,\n} satisfies CommandSchema\n\n// command schemas\n\nconst generateSchema = {\n ...projectSchema,\n} satisfies CommandSchema\n\nconst bundleSchema = {\n ...projectSchema,\n sourceMap,\n} satisfies CommandSchema\n\nconst buildSchema = {\n ...projectSchema,\n sourceMap,\n} satisfies CommandSchema\n\nconst serveSchema = {\n ...projectSchema,\n ...secretsSchema,\n port,\n} satisfies CommandSchema\n\nconst deploySchema = {\n ...projectSchema,\n ...credentialsSchema,\n ...secretsSchema,\n botId: { type: 'string', description: 'The bot ID to deploy. Only used when deploying a bot' },\n noBuild,\n createNewBot: { type: 'boolean', description: 'Create a new bot when deploying. Only used when deploying a bot' },\n sourceMap,\n} satisfies CommandSchema\n\nconst devSchema = {\n ...projectSchema,\n ...credentialsSchema,\n ...secretsSchema,\n sourceMap,\n port,\n tunnelUrl: {\n type: 'string',\n description: 'The tunnel HTTP URL to use',\n default: consts.defaultTunnelUrl,\n },\n} satisfies CommandSchema\n\nconst addSchema = {\n ...projectSchema,\n ...credentialsSchema,\n integrationRef,\n} satisfies CommandSchema\n\nconst loginSchema = {\n ...globalSchema,\n token,\n workspaceId,\n apiUrl: { ...apiUrl, default: consts.defaultBotpressApiUrl },\n} satisfies CommandSchema\n\nconst logoutSchema = {\n ...globalSchema,\n} satisfies CommandSchema\n\nconst createBotSchema = {\n ...globalSchema,\n ...credentialsSchema,\n name: { type: 'string', description: 'The name of the bot to create' },\n} satisfies CommandSchema\n\nconst getBotSchema = {\n ...globalSchema,\n ...credentialsSchema,\n botRef,\n} satisfies CommandSchema\n\nconst deleteBotSchema = {\n ...globalSchema,\n ...credentialsSchema,\n botRef,\n} satisfies CommandSchema\n\nconst listBotsSchema = {\n ...globalSchema,\n ...credentialsSchema,\n} satisfies CommandSchema\n\nconst getIntegrationSchema = {\n ...globalSchema,\n ...credentialsSchema,\n integrationRef,\n} satisfies CommandSchema\n\nconst listIntegrationsSchema = {\n ...globalSchema,\n ...credentialsSchema,\n name: { type: 'string', description: 'The name filter when listing integrations' },\n version: { type: 'string', description: 'The version filter when listing integrations' },\n} satisfies CommandSchema\n\nconst deleteIntegrationSchema = {\n ...globalSchema,\n ...credentialsSchema,\n integrationRef,\n} satisfies CommandSchema\n\nconst initSchema = {\n ...globalSchema,\n workDir,\n type: { type: 'string', choices: ['bot', 'integration'] as const },\n name: { type: 'string', description: 'The name of the project' },\n} satisfies CommandSchema\n\n// exports\n\nexport const schemas = {\n global: globalSchema,\n project: projectSchema,\n credentials: credentialsSchema,\n secrets: secretsSchema,\n\n login: loginSchema,\n logout: logoutSchema,\n createBot: createBotSchema,\n getBot: getBotSchema,\n deleteBot: deleteBotSchema,\n listBots: listBotsSchema,\n getIntegration: getIntegrationSchema,\n listIntegrations: listIntegrationsSchema,\n deleteIntegration: deleteIntegrationSchema,\n init: initSchema,\n generate: generateSchema,\n bundle: bundleSchema,\n build: buildSchema,\n serve: serveSchema,\n deploy: deploySchema,\n add: addSchema,\n dev: devSchema,\n} as const\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,aAAwB;AAKxB,MAAM,OAAO;AAAA,EACX,MAAM;AAAA,EACN,aAAa;AACf;AAEA,MAAM,UAAU;AAAA,EACd,MAAM;AAAA,EACN,aAAa;AAAA,EACb,SAAS,QAAQ,IAAI;AACvB;AAEA,MAAM,UAAU;AAAA,EACd,MAAM;AAAA,EACN,aAAa;AAAA,EACb,SAAS;AACX;AAEA,MAAM,SAAS;AAAA,EACb,MAAM;AAAA,EACN,aAAa;AACf;AAEA,MAAM,QAAQ;AAAA,EACZ,MAAM;AAAA,EACN,aAAa;AACf;AAEA,MAAM,cAAc;AAAA,EAClB,MAAM;AAAA,EACN,aAAa;AACf;AAEA,MAAM,UAAU;AAAA,EACd,MAAM;AAAA,EACN,aAAa;AAAA,EACb,OAAO;AAAA,EACP,SAAS,CAAC;AACZ;AAEA,MAAM,SAAS;AAAA,EACb,MAAM;AAAA,EACN,aAAa;AAAA,EACb,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,KAAK;AACP;AAEA,MAAM,iBAAiB;AAAA,EACrB,MAAM;AAAA,EACN,aAAa;AAAA,EACb,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,KAAK;AACP;AAEA,MAAM,YAAY,EAAE,MAAM,WAAW,aAAa,uBAAuB,SAAS,MAAM;AAIxF,MAAM,eAAe;AAAA,EACnB,SAAS;AAAA,IACP,MAAM;AAAA,IACN,aAAa;AAAA,IACb,OAAO;AAAA,IACP,SAAS;AAAA,EACX;AAAA,EACA,SAAS;AAAA,IACP,MAAM;AAAA,IACN,aAAa;AAAA,IACb,OAAO;AAAA,IACP,SAAS;AAAA,EACX;AAAA,EACA,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,aAAa;AAAA,IACb,SAAS;AAAA,EACX;AAAA,EACA,c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consts_exports, {
|
|
|
29
29
|
defaultBotpressHome: () => defaultBotpressHome,
|
|
30
30
|
defaultEntrypoint: () => defaultEntrypoint,
|
|
31
31
|
defaultOutputFolder: () => defaultOutputFolder,
|
|
32
|
+
defaultTunnelUrl: () => defaultTunnelUrl,
|
|
32
33
|
echoBotDirName: () => echoBotDirName,
|
|
33
34
|
emptyIntegrationDirName: () => emptyIntegrationDirName,
|
|
34
35
|
fromCliRootDir: () => fromCliRootDir,
|
|
@@ -44,6 +45,7 @@ const defaultOutputFolder = ".botpress";
|
|
|
44
45
|
const defaultEntrypoint = import_path.default.join("src", "index.ts");
|
|
45
46
|
const defaultBotpressApiUrl = "https://api.botpress.cloud";
|
|
46
47
|
const defaultBotpressAppUrl = "https://app.botpress.cloud";
|
|
48
|
+
const defaultTunnelUrl = "https://tunnel.botpress.cloud";
|
|
47
49
|
const echoBotDirName = "echo-bot";
|
|
48
50
|
const emptyIntegrationDirName = "empty-integration";
|
|
49
51
|
const fromCliRootDir = {
|
|
@@ -72,6 +74,7 @@ const fromOutDir = {
|
|
|
72
74
|
defaultBotpressHome,
|
|
73
75
|
defaultEntrypoint,
|
|
74
76
|
defaultOutputFolder,
|
|
77
|
+
defaultTunnelUrl,
|
|
75
78
|
echoBotDirName,
|
|
76
79
|
emptyIntegrationDirName,
|
|
77
80
|
fromCliRootDir,
|
package/dist/consts.js.map
CHANGED
|
@@ -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'\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,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;
|
|
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;",
|
|
6
6
|
"names": ["pathlib", "os"]
|
|
7
7
|
}
|
package/dist/utils/index.js
CHANGED
|
@@ -32,7 +32,9 @@ __export(utils_exports, {
|
|
|
32
32
|
path: () => path,
|
|
33
33
|
prompt: () => prompt,
|
|
34
34
|
records: () => records,
|
|
35
|
-
require: () => require2
|
|
35
|
+
require: () => require2,
|
|
36
|
+
tunnel: () => tunnel,
|
|
37
|
+
url: () => url
|
|
36
38
|
});
|
|
37
39
|
module.exports = __toCommonJS(utils_exports);
|
|
38
40
|
var esbuild = __toESM(require("./esbuild-utils"));
|
|
@@ -44,6 +46,8 @@ var cache = __toESM(require("./cache-utils"));
|
|
|
44
46
|
var casing = __toESM(require("./case-utils"));
|
|
45
47
|
var prompt = __toESM(require("./prompt-utils"));
|
|
46
48
|
var records = __toESM(require("./record-utils"));
|
|
49
|
+
var url = __toESM(require("./url-utils"));
|
|
50
|
+
var tunnel = __toESM(require("./tunnel-utils"));
|
|
47
51
|
// Annotate the CommonJS export names for ESM import in node:
|
|
48
52
|
0 && (module.exports = {
|
|
49
53
|
cache,
|
|
@@ -54,6 +58,8 @@ var records = __toESM(require("./record-utils"));
|
|
|
54
58
|
path,
|
|
55
59
|
prompt,
|
|
56
60
|
records,
|
|
57
|
-
require
|
|
61
|
+
require,
|
|
62
|
+
tunnel,
|
|
63
|
+
url
|
|
58
64
|
});
|
|
59
65
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * as esbuild from './esbuild-utils'\nexport * as path from './path-utils'\nexport * as require from './require-utils'\nexport * as filewatcher from './file-watcher'\nexport * as emitter from './event-emitter'\nexport * as cache from './cache-utils'\nexport * as casing from './case-utils'\nexport * as prompt from './prompt-utils'\nexport * as records from './record-utils'\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAAA;AAAA;AAAA;AAAA,cAAyB;AACzB,WAAsB;AACtB,IAAAA,WAAyB;AACzB,kBAA6B;AAC7B,cAAyB;AACzB,YAAuB;AACvB,aAAwB;AACxB,aAAwB;AACxB,cAAyB;",
|
|
4
|
+
"sourcesContent": ["export * as esbuild from './esbuild-utils'\nexport * as path from './path-utils'\nexport * as require from './require-utils'\nexport * as filewatcher from './file-watcher'\nexport * as emitter from './event-emitter'\nexport * as cache from './cache-utils'\nexport * as casing from './case-utils'\nexport * as prompt from './prompt-utils'\nexport * as records from './record-utils'\nexport * as url from './url-utils'\nexport * as tunnel from './tunnel-utils'\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,cAAyB;AACzB,WAAsB;AACtB,IAAAA,WAAyB;AACzB,kBAA6B;AAC7B,cAAyB;AACzB,YAAuB;AACvB,aAAwB;AACxB,aAAwB;AACxB,cAAyB;AACzB,UAAqB;AACrB,aAAwB;",
|
|
6
6
|
"names": ["require"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var tunnel_utils_exports = {};
|
|
20
|
+
__export(tunnel_utils_exports, {
|
|
21
|
+
ReconnectionFailedError: () => ReconnectionFailedError,
|
|
22
|
+
TunnelSupervisor: () => TunnelSupervisor
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(tunnel_utils_exports);
|
|
25
|
+
var import_tunnel = require("@bpinternal/tunnel");
|
|
26
|
+
var import_event_emitter = require("./event-emitter");
|
|
27
|
+
class ReconnectionFailedError extends Error {
|
|
28
|
+
constructor(event) {
|
|
29
|
+
const reason = ReconnectionFailedError._reason(event);
|
|
30
|
+
super(`Reconnection failed: ${reason}`);
|
|
31
|
+
this.event = event;
|
|
32
|
+
}
|
|
33
|
+
static _reason(event) {
|
|
34
|
+
if (event.type === "error") {
|
|
35
|
+
return "error";
|
|
36
|
+
}
|
|
37
|
+
if (event.type === "close") {
|
|
38
|
+
return `${event.ev.code} ${event.ev.reason}`;
|
|
39
|
+
}
|
|
40
|
+
return "init";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
class TunnelSupervisor {
|
|
44
|
+
constructor(_tunnelUrl, _tunnelId, _logger) {
|
|
45
|
+
this._tunnelUrl = _tunnelUrl;
|
|
46
|
+
this._tunnelId = _tunnelId;
|
|
47
|
+
this._logger = _logger;
|
|
48
|
+
}
|
|
49
|
+
_tunnel;
|
|
50
|
+
_closed = false;
|
|
51
|
+
_started = false;
|
|
52
|
+
events = new import_event_emitter.EventEmitter();
|
|
53
|
+
async start() {
|
|
54
|
+
if (this._closed) {
|
|
55
|
+
throw new Error("Tunnel is closed");
|
|
56
|
+
}
|
|
57
|
+
if (this._started) {
|
|
58
|
+
throw new Error("Tunnel is already started");
|
|
59
|
+
}
|
|
60
|
+
this._started = true;
|
|
61
|
+
const tunnel = await this._reconnect({ type: "init", ev: null });
|
|
62
|
+
this._tunnel = tunnel;
|
|
63
|
+
}
|
|
64
|
+
get closed() {
|
|
65
|
+
return this._closed;
|
|
66
|
+
}
|
|
67
|
+
async wait() {
|
|
68
|
+
if (this._closed) {
|
|
69
|
+
throw new Error("Tunnel is closed");
|
|
70
|
+
}
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
this.events.on("connectionFailed", (ev) => {
|
|
73
|
+
reject(new ReconnectionFailedError(ev));
|
|
74
|
+
});
|
|
75
|
+
this.events.on("manuallyClosed", () => {
|
|
76
|
+
resolve();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
close() {
|
|
81
|
+
if (this._closed) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
this._closed = true;
|
|
85
|
+
this._tunnel?.close();
|
|
86
|
+
this.events.emit("manuallyClosed", null);
|
|
87
|
+
}
|
|
88
|
+
_reconnectSync(ev) {
|
|
89
|
+
void this._reconnect(ev).then((t) => {
|
|
90
|
+
this._tunnel = t;
|
|
91
|
+
}).catch(() => this.events.emit("connectionFailed", ev));
|
|
92
|
+
}
|
|
93
|
+
async _reconnect(ev) {
|
|
94
|
+
const newTunnel = async () => {
|
|
95
|
+
const tunnel2 = await import_tunnel.TunnelTail.new(this._tunnelUrl, this._tunnelId);
|
|
96
|
+
this._registerListeners(tunnel2);
|
|
97
|
+
this.events.emit("connected", { tunnel: tunnel2, ev });
|
|
98
|
+
return tunnel2;
|
|
99
|
+
};
|
|
100
|
+
if (ev.type === "init") {
|
|
101
|
+
return newTunnel();
|
|
102
|
+
}
|
|
103
|
+
const line = this._logger.line();
|
|
104
|
+
line.started("Reconnecting tunnel...");
|
|
105
|
+
const tunnel = await newTunnel();
|
|
106
|
+
line.success("Reconnected");
|
|
107
|
+
line.commit();
|
|
108
|
+
return tunnel;
|
|
109
|
+
}
|
|
110
|
+
_registerListeners(tunnel) {
|
|
111
|
+
tunnel.events.on("error", ({ target, type }) => {
|
|
112
|
+
this._logger.error(`Tunnel error: ${type}`);
|
|
113
|
+
this._reconnectSync({ type: "error", ev: { target, type } });
|
|
114
|
+
});
|
|
115
|
+
tunnel.events.on("close", ({ code, reason, target, type, wasClean }) => {
|
|
116
|
+
this._logger.error(`Tunnel closed: ${code} ${reason}`);
|
|
117
|
+
this._reconnectSync({ type: "close", ev: { code, reason, target, type, wasClean } });
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
+
0 && (module.exports = {
|
|
123
|
+
ReconnectionFailedError,
|
|
124
|
+
TunnelSupervisor
|
|
125
|
+
});
|
|
126
|
+
//# sourceMappingURL=tunnel-utils.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/tunnel-utils.ts"],
|
|
4
|
+
"sourcesContent": ["import { TunnelTail, ClientCloseEvent, ClientErrorEvent } from '@bpinternal/tunnel'\nimport { Logger } from '../logger'\nimport { EventEmitter } from './event-emitter'\n\nexport type ReconnectionTriggerEvent =\n | {\n type: 'init'\n ev: null\n }\n | {\n type: 'error'\n ev: ClientErrorEvent\n }\n | {\n type: 'close'\n ev: ClientCloseEvent\n }\n\nexport type ReconnectedEvent = {\n tunnel: TunnelTail\n ev: ReconnectionTriggerEvent\n}\n\nexport class ReconnectionFailedError extends Error {\n public constructor(public readonly event: ReconnectionTriggerEvent) {\n const reason = ReconnectionFailedError._reason(event)\n super(`Reconnection failed: ${reason}`)\n }\n\n private static _reason(event: ReconnectionTriggerEvent): string {\n if (event.type === 'error') {\n return 'error'\n }\n\n if (event.type === 'close') {\n return `${event.ev.code} ${event.ev.reason}`\n }\n\n return 'init'\n }\n}\n\nexport class TunnelSupervisor {\n private _tunnel?: TunnelTail\n private _closed = false\n private _started = false\n\n public readonly events = new EventEmitter<{\n connectionFailed: ReconnectionTriggerEvent\n manuallyClosed: null\n connected: {\n tunnel: TunnelTail\n ev: ReconnectionTriggerEvent\n }\n }>()\n\n constructor(private _tunnelUrl: string, private _tunnelId: string, private _logger: Logger) {}\n\n public async start(): Promise<void> {\n if (this._closed) {\n throw new Error('Tunnel is closed')\n }\n if (this._started) {\n throw new Error('Tunnel is already started')\n }\n\n this._started = true\n const tunnel = await this._reconnect({ type: 'init', ev: null })\n this._tunnel = tunnel\n }\n\n public get closed(): boolean {\n return this._closed\n }\n\n /**\n * @returns Promise that rejects when a reconnection attempt fails and resolves when the tunnel is closed manually\n */\n public async wait(): Promise<void> {\n if (this._closed) {\n throw new Error('Tunnel is closed')\n }\n\n return new Promise((resolve, reject) => {\n this.events.on('connectionFailed', (ev) => {\n reject(new ReconnectionFailedError(ev))\n })\n\n this.events.on('manuallyClosed', () => {\n resolve()\n })\n })\n }\n\n public close(): void {\n if (this._closed) {\n return\n }\n\n this._closed = true\n this._tunnel?.close()\n this.events.emit('manuallyClosed', null)\n }\n\n private _reconnectSync(ev: ReconnectionTriggerEvent): void {\n void this._reconnect(ev)\n .then((t) => {\n this._tunnel = t\n })\n .catch(() => this.events.emit('connectionFailed', ev))\n }\n\n private async _reconnect(ev: ReconnectionTriggerEvent): Promise<TunnelTail> {\n const newTunnel = async () => {\n const tunnel = await TunnelTail.new(this._tunnelUrl, this._tunnelId)\n this._registerListeners(tunnel)\n this.events.emit('connected', { tunnel, ev })\n return tunnel\n }\n\n if (ev.type === 'init') {\n // skip logging on the first connection attempt\n return newTunnel()\n }\n\n const line = this._logger.line()\n line.started('Reconnecting tunnel...')\n const tunnel = await newTunnel()\n line.success('Reconnected')\n line.commit()\n return tunnel\n }\n\n private _registerListeners(tunnel: TunnelTail) {\n tunnel.events.on('error', ({ target, type }) => {\n this._logger.error(`Tunnel error: ${type}`)\n this._reconnectSync({ type: 'error', ev: { target, type } })\n })\n tunnel.events.on('close', ({ code, reason, target, type, wasClean }) => {\n this._logger.error(`Tunnel closed: ${code} ${reason}`)\n this._reconnectSync({ type: 'close', ev: { code, reason, target, type, wasClean } })\n })\n }\n}\n"],
|
|
5
|
+
"mappings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AAE,MAAM,SAAS,IAAI,EAAE,MAAM,QAAQ,QAAQ,MAAM,SAAS,EAAE,CAAC;AAAA,IACrF,CAAC;AAAA,EACH;AACF;",
|
|
6
|
+
"names": ["tunnel"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var url_utils_exports = {};
|
|
20
|
+
__export(url_utils_exports, {
|
|
21
|
+
format: () => format,
|
|
22
|
+
parse: () => parse
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(url_utils_exports);
|
|
25
|
+
const PROTOCOLS = ["http", "https", "ws", "wss"];
|
|
26
|
+
const toPath = (path) => {
|
|
27
|
+
if (!path.startsWith("/")) {
|
|
28
|
+
return `/${path}`;
|
|
29
|
+
}
|
|
30
|
+
return path;
|
|
31
|
+
};
|
|
32
|
+
function parse(hostOrUrl) {
|
|
33
|
+
try {
|
|
34
|
+
const url = new URL(hostOrUrl);
|
|
35
|
+
return {
|
|
36
|
+
status: "success",
|
|
37
|
+
url: {
|
|
38
|
+
protocol: url.protocol.replace(":", ""),
|
|
39
|
+
host: url.hostname,
|
|
40
|
+
port: url.port ? parseInt(url.port) : void 0,
|
|
41
|
+
path: toPath(url.pathname)
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
} catch (thrown) {
|
|
45
|
+
const message = thrown instanceof Error ? thrown.message : `${thrown}`;
|
|
46
|
+
return {
|
|
47
|
+
status: "error",
|
|
48
|
+
error: message
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const format = (url) => {
|
|
53
|
+
let formatted = `${url.protocol}://${url.host}`;
|
|
54
|
+
if (url.port) {
|
|
55
|
+
formatted += `:${url.port}`;
|
|
56
|
+
}
|
|
57
|
+
if (url.path && url.path !== "/") {
|
|
58
|
+
formatted += url.path;
|
|
59
|
+
}
|
|
60
|
+
return formatted;
|
|
61
|
+
};
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
format,
|
|
65
|
+
parse
|
|
66
|
+
});
|
|
67
|
+
//# sourceMappingURL=url-utils.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/url-utils.ts"],
|
|
4
|
+
"sourcesContent": ["const PROTOCOLS = ['http', 'https', 'ws', 'wss'] as const\n\nexport type Protocol = (typeof PROTOCOLS)[number]\n\nexport type Path = `/${string}`\n\nexport type Url = {\n protocol: Protocol\n host: string\n port?: number\n path?: Path\n}\n\nexport type UrlParseResult =\n | {\n status: 'success'\n url: Url\n }\n | {\n status: 'error'\n error: string\n }\n\nconst toPath = (path: string): Path => {\n if (!path.startsWith('/')) {\n return `/${path}`\n }\n return path as Path\n}\n\nexport function parse(hostOrUrl: string): UrlParseResult {\n try {\n const url = new URL(hostOrUrl)\n return {\n status: 'success',\n url: {\n protocol: url.protocol.replace(':', '') as Url['protocol'],\n host: url.hostname,\n port: url.port ? parseInt(url.port) : undefined,\n path: toPath(url.pathname),\n },\n }\n } catch (thrown) {\n const message = thrown instanceof Error ? thrown.message : `${thrown}`\n return {\n status: 'error',\n error: message,\n }\n }\n}\n\nexport const format = (url: Url): string => {\n let formatted = `${url.protocol}://${url.host}`\n if (url.port) {\n formatted += `:${url.port}`\n }\n if (url.path && url.path !== '/') {\n formatted += url.path\n }\n return formatted\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAM,YAAY,CAAC,QAAQ,SAAS,MAAM,KAAK;AAuB/C,MAAM,SAAS,CAAC,SAAuB;AACrC,MAAI,CAAC,KAAK,WAAW,GAAG,GAAG;AACzB,WAAO,IAAI;AAAA,EACb;AACA,SAAO;AACT;AAEO,SAAS,MAAM,WAAmC;AACvD,MAAI;AACF,UAAM,MAAM,IAAI,IAAI,SAAS;AAC7B,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,KAAK;AAAA,QACH,UAAU,IAAI,SAAS,QAAQ,KAAK,EAAE;AAAA,QACtC,MAAM,IAAI;AAAA,QACV,MAAM,IAAI,OAAO,SAAS,IAAI,IAAI,IAAI;AAAA,QACtC,MAAM,OAAO,IAAI,QAAQ;AAAA,MAC3B;AAAA,IACF;AAAA,EACF,SAAS,QAAP;AACA,UAAM,UAAU,kBAAkB,QAAQ,OAAO,UAAU,GAAG;AAC9D,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,OAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,MAAM,SAAS,CAAC,QAAqB;AAC1C,MAAI,YAAY,GAAG,IAAI,cAAc,IAAI;AACzC,MAAI,IAAI,MAAM;AACZ,iBAAa,IAAI,IAAI;AAAA,EACvB;AACA,MAAI,IAAI,QAAQ,IAAI,SAAS,KAAK;AAChC,iBAAa,IAAI;AAAA,EACnB;AACA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -31,6 +31,9 @@ var childProcess = __toESM(require("child_process"));
|
|
|
31
31
|
var import_child_entrypoint = require("./child-entrypoint");
|
|
32
32
|
var import_config = require("./config");
|
|
33
33
|
var import_is_child = require("./is-child");
|
|
34
|
+
const SPAWN_SHELL_ENV = {
|
|
35
|
+
FORCE_COLOR: "true"
|
|
36
|
+
};
|
|
34
37
|
const listenForChildSpawn = (child, logger) => new Promise((resolve, reject) => {
|
|
35
38
|
child.on("spawn", () => {
|
|
36
39
|
logger.debug(`Child process spawned with pid ${child.pid}`);
|
|
@@ -72,6 +75,7 @@ class ChildProcessWrapper {
|
|
|
72
75
|
const child = childProcess.fork(import_child_entrypoint.ENTRY_POINT, [], {
|
|
73
76
|
stdio: "inherit",
|
|
74
77
|
env: {
|
|
78
|
+
...SPAWN_SHELL_ENV,
|
|
75
79
|
[import_is_child.CHILD_ENV_KEY]: import_is_child.CHILD_ENV_VALUE,
|
|
76
80
|
[import_config.CONFIG_ENV_KEY]: JSON.stringify(config),
|
|
77
81
|
...config.env
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/worker/child-wrapper.ts"],
|
|
4
|
-
"sourcesContent": ["import * as childProcess from 'child_process'\nimport type { Logger } from '../logger'\nimport { ENTRY_POINT } from './child-entrypoint'\nimport { CONFIG_ENV_KEY, Config } from './config'\nimport { CHILD_ENV_KEY, CHILD_ENV_VALUE, isChildProcess } from './is-child'\n\nexport type ChildOutput = {\n exitCode: number | null\n signal: NodeJS.Signals | null\n}\n\nconst listenForChildSpawn = (child: childProcess.ChildProcess, logger: Logger) =>\n new Promise<void>((resolve, reject) => {\n child.on('spawn', () => {\n logger.debug(`Child process spawned with pid ${child.pid}`)\n resolve()\n })\n child.on('error', (err: Error) => {\n /**\n * The 'error' event is emitted whenever:\n * - The process could not be spawned.\n * - The child process was aborted via the signal option.\n */\n logger.debug(`Child process error: ${err.message}`)\n reject(err)\n })\n })\n\nconst listenForChildExit = (child: childProcess.ChildProcess, logger: Logger) =>\n new Promise<ChildOutput>((resolve, reject) => {\n child.on('disconnect', () => {\n logger.debug('Child process disconnected')\n })\n child.on('close', (exitCode: number | null, signal: NodeJS.Signals | null) => {\n /**\n * this event usually fires after exit unless stdio streams are shared across multiple processes.\n * see https://stackoverflow.com/questions/37522010/difference-between-childprocess-close-exit-events\n */\n logger.debug(`Child process closed with code ${exitCode} and signal ${signal}`)\n })\n child.on('exit', (exitCode: number | null, signal: NodeJS.Signals | null) => {\n logger.debug(`Child process exited with code ${exitCode} and signal ${signal}`)\n resolve({ exitCode, signal })\n })\n child.on('error', (err: Error) => {\n /**\n * The 'error' event is emitted whenever:\n * - The process could not be killed.\n * - The child process was aborted via the signal option.\n */\n logger.debug(`Child process error: ${err.message}`)\n reject(err)\n })\n child.on('message', (message) => {\n logger.debug(`Child process message: ${message}`)\n })\n })\n\n/**\n * Wrapper above child_process.ChildProcess to simplify usage\n */\nexport class ChildProcessWrapper {\n public static async spawn(config: Config, logger: Logger): Promise<ChildProcessWrapper> {\n if (isChildProcess) {\n throw new Error('Cannot spawn child process from child process')\n }\n\n const child = childProcess.fork(ENTRY_POINT, [], {\n stdio: 'inherit',\n env: {\n [CHILD_ENV_KEY]: CHILD_ENV_VALUE,\n [CONFIG_ENV_KEY]: JSON.stringify(config),\n ...config.env,\n },\n })\n\n const childSpawnPromise = listenForChildSpawn(child, logger)\n const childExitPromise = listenForChildExit(child, logger)\n\n const instance = new ChildProcessWrapper(child, childExitPromise)\n\n childExitPromise.finally(() => {\n instance._exited = true\n })\n\n await childSpawnPromise\n\n return instance\n }\n\n private _exited = false\n private constructor(private _child: childProcess.ChildProcess, private _exitPromise: Promise<ChildOutput>) {}\n\n public async kill(): Promise<ChildOutput> {\n if (this._exited) {\n throw new Error('Child process already exited and cannot be killed')\n }\n this._child.kill()\n const res = await this._exitPromise\n return res\n }\n\n public async listen(): Promise<ChildOutput> {\n if (this._exited) {\n throw new Error('Child process already exited and cannot be listened on')\n }\n const res = await this._exitPromise\n return res\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8B;AAE9B,8BAA4B;AAC5B,oBAAuC;AACvC,sBAA+D;AAO/D,MAAM,sBAAsB,CAAC,OAAkC,WAC7D,IAAI,QAAc,CAAC,SAAS,WAAW;AACrC,QAAM,GAAG,SAAS,MAAM;AACtB,WAAO,MAAM,kCAAkC,MAAM,KAAK;AAC1D,YAAQ;AAAA,EACV,CAAC;AACD,QAAM,GAAG,SAAS,CAAC,QAAe;AAMhC,WAAO,MAAM,wBAAwB,IAAI,SAAS;AAClD,WAAO,GAAG;AAAA,EACZ,CAAC;AACH,CAAC;AAEH,MAAM,qBAAqB,CAAC,OAAkC,WAC5D,IAAI,QAAqB,CAAC,SAAS,WAAW;AAC5C,QAAM,GAAG,cAAc,MAAM;AAC3B,WAAO,MAAM,4BAA4B;AAAA,EAC3C,CAAC;AACD,QAAM,GAAG,SAAS,CAAC,UAAyB,WAAkC;AAK5E,WAAO,MAAM,kCAAkC,uBAAuB,QAAQ;AAAA,EAChF,CAAC;AACD,QAAM,GAAG,QAAQ,CAAC,UAAyB,WAAkC;AAC3E,WAAO,MAAM,kCAAkC,uBAAuB,QAAQ;AAC9E,YAAQ,EAAE,UAAU,OAAO,CAAC;AAAA,EAC9B,CAAC;AACD,QAAM,GAAG,SAAS,CAAC,QAAe;AAMhC,WAAO,MAAM,wBAAwB,IAAI,SAAS;AAClD,WAAO,GAAG;AAAA,EACZ,CAAC;AACD,QAAM,GAAG,WAAW,CAAC,YAAY;AAC/B,WAAO,MAAM,0BAA0B,SAAS;AAAA,EAClD,CAAC;AACH,CAAC;AAKI,MAAM,oBAAoB;AAAA,
|
|
4
|
+
"sourcesContent": ["import * as childProcess from 'child_process'\nimport type { Logger } from '../logger'\nimport { ENTRY_POINT } from './child-entrypoint'\nimport { CONFIG_ENV_KEY, Config } from './config'\nimport { CHILD_ENV_KEY, CHILD_ENV_VALUE, isChildProcess } from './is-child'\n\nexport type ChildOutput = {\n exitCode: number | null\n signal: NodeJS.Signals | null\n}\n\nconst SPAWN_SHELL_ENV: Record<string, string> = {\n FORCE_COLOR: 'true', // well-known env var used by most shells to enable color output in child processes\n} as const\n\nconst listenForChildSpawn = (child: childProcess.ChildProcess, logger: Logger) =>\n new Promise<void>((resolve, reject) => {\n child.on('spawn', () => {\n logger.debug(`Child process spawned with pid ${child.pid}`)\n resolve()\n })\n child.on('error', (err: Error) => {\n /**\n * The 'error' event is emitted whenever:\n * - The process could not be spawned.\n * - The child process was aborted via the signal option.\n */\n logger.debug(`Child process error: ${err.message}`)\n reject(err)\n })\n })\n\nconst listenForChildExit = (child: childProcess.ChildProcess, logger: Logger) =>\n new Promise<ChildOutput>((resolve, reject) => {\n child.on('disconnect', () => {\n logger.debug('Child process disconnected')\n })\n child.on('close', (exitCode: number | null, signal: NodeJS.Signals | null) => {\n /**\n * this event usually fires after exit unless stdio streams are shared across multiple processes.\n * see https://stackoverflow.com/questions/37522010/difference-between-childprocess-close-exit-events\n */\n logger.debug(`Child process closed with code ${exitCode} and signal ${signal}`)\n })\n child.on('exit', (exitCode: number | null, signal: NodeJS.Signals | null) => {\n logger.debug(`Child process exited with code ${exitCode} and signal ${signal}`)\n resolve({ exitCode, signal })\n })\n child.on('error', (err: Error) => {\n /**\n * The 'error' event is emitted whenever:\n * - The process could not be killed.\n * - The child process was aborted via the signal option.\n */\n logger.debug(`Child process error: ${err.message}`)\n reject(err)\n })\n child.on('message', (message) => {\n logger.debug(`Child process message: ${message}`)\n })\n })\n\n/**\n * Wrapper above child_process.ChildProcess to simplify usage\n */\nexport class ChildProcessWrapper {\n public static async spawn(config: Config, logger: Logger): Promise<ChildProcessWrapper> {\n if (isChildProcess) {\n throw new Error('Cannot spawn child process from child process')\n }\n\n const child = childProcess.fork(ENTRY_POINT, [], {\n stdio: 'inherit',\n env: {\n ...SPAWN_SHELL_ENV,\n [CHILD_ENV_KEY]: CHILD_ENV_VALUE,\n [CONFIG_ENV_KEY]: JSON.stringify(config),\n ...config.env,\n },\n })\n\n const childSpawnPromise = listenForChildSpawn(child, logger)\n const childExitPromise = listenForChildExit(child, logger)\n\n const instance = new ChildProcessWrapper(child, childExitPromise)\n\n childExitPromise.finally(() => {\n instance._exited = true\n })\n\n await childSpawnPromise\n\n return instance\n }\n\n private _exited = false\n private constructor(private _child: childProcess.ChildProcess, private _exitPromise: Promise<ChildOutput>) {}\n\n public async kill(): Promise<ChildOutput> {\n if (this._exited) {\n throw new Error('Child process already exited and cannot be killed')\n }\n this._child.kill()\n const res = await this._exitPromise\n return res\n }\n\n public async listen(): Promise<ChildOutput> {\n if (this._exited) {\n throw new Error('Child process already exited and cannot be listened on')\n }\n const res = await this._exitPromise\n return res\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8B;AAE9B,8BAA4B;AAC5B,oBAAuC;AACvC,sBAA+D;AAO/D,MAAM,kBAA0C;AAAA,EAC9C,aAAa;AACf;AAEA,MAAM,sBAAsB,CAAC,OAAkC,WAC7D,IAAI,QAAc,CAAC,SAAS,WAAW;AACrC,QAAM,GAAG,SAAS,MAAM;AACtB,WAAO,MAAM,kCAAkC,MAAM,KAAK;AAC1D,YAAQ;AAAA,EACV,CAAC;AACD,QAAM,GAAG,SAAS,CAAC,QAAe;AAMhC,WAAO,MAAM,wBAAwB,IAAI,SAAS;AAClD,WAAO,GAAG;AAAA,EACZ,CAAC;AACH,CAAC;AAEH,MAAM,qBAAqB,CAAC,OAAkC,WAC5D,IAAI,QAAqB,CAAC,SAAS,WAAW;AAC5C,QAAM,GAAG,cAAc,MAAM;AAC3B,WAAO,MAAM,4BAA4B;AAAA,EAC3C,CAAC;AACD,QAAM,GAAG,SAAS,CAAC,UAAyB,WAAkC;AAK5E,WAAO,MAAM,kCAAkC,u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EA,MAAa,SAA+B;AAC1C,QAAI,KAAK,SAAS;AAChB,YAAM,IAAI,MAAM,wDAAwD;AAAA,IAC1E;AACA,UAAM,MAAM,MAAM,KAAK;AACvB,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botpress/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Botpress CLI",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "pnpm run bundle && pnpm run template:gen",
|
|
@@ -18,13 +18,14 @@
|
|
|
18
18
|
},
|
|
19
19
|
"main": "dist/index.js",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@botpress/client": "0.1.
|
|
21
|
+
"@botpress/client": "0.1.2",
|
|
22
|
+
"@bpinternal/tunnel": "^0.0.2",
|
|
22
23
|
"@bpinternal/yargs-extra": "^0.0.3",
|
|
23
24
|
"@parcel/watcher": "^2.1.0",
|
|
24
25
|
"@types/lodash": "^4.14.191",
|
|
25
26
|
"@types/node": "^18.11.17",
|
|
26
27
|
"@types/verror": "^1.10.6",
|
|
27
|
-
"axios": "^1.
|
|
28
|
+
"axios": "^1.4.0",
|
|
28
29
|
"bluebird": "^3.7.2",
|
|
29
30
|
"boxen": "5.1.2",
|
|
30
31
|
"chalk": "^4.1.2",
|
|
@@ -44,7 +45,7 @@
|
|
|
44
45
|
"zod-to-json-schema": "^3.20.1"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"@botpress/sdk": "0.1.
|
|
48
|
+
"@botpress/sdk": "0.1.4",
|
|
48
49
|
"@types/bluebird": "^3.5.38",
|
|
49
50
|
"@types/prompts": "^2.0.14",
|
|
50
51
|
"@types/semver": "^7.3.11",
|