@botpress/cli 0.1.1 → 0.1.3
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-impl.js +2 -0
- package/dist/code-generation/integration-impl.js.map +2 -2
- package/dist/command-implementations/deploy-command.js +57 -3
- package/dist/command-implementations/deploy-command.js.map +2 -2
- package/dist/command-implementations/dev-command.js +59 -29
- package/dist/command-implementations/dev-command.js.map +2 -2
- package/dist/command-implementations/project-command.js +1 -1
- package/dist/command-implementations/project-command.js.map +2 -2
- package/dist/config.js +0 -1
- package/dist/config.js.map +2 -2
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +2 -2
- package/dist/utils/record-utils.js +40 -0
- package/dist/utils/record-utils.js.map +7 -0
- package/package.json +3 -3
- package/templates/echo-bot/package.json +1 -1
- package/templates/empty-integration/.botpress/implementation/index.ts +1 -0
- package/templates/empty-integration/package.json +1 -1
|
@@ -97,6 +97,8 @@ class IntegrationImplementationIndexModule extends import_module.Module {
|
|
|
97
97
|
content += "\n";
|
|
98
98
|
content += `export class Integration
|
|
99
99
|
extends sdk.Integration<${configModule.name}.${configModule.exports}, ${actionsModule.name}.${actionsModule.exports}, ${channelsModule.name}.${channelsModule.exports}, ${eventsModule.name}.${eventsModule.exports}> {}
|
|
100
|
+
`;
|
|
101
|
+
content += `export type IntegrationProps = sdk.IntegrationProps<${configModule.name}.${configModule.exports}, ${actionsModule.name}.${actionsModule.exports}, ${channelsModule.name}.${channelsModule.exports}, ${eventsModule.name}.${eventsModule.exports}>;
|
|
100
102
|
`;
|
|
101
103
|
return content;
|
|
102
104
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/code-generation/integration-impl.ts"],
|
|
4
|
-
"sourcesContent": ["import type { IntegrationDefinition } from '@botpress/sdk'\nimport bluebird from 'bluebird'\nimport { ActionModule } from './action'\nimport { ChannelModule } from './channel'\nimport { ConfigurationModule } from './configuration'\nimport { GENERATED_HEADER, INDEX_FILE } from './const'\nimport { EventModule } from './event'\nimport { Module, ModuleDef, ReExportTypeModule } from './module'\nimport type * as types from './typings'\n\nexport class IntegrationImplementationIndexModule extends Module {\n public static async create(integration: IntegrationDefinition): Promise<IntegrationImplementationIndexModule> {\n const configModule = await ConfigurationModule.create(integration.configuration ?? { schema: {} })\n\n const actionsModule = await ActionsModule.create(integration.actions ?? {})\n actionsModule.unshift('actions')\n\n const channelsModule = await ChannelsModule.create(integration.channels ?? {})\n channelsModule.unshift('channels')\n\n const eventsModule = await EventsModule.create(integration.events ?? {})\n eventsModule.unshift('events')\n\n const { name, version } = integration\n const inst = new IntegrationImplementationIndexModule(\n configModule,\n actionsModule,\n channelsModule,\n eventsModule,\n { name, version },\n {\n path: INDEX_FILE,\n exportName: 'Integration',\n content: '',\n }\n )\n\n inst.pushDep(configModule)\n inst.pushDep(actionsModule)\n inst.pushDep(channelsModule)\n inst.pushDep(eventsModule)\n return inst\n }\n\n private constructor(\n private configModule: ConfigurationModule,\n private actionsModule: ActionsModule,\n private channelsModule: ChannelsModule,\n private eventsModule: EventsModule,\n private integrationID: { name: string; version: string },\n def: ModuleDef\n ) {\n super(def)\n }\n\n public override get content(): string {\n let content = GENERATED_HEADER\n\n const { configModule, actionsModule, channelsModule, eventsModule } = this\n\n content += 'import * as sdk from \"@botpress/sdk\";\\n\\n'\n\n const configImport = configModule.import(this)\n const actionsImport = actionsModule.import(this)\n const channelsImport = channelsModule.import(this)\n const eventsImport = eventsModule.import(this)\n\n content += `import type * as ${configModule.name} from \"./${configImport}\";\\n`\n content += `import type * as ${actionsModule.name} from \"./${actionsImport}\";\\n`\n content += `import type * as ${channelsModule.name} from \"./${channelsImport}\";\\n`\n content += `import type * as ${eventsModule.name} from \"./${eventsImport}\";\\n`\n content += `export * as ${configModule.name} from \"./${configImport}\";\\n`\n content += `export * as ${actionsModule.name} from \"./${actionsImport}\";\\n`\n content += `export * as ${channelsModule.name} from \"./${channelsImport}\";\\n`\n content += `export * as ${eventsModule.name} from \"./${eventsImport}\";\\n`\n\n content += '\\n'\n\n content += `export class Integration\n extends sdk.Integration<${configModule.name}.${configModule.exports}, ${actionsModule.name}.${actionsModule.exports}, ${channelsModule.name}.${channelsModule.exports}, ${eventsModule.name}.${eventsModule.exports}> {}\\n`\n\n return content\n }\n}\n\nclass ChannelsModule extends ReExportTypeModule {\n public static async create(channels: Record<string, types.Channel>): Promise<ChannelsModule> {\n const channelModules = await bluebird.map(Object.entries(channels), async ([channelName, channel]) => {\n const mod = await ChannelModule.create(channelName, channel)\n return mod.unshift(channelName)\n })\n const inst = new ChannelsModule({ exportName: 'Channels' })\n inst.pushDep(...channelModules)\n return inst\n }\n}\n\nclass ActionsModule extends ReExportTypeModule {\n public static async create(actions: Record<string, types.Action>): Promise<ActionsModule> {\n const actionModules = await bluebird.map(Object.entries(actions), async ([actionName, action]) => {\n const mod = await ActionModule.create(actionName, action)\n return mod.unshift(actionName)\n })\n\n const inst = new ActionsModule({\n exportName: 'Actions',\n })\n\n inst.pushDep(...actionModules)\n return inst\n }\n}\n\nclass EventsModule extends ReExportTypeModule {\n public static async create(events: Record<string, types.Event>): Promise<EventsModule> {\n const eventModules = await bluebird.map(Object.entries(events), async ([eventName, event]) =>\n EventModule.create(eventName, event)\n )\n\n const inst = new EventsModule({\n exportName: 'Events',\n })\n inst.pushDep(...eventModules)\n return inst\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAqB;AACrB,oBAA6B;AAC7B,qBAA8B;AAC9B,2BAAoC;AACpC,mBAA6C;AAC7C,mBAA4B;AAC5B,oBAAsD;AAG/C,MAAM,6CAA6C,qBAAO;AAAA,EAkCvD,YACE,cACA,eACA,gBACA,cACA,eACR,KACA;AACA,UAAM,GAAG;AAPD;AACA;AACA;AACA;AACA;AAAA,EAIV;AAAA,EA1CA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EA,UAAM,OAAO,IAAI,aAAa;AAAA,MAC5B,YAAY;AAAA,IACd,CAAC;AACD,SAAK,QAAQ,GAAG,YAAY;AAC5B,WAAO;AAAA,EACT;AACF;",
|
|
4
|
+
"sourcesContent": ["import type { IntegrationDefinition } from '@botpress/sdk'\nimport bluebird from 'bluebird'\nimport { ActionModule } from './action'\nimport { ChannelModule } from './channel'\nimport { ConfigurationModule } from './configuration'\nimport { GENERATED_HEADER, INDEX_FILE } from './const'\nimport { EventModule } from './event'\nimport { Module, ModuleDef, ReExportTypeModule } from './module'\nimport type * as types from './typings'\n\nexport class IntegrationImplementationIndexModule extends Module {\n public static async create(integration: IntegrationDefinition): Promise<IntegrationImplementationIndexModule> {\n const configModule = await ConfigurationModule.create(integration.configuration ?? { schema: {} })\n\n const actionsModule = await ActionsModule.create(integration.actions ?? {})\n actionsModule.unshift('actions')\n\n const channelsModule = await ChannelsModule.create(integration.channels ?? {})\n channelsModule.unshift('channels')\n\n const eventsModule = await EventsModule.create(integration.events ?? {})\n eventsModule.unshift('events')\n\n const { name, version } = integration\n const inst = new IntegrationImplementationIndexModule(\n configModule,\n actionsModule,\n channelsModule,\n eventsModule,\n { name, version },\n {\n path: INDEX_FILE,\n exportName: 'Integration',\n content: '',\n }\n )\n\n inst.pushDep(configModule)\n inst.pushDep(actionsModule)\n inst.pushDep(channelsModule)\n inst.pushDep(eventsModule)\n return inst\n }\n\n private constructor(\n private configModule: ConfigurationModule,\n private actionsModule: ActionsModule,\n private channelsModule: ChannelsModule,\n private eventsModule: EventsModule,\n private integrationID: { name: string; version: string },\n def: ModuleDef\n ) {\n super(def)\n }\n\n public override get content(): string {\n let content = GENERATED_HEADER\n\n const { configModule, actionsModule, channelsModule, eventsModule } = this\n\n content += 'import * as sdk from \"@botpress/sdk\";\\n\\n'\n\n const configImport = configModule.import(this)\n const actionsImport = actionsModule.import(this)\n const channelsImport = channelsModule.import(this)\n const eventsImport = eventsModule.import(this)\n\n content += `import type * as ${configModule.name} from \"./${configImport}\";\\n`\n content += `import type * as ${actionsModule.name} from \"./${actionsImport}\";\\n`\n content += `import type * as ${channelsModule.name} from \"./${channelsImport}\";\\n`\n content += `import type * as ${eventsModule.name} from \"./${eventsImport}\";\\n`\n content += `export * as ${configModule.name} from \"./${configImport}\";\\n`\n content += `export * as ${actionsModule.name} from \"./${actionsImport}\";\\n`\n content += `export * as ${channelsModule.name} from \"./${channelsImport}\";\\n`\n content += `export * as ${eventsModule.name} from \"./${eventsImport}\";\\n`\n\n content += '\\n'\n\n content += `export class Integration\n extends sdk.Integration<${configModule.name}.${configModule.exports}, ${actionsModule.name}.${actionsModule.exports}, ${channelsModule.name}.${channelsModule.exports}, ${eventsModule.name}.${eventsModule.exports}> {}\\n`\n\n content += `export type IntegrationProps = sdk.IntegrationProps<${configModule.name}.${configModule.exports}, ${actionsModule.name}.${actionsModule.exports}, ${channelsModule.name}.${channelsModule.exports}, ${eventsModule.name}.${eventsModule.exports}>;\\n`\n\n return content\n }\n}\n\nclass ChannelsModule extends ReExportTypeModule {\n public static async create(channels: Record<string, types.Channel>): Promise<ChannelsModule> {\n const channelModules = await bluebird.map(Object.entries(channels), async ([channelName, channel]) => {\n const mod = await ChannelModule.create(channelName, channel)\n return mod.unshift(channelName)\n })\n const inst = new ChannelsModule({ exportName: 'Channels' })\n inst.pushDep(...channelModules)\n return inst\n }\n}\n\nclass ActionsModule extends ReExportTypeModule {\n public static async create(actions: Record<string, types.Action>): Promise<ActionsModule> {\n const actionModules = await bluebird.map(Object.entries(actions), async ([actionName, action]) => {\n const mod = await ActionModule.create(actionName, action)\n return mod.unshift(actionName)\n })\n\n const inst = new ActionsModule({\n exportName: 'Actions',\n })\n\n inst.pushDep(...actionModules)\n return inst\n }\n}\n\nclass EventsModule extends ReExportTypeModule {\n public static async create(events: Record<string, types.Event>): Promise<EventsModule> {\n const eventModules = await bluebird.map(Object.entries(events), async ([eventName, event]) =>\n EventModule.create(eventName, event)\n )\n\n const inst = new EventsModule({\n exportName: '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,OAAO,QAAQ,OAAO,GAAG,OAAO,CAAC,YAAY,MAAM,MAAM;AAChG,YAAM,MAAM,MAAM,2BAAa,OAAO,YAAY,MAAM;AACxD,aAAO,IAAI,QAAQ,UAAU;AAAA,IAC/B,CAAC;AAED,UAAM,OAAO,IAAI,cAAc;AAAA,MAC7B,YAAY;AAAA,IACd,CAAC;AAED,SAAK,QAAQ,GAAG,aAAa;AAC7B,WAAO;AAAA,EACT;AACF;AAEA,MAAM,qBAAqB,iCAAmB;AAAA,EAC5C,aAAoB,OAAO,QAA4D;AACrF,UAAM,eAAe,MAAM,gBAAAA,QAAS;AAAA,MAAI,OAAO,QAAQ,MAAM;AAAA,MAAG,OAAO,CAAC,WAAW,KAAK,MACtF,yBAAY,OAAO,WAAW,KAAK;AAAA,IACrC;AAEA,UAAM,OAAO,IAAI,aAAa;AAAA,MAC5B,YAAY;AAAA,IACd,CAAC;AACD,SAAK,QAAQ,GAAG,YAAY;AAC5B,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": ["bluebird"]
|
|
7
7
|
}
|
|
@@ -84,7 +84,11 @@ class DeployCommand extends import_project_command.ProjectCommand {
|
|
|
84
84
|
const line = this.logger.line();
|
|
85
85
|
line.started(`Deploying integration ${import_chalk.default.bold(integrationDef.name)} v${integrationDef.version}...`);
|
|
86
86
|
if (integration) {
|
|
87
|
-
|
|
87
|
+
const publishUpdateBody = this._prepareUpdateIntegrationBody(integration, {
|
|
88
|
+
id: integration.id,
|
|
89
|
+
...publishBody
|
|
90
|
+
});
|
|
91
|
+
await api.client.updateIntegration(publishUpdateBody).catch((thrown) => {
|
|
88
92
|
throw errors.BotpressCLIError.wrap(thrown, `Could not update integration "${integrationDef.name}"`);
|
|
89
93
|
});
|
|
90
94
|
} else {
|
|
@@ -94,6 +98,37 @@ class DeployCommand extends import_project_command.ProjectCommand {
|
|
|
94
98
|
}
|
|
95
99
|
line.success("Integration deployed");
|
|
96
100
|
}
|
|
101
|
+
_prepareUpdateIntegrationBody = (integration, body) => ({
|
|
102
|
+
...body,
|
|
103
|
+
actions: utils.records.setOnNullMissingValues(body.actions, integration.actions),
|
|
104
|
+
events: utils.records.setOnNullMissingValues(body.events, integration.events),
|
|
105
|
+
states: utils.records.setOnNullMissingValues(body.states, integration.states),
|
|
106
|
+
user: {
|
|
107
|
+
...body.user,
|
|
108
|
+
tags: utils.records.setOnNullMissingValues(body.user?.tags, integration.user?.tags)
|
|
109
|
+
},
|
|
110
|
+
channels: Object.entries(body.channels ?? {}).reduce((acc, [channelName, channelDef]) => {
|
|
111
|
+
const currentChannel = integration.channels[channelName];
|
|
112
|
+
return {
|
|
113
|
+
...acc,
|
|
114
|
+
[channelName]: {
|
|
115
|
+
...channelDef,
|
|
116
|
+
messages: utils.records.setOnNullMissingValues(channelDef.messages, currentChannel?.messages),
|
|
117
|
+
message: {
|
|
118
|
+
...channelDef.message,
|
|
119
|
+
tags: utils.records.setOnNullMissingValues(channelDef.message?.tags, currentChannel?.message.tags)
|
|
120
|
+
},
|
|
121
|
+
conversation: {
|
|
122
|
+
...channelDef.conversation,
|
|
123
|
+
tags: utils.records.setOnNullMissingValues(
|
|
124
|
+
channelDef.conversation?.tags,
|
|
125
|
+
currentChannel?.conversation.tags
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}, {})
|
|
131
|
+
});
|
|
97
132
|
_readMediaFile = async (filePurpose, filePath) => {
|
|
98
133
|
if (!filePath) {
|
|
99
134
|
return void 0;
|
|
@@ -137,7 +172,7 @@ class DeployCommand extends import_project_command.ProjectCommand {
|
|
|
137
172
|
const integrations = this.prepareIntegrations(botImpl, bot);
|
|
138
173
|
const line = this.logger.line();
|
|
139
174
|
line.started(`Deploying bot ${import_chalk.default.bold(bot.name)}...`);
|
|
140
|
-
const
|
|
175
|
+
const updateBotBody = this._prepareUpdateBotBody(bot, {
|
|
141
176
|
id: bot.id,
|
|
142
177
|
code,
|
|
143
178
|
states,
|
|
@@ -148,12 +183,31 @@ class DeployCommand extends import_project_command.ProjectCommand {
|
|
|
148
183
|
conversation,
|
|
149
184
|
message,
|
|
150
185
|
integrations
|
|
151
|
-
})
|
|
186
|
+
});
|
|
187
|
+
const { bot: updatedBot } = await api.client.updateBot(updateBotBody).catch((thrown) => {
|
|
152
188
|
throw errors.BotpressCLIError.wrap(thrown, `Could not update bot "${bot.name}"`);
|
|
153
189
|
});
|
|
154
190
|
line.success("Bot deployed");
|
|
155
191
|
this.displayWebhookUrls(updatedBot);
|
|
156
192
|
}
|
|
193
|
+
_prepareUpdateBotBody = (bot, body) => ({
|
|
194
|
+
...body,
|
|
195
|
+
states: utils.records.setOnNullMissingValues(body.states, bot.states),
|
|
196
|
+
recurringEvents: utils.records.setOnNullMissingValues(body.recurringEvents, bot.recurringEvents),
|
|
197
|
+
events: utils.records.setOnNullMissingValues(body.events, bot.events),
|
|
198
|
+
user: {
|
|
199
|
+
...body.user,
|
|
200
|
+
tags: utils.records.setOnNullMissingValues(body.user?.tags, bot.user?.tags)
|
|
201
|
+
},
|
|
202
|
+
conversation: {
|
|
203
|
+
...body.conversation,
|
|
204
|
+
tags: utils.records.setOnNullMissingValues(body.conversation?.tags, bot.conversation?.tags)
|
|
205
|
+
},
|
|
206
|
+
message: {
|
|
207
|
+
...body.message,
|
|
208
|
+
tags: utils.records.setOnNullMissingValues(body.message?.tags, bot.message?.tags)
|
|
209
|
+
}
|
|
210
|
+
});
|
|
157
211
|
async _createNewBot(api) {
|
|
158
212
|
const line = this.logger.line();
|
|
159
213
|
const { bot: createdBot } = await api.client.createBot({}).catch((thrown) => {
|
|
@@ -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\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.host !== consts.defaultBotpressApi) {\n this.logger.log(`Using custom host ${api.host}`)\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: Parameters<typeof api.client.createIntegration>[0] = {\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 await api.client.updateIntegration({ id: integration.id, ...publishBody }).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 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 const { bot: updatedBot } = await api.client\n .updateBot({\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 .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 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;
|
|
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.host !== consts.defaultBotpressApi) {\n this.logger.log(`Using custom host ${api.host}`)\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,SAAS,OAAO,oBAAoB;AAC1C,WAAK,OAAO,IAAI,qBAAqB,IAAI,MAAM;AAAA,IACjD;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,GAAG,SAAS,SAAS,SAAS,OAAO;AAEtD,UAAM,UAAU,MAAM,KAAK,cAAc,gBAAgB,KAAK,IAAI;AAElE,eAAW,CAAC,YAAY,WAAW,KAAK,OAAO,QAAQ,OAAO,GAAG;AAC/D,aAAO,KAAK,QAAQ,IAAI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SAAS,WAAW,EAAE;AAClD,WAAO;AAAA,EACT;AAAA,EAEA,MAAc,gBAAgB,KAAgB,OAAkD;AAC9F,UAAM,gBAAgB,MAAM,KAAK,aAAa,KAAK,SAAS,OAAO,OAAO,cAAc;AACtF,YAAM,WAAW,MAAM,IACpB,aAAa,IAAI,OAAO,UAAU,CAAC,MAAM,EAAE,IAAI,EAC/C,MAAM,CAAC,WAAW;AACjB,cAAM,OAAO,iBAAiB,KAAK,QAAQ,+BAA+B;AAAA,MAC5E,CAAC;AAEH,UAAI,CAAC,SAAS,QAAQ;AACpB,cAAM,IAAI,OAAO,iBAAiB;AAAA,MACpC;AAEA,YAAM,UAAU,SAAS,KAAK,CAAC,QAAQ,IAAI,OAAO,SAAS;AAE3D,YAAM,WAAW,MAAM,KAAK,OAAO,OAAO,oCAAoC;AAAA,QAC5E,SAAS,WAAW,EAAE,OAAO,QAAQ,MAAM,OAAO,QAAQ,GAAG;AAAA,QAC7D,SAAS,SAAS,IAAI,CAAC,SAAS,EAAE,OAAO,IAAI,MAAM,OAAO,IAAI,GAAG,EAAE;AAAA,MACrE,CAAC;AAED,UAAI,CAAC,UAAU;AACb,cAAM,IAAI,OAAO,mBAAmB,QAAQ;AAAA,MAC9C;AAEA,aAAO;AAAA,IACT,CAAC;AAED,UAAM,EAAE,KAAK,WAAW,IAAI,MAAM,IAAI,OAAO,OAAO,EAAE,IAAI,cAAc,CAAC,EAAE,MAAM,CAAC,WAAW;AAC3F,YAAM,OAAO,iBAAiB,KAAK,QAAQ,wBAAwB;AAAA,IACrE,CAAC;AAED,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": ["chalk"]
|
|
7
7
|
}
|
|
@@ -35,38 +35,22 @@ var import_worker = require("../worker");
|
|
|
35
35
|
var import_build_command = require("./build-command");
|
|
36
36
|
var import_project_command = require("./project-command");
|
|
37
37
|
class DevCommand extends import_project_command.ProjectCommand {
|
|
38
|
+
_initialDef = void 0;
|
|
38
39
|
async run() {
|
|
39
40
|
this.logger.warn("This command is experimental and subject to breaking changes without notice.");
|
|
40
|
-
if (!this.argv.noBuild) {
|
|
41
|
-
await this._runBuild();
|
|
42
|
-
}
|
|
43
41
|
const api = await this.ensureLoginAndCreateClient(this.argv);
|
|
44
|
-
|
|
42
|
+
this._initialDef = await this.readIntegrationDefinitionFromFS();
|
|
45
43
|
let env = {
|
|
46
44
|
BP_API_URL: api.host,
|
|
47
45
|
BP_TOKEN: api.token
|
|
48
46
|
};
|
|
49
|
-
if (
|
|
50
|
-
await this.
|
|
51
|
-
const secrets = await this.promptSecrets(integrationDef, this.argv);
|
|
47
|
+
if (this._initialDef) {
|
|
48
|
+
const secrets = await this.promptSecrets(this._initialDef, this.argv);
|
|
52
49
|
env = { ...env, ...secrets };
|
|
53
|
-
} else {
|
|
54
|
-
await this._deployDevBot(api, this.argv.url);
|
|
55
50
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
const code = `require('${requireFrom}').default.start(${this.argv.port})`;
|
|
60
|
-
const worker = await import_worker.Worker.spawn(
|
|
61
|
-
{
|
|
62
|
-
type: "code",
|
|
63
|
-
code,
|
|
64
|
-
env
|
|
65
|
-
},
|
|
66
|
-
this.logger
|
|
67
|
-
).catch((thrown) => {
|
|
68
|
-
throw errors.BotpressCLIError.wrap(thrown, "Could not start dev worker");
|
|
69
|
-
});
|
|
51
|
+
await this._deploy(api);
|
|
52
|
+
await this._runBuild();
|
|
53
|
+
const worker = await this._spawnWorker(env);
|
|
70
54
|
try {
|
|
71
55
|
const watcher = await utils.filewatcher.FileWatcher.watch(
|
|
72
56
|
this.argv.workDir,
|
|
@@ -75,11 +59,12 @@ class DevCommand extends import_project_command.ProjectCommand {
|
|
|
75
59
|
if (typescriptEvents.length === 0) {
|
|
76
60
|
return;
|
|
77
61
|
}
|
|
78
|
-
this.logger.log("Changes detected,
|
|
79
|
-
await this.
|
|
80
|
-
await worker.reload();
|
|
62
|
+
this.logger.log("Changes detected, rebuilding");
|
|
63
|
+
await this._restart(api, worker);
|
|
81
64
|
},
|
|
82
|
-
{
|
|
65
|
+
{
|
|
66
|
+
ignore: [this.projectPaths.abs.outDir]
|
|
67
|
+
}
|
|
83
68
|
);
|
|
84
69
|
await Promise.race([worker.wait(), watcher.wait()]);
|
|
85
70
|
await watcher.close();
|
|
@@ -91,6 +76,51 @@ class DevCommand extends import_project_command.ProjectCommand {
|
|
|
91
76
|
}
|
|
92
77
|
}
|
|
93
78
|
}
|
|
79
|
+
_restart = async (api, worker) => {
|
|
80
|
+
await this._deploy(api);
|
|
81
|
+
try {
|
|
82
|
+
await this._runBuild();
|
|
83
|
+
} catch (thrown) {
|
|
84
|
+
const error = errors.BotpressCLIError.wrap(thrown, "Build failed");
|
|
85
|
+
this.logger.error(error.message);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
await worker.reload();
|
|
89
|
+
};
|
|
90
|
+
_deploy = async (api) => {
|
|
91
|
+
const integrationDef = await this.readIntegrationDefinitionFromFS();
|
|
92
|
+
if (integrationDef) {
|
|
93
|
+
this._checkSecrets(integrationDef);
|
|
94
|
+
await this._deployDevIntegration(api, this.argv.url, integrationDef);
|
|
95
|
+
} else {
|
|
96
|
+
await this._deployDevBot(api, this.argv.url);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
_checkSecrets(integrationDef) {
|
|
100
|
+
const initialSecrets = this._initialDef?.secrets ?? [];
|
|
101
|
+
const currentSecrets = integrationDef.secrets ?? [];
|
|
102
|
+
const newSecrets = currentSecrets.filter((s) => !initialSecrets.includes(s));
|
|
103
|
+
if (newSecrets.length > 0) {
|
|
104
|
+
throw new errors.BotpressCLIError("Secrets were added while the server was running. A restart is required.");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
_spawnWorker = async (env) => {
|
|
108
|
+
const outfile = this.projectPaths.abs.outFile;
|
|
109
|
+
const importPath = utils.path.toUnix(outfile);
|
|
110
|
+
const requireFrom = utils.path.rmExtension(importPath);
|
|
111
|
+
const code = `require('${requireFrom}').default.start(${this.argv.port})`;
|
|
112
|
+
const worker = await import_worker.Worker.spawn(
|
|
113
|
+
{
|
|
114
|
+
type: "code",
|
|
115
|
+
code,
|
|
116
|
+
env
|
|
117
|
+
},
|
|
118
|
+
this.logger
|
|
119
|
+
).catch((thrown) => {
|
|
120
|
+
throw errors.BotpressCLIError.wrap(thrown, "Could not start dev worker");
|
|
121
|
+
});
|
|
122
|
+
return worker;
|
|
123
|
+
};
|
|
94
124
|
_runBuild() {
|
|
95
125
|
return new import_build_command.BuildCommand(this.api, this.prompt, this.logger, this.argv).run();
|
|
96
126
|
}
|
|
@@ -157,11 +187,11 @@ class DevCommand extends import_project_command.ProjectCommand {
|
|
|
157
187
|
const { default: botImpl } = utils.require.requireJsFile(outfile);
|
|
158
188
|
const integrations = this.prepareIntegrations(botImpl, bot);
|
|
159
189
|
const updateLine = this.logger.line();
|
|
160
|
-
updateLine.started("
|
|
190
|
+
updateLine.started("Deploying dev bot...");
|
|
161
191
|
const { bot: updatedBot } = await api.client.updateBot({ id: bot.id, integrations, url: externalUrl }).catch((thrown) => {
|
|
162
192
|
throw errors.BotpressCLIError.wrap(thrown, "Could not deploy dev bot");
|
|
163
193
|
});
|
|
164
|
-
updateLine.success("
|
|
194
|
+
updateLine.success("Dev Bot deployed");
|
|
165
195
|
this.displayWebhookUrls(updatedBot);
|
|
166
196
|
}
|
|
167
197
|
}
|
|
@@ -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 public async run(): Promise<void> {\n this.logger.warn('This command is experimental and subject to breaking changes without notice.')\n\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAkB;AAClB,cAAyB;AAGzB,aAAwB;AACxB,YAAuB;AACvB,oBAAuB;AACvB,2BAA6B;AAC7B,6BAA+B;AAExB,MAAM,mBAAmB,sCAAqC;AAAA,
|
|
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.host,\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;AAEA,mBAAkB;AAClB,cAAyB;AAGzB,aAAwB;AACxB,YAAuB;AACvB,oBAAuB;AACvB,2BAA6B;AAC7B,6BAA+B;AAExB,MAAM,mBAAmB,sCAAqC;AAAA,EAC3D,cAAiD;AAAA,EAEzD,MAAa,MAAqB;AAChC,SAAK,OAAO,KAAK,8EAA8E;AAE/F,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAE3D,SAAK,cAAc,MAAM,KAAK,gCAAgC;AAE9D,QAAI,MAA8B;AAAA,MAChC,YAAY,IAAI;AAAA,MAChB,UAAU,IAAI;AAAA,IAChB;AAEA,QAAI,KAAK,aAAa;AACpB,YAAM,UAAU,MAAM,KAAK,cAAc,KAAK,aAAa,KAAK,IAAI;AACpE,YAAM,EAAE,GAAG,KAAK,GAAG,QAAQ;AAAA,IAC7B;AAEA,UAAM,KAAK,QAAQ,GAAG;AACtB,UAAM,KAAK,UAAU;AACrB,UAAM,SAAS,MAAM,KAAK,aAAa,GAAG;AAE1C,QAAI;AACF,YAAM,UAAU,MAAM,MAAM,YAAY,YAAY;AAAA,QAClD,KAAK,KAAK;AAAA,QACV,OAAO,WAAW;AAChB,gBAAM,mBAAmB,OAAO,OAAO,CAAC,MAAM,QAAQ,QAAQ,EAAE,IAAI,MAAM,KAAK;AAC/E,cAAI,iBAAiB,WAAW,GAAG;AACjC;AAAA,UACF;AAEA,eAAK,OAAO,IAAI,8BAA8B;AAC9C,gBAAM,KAAK,SAAS,KAAK,MAAM;AAAA,QACjC;AAAA,QACA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IAAI,KAAK;AACxD,YAAM,KAAK,aAAa,IAAI,SAAS,IAAI,EAAE;AAAA,IAC7C;AAEA,UAAM,UAAU,KAAK,aAAa,IAAI;AACtC,UAAM,EAAE,SAAS,QAAQ,IAAI,MAAM,QAAQ,cAAoC,OAAO;AAEtF,UAAM,eAAe,KAAK,oBAAoB,SAAS,GAAG;AAE1D,UAAM,aAAa,KAAK,OAAO,KAAK;AACpC,eAAW,QAAQ,sBAAsB;AAEzC,UAAM,EAAE,KAAK,WAAW,IAAI,MAAM,IAAI,OACnC,UAAU,EAAE,IAAI,IAAI,IAAI,cAAc,KAAK,YAAY,CAAC,EACxD,MAAM,CAAC,WAAW;AACjB,YAAM,OAAO,iBAAiB,KAAK,QAAQ,0BAA0B;AAAA,IACvE,CAAC;AACH,eAAW,QAAQ,kBAAkB;AAErC,SAAK,mBAAmB,UAAU;AAAA,EACpC;AACF;",
|
|
6
6
|
"names": ["chalk"]
|
|
7
7
|
}
|
|
@@ -93,7 +93,7 @@ class ProjectCommand extends import_global_command.GlobalCommand {
|
|
|
93
93
|
}
|
|
94
94
|
displayWebhookUrls(bot) {
|
|
95
95
|
if (!import_lodash.default.keys(bot.integrations).length) {
|
|
96
|
-
this.logger.
|
|
96
|
+
this.logger.debug("No integrations in bot");
|
|
97
97
|
return;
|
|
98
98
|
}
|
|
99
99
|
this.logger.log("Integrations:");
|
|
@@ -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(\n botImpl: BotImpl,\n botInfo: bpclient.Bot\n ): Parameters<bpclient.Client['updateBot']>[0]['integrations'] {\n const { integrations: integrationList } = botImpl.definition\n\n const integrationsToUninstall = _(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 = _(integrationList ?? [])\n .keyBy((i) => i.id)\n .mapValues(({ enabled, configuration }) => ({ enabled, configuration }))\n .value()\n\n return { ...integrationsToUninstall, ...integrationsToInstall } as Record<string, any> // TODO: fix client typings\n }\n\n protected displayWebhookUrls(bot: bpclient.Bot) {\n if (!_.keys(bot.integrations).length) {\n this.logger.
|
|
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;AAS9B,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,CAA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;AAAA,EACF;AAAA,EAEU,oBACR,SACA,SAC6D;AAC7D,UAAM,EAAE,cAAc,gBAAgB,IAAI,QAAQ;AAElD,UAAM,8BAA0B,cAAAD,SAAE,QAAQ,YAAY,EACnD,KAAK,EACL,OAAO,CAAC,QAAQ,CAAC,iBAAiB,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,SAAS,GAAG,CAAC,EAChE,UAAU,EACV,UAAU,MAAM,IAAI,EACpB,MAAM;AAET,UAAM,4BAAwB,cAAAA,SAAE,mBAAmB,CAAC,CAAC,EAClD,MAAM,CAAC,MAAM,EAAE,EAAE,EACjB,UAAU,CAAC,EAAE,SAAS,cAAc,OAAO,EAAE,SAAS,cAAc,EAAE,EACtE,MAAM;AAET,WAAO,EAAE,GAAG,yBAAyB,GAAG,sBAAsB;AAAA,EAChE;AAAA,EAEU,mBAAmB,KAAmB;AAC9C,QAAI,CAAC,cAAAA,QAAE,KAAK,IAAI,YAAY,EAAE,QAAQ;AACpC,WAAK,OAAO,
|
|
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(\n botImpl: BotImpl,\n botInfo: bpclient.Bot\n ): Parameters<bpclient.Client['updateBot']>[0]['integrations'] {\n const { integrations: integrationList } = botImpl.definition\n\n const integrationsToUninstall = _(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 = _(integrationList ?? [])\n .keyBy((i) => i.id)\n .mapValues(({ enabled, configuration }) => ({ enabled, configuration }))\n .value()\n\n return { ...integrationsToUninstall, ...integrationsToInstall } as Record<string, any> // TODO: fix client typings\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;AAS9B,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,YAAY,CAAC,CAAC;AAAA,IAClF,CAAC;AAAA,EACH;AACF;AAEO,MAAe,uBAA2D,oCAAiB;AAAA,EAChG,IAAc,eAAe;AAC3B,WAAO,IAAI,aAAa,KAAK,IAAI;AAAA,EACnC;AAAA,EAEA,IAAc,eAAe;AAC3B,WAAO,IAAI,MAAM,MAAM,gBAA8B,KAAK,aA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,YAAM,aAAa,WAAW;AAC9B,UAAI,YAAY;AACd,aAAK,OAAO,MAAM,iBAAiB,sBAAsB;AACzD,eAAO,aAAa;AACpB;AAAA,MACF;AAEA,YAAM,WAAW,MAAM,KAAK,OAAO,KAAK,2BAA2B,YAAY;AAC/E,UAAI,CAAC,UAAU;AACb,cAAM,IAAI,OAAO,iBAAiB,oBAAoB;AAAA,MACxD;AACA,aAAO,aAAa;AAAA,IACtB;AAEA,UAAM,eAAe,cAAAH,QAAE,QAAQ,QAAQ,CAAC,IAAI,MAAM,QAAQ,sBAAsB,CAAC,CAAC;AAClF,WAAO;AAAA,EACT;AAAA,EAEQ,kBAAkB,aAA+C;AACvE,UAAM,SAAiC,CAAC;AACxC,eAAW,UAAU,aAAa;AAChC,YAAM,CAAC,KAAK,KAAK,IAAI,KAAK,WAAW,QAAQ,GAAG;AAChD,UAAI,CAAC,OAAO;AACV,cAAM,IAAI,OAAO;AAAA,UACf,WAAW;AAAA,QACb;AAAA,MACF;AACA,aAAO,OAAQ;AAAA,IACjB;AAEA,WAAO;AAAA,EACT;AAAA,EAEQ,aAAa,CAAC,MAAc,cAAoD;AACtF,UAAM,QAAQ,KAAK,QAAQ,SAAS;AACpC,QAAI,UAAU,IAAI;AAChB,aAAO,CAAC,MAAM,MAAS;AAAA,IACzB;AACA,WAAO,CAAC,KAAK,MAAM,GAAG,KAAK,GAAG,KAAK,MAAM,QAAQ,CAAC,CAAC;AAAA,EACrD;AACF;",
|
|
6
6
|
"names": ["_", "fs", "pathlib", "chalk"]
|
|
7
7
|
}
|
package/dist/config.js
CHANGED
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 host = {\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 host,\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 url: {\n type: 'string',\n description: 'The publicly available URL of the bot or integration (often using ngrok)',\n demandOption: true,\n },\n port,\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,OAAO;AAAA,EACX,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,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,GAAG;AAAA,EACH,GAAG;AAAA,EACH,KAAK;AAAA,IACH,MAAM;AAAA,IACN,aAAa;AAAA,IACb,cAAc;AAAA,EAChB;AAAA,EACA;AAAA,EACA;
|
|
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 host = {\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 host,\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 url: {\n type: 'string',\n description: 'The publicly available URL of the bot or integration (often using ngrok)',\n demandOption: true,\n },\n port,\n sourceMap,\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 host: { ...host, default: consts.defaultBotpressApi },\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,OAAO;AAAA,EACX,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;A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EACH,GAAG;AAAA,EACH;AACF;AAEA,MAAM,aAAa;AAAA,EACjB,GAAG;AAAA,EACH;AAAA,EACA,MAAM,EAAE,MAAM,UAAU,SAAS,CAAC,OAAO,aAAa,EAAW;AAAA,EACjE,MAAM,EAAE,MAAM,UAAU,aAAa,0BAA0B;AACjE;AAIO,MAAM,UAAU;AAAA,EACrB,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,aAAa;AAAA,EACb,SAAS;AAAA,EAET,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,kBAAkB;AAAA,EAClB,mBAAmB;AAAA,EACnB,MAAM;AAAA,EACN,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,KAAK;AACP;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/utils/index.js
CHANGED
|
@@ -31,6 +31,7 @@ __export(utils_exports, {
|
|
|
31
31
|
filewatcher: () => filewatcher,
|
|
32
32
|
path: () => path,
|
|
33
33
|
prompt: () => prompt,
|
|
34
|
+
records: () => records,
|
|
34
35
|
require: () => require2
|
|
35
36
|
});
|
|
36
37
|
module.exports = __toCommonJS(utils_exports);
|
|
@@ -42,6 +43,7 @@ var emitter = __toESM(require("./event-emitter"));
|
|
|
42
43
|
var cache = __toESM(require("./cache-utils"));
|
|
43
44
|
var casing = __toESM(require("./case-utils"));
|
|
44
45
|
var prompt = __toESM(require("./prompt-utils"));
|
|
46
|
+
var records = __toESM(require("./record-utils"));
|
|
45
47
|
// Annotate the CommonJS export names for ESM import in node:
|
|
46
48
|
0 && (module.exports = {
|
|
47
49
|
cache,
|
|
@@ -51,6 +53,7 @@ var prompt = __toESM(require("./prompt-utils"));
|
|
|
51
53
|
filewatcher,
|
|
52
54
|
path,
|
|
53
55
|
prompt,
|
|
56
|
+
records,
|
|
54
57
|
require
|
|
55
58
|
});
|
|
56
59
|
//# 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'\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;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;",
|
|
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;",
|
|
6
6
|
"names": ["require"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 record_utils_exports = {};
|
|
20
|
+
__export(record_utils_exports, {
|
|
21
|
+
setOnNullMissingValues: () => setOnNullMissingValues
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(record_utils_exports);
|
|
24
|
+
const setOnNullMissingValues = (record = {}, oldRecord = {}) => {
|
|
25
|
+
const newRecord = {};
|
|
26
|
+
for (const [key, value] of Object.entries(record)) {
|
|
27
|
+
newRecord[key] = value;
|
|
28
|
+
}
|
|
29
|
+
for (const value of Object.keys(oldRecord)) {
|
|
30
|
+
if (!record[value]) {
|
|
31
|
+
newRecord[value] = null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return newRecord;
|
|
35
|
+
};
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
setOnNullMissingValues
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=record-utils.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/record-utils.ts"],
|
|
4
|
+
"sourcesContent": ["export const setOnNullMissingValues = <A, B>(\n record: Record<string, A> = {},\n oldRecord: Record<string, B> = {}\n): Record<string, A | null> => {\n const newRecord: Record<string, A | null> = {}\n\n for (const [key, value] of Object.entries(record)) {\n newRecord[key] = value\n }\n\n for (const value of Object.keys(oldRecord)) {\n if (!record[value]) {\n newRecord[value] = null\n }\n }\n\n return newRecord\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,yBAAyB,CACpC,SAA4B,CAAC,GAC7B,YAA+B,CAAC,MACH;AAC7B,QAAM,YAAsC,CAAC;AAE7C,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AACjD,cAAU,OAAO;AAAA,EACnB;AAEA,aAAW,SAAS,OAAO,KAAK,SAAS,GAAG;AAC1C,QAAI,CAAC,OAAO,QAAQ;AAClB,gBAAU,SAAS;AAAA,IACrB;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botpress/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Botpress CLI",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "pnpm run bundle && pnpm run template:gen",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"start": "node dist/index.js",
|
|
9
9
|
"type:check": "tsc --noEmit",
|
|
10
10
|
"bundle": "ts-node -T build.ts",
|
|
11
|
-
"template:gen": "pnpm -r --stream -F
|
|
11
|
+
"template:gen": "pnpm -r --stream -F echo-bot -F empty-integration exec bp gen"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [],
|
|
14
14
|
"author": "",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"zod-to-json-schema": "^3.20.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@botpress/sdk": "0.1.
|
|
47
|
+
"@botpress/sdk": "0.1.2",
|
|
48
48
|
"@types/bluebird": "^3.5.38",
|
|
49
49
|
"@types/prompts": "^2.0.14",
|
|
50
50
|
"@types/semver": "^7.3.11",
|
|
@@ -15,3 +15,4 @@ export * as events from "./events/index";
|
|
|
15
15
|
|
|
16
16
|
export class Integration
|
|
17
17
|
extends sdk.Integration<configuration.Configuration, actions.Actions, channels.Channels, events.Events> {}
|
|
18
|
+
export type IntegrationProps = sdk.IntegrationProps<configuration.Configuration, actions.Actions, channels.Channels, events.Events>;
|