@botpress/cli 4.27.3 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +13 -13
- package/dist/code-generation/bot-implementation/bot-implementation.js +2 -3
- package/dist/code-generation/bot-implementation/bot-implementation.js.map +2 -2
- package/dist/code-generation/bot-implementation/bot-plugins/plugin-module.js +2 -2
- package/dist/code-generation/bot-implementation/bot-plugins/plugin-module.js.map +2 -2
- package/dist/code-generation/plugin-implementation/plugin-implementation.js +2 -3
- package/dist/code-generation/plugin-implementation/plugin-implementation.js.map +2 -2
- package/dist/code-generation/plugin-implementation/plugin-typings/conversation-module.d.ts +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/conversation-module.js +63 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/conversation-module.js.map +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/index.js +32 -2
- package/dist/code-generation/plugin-implementation/plugin-typings/index.js.map +2 -2
- package/dist/code-generation/plugin-implementation/plugin-typings/message-module.d.ts +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/message-module.js +63 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/message-module.js.map +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/user-module.d.ts +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/user-module.js +63 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/user-module.js.map +7 -0
- package/dist/command-definitions.d.ts +57 -5
- package/dist/command-definitions.js +10 -1
- package/dist/command-definitions.js.map +2 -2
- package/dist/command-implementations/add-command.d.ts +2 -0
- package/dist/command-implementations/add-command.js +52 -25
- package/dist/command-implementations/add-command.js.map +2 -2
- package/dist/command-implementations/index.d.ts +59 -5
- package/dist/command-implementations/index.js +2 -0
- package/dist/command-implementations/index.js.map +2 -2
- package/dist/command-implementations/project-command.d.ts +1 -0
- package/dist/command-implementations/project-command.js +62 -29
- package/dist/command-implementations/project-command.js.map +2 -2
- package/dist/command-implementations/remove-command.d.ts +10 -0
- package/dist/command-implementations/remove-command.js +95 -0
- package/dist/command-implementations/remove-command.js.map +7 -0
- package/dist/config.d.ts +52 -5
- package/dist/config.js +8 -7
- package/dist/config.js.map +2 -2
- package/dist/index.d.ts +59 -5
- package/dist/index.js +1 -0
- package/dist/index.js.map +2 -2
- package/dist/register-yargs.js +8 -1
- package/dist/register-yargs.js.map +2 -2
- package/dist/typings.d.ts +1 -1
- package/dist/typings.js.map +1 -1
- package/dist/utils/pkgjson-utils.d.ts +2 -0
- package/dist/utils/pkgjson-utils.js +7 -2
- package/dist/utils/pkgjson-utils.js.map +2 -2
- package/package.json +2 -2
- package/templates/empty-bot/package.json +1 -1
- package/templates/empty-integration/package.json +1 -1
- package/templates/empty-plugin/package.json +1 -1
- package/templates/hello-world/package.json +1 -1
- package/templates/webhook-message/package.json +1 -1
|
@@ -70,6 +70,7 @@ class ProjectDefinitionContext {
|
|
|
70
70
|
}
|
|
71
71
|
class ProjectCommand extends import_global_command.GlobalCommand {
|
|
72
72
|
projectContext = new ProjectDefinitionContext();
|
|
73
|
+
_dependencyCache = /* @__PURE__ */ new Map();
|
|
73
74
|
setProjectContext(projectContext) {
|
|
74
75
|
this.projectContext = projectContext;
|
|
75
76
|
return this;
|
|
@@ -465,20 +466,28 @@ class ProjectCommand extends import_global_command.GlobalCommand {
|
|
|
465
466
|
};
|
|
466
467
|
}
|
|
467
468
|
async prepareBotDependencies(botDef, api) {
|
|
468
|
-
const integrations = await this._fetchDependencies(
|
|
469
|
-
botDef.integrations ?? {},
|
|
470
|
-
({ name, version }) => api.getPublicOrPrivateIntegration({ type: "name", name, version })
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
469
|
+
const integrations = await this._fetchDependencies({
|
|
470
|
+
deps: botDef.integrations ?? {},
|
|
471
|
+
fetcher: ({ name, version }) => api.getPublicOrPrivateIntegration({ type: "name", name, version }),
|
|
472
|
+
cacheKey: ({ name, version }) => `integration:${name}@${version}`
|
|
473
|
+
});
|
|
474
|
+
const plugins = await this._fetchDependencies({
|
|
475
|
+
deps: botDef.plugins ?? {},
|
|
476
|
+
fetcher: async ({ name, version }) => await api.getPublicOrPrivatePlugin({ type: "name", name, version }),
|
|
477
|
+
cacheKey: ({ name, version }) => `plugin:${name}@${version}`
|
|
478
|
+
});
|
|
476
479
|
const pluginsWithBackingIntegrations = await utils.records.mapValuesAsync(plugins, async (plugin) => ({
|
|
477
480
|
...plugin,
|
|
478
|
-
interfaces: await this._fetchDependencies(
|
|
479
|
-
plugin.interfaces ?? {},
|
|
480
|
-
async (
|
|
481
|
-
|
|
481
|
+
interfaces: await this._fetchDependencies({
|
|
482
|
+
deps: plugin.interfaces ?? {},
|
|
483
|
+
fetcher: async ({ name, version }) => await api.getPublicOrPrivateIntegration({ name, version, type: "name" }),
|
|
484
|
+
cacheKey: ({ name, version }) => `interface:${name}@${version}`
|
|
485
|
+
}),
|
|
486
|
+
integrations: await this._fetchDependencies({
|
|
487
|
+
deps: plugin.integrations ?? {},
|
|
488
|
+
fetcher: async ({ name, version }) => await api.getPublicOrPrivateIntegration({ name, version, type: "name" }),
|
|
489
|
+
cacheKey: ({ name, version }) => `integration:${name}@${version}`
|
|
490
|
+
})
|
|
482
491
|
}));
|
|
483
492
|
return {
|
|
484
493
|
integrations: utils.records.mapValues(
|
|
@@ -493,29 +502,43 @@ class ProjectCommand extends import_global_command.GlobalCommand {
|
|
|
493
502
|
),
|
|
494
503
|
plugins: utils.records.mapValues(pluginsWithBackingIntegrations, (plugin) => ({
|
|
495
504
|
...plugin,
|
|
496
|
-
interfaces: utils.records.mapValues(
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
505
|
+
interfaces: utils.records.mapValues(
|
|
506
|
+
plugin.interfaces ?? {},
|
|
507
|
+
(iface) => ({
|
|
508
|
+
integrationId: iface.id,
|
|
509
|
+
integrationAlias: iface.integrationAlias,
|
|
510
|
+
integrationInterfaceAlias: iface.integrationInterfaceAlias
|
|
511
|
+
})
|
|
512
|
+
),
|
|
513
|
+
integrations: utils.records.mapValues(
|
|
514
|
+
plugin.integrations ?? {},
|
|
515
|
+
(integration) => ({
|
|
516
|
+
integrationId: integration.id,
|
|
517
|
+
integrationAlias: integration.integrationAlias
|
|
518
|
+
})
|
|
519
|
+
)
|
|
500
520
|
}))
|
|
501
521
|
};
|
|
502
522
|
}
|
|
503
523
|
async prepareIntegrationDependencies(integrationDef, api) {
|
|
504
|
-
const interfaces = await this._fetchDependencies(
|
|
505
|
-
integrationDef.interfaces ?? {},
|
|
506
|
-
({ name, version }) => api.getPublicInterface({ type: "name", name, version })
|
|
507
|
-
|
|
524
|
+
const interfaces = await this._fetchDependencies({
|
|
525
|
+
deps: integrationDef.interfaces ?? {},
|
|
526
|
+
fetcher: ({ name, version }) => api.getPublicInterface({ type: "name", name, version }),
|
|
527
|
+
cacheKey: (dep) => `interface:${dep.name}@${dep.version}`
|
|
528
|
+
});
|
|
508
529
|
return { interfaces };
|
|
509
530
|
}
|
|
510
531
|
async preparePluginDependencies(pluginDef, api) {
|
|
511
|
-
const integrations = await this._fetchDependencies(
|
|
512
|
-
pluginDef.integrations ?? {},
|
|
513
|
-
({ name, version }) => api.getPublicOrPrivateIntegration({ type: "name", name, version })
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
532
|
+
const integrations = await this._fetchDependencies({
|
|
533
|
+
deps: pluginDef.integrations ?? {},
|
|
534
|
+
fetcher: ({ name, version }) => api.getPublicOrPrivateIntegration({ type: "name", name, version }),
|
|
535
|
+
cacheKey: (dep) => `integration:${dep.name}@${dep.version}`
|
|
536
|
+
});
|
|
537
|
+
const interfaces = await this._fetchDependencies({
|
|
538
|
+
deps: pluginDef.interfaces ?? {},
|
|
539
|
+
fetcher: ({ name, version }) => api.getPublicInterface({ type: "name", name, version }),
|
|
540
|
+
cacheKey: (dep) => `interface:${dep.name}@${dep.version}`
|
|
541
|
+
});
|
|
519
542
|
return {
|
|
520
543
|
dependencies: {
|
|
521
544
|
integrations,
|
|
@@ -523,13 +546,23 @@ class ProjectCommand extends import_global_command.GlobalCommand {
|
|
|
523
546
|
}
|
|
524
547
|
};
|
|
525
548
|
}
|
|
526
|
-
_fetchDependencies = async (
|
|
549
|
+
_fetchDependencies = async ({
|
|
550
|
+
deps,
|
|
551
|
+
fetcher,
|
|
552
|
+
cacheKey: getCacheKey
|
|
553
|
+
}) => {
|
|
527
554
|
const isRemote = (dep) => dep.id !== void 0;
|
|
528
555
|
return utils.records.mapValuesAsync(deps, async (dep) => {
|
|
529
556
|
if (isRemote(dep)) {
|
|
530
557
|
return dep;
|
|
531
558
|
}
|
|
559
|
+
const cacheKey = getCacheKey(dep);
|
|
560
|
+
const cached = this._dependencyCache.get(cacheKey);
|
|
561
|
+
if (cached) {
|
|
562
|
+
return { ...dep, id: cached.id };
|
|
563
|
+
}
|
|
532
564
|
const { id } = await fetcher(dep);
|
|
565
|
+
this._dependencyCache.set(cacheKey, { id });
|
|
533
566
|
return { ...dep, id };
|
|
534
567
|
});
|
|
535
568
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/command-implementations/project-command.ts"],
|
|
4
|
-
"sourcesContent": ["import type * as client from '@botpress/client'\nimport type * as sdk from '@botpress/sdk'\nimport type { YargsConfig } from '@bpinternal/yargs-extra'\nimport chalk from 'chalk'\nimport fs from 'fs'\nimport _ from 'lodash'\nimport semver from 'semver'\nimport * as apiUtils from '../api'\nimport * as codegen from '../code-generation'\nimport * as config from '../config'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport { validateIntegrationDefinition, validateBotDefinition } from '../sdk'\nimport type { CommandArgv, CommandDefinition } from '../typings'\nimport * as utils from '../utils'\nimport { GlobalCommand } from './global-command'\n\nexport type ProjectCommandDefinition = CommandDefinition<typeof config.schemas.project>\nexport type ProjectCache = { botId: string; devId: string; tunnelId: string }\n\ntype ConfigurableProjectPaths = { workDir: string }\ntype ConstantProjectPaths = typeof consts.fromWorkDir\ntype AllProjectPaths = ConfigurableProjectPaths & ConstantProjectPaths\n\ntype LintIgnoredConfig = { bpLintDisabled?: boolean }\n\nexport type ProjectType = ProjectDefinition['type']\nexport type ProjectDefinition = LintIgnoredConfig &\n (\n | { type: 'integration'; definition: sdk.IntegrationDefinition }\n | { type: 'interface'; definition: sdk.InterfaceDefinition }\n | { type: 'bot'; definition: sdk.BotDefinition }\n | { type: 'plugin'; definition: sdk.PluginDefinition }\n )\n\ntype ProjectDefinitionResolver<T> = () => Promise<LintIgnoredConfig & T>\n\nexport type ProjectDefinitionLazy =\n | {\n projectType: 'integration'\n resolveProjectDefinition: ProjectDefinitionResolver<{\n type: 'integration'\n definition: sdk.IntegrationDefinition\n }>\n }\n | {\n projectType: 'bot'\n resolveProjectDefinition: ProjectDefinitionResolver<{ type: 'bot'; definition: sdk.BotDefinition }>\n }\n | {\n projectType: 'interface'\n resolveProjectDefinition: ProjectDefinitionResolver<{ type: 'interface'; definition: sdk.InterfaceDefinition }>\n }\n | {\n projectType: 'plugin'\n resolveProjectDefinition: ProjectDefinitionResolver<{ type: 'plugin'; definition: sdk.PluginDefinition }>\n }\n\ntype UpdatedBot = client.Bot\n\ntype ClientIntegrationDefinitions = Record<string, client.Integration>\ntype ClientIntegration = client.Bot['integrations'][string]\n\nclass ProjectPaths extends utils.path.PathStore<keyof AllProjectPaths> {\n public constructor(argv: CommandArgv<ProjectCommandDefinition>) {\n const absWorkDir = utils.path.absoluteFrom(utils.path.cwd(), argv.workDir)\n super({\n workDir: absWorkDir,\n ..._.mapValues(consts.fromWorkDir, (p) => utils.path.absoluteFrom(absWorkDir, p)),\n })\n }\n}\n\nexport class ProjectDefinitionContext {\n private _codeCache: Map<string, object> = new Map()\n private _buildContext: utils.esbuild.BuildEntrypointContext = new utils.esbuild.BuildEntrypointContext()\n\n public getOrResolveDefinition<T extends object>(code: string): T {\n const definition = this._codeCache.get(code)\n if (definition) {\n return definition as T\n }\n const result = utils.require.requireJsCode<{ default: object }>(code)\n this._codeCache.set(code, result.default)\n return result.default as T\n }\n\n public rebuildEntrypoint(...args: Parameters<utils.esbuild.BuildEntrypointContext['rebuild']>) {\n return this._buildContext.rebuild(...args)\n }\n}\n\nexport abstract class ProjectCommand<C extends ProjectCommandDefinition> extends GlobalCommand<C> {\n protected projectContext: ProjectDefinitionContext = new ProjectDefinitionContext()\n\n public setProjectContext(projectContext: ProjectDefinitionContext) {\n this.projectContext = projectContext\n return this\n }\n\n protected override async bootstrap() {\n await super.bootstrap()\n await this._notifyUpdateSdk()\n }\n\n protected get projectPaths() {\n return new ProjectPaths(this.argv)\n }\n\n protected get projectCache() {\n return new utils.cache.FSKeyValueCache<ProjectCache>(this.projectPaths.abs.projectCacheFile)\n }\n\n private _readProjectType(projectPaths: ProjectPaths): ProjectType {\n const abs = projectPaths.abs\n if (fs.existsSync(abs.integrationDefinition)) {\n return 'integration'\n }\n if (fs.existsSync(abs.interfaceDefinition)) {\n return 'interface'\n }\n if (fs.existsSync(abs.botDefinition)) {\n return 'bot'\n }\n if (fs.existsSync(abs.pluginDefinition)) {\n return 'plugin'\n }\n throw new errors.UnsupportedProjectType()\n }\n\n protected readProjectDefinitionFromFS(): ProjectDefinitionLazy {\n try {\n const type = this._readProjectType(this.projectPaths)\n if (type === 'integration') {\n return {\n projectType: 'integration',\n resolveProjectDefinition: async () => ({\n type: 'integration',\n ...(await this._readIntegrationDefinitionFromFS(this.projectPaths)),\n }),\n }\n }\n if (type === 'plugin') {\n return {\n projectType: 'plugin',\n resolveProjectDefinition: async () => ({\n type: 'plugin',\n ...(await this._readPluginDefinitionFromFS(this.projectPaths)),\n }),\n }\n }\n if (type === 'interface') {\n return {\n projectType: 'interface',\n resolveProjectDefinition: async () => ({\n type: 'interface',\n ...(await this._readInterfaceDefinitionFromFS(this.projectPaths)),\n }),\n }\n }\n if (type === 'bot') {\n return {\n projectType: 'bot',\n resolveProjectDefinition: async () => ({\n type: 'bot',\n ...(await this._readBotDefinitionFromFS(this.projectPaths)),\n }),\n }\n }\n } catch (thrown: unknown) {\n throw errors.BotpressCLIError.wrap(thrown, 'Error while reading project definition')\n }\n throw new errors.ProjectDefinitionNotFoundError(this.projectPaths.abs.workDir)\n }\n\n private async _readIntegrationDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'integrationDefinition'>\n ): Promise<{ definition: sdk.IntegrationDefinition } & LintIgnoredConfig> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.integrationDefinition)) {\n throw new errors.BotpressCLIError('Could not read integration definition')\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.integrationDefinition)\n\n const { outputFiles } = await this.projectContext.rebuildEntrypoint({\n absWorkingDir: abs.workDir,\n entrypoint: rel.integrationDefinition,\n })\n\n const artifact = outputFiles?.[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read integration definition')\n }\n\n const definition = this.projectContext.getOrResolveDefinition<sdk.IntegrationDefinition>(artifact.text)\n validateIntegrationDefinition(definition)\n return { definition, bpLintDisabled }\n }\n\n private async _readInterfaceDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'interfaceDefinition'>\n ): Promise<{ definition: sdk.InterfaceDefinition } & LintIgnoredConfig> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.interfaceDefinition)) {\n throw new errors.BotpressCLIError('Could not read interface definition')\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.interfaceDefinition)\n\n const { outputFiles } = await this.projectContext.rebuildEntrypoint({\n absWorkingDir: abs.workDir,\n entrypoint: rel.interfaceDefinition,\n })\n\n const artifact = outputFiles?.[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read interface definition')\n }\n\n const definition = this.projectContext.getOrResolveDefinition<sdk.InterfaceDefinition>(artifact.text)\n\n return { definition, bpLintDisabled }\n }\n\n private async _readBotDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'botDefinition'>\n ): Promise<{ definition: sdk.BotDefinition } & LintIgnoredConfig> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.botDefinition)) {\n throw new errors.BotpressCLIError('Could not read bot definition')\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.botDefinition)\n\n const { outputFiles } = await this.projectContext.rebuildEntrypoint({\n absWorkingDir: abs.workDir,\n entrypoint: rel.botDefinition,\n })\n\n const artifact = outputFiles?.[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read bot definition')\n }\n\n const definition = this.projectContext.getOrResolveDefinition<sdk.BotDefinition>(artifact.text)\n validateBotDefinition(definition)\n return { definition, bpLintDisabled }\n }\n\n private async _readPluginDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'pluginDefinition'>\n ): Promise<{ definition: sdk.PluginDefinition } & LintIgnoredConfig> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.pluginDefinition)) {\n throw new errors.BotpressCLIError('Could not read plugin definition')\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.pluginDefinition)\n\n const { outputFiles } = await this.projectContext.rebuildEntrypoint({\n absWorkingDir: abs.workDir,\n entrypoint: rel.pluginDefinition,\n })\n\n const artifact = outputFiles?.[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read plugin definition')\n }\n\n const definition = this.projectContext.getOrResolveDefinition<sdk.PluginDefinition>(artifact.text)\n // TODO: validate plugin definition\n return { definition, bpLintDisabled }\n }\n\n private async _isBpLintDisabled(definitionPath: string): Promise<boolean> {\n const tsContent = await fs.promises.readFile(definitionPath, 'utf-8')\n const regex = /\\/\\* bplint-disable \\*\\//\n return regex.test(tsContent)\n }\n\n protected async displayIntegrationUrls({ api, bot }: { api: apiUtils.ApiClient; bot: client.Bot }) {\n if (!_.keys(bot.integrations).length) {\n this.logger.debug('No integrations in bot')\n return\n }\n\n const integrationDefinitions = await utils.records.mapValuesAsync(bot.integrations, async (integration) =>\n api.getPublicOrPrivateIntegration({\n type: 'id',\n id: integration.id,\n })\n )\n\n this.logger.log('Integrations:')\n for (const [alias, integration] of Object.entries(bot.integrations)) {\n if (integration.enabled) {\n this.logger.log(`${alias}:`, { prefix: { symbol: '\u2192', indent: 2 } })\n } else {\n this.logger.log(`${alias} ${chalk.italic('(disabled)')}:`, {\n prefix: { symbol: '\u2192', indent: 2 },\n })\n }\n\n const integrationDefinition = integrationDefinitions[alias]\n const linkTemplateScript = integrationDefinition\n ? this._getLinkTemplateScript({ integration, integrationDefinition })\n : undefined\n this._displayWebhookUrl({ integration, integrationDefinition, linkTemplateScript })\n if (!integrationDefinition) {\n this.logger.debug(\n `No integration definition for integration ${alias} (${integration.name}, ${integration.id}), skipping OAuth or Sandbox links`\n )\n this.logger.line().commit()\n continue\n }\n const isSandbox =\n integration.configurationType === 'sandbox' && !!integrationDefinition.sandbox?.identifierExtractScript\n const showLink = !!linkTemplateScript && (isSandbox || !!integrationDefinition.identifier?.extractScript)\n if (showLink && isSandbox) {\n await this._displaySandboxLinkAndCode({ integration, alias, bot, api, linkTemplateScript })\n } else if (showLink) {\n this._displayAuthorizationLink({ integration, api, linkTemplateScript })\n }\n this.logger.line().commit()\n }\n }\n\n private _getLinkTemplateScript({\n integration,\n integrationDefinition,\n }: {\n integration: ClientIntegration\n integrationDefinition?: ClientIntegrationDefinitions[string]\n }) {\n const config =\n integration.configurationType === null\n ? integrationDefinition?.configuration\n : integrationDefinition?.configurations[integration.configurationType]\n return config?.identifier?.linkTemplateScript\n }\n\n private _displayWebhookUrl({\n integration,\n integrationDefinition,\n linkTemplateScript,\n }: {\n integration: ClientIntegration\n integrationDefinition?: ClientIntegrationDefinitions[string]\n linkTemplateScript?: string\n }) {\n const needsWebhook = !(integrationDefinition?.identifier && linkTemplateScript)\n const logFn = (needsWebhook ? this.logger.log : this.logger.debug).bind(this.logger)\n\n if (integration.enabled) {\n logFn(`${chalk.bold('Webhook')}: ${integration.webhookUrl}`, {\n prefix: { symbol: '\u25CF', indent: 4 },\n })\n } else {\n logFn(`Webhook: ${integration.webhookUrl}`, {\n prefix: { symbol: '\u25CB', indent: 4 },\n })\n }\n }\n\n private _displayAuthorizationLink({\n integration,\n api,\n linkTemplateScript,\n }: {\n integration: ClientIntegration\n api: apiUtils.ApiClient\n linkTemplateScript: string\n }) {\n const authorizationLink = this._getAuthorizationLink({ integration, api, linkTemplateScript })\n const isAuthorized = !!integration.identifier\n const authorizationStatus = integration.identifier ? 'Authorized \u2713' : 'Authorize'\n if (integration.enabled && isAuthorized) {\n this.logger.log(`${chalk.bold(authorizationStatus)} : ${authorizationLink}`, {\n prefix: { symbol: '\u25CF', indent: 4 },\n })\n } else {\n this.logger.log(`${authorizationStatus}: ${authorizationLink}`, {\n prefix: { symbol: '\u25CB', indent: 4 },\n })\n }\n }\n\n private _getLinkTemplateArgs({ integration, api }: { integration: ClientIntegration; api: apiUtils.ApiClient }) {\n // These are the values used by the studio\n let env: 'development' | 'preview' | 'production'\n if (api.url.includes(consts.stagingBotpressDomain)) {\n env = 'preview'\n } else if (api.url.includes(consts.productionBotpressDomain)) {\n env = 'production'\n } else {\n env = 'development'\n }\n return {\n env,\n webhookId: integration.webhookId,\n webhookUrl: api.url.replace('api', 'webhook'),\n }\n }\n\n private _getAuthorizationLink({\n integration,\n api,\n linkTemplateScript,\n }: {\n integration: client.Bot['integrations'][string]\n api: apiUtils.ApiClient\n linkTemplateScript: string\n }) {\n return utils.vrl.getStringResult({\n code: linkTemplateScript,\n data: this._getLinkTemplateArgs({ integration, api }),\n })\n }\n\n private _getSandboxLink({\n shareableId,\n integration,\n api,\n linkTemplateScript,\n }: {\n shareableId: string\n integration: ClientIntegration\n api: apiUtils.ApiClient\n linkTemplateScript: string\n }) {\n return utils.vrl.getStringResult({\n code: linkTemplateScript,\n data: { shareableId, ...this._getLinkTemplateArgs({ integration, api }) },\n })\n }\n\n private async _displaySandboxLinkAndCode({\n integration,\n alias,\n bot,\n api,\n linkTemplateScript,\n }: {\n integration: ClientIntegration\n alias: string\n bot: client.Bot\n api: apiUtils.ApiClient\n linkTemplateScript: string\n }) {\n const shareableId = await api.getOrGenerateShareableId(bot.id, integration.id, alias)\n const sandboxLink = this._getSandboxLink({ shareableId, integration, api, linkTemplateScript })\n const sandboxInstruction = `Send '${shareableId}' to ${sandboxLink}`\n if (integration.enabled) {\n this.logger.log(`${chalk.bold('Sandbox')}: ${sandboxInstruction}`, {\n prefix: { symbol: '\u25CF', indent: 4 },\n })\n } else {\n this.logger.log(`Sandbox: ${sandboxInstruction}`, {\n prefix: { symbol: '\u25CB', indent: 4 },\n })\n }\n }\n\n protected async promptSecrets(\n integrationDef: sdk.IntegrationDefinition,\n argv: YargsConfig<typeof config.schemas.secrets>,\n opts: { formatEnv?: boolean; knownSecrets?: string[] } = {}\n ): Promise<Record<string, string | null>> {\n const formatEnv = opts.formatEnv ?? false\n const knownSecrets = opts.knownSecrets ?? []\n\n const { secrets: secretDefinitions } = integrationDef\n if (!secretDefinitions) {\n return {}\n }\n\n const secretArgv = this._parseArgvSecrets(argv.secrets)\n const invalidSecret = Object.keys(secretArgv).find((s) => !secretDefinitions[s])\n if (invalidSecret) {\n throw new errors.BotpressCLIError(`Secret ${invalidSecret} is not defined in integration definition`)\n }\n\n const values: Record<string, string | null> = {}\n for (const [secretName, { optional }] of Object.entries(secretDefinitions)) {\n const argvSecret = secretArgv[secretName]\n if (argvSecret) {\n this.logger.debug(`Using secret \"${secretName}\" from argv`)\n values[secretName] = argvSecret\n continue\n }\n\n const alreadyKnown = knownSecrets.includes(secretName)\n let mode: string\n if (alreadyKnown) {\n mode = 'already set'\n } else if (optional) {\n mode = 'optional'\n } else {\n mode = 'required'\n }\n\n const prompted = await this.prompt.text(`Enter value for secret \"${secretName}\" (${mode})`)\n if (prompted) {\n values[secretName] = prompted\n continue\n }\n\n if (alreadyKnown) {\n this.logger.log(`Secret \"${secretName}\" is unchanged`)\n } else if (optional) {\n this.logger.warn(`Secret \"${secretName}\" is unassigned`)\n } else {\n throw new errors.BotpressCLIError(`Secret \"${secretName}\" is required`)\n }\n }\n\n for (const secretName of knownSecrets) {\n const isDefined = secretName in secretDefinitions\n if (isDefined) {\n continue\n }\n const prompted = await this.prompt.confirm(`Secret \"${secretName}\" was removed. Do you wish to delete it?`)\n if (prompted) {\n this.logger.log(`Deleting secret \"${secretName}\"`, { prefix: { symbol: '\u00D7', fg: 'red' } })\n values[secretName] = null\n }\n }\n\n if (!formatEnv) {\n return values\n }\n\n const envVariables = _.mapKeys(values, (_v, k) => codegen.secretEnvVariableName(k))\n return envVariables\n }\n\n protected async prepareCreateIntegrationBody(\n integrationDef: sdk.IntegrationDefinition\n ): Promise<apiUtils.CreateIntegrationRequestBody> {\n const partialBody = await apiUtils.prepareCreateIntegrationBody(integrationDef)\n\n let code: string | undefined = undefined\n if (fs.existsSync(this.projectPaths.abs.outFileCJS)) {\n code = await this.readProjectFile(this.projectPaths.abs.outFileCJS)\n }\n\n const icon = await this.readProjectFile(integrationDef.icon, 'base64')\n const readme = await this.readProjectFile(integrationDef.readme, 'base64')\n const extractScript = await this.readProjectFile(integrationDef.identifier?.extractScript)\n const fallbackHandlerScript = await this.readProjectFile(integrationDef.identifier?.fallbackHandlerScript)\n return {\n ...partialBody,\n code,\n icon,\n readme,\n identifier: {\n extractScript,\n fallbackHandlerScript,\n },\n configuration: integrationDef.configuration\n ? {\n schema: await utils.schema.mapZodToJsonSchema(integrationDef.configuration, {\n useLegacyZuiTransformer: integrationDef.__advanced?.useLegacyZuiTransformer,\n }),\n identifier: {\n required: integrationDef.configuration.identifier?.required,\n linkTemplateScript: await this.readProjectFile(\n integrationDef.configuration.identifier?.linkTemplateScript\n ),\n },\n }\n : undefined,\n configurations: integrationDef.configurations\n ? await utils.records.mapValuesAsync(integrationDef.configurations, async (configuration) => ({\n title: configuration.title,\n description: configuration.description,\n schema: await utils.schema.mapZodToJsonSchema(configuration, {\n useLegacyZuiTransformer: integrationDef.__advanced?.useLegacyZuiTransformer,\n }),\n identifier: {\n required: configuration.identifier?.required,\n linkTemplateScript: await this.readProjectFile(configuration.identifier?.linkTemplateScript),\n },\n }))\n : undefined,\n }\n }\n\n protected async prepareBotDependencies(\n botDef: sdk.BotDefinition,\n api: apiUtils.ApiClient\n ): Promise<Partial<apiUtils.UpdateBotRequestBody>> {\n const integrations = await this._fetchDependencies(botDef.integrations ?? {}, ({ name, version }) =>\n api.getPublicOrPrivateIntegration({ type: 'name', name, version })\n )\n\n const plugins = await this._fetchDependencies(\n botDef.plugins ?? {},\n async ({ name, version }) => await api.getPublicOrPrivatePlugin({ type: 'name', name, version })\n )\n\n const pluginsWithBackingIntegrations = await utils.records.mapValuesAsync(plugins, async (plugin) => ({\n ...plugin,\n interfaces: await this._fetchDependencies(\n plugin.interfaces ?? {},\n async (interfaceExtension) => await api.getPublicOrPrivateIntegration({ ...interfaceExtension, type: 'name' })\n ),\n }))\n\n return {\n integrations: utils.records.mapValues(\n integrations,\n ({ enabled, configurationType, configuration, disabledChannels, id }) =>\n ({\n enabled,\n configurationType,\n configuration,\n disabledChannels,\n integrationId: id,\n }) satisfies NonNullable<apiUtils.UpdateBotRequestBody['integrations']>[string]\n ),\n plugins: utils.records.mapValues(pluginsWithBackingIntegrations, (plugin) => ({\n ...plugin,\n interfaces: utils.records.mapValues(plugin.interfaces ?? {}, (iface) => ({\n ...iface,\n integrationId: iface.id,\n })),\n })),\n }\n }\n\n protected async prepareIntegrationDependencies(\n integrationDef: sdk.IntegrationDefinition,\n api: apiUtils.ApiClient\n ): Promise<Partial<apiUtils.CreateIntegrationRequestBody>> {\n const interfaces = await this._fetchDependencies(integrationDef.interfaces ?? {}, ({ name, version }) =>\n api.getPublicInterface({ type: 'name', name, version })\n )\n return { interfaces }\n }\n\n protected async preparePluginDependencies(\n pluginDef: sdk.PluginDefinition,\n api: apiUtils.ApiClient\n ): Promise<Partial<apiUtils.CreatePluginRequestBody>> {\n const integrations = await this._fetchDependencies(pluginDef.integrations ?? {}, ({ name, version }) =>\n api.getPublicOrPrivateIntegration({ type: 'name', name, version })\n )\n const interfaces = await this._fetchDependencies(pluginDef.interfaces ?? {}, ({ name, version }) =>\n api.getPublicInterface({ type: 'name', name, version })\n )\n return {\n dependencies: {\n integrations,\n interfaces,\n },\n }\n }\n\n private _fetchDependencies = async <T extends { id?: string; name: string; version: string }>(\n deps: Record<string, T>,\n fetcher: (dep: T) => Promise<{ id: string }>\n ): Promise<Record<string, T & { id: string }>> => {\n const isRemote = (dep: T): dep is T & { id: string } => dep.id !== undefined\n return utils.records.mapValuesAsync(deps, async (dep): Promise<T & { id: string }> => {\n if (isRemote(dep)) {\n return dep\n }\n const { id } = await fetcher(dep)\n return { ...dep, id }\n })\n }\n\n protected readProjectFile = async (\n filePath: string | undefined,\n encoding: BufferEncoding = 'utf-8'\n ): Promise<string | undefined> => {\n if (!filePath) {\n return undefined\n }\n const absoluteFilePath = utils.path.absoluteFrom(this.projectPaths.abs.workDir, filePath)\n return fs.promises.readFile(absoluteFilePath, encoding).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not read file \"${absoluteFilePath}\"`)\n })\n }\n\n private _parseArgvSecrets(argvSecrets: string[]): Record<string, string> {\n const parsed: Record<string, string> = {}\n for (const secret of argvSecrets) {\n const [key, value] = utils.string.splitOnce(secret, '=')\n if (!value) {\n throw new errors.BotpressCLIError(\n `Secret \"${key}\" is missing a value. Expected format: \"SECRET_NAME=secretValue\"`\n )\n }\n parsed[key!] = value\n }\n\n return parsed\n }\n\n private _notifyUpdateSdk = async (): Promise<void> => {\n try {\n this.logger.debug('Checking if sdk is up to date')\n\n const { workDir } = this.projectPaths.abs\n const readProjectPkgJsonResult = await utils.pkgJson.safeReadPackageJson(workDir)\n if (!readProjectPkgJsonResult.success) {\n this.logger.debug(`Could not read package.json at \"${workDir}\": ${readProjectPkgJsonResult.error.message}`)\n return\n }\n\n if (!readProjectPkgJsonResult.pkgJson) {\n this.logger.debug(`Could not find package.json at \"${workDir}\"`)\n return\n }\n\n const { pkgJson: projectPkgJson } = readProjectPkgJsonResult\n const sdkPackageName = '@botpress/sdk'\n const actualSdkVersion = utils.pkgJson.findDependency(projectPkgJson, sdkPackageName)\n if (!actualSdkVersion) {\n this.logger.debug(`Could not find dependency \"${sdkPackageName}\" in project package.json`)\n return\n }\n\n if (actualSdkVersion.startsWith('workspace:')) {\n return\n }\n\n const actualCleanedSdkVersion = semver.valid(semver.coerce(actualSdkVersion))\n if (!actualCleanedSdkVersion) {\n this.logger.debug(`Invalid sdk version \"${actualSdkVersion}\" in project package.json`)\n return\n }\n\n const cliPkgJson = await this.readCLIPkgJson()\n const expectedSdkVersion = utils.pkgJson.findDependency(cliPkgJson, sdkPackageName)\n if (!expectedSdkVersion) {\n this.logger.debug(`Could not find dependency \"${sdkPackageName}\" in cli package.json`)\n return\n }\n\n const expectedCleanedSdkVersion = semver.valid(semver.coerce(expectedSdkVersion))\n if (!expectedCleanedSdkVersion) {\n this.logger.debug(`Invalid sdk version \"${expectedSdkVersion}\" in cli package.json`)\n return\n }\n\n if (semver.eq(actualCleanedSdkVersion, expectedCleanedSdkVersion)) {\n return\n }\n\n const diff = semver.diff(actualCleanedSdkVersion, expectedCleanedSdkVersion)\n if (!diff) {\n this.logger.debug(`Could not compare versions \"${actualCleanedSdkVersion}\" and \"${expectedCleanedSdkVersion}\"`)\n return\n }\n\n const errorMsg = `Project SDK version is \"${actualCleanedSdkVersion}\", but expected \"${expectedCleanedSdkVersion}\"`\n if (utils.semver.releases.lt(diff, 'minor')) {\n this.logger.debug(`${errorMsg}. This may cause compatibility issues.`)\n return\n }\n\n this.logger.warn(chalk.bold(`${errorMsg}. This will cause compatibility issues.`))\n } catch (thrown) {\n const err = errors.BotpressCLIError.map(thrown)\n this.logger.debug(`Failed to check if sdk is up to date: ${err.message}`)\n }\n }\n protected validateIntegrationRegistration(\n updatedBot: UpdatedBot,\n onFailCallback: (failedIntegrations: UpdatedBot['integrations']) => void\n ) {\n let failedIntegrations: UpdatedBot['integrations'] = {}\n for (const [integrationName, integration] of Object.entries(updatedBot.integrations)) {\n if (integration.status === 'registration_failed') {\n failedIntegrations = { ...failedIntegrations, [integrationName]: integration }\n }\n }\n if (Object.keys(failedIntegrations).length > 0) {\n onFailCallback(failedIntegrations)\n }\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAkB;AAClB,gBAAe;AACf,oBAAc;AACd,oBAAmB;AACnB,eAA0B;AAC1B,cAAyB;AAEzB,aAAwB;AACxB,aAAwB;AACxB,iBAAqE;AAErE,YAAuB;AACvB,4BAA8B;AAgD9B,MAAM,qBAAqB,MAAM,KAAK,UAAiC;AAAA,EAC9D,YAAY,MAA6C;AAC9D,UAAM,aAAa,MAAM,KAAK,aAAa,MAAM,KAAK,IAAI,GAAG,KAAK,OAAO;AACzE,UAAM;AAAA,MACJ,SAAS;AAAA,MACT,GAAG,cAAAA,QAAE,UAAU,OAAO,aAAa,CAAC,MAAM,MAAM,KAAK,aAAa,YAAY,CAAC,CAAC;AAAA,IAClF,CAAC;AAAA,EACH;AACF;AAEO,MAAM,yBAAyB;AAAA,EAC5B,aAAkC,oBAAI,IAAI;AAAA,EAC1C,gBAAsD,IAAI,MAAM,QAAQ,uBAAuB;AAAA,EAEhG,uBAAyC,MAAiB;AAC/D,UAAM,aAAa,KAAK,WAAW,IAAI,IAAI;AAC3C,QAAI,YAAY;AACd,aAAO;AAAA,IACT;AACA,UAAM,SAAS,MAAM,QAAQ,cAAmC,IAAI;AACpE,SAAK,WAAW,IAAI,MAAM,OAAO,OAAO;AACxC,WAAO,OAAO;AAAA,EAChB;AAAA,EAEO,qBAAqB,MAAmE;AAC7F,WAAO,KAAK,cAAc,QAAQ,GAAG,IAAI;AAAA,EAC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AAG,YAAY;AAAA,MAC/E;AAAA,IACF;AACA,QAAI,OAAO,KAAK,kBAAkB,EAAE,SAAS,GAAG;AAC9C,qBAAe,kBAAkB;AAAA,IACnC;AAAA,EACF;AACF;",
|
|
4
|
+
"sourcesContent": ["import type * as client from '@botpress/client'\nimport type * as sdk from '@botpress/sdk'\nimport type { YargsConfig } from '@bpinternal/yargs-extra'\nimport chalk from 'chalk'\nimport fs from 'fs'\nimport _ from 'lodash'\nimport semver from 'semver'\nimport * as apiUtils from '../api'\nimport * as codegen from '../code-generation'\nimport * as config from '../config'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport { validateIntegrationDefinition, validateBotDefinition } from '../sdk'\nimport type { CommandArgv, CommandDefinition } from '../typings'\nimport * as utils from '../utils'\nimport { GlobalCommand } from './global-command'\n\nexport type ProjectCommandDefinition = CommandDefinition<typeof config.schemas.project>\nexport type ProjectCache = { botId: string; devId: string; tunnelId: string }\n\ntype ConfigurableProjectPaths = { workDir: string }\ntype ConstantProjectPaths = typeof consts.fromWorkDir\ntype AllProjectPaths = ConfigurableProjectPaths & ConstantProjectPaths\n\ntype LintIgnoredConfig = { bpLintDisabled?: boolean }\n\nexport type ProjectType = ProjectDefinition['type']\nexport type ProjectDefinition = LintIgnoredConfig &\n (\n | { type: 'integration'; definition: sdk.IntegrationDefinition }\n | { type: 'interface'; definition: sdk.InterfaceDefinition }\n | { type: 'bot'; definition: sdk.BotDefinition }\n | { type: 'plugin'; definition: sdk.PluginDefinition }\n )\n\ntype ProjectDefinitionResolver<T> = () => Promise<LintIgnoredConfig & T>\n\nexport type ProjectDefinitionLazy =\n | {\n projectType: 'integration'\n resolveProjectDefinition: ProjectDefinitionResolver<{\n type: 'integration'\n definition: sdk.IntegrationDefinition\n }>\n }\n | {\n projectType: 'bot'\n resolveProjectDefinition: ProjectDefinitionResolver<{ type: 'bot'; definition: sdk.BotDefinition }>\n }\n | {\n projectType: 'interface'\n resolveProjectDefinition: ProjectDefinitionResolver<{ type: 'interface'; definition: sdk.InterfaceDefinition }>\n }\n | {\n projectType: 'plugin'\n resolveProjectDefinition: ProjectDefinitionResolver<{ type: 'plugin'; definition: sdk.PluginDefinition }>\n }\n\ntype UpdatedBot = client.Bot\n\ntype ClientIntegrationDefinitions = Record<string, client.Integration>\ntype ClientIntegration = client.Bot['integrations'][string]\n\nclass ProjectPaths extends utils.path.PathStore<keyof AllProjectPaths> {\n public constructor(argv: CommandArgv<ProjectCommandDefinition>) {\n const absWorkDir = utils.path.absoluteFrom(utils.path.cwd(), argv.workDir)\n super({\n workDir: absWorkDir,\n ..._.mapValues(consts.fromWorkDir, (p) => utils.path.absoluteFrom(absWorkDir, p)),\n })\n }\n}\n\nexport class ProjectDefinitionContext {\n private _codeCache: Map<string, object> = new Map()\n private _buildContext: utils.esbuild.BuildEntrypointContext = new utils.esbuild.BuildEntrypointContext()\n\n public getOrResolveDefinition<T extends object>(code: string): T {\n const definition = this._codeCache.get(code)\n if (definition) {\n return definition as T\n }\n const result = utils.require.requireJsCode<{ default: object }>(code)\n this._codeCache.set(code, result.default)\n return result.default as T\n }\n\n public rebuildEntrypoint(...args: Parameters<utils.esbuild.BuildEntrypointContext['rebuild']>) {\n return this._buildContext.rebuild(...args)\n }\n}\n\ntype ResolvedDependency = { id: string }\ntype DependencyCacheKey = `${'integration' | 'plugin' | 'interface'}:${string}@${string}`\n\nexport abstract class ProjectCommand<C extends ProjectCommandDefinition> extends GlobalCommand<C> {\n protected projectContext: ProjectDefinitionContext = new ProjectDefinitionContext()\n private _dependencyCache = new Map<DependencyCacheKey, ResolvedDependency>()\n\n public setProjectContext(projectContext: ProjectDefinitionContext) {\n this.projectContext = projectContext\n return this\n }\n\n protected override async bootstrap() {\n await super.bootstrap()\n await this._notifyUpdateSdk()\n }\n\n protected get projectPaths() {\n return new ProjectPaths(this.argv)\n }\n\n protected get projectCache() {\n return new utils.cache.FSKeyValueCache<ProjectCache>(this.projectPaths.abs.projectCacheFile)\n }\n\n private _readProjectType(projectPaths: ProjectPaths): ProjectType {\n const abs = projectPaths.abs\n if (fs.existsSync(abs.integrationDefinition)) {\n return 'integration'\n }\n if (fs.existsSync(abs.interfaceDefinition)) {\n return 'interface'\n }\n if (fs.existsSync(abs.botDefinition)) {\n return 'bot'\n }\n if (fs.existsSync(abs.pluginDefinition)) {\n return 'plugin'\n }\n throw new errors.UnsupportedProjectType()\n }\n\n protected readProjectDefinitionFromFS(): ProjectDefinitionLazy {\n try {\n const type = this._readProjectType(this.projectPaths)\n if (type === 'integration') {\n return {\n projectType: 'integration',\n resolveProjectDefinition: async () => ({\n type: 'integration',\n ...(await this._readIntegrationDefinitionFromFS(this.projectPaths)),\n }),\n }\n }\n if (type === 'plugin') {\n return {\n projectType: 'plugin',\n resolveProjectDefinition: async () => ({\n type: 'plugin',\n ...(await this._readPluginDefinitionFromFS(this.projectPaths)),\n }),\n }\n }\n if (type === 'interface') {\n return {\n projectType: 'interface',\n resolveProjectDefinition: async () => ({\n type: 'interface',\n ...(await this._readInterfaceDefinitionFromFS(this.projectPaths)),\n }),\n }\n }\n if (type === 'bot') {\n return {\n projectType: 'bot',\n resolveProjectDefinition: async () => ({\n type: 'bot',\n ...(await this._readBotDefinitionFromFS(this.projectPaths)),\n }),\n }\n }\n } catch (thrown: unknown) {\n throw errors.BotpressCLIError.wrap(thrown, 'Error while reading project definition')\n }\n throw new errors.ProjectDefinitionNotFoundError(this.projectPaths.abs.workDir)\n }\n\n private async _readIntegrationDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'integrationDefinition'>\n ): Promise<{ definition: sdk.IntegrationDefinition } & LintIgnoredConfig> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.integrationDefinition)) {\n throw new errors.BotpressCLIError('Could not read integration definition')\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.integrationDefinition)\n\n const { outputFiles } = await this.projectContext.rebuildEntrypoint({\n absWorkingDir: abs.workDir,\n entrypoint: rel.integrationDefinition,\n })\n\n const artifact = outputFiles?.[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read integration definition')\n }\n\n const definition = this.projectContext.getOrResolveDefinition<sdk.IntegrationDefinition>(artifact.text)\n validateIntegrationDefinition(definition)\n return { definition, bpLintDisabled }\n }\n\n private async _readInterfaceDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'interfaceDefinition'>\n ): Promise<{ definition: sdk.InterfaceDefinition } & LintIgnoredConfig> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.interfaceDefinition)) {\n throw new errors.BotpressCLIError('Could not read interface definition')\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.interfaceDefinition)\n\n const { outputFiles } = await this.projectContext.rebuildEntrypoint({\n absWorkingDir: abs.workDir,\n entrypoint: rel.interfaceDefinition,\n })\n\n const artifact = outputFiles?.[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read interface definition')\n }\n\n const definition = this.projectContext.getOrResolveDefinition<sdk.InterfaceDefinition>(artifact.text)\n\n return { definition, bpLintDisabled }\n }\n\n private async _readBotDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'botDefinition'>\n ): Promise<{ definition: sdk.BotDefinition } & LintIgnoredConfig> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.botDefinition)) {\n throw new errors.BotpressCLIError('Could not read bot definition')\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.botDefinition)\n\n const { outputFiles } = await this.projectContext.rebuildEntrypoint({\n absWorkingDir: abs.workDir,\n entrypoint: rel.botDefinition,\n })\n\n const artifact = outputFiles?.[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read bot definition')\n }\n\n const definition = this.projectContext.getOrResolveDefinition<sdk.BotDefinition>(artifact.text)\n validateBotDefinition(definition)\n return { definition, bpLintDisabled }\n }\n\n private async _readPluginDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'pluginDefinition'>\n ): Promise<{ definition: sdk.PluginDefinition } & LintIgnoredConfig> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.pluginDefinition)) {\n throw new errors.BotpressCLIError('Could not read plugin definition')\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.pluginDefinition)\n\n const { outputFiles } = await this.projectContext.rebuildEntrypoint({\n absWorkingDir: abs.workDir,\n entrypoint: rel.pluginDefinition,\n })\n\n const artifact = outputFiles?.[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read plugin definition')\n }\n\n const definition = this.projectContext.getOrResolveDefinition<sdk.PluginDefinition>(artifact.text)\n // TODO: validate plugin definition\n return { definition, bpLintDisabled }\n }\n\n private async _isBpLintDisabled(definitionPath: string): Promise<boolean> {\n const tsContent = await fs.promises.readFile(definitionPath, 'utf-8')\n const regex = /\\/\\* bplint-disable \\*\\//\n return regex.test(tsContent)\n }\n\n protected async displayIntegrationUrls({ api, bot }: { api: apiUtils.ApiClient; bot: client.Bot }) {\n if (!_.keys(bot.integrations).length) {\n this.logger.debug('No integrations in bot')\n return\n }\n\n const integrationDefinitions = await utils.records.mapValuesAsync(bot.integrations, async (integration) =>\n api.getPublicOrPrivateIntegration({\n type: 'id',\n id: integration.id,\n })\n )\n\n this.logger.log('Integrations:')\n for (const [alias, integration] of Object.entries(bot.integrations)) {\n if (integration.enabled) {\n this.logger.log(`${alias}:`, { prefix: { symbol: '\u2192', indent: 2 } })\n } else {\n this.logger.log(`${alias} ${chalk.italic('(disabled)')}:`, {\n prefix: { symbol: '\u2192', indent: 2 },\n })\n }\n\n const integrationDefinition = integrationDefinitions[alias]\n const linkTemplateScript = integrationDefinition\n ? this._getLinkTemplateScript({ integration, integrationDefinition })\n : undefined\n this._displayWebhookUrl({ integration, integrationDefinition, linkTemplateScript })\n if (!integrationDefinition) {\n this.logger.debug(\n `No integration definition for integration ${alias} (${integration.name}, ${integration.id}), skipping OAuth or Sandbox links`\n )\n this.logger.line().commit()\n continue\n }\n const isSandbox =\n integration.configurationType === 'sandbox' && !!integrationDefinition.sandbox?.identifierExtractScript\n const showLink = !!linkTemplateScript && (isSandbox || !!integrationDefinition.identifier?.extractScript)\n if (showLink && isSandbox) {\n await this._displaySandboxLinkAndCode({ integration, alias, bot, api, linkTemplateScript })\n } else if (showLink) {\n this._displayAuthorizationLink({ integration, api, linkTemplateScript })\n }\n this.logger.line().commit()\n }\n }\n\n private _getLinkTemplateScript({\n integration,\n integrationDefinition,\n }: {\n integration: ClientIntegration\n integrationDefinition?: ClientIntegrationDefinitions[string]\n }) {\n const config =\n integration.configurationType === null\n ? integrationDefinition?.configuration\n : integrationDefinition?.configurations[integration.configurationType]\n return config?.identifier?.linkTemplateScript\n }\n\n private _displayWebhookUrl({\n integration,\n integrationDefinition,\n linkTemplateScript,\n }: {\n integration: ClientIntegration\n integrationDefinition?: ClientIntegrationDefinitions[string]\n linkTemplateScript?: string\n }) {\n const needsWebhook = !(integrationDefinition?.identifier && linkTemplateScript)\n const logFn = (needsWebhook ? this.logger.log : this.logger.debug).bind(this.logger)\n\n if (integration.enabled) {\n logFn(`${chalk.bold('Webhook')}: ${integration.webhookUrl}`, {\n prefix: { symbol: '\u25CF', indent: 4 },\n })\n } else {\n logFn(`Webhook: ${integration.webhookUrl}`, {\n prefix: { symbol: '\u25CB', indent: 4 },\n })\n }\n }\n\n private _displayAuthorizationLink({\n integration,\n api,\n linkTemplateScript,\n }: {\n integration: ClientIntegration\n api: apiUtils.ApiClient\n linkTemplateScript: string\n }) {\n const authorizationLink = this._getAuthorizationLink({ integration, api, linkTemplateScript })\n const isAuthorized = !!integration.identifier\n const authorizationStatus = integration.identifier ? 'Authorized \u2713' : 'Authorize'\n if (integration.enabled && isAuthorized) {\n this.logger.log(`${chalk.bold(authorizationStatus)} : ${authorizationLink}`, {\n prefix: { symbol: '\u25CF', indent: 4 },\n })\n } else {\n this.logger.log(`${authorizationStatus}: ${authorizationLink}`, {\n prefix: { symbol: '\u25CB', indent: 4 },\n })\n }\n }\n\n private _getLinkTemplateArgs({ integration, api }: { integration: ClientIntegration; api: apiUtils.ApiClient }) {\n // These are the values used by the studio\n let env: 'development' | 'preview' | 'production'\n if (api.url.includes(consts.stagingBotpressDomain)) {\n env = 'preview'\n } else if (api.url.includes(consts.productionBotpressDomain)) {\n env = 'production'\n } else {\n env = 'development'\n }\n return {\n env,\n webhookId: integration.webhookId,\n webhookUrl: api.url.replace('api', 'webhook'),\n }\n }\n\n private _getAuthorizationLink({\n integration,\n api,\n linkTemplateScript,\n }: {\n integration: client.Bot['integrations'][string]\n api: apiUtils.ApiClient\n linkTemplateScript: string\n }) {\n return utils.vrl.getStringResult({\n code: linkTemplateScript,\n data: this._getLinkTemplateArgs({ integration, api }),\n })\n }\n\n private _getSandboxLink({\n shareableId,\n integration,\n api,\n linkTemplateScript,\n }: {\n shareableId: string\n integration: ClientIntegration\n api: apiUtils.ApiClient\n linkTemplateScript: string\n }) {\n return utils.vrl.getStringResult({\n code: linkTemplateScript,\n data: { shareableId, ...this._getLinkTemplateArgs({ integration, api }) },\n })\n }\n\n private async _displaySandboxLinkAndCode({\n integration,\n alias,\n bot,\n api,\n linkTemplateScript,\n }: {\n integration: ClientIntegration\n alias: string\n bot: client.Bot\n api: apiUtils.ApiClient\n linkTemplateScript: string\n }) {\n const shareableId = await api.getOrGenerateShareableId(bot.id, integration.id, alias)\n const sandboxLink = this._getSandboxLink({ shareableId, integration, api, linkTemplateScript })\n const sandboxInstruction = `Send '${shareableId}' to ${sandboxLink}`\n if (integration.enabled) {\n this.logger.log(`${chalk.bold('Sandbox')}: ${sandboxInstruction}`, {\n prefix: { symbol: '\u25CF', indent: 4 },\n })\n } else {\n this.logger.log(`Sandbox: ${sandboxInstruction}`, {\n prefix: { symbol: '\u25CB', indent: 4 },\n })\n }\n }\n\n protected async promptSecrets(\n integrationDef: sdk.IntegrationDefinition,\n argv: YargsConfig<typeof config.schemas.secrets>,\n opts: { formatEnv?: boolean; knownSecrets?: string[] } = {}\n ): Promise<Record<string, string | null>> {\n const formatEnv = opts.formatEnv ?? false\n const knownSecrets = opts.knownSecrets ?? []\n\n const { secrets: secretDefinitions } = integrationDef\n if (!secretDefinitions) {\n return {}\n }\n\n const secretArgv = this._parseArgvSecrets(argv.secrets)\n const invalidSecret = Object.keys(secretArgv).find((s) => !secretDefinitions[s])\n if (invalidSecret) {\n throw new errors.BotpressCLIError(`Secret ${invalidSecret} is not defined in integration definition`)\n }\n\n const values: Record<string, string | null> = {}\n for (const [secretName, { optional }] of Object.entries(secretDefinitions)) {\n const argvSecret = secretArgv[secretName]\n if (argvSecret) {\n this.logger.debug(`Using secret \"${secretName}\" from argv`)\n values[secretName] = argvSecret\n continue\n }\n\n const alreadyKnown = knownSecrets.includes(secretName)\n let mode: string\n if (alreadyKnown) {\n mode = 'already set'\n } else if (optional) {\n mode = 'optional'\n } else {\n mode = 'required'\n }\n\n const prompted = await this.prompt.text(`Enter value for secret \"${secretName}\" (${mode})`)\n if (prompted) {\n values[secretName] = prompted\n continue\n }\n\n if (alreadyKnown) {\n this.logger.log(`Secret \"${secretName}\" is unchanged`)\n } else if (optional) {\n this.logger.warn(`Secret \"${secretName}\" is unassigned`)\n } else {\n throw new errors.BotpressCLIError(`Secret \"${secretName}\" is required`)\n }\n }\n\n for (const secretName of knownSecrets) {\n const isDefined = secretName in secretDefinitions\n if (isDefined) {\n continue\n }\n const prompted = await this.prompt.confirm(`Secret \"${secretName}\" was removed. Do you wish to delete it?`)\n if (prompted) {\n this.logger.log(`Deleting secret \"${secretName}\"`, { prefix: { symbol: '\u00D7', fg: 'red' } })\n values[secretName] = null\n }\n }\n\n if (!formatEnv) {\n return values\n }\n\n const envVariables = _.mapKeys(values, (_v, k) => codegen.secretEnvVariableName(k))\n return envVariables\n }\n\n protected async prepareCreateIntegrationBody(\n integrationDef: sdk.IntegrationDefinition\n ): Promise<apiUtils.CreateIntegrationRequestBody> {\n const partialBody = await apiUtils.prepareCreateIntegrationBody(integrationDef)\n\n let code: string | undefined = undefined\n if (fs.existsSync(this.projectPaths.abs.outFileCJS)) {\n code = await this.readProjectFile(this.projectPaths.abs.outFileCJS)\n }\n\n const icon = await this.readProjectFile(integrationDef.icon, 'base64')\n const readme = await this.readProjectFile(integrationDef.readme, 'base64')\n const extractScript = await this.readProjectFile(integrationDef.identifier?.extractScript)\n const fallbackHandlerScript = await this.readProjectFile(integrationDef.identifier?.fallbackHandlerScript)\n return {\n ...partialBody,\n code,\n icon,\n readme,\n identifier: {\n extractScript,\n fallbackHandlerScript,\n },\n configuration: integrationDef.configuration\n ? {\n schema: await utils.schema.mapZodToJsonSchema(integrationDef.configuration, {\n useLegacyZuiTransformer: integrationDef.__advanced?.useLegacyZuiTransformer,\n }),\n identifier: {\n required: integrationDef.configuration.identifier?.required,\n linkTemplateScript: await this.readProjectFile(\n integrationDef.configuration.identifier?.linkTemplateScript\n ),\n },\n }\n : undefined,\n configurations: integrationDef.configurations\n ? await utils.records.mapValuesAsync(integrationDef.configurations, async (configuration) => ({\n title: configuration.title,\n description: configuration.description,\n schema: await utils.schema.mapZodToJsonSchema(configuration, {\n useLegacyZuiTransformer: integrationDef.__advanced?.useLegacyZuiTransformer,\n }),\n identifier: {\n required: configuration.identifier?.required,\n linkTemplateScript: await this.readProjectFile(configuration.identifier?.linkTemplateScript),\n },\n }))\n : undefined,\n }\n }\n\n protected async prepareBotDependencies(\n botDef: sdk.BotDefinition,\n api: apiUtils.ApiClient\n ): Promise<Partial<apiUtils.UpdateBotRequestBody>> {\n const integrations = await this._fetchDependencies({\n deps: botDef.integrations ?? {},\n fetcher: ({ name, version }) => api.getPublicOrPrivateIntegration({ type: 'name', name, version }),\n cacheKey: ({ name, version }) => `integration:${name}@${version}`,\n })\n\n const plugins = await this._fetchDependencies({\n deps: botDef.plugins ?? {},\n fetcher: async ({ name, version }) => await api.getPublicOrPrivatePlugin({ type: 'name', name, version }),\n cacheKey: ({ name, version }) => `plugin:${name}@${version}`,\n })\n\n const pluginsWithBackingIntegrations = await utils.records.mapValuesAsync(plugins, async (plugin) => ({\n ...plugin,\n interfaces: await this._fetchDependencies({\n deps: plugin.interfaces ?? {},\n fetcher: async ({ name, version }) => await api.getPublicOrPrivateIntegration({ name, version, type: 'name' }),\n cacheKey: ({ name, version }) => `interface:${name}@${version}`,\n }),\n integrations: await this._fetchDependencies({\n deps: plugin.integrations ?? {},\n fetcher: async ({ name, version }) => await api.getPublicOrPrivateIntegration({ name, version, type: 'name' }),\n cacheKey: ({ name, version }) => `integration:${name}@${version}`,\n }),\n }))\n\n return {\n integrations: utils.records.mapValues(\n integrations,\n ({ enabled, configurationType, configuration, disabledChannels, id }) =>\n ({\n enabled,\n configurationType,\n configuration,\n disabledChannels,\n integrationId: id,\n }) satisfies NonNullable<apiUtils.UpdateBotRequestBody['integrations']>[string]\n ),\n plugins: utils.records.mapValues(pluginsWithBackingIntegrations, (plugin) => ({\n ...plugin,\n interfaces: utils.records.mapValues(\n plugin.interfaces ?? {},\n (iface) =>\n ({\n integrationId: iface.id,\n integrationAlias: iface.integrationAlias,\n integrationInterfaceAlias: iface.integrationInterfaceAlias,\n }) satisfies NonNullable<\n NonNullable<NonNullable<apiUtils.UpdateBotRequestBody['plugins']>[string]>['interfaces']\n >[string]\n ),\n integrations: utils.records.mapValues(\n plugin.integrations ?? {},\n (integration) =>\n ({\n integrationId: integration.id,\n integrationAlias: integration.integrationAlias,\n }) satisfies NonNullable<\n NonNullable<NonNullable<apiUtils.UpdateBotRequestBody['plugins']>[string]>['integrations']\n >[string]\n ),\n })),\n }\n }\n\n protected async prepareIntegrationDependencies(\n integrationDef: sdk.IntegrationDefinition,\n api: apiUtils.ApiClient\n ): Promise<Partial<apiUtils.CreateIntegrationRequestBody>> {\n const interfaces = await this._fetchDependencies({\n deps: integrationDef.interfaces ?? {},\n fetcher: ({ name, version }) => api.getPublicInterface({ type: 'name', name, version }),\n cacheKey: (dep) => `interface:${dep.name}@${dep.version}`,\n })\n return { interfaces }\n }\n\n protected async preparePluginDependencies(\n pluginDef: sdk.PluginDefinition,\n api: apiUtils.ApiClient\n ): Promise<Partial<apiUtils.CreatePluginRequestBody>> {\n const integrations = await this._fetchDependencies({\n deps: pluginDef.integrations ?? {},\n fetcher: ({ name, version }) => api.getPublicOrPrivateIntegration({ type: 'name', name, version }),\n cacheKey: (dep) => `integration:${dep.name}@${dep.version}`,\n })\n const interfaces = await this._fetchDependencies({\n deps: pluginDef.interfaces ?? {},\n fetcher: ({ name, version }) => api.getPublicInterface({ type: 'name', name, version }),\n cacheKey: (dep) => `interface:${dep.name}@${dep.version}`,\n })\n return {\n dependencies: {\n integrations,\n interfaces,\n },\n }\n }\n\n private _fetchDependencies = async <T extends { id?: string; name: string; version: string }>({\n deps,\n fetcher,\n cacheKey: getCacheKey,\n }: {\n deps: Record<string, T>\n fetcher: (dep: T) => Promise<ResolvedDependency>\n cacheKey: (dep: T) => DependencyCacheKey\n }): Promise<Record<string, T & ResolvedDependency>> => {\n const isRemote = (dep: T): dep is T & ResolvedDependency => dep.id !== undefined\n return utils.records.mapValuesAsync(deps, async (dep): Promise<T & ResolvedDependency> => {\n if (isRemote(dep)) {\n return dep\n }\n\n const cacheKey = getCacheKey(dep)\n const cached = this._dependencyCache.get(cacheKey)\n\n if (cached) {\n return { ...dep, id: cached.id }\n }\n\n const { id } = await fetcher(dep)\n this._dependencyCache.set(cacheKey, { id })\n\n return { ...dep, id }\n })\n }\n\n protected readProjectFile = async (\n filePath: string | undefined,\n encoding: BufferEncoding = 'utf-8'\n ): Promise<string | undefined> => {\n if (!filePath) {\n return undefined\n }\n const absoluteFilePath = utils.path.absoluteFrom(this.projectPaths.abs.workDir, filePath)\n return fs.promises.readFile(absoluteFilePath, encoding).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not read file \"${absoluteFilePath}\"`)\n })\n }\n\n private _parseArgvSecrets(argvSecrets: string[]): Record<string, string> {\n const parsed: Record<string, string> = {}\n for (const secret of argvSecrets) {\n const [key, value] = utils.string.splitOnce(secret, '=')\n if (!value) {\n throw new errors.BotpressCLIError(\n `Secret \"${key}\" is missing a value. Expected format: \"SECRET_NAME=secretValue\"`\n )\n }\n parsed[key!] = value\n }\n\n return parsed\n }\n\n private _notifyUpdateSdk = async (): Promise<void> => {\n try {\n this.logger.debug('Checking if sdk is up to date')\n\n const { workDir } = this.projectPaths.abs\n const readProjectPkgJsonResult = await utils.pkgJson.safeReadPackageJson(workDir)\n if (!readProjectPkgJsonResult.success) {\n this.logger.debug(`Could not read package.json at \"${workDir}\": ${readProjectPkgJsonResult.error.message}`)\n return\n }\n\n if (!readProjectPkgJsonResult.pkgJson) {\n this.logger.debug(`Could not find package.json at \"${workDir}\"`)\n return\n }\n\n const { pkgJson: projectPkgJson } = readProjectPkgJsonResult\n const sdkPackageName = '@botpress/sdk'\n const actualSdkVersion = utils.pkgJson.findDependency(projectPkgJson, sdkPackageName)\n if (!actualSdkVersion) {\n this.logger.debug(`Could not find dependency \"${sdkPackageName}\" in project package.json`)\n return\n }\n\n if (actualSdkVersion.startsWith('workspace:')) {\n return\n }\n\n const actualCleanedSdkVersion = semver.valid(semver.coerce(actualSdkVersion))\n if (!actualCleanedSdkVersion) {\n this.logger.debug(`Invalid sdk version \"${actualSdkVersion}\" in project package.json`)\n return\n }\n\n const cliPkgJson = await this.readCLIPkgJson()\n const expectedSdkVersion = utils.pkgJson.findDependency(cliPkgJson, sdkPackageName)\n if (!expectedSdkVersion) {\n this.logger.debug(`Could not find dependency \"${sdkPackageName}\" in cli package.json`)\n return\n }\n\n const expectedCleanedSdkVersion = semver.valid(semver.coerce(expectedSdkVersion))\n if (!expectedCleanedSdkVersion) {\n this.logger.debug(`Invalid sdk version \"${expectedSdkVersion}\" in cli package.json`)\n return\n }\n\n if (semver.eq(actualCleanedSdkVersion, expectedCleanedSdkVersion)) {\n return\n }\n\n const diff = semver.diff(actualCleanedSdkVersion, expectedCleanedSdkVersion)\n if (!diff) {\n this.logger.debug(`Could not compare versions \"${actualCleanedSdkVersion}\" and \"${expectedCleanedSdkVersion}\"`)\n return\n }\n\n const errorMsg = `Project SDK version is \"${actualCleanedSdkVersion}\", but expected \"${expectedCleanedSdkVersion}\"`\n if (utils.semver.releases.lt(diff, 'minor')) {\n this.logger.debug(`${errorMsg}. This may cause compatibility issues.`)\n return\n }\n\n this.logger.warn(chalk.bold(`${errorMsg}. This will cause compatibility issues.`))\n } catch (thrown) {\n const err = errors.BotpressCLIError.map(thrown)\n this.logger.debug(`Failed to check if sdk is up to date: ${err.message}`)\n }\n }\n protected validateIntegrationRegistration(\n updatedBot: UpdatedBot,\n onFailCallback: (failedIntegrations: UpdatedBot['integrations']) => void\n ) {\n let failedIntegrations: UpdatedBot['integrations'] = {}\n for (const [integrationName, integration] of Object.entries(updatedBot.integrations)) {\n if (integration.status === 'registration_failed') {\n failedIntegrations = { ...failedIntegrations, [integrationName]: integration }\n }\n }\n if (Object.keys(failedIntegrations).length > 0) {\n onFailCallback(failedIntegrations)\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAkB;AAClB,gBAAe;AACf,oBAAc;AACd,oBAAmB;AACnB,eAA0B;AAC1B,cAAyB;AAEzB,aAAwB;AACxB,aAAwB;AACxB,iBAAqE;AAErE,YAAuB;AACvB,4BAA8B;AAgD9B,MAAM,qBAAqB,MAAM,KAAK,UAAiC;AAAA,EAC9D,YAAY,MAA6C;AAC9D,UAAM,aAAa,MAAM,KAAK,aAAa,MAAM,KAAK,IAAI,GAAG,KAAK,OAAO;AACzE,UAAM;AAAA,MACJ,SAAS;AAAA,MACT,GAAG,cAAAA,QAAE,UAAU,OAAO,aAAa,CAAC,MAAM,MAAM,KAAK,aAAa,YAAY,CAAC,CAAC;AAAA,IAClF,CAAC;AAAA,EACH;AACF;AAEO,MAAM,yBAAyB;AAAA,EAC5B,aAAkC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MAAM,OAAO,SAAS,GAAG,MAAM,OAAO,GAAG;AAC3C,aAAK,OAAO,MAAM,GAAG,QAAQ,wCAAwC;AACrE;AAAA,MACF;AAEA,WAAK,OAAO,KAAK,aAAAF,QAAM,KAAK,GAAG,QAAQ,yCAAyC,CAAC;AAAA,IACnF,SAAS,QAAQ;AACf,YAAM,MAAM,OAAO,iBAAiB,IAAI,MAAM;AAC9C,WAAK,OAAO,MAAM,yCAAyC,IAAI,OAAO,EAAE;AAAA,IAC1E;AAAA,EACF;AAAA,EACU,gCACR,YACA,gBACA;AACA,QAAI,qBAAiD,CAAC;AACtD,eAAW,CAAC,iBAAiB,WAAW,KAAK,OAAO,QAAQ,WAAW,YAAY,GAAG;AACpF,UAAI,YAAY,WAAW,uBAAuB;AAChD,6BAAqB,EAAE,GAAG,oBAAoB,CAAC,eAAe,GAAG,YAAY;AAAA,MAC/E;AAAA,IACF;AACA,QAAI,OAAO,KAAK,kBAAkB,EAAE,SAAS,GAAG;AAC9C,qBAAe,kBAAkB;AAAA,IACnC;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["_", "fs", "chalk", "config", "semver"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type commandDefinitions from '../command-definitions';
|
|
2
|
+
import { ProjectCommand } from './project-command';
|
|
3
|
+
export type RemoveCommandDefinition = typeof commandDefinitions.remove;
|
|
4
|
+
export declare class RemoveCommand extends ProjectCommand<RemoveCommandDefinition> {
|
|
5
|
+
protected run(): Promise<void>;
|
|
6
|
+
private _validatePkgJson;
|
|
7
|
+
private _removeDepFromBpModules;
|
|
8
|
+
private _removeDepFromPkgJson;
|
|
9
|
+
private _findCorrespondingPackage;
|
|
10
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var remove_command_exports = {};
|
|
30
|
+
__export(remove_command_exports, {
|
|
31
|
+
RemoveCommand: () => RemoveCommand
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(remove_command_exports);
|
|
34
|
+
var sdk = __toESM(require("@botpress/sdk"));
|
|
35
|
+
var fslib = __toESM(require("fs"));
|
|
36
|
+
var consts = __toESM(require("../consts"));
|
|
37
|
+
var errors = __toESM(require("../errors"));
|
|
38
|
+
var utils = __toESM(require("../utils"));
|
|
39
|
+
var import_pkgjson_utils = require("../utils/pkgjson-utils");
|
|
40
|
+
var import_project_command = require("./project-command");
|
|
41
|
+
class RemoveCommand extends import_project_command.ProjectCommand {
|
|
42
|
+
async run() {
|
|
43
|
+
const alias = this.argv.alias;
|
|
44
|
+
if (!alias) {
|
|
45
|
+
throw new errors.BotpressCLIError("You have to provide the alias of the package to remove");
|
|
46
|
+
}
|
|
47
|
+
const workDir = utils.path.absoluteFrom(utils.path.cwd(), this.argv.workDir);
|
|
48
|
+
const { validatedBpDeps, pkgJson } = await this._validatePkgJson(workDir);
|
|
49
|
+
const correspondingPackageAlias = this._findCorrespondingPackage(alias, validatedBpDeps);
|
|
50
|
+
await this._removeDepFromBpModules(correspondingPackageAlias, workDir, alias);
|
|
51
|
+
await this._removeDepFromPkgJson(correspondingPackageAlias, validatedBpDeps, pkgJson, workDir, alias);
|
|
52
|
+
}
|
|
53
|
+
async _validatePkgJson(workDir) {
|
|
54
|
+
const pkgJson = await utils.pkgJson.readPackageJson(workDir);
|
|
55
|
+
if (!pkgJson) {
|
|
56
|
+
throw new errors.BotpressCLIError(`No ${import_pkgjson_utils.PKGJSON_FILE_NAME} found in path ${workDir}`);
|
|
57
|
+
}
|
|
58
|
+
const bpDependencies = pkgJson[import_pkgjson_utils.BP_DEPENDENCIES_KEY];
|
|
59
|
+
if (!bpDependencies) {
|
|
60
|
+
throw new errors.BotpressCLIError("package");
|
|
61
|
+
}
|
|
62
|
+
const bpDependenciesSchema = sdk.z.record(sdk.z.string());
|
|
63
|
+
const parseResult = bpDependenciesSchema.safeParse(bpDependencies);
|
|
64
|
+
if (!parseResult.success) {
|
|
65
|
+
throw new errors.BotpressCLIError(`Invalid ${import_pkgjson_utils.BP_DEPENDENCIES_KEY} found in ${import_pkgjson_utils.PKGJSON_FILE_NAME}`);
|
|
66
|
+
}
|
|
67
|
+
return { validatedBpDeps: parseResult.data, pkgJson };
|
|
68
|
+
}
|
|
69
|
+
async _removeDepFromBpModules(correspondingPackageAlias, workDir, alias) {
|
|
70
|
+
const packageDirName = utils.casing.to.kebabCase(correspondingPackageAlias);
|
|
71
|
+
const installPath = utils.path.join(workDir, consts.installDirName, packageDirName);
|
|
72
|
+
await fslib.promises.rm(installPath, { force: true, recursive: true });
|
|
73
|
+
this.logger.log(`Package "${alias}" was removed from bp_modules`);
|
|
74
|
+
}
|
|
75
|
+
async _removeDepFromPkgJson(correspondingPackageAlias, validatedBpDeps, pkgJson, workDir, alias) {
|
|
76
|
+
const { [correspondingPackageAlias]: _, ...newBpDependencies } = validatedBpDeps;
|
|
77
|
+
pkgJson[import_pkgjson_utils.BP_DEPENDENCIES_KEY] = newBpDependencies;
|
|
78
|
+
await utils.pkgJson.writePackageJson(workDir, pkgJson);
|
|
79
|
+
this.logger.log(`Package with alias "${alias}" was removed from ${import_pkgjson_utils.PKGJSON_FILE_NAME}`);
|
|
80
|
+
}
|
|
81
|
+
_findCorrespondingPackage(alias, bpDependencies) {
|
|
82
|
+
const correspondingPackage = Object.keys(bpDependencies).find((key) => key === alias);
|
|
83
|
+
if (!correspondingPackage) {
|
|
84
|
+
throw new errors.BotpressCLIError(
|
|
85
|
+
`No corresponding package for alias "${alias}" was found in ${import_pkgjson_utils.BP_DEPENDENCIES_KEY}`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
return correspondingPackage;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
+
0 && (module.exports = {
|
|
93
|
+
RemoveCommand
|
|
94
|
+
});
|
|
95
|
+
//# sourceMappingURL=remove-command.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/command-implementations/remove-command.ts"],
|
|
4
|
+
"sourcesContent": ["import * as sdk from '@botpress/sdk'\nimport * as fslib from 'fs'\nimport type commandDefinitions from '../command-definitions'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport * as utils from '../utils'\nimport { BP_DEPENDENCIES_KEY, PKGJSON_FILE_NAME } from '../utils/pkgjson-utils'\nimport { ProjectCommand } from './project-command'\n\nexport type RemoveCommandDefinition = typeof commandDefinitions.remove\nexport class RemoveCommand extends ProjectCommand<RemoveCommandDefinition> {\n protected async run(): Promise<void> {\n const alias = this.argv.alias\n if (!alias) {\n throw new errors.BotpressCLIError('You have to provide the alias of the package to remove')\n }\n\n const workDir = utils.path.absoluteFrom(utils.path.cwd(), this.argv.workDir)\n\n const { validatedBpDeps, pkgJson } = await this._validatePkgJson(workDir)\n\n const correspondingPackageAlias = this._findCorrespondingPackage(alias, validatedBpDeps)\n\n await this._removeDepFromBpModules(correspondingPackageAlias, workDir, alias)\n\n await this._removeDepFromPkgJson(correspondingPackageAlias, validatedBpDeps, pkgJson, workDir, alias)\n }\n\n private async _validatePkgJson(workDir: string): Promise<{\n validatedBpDeps: Record<string, string>\n pkgJson: utils.pkgJson.PackageJson\n }> {\n const pkgJson = await utils.pkgJson.readPackageJson(workDir)\n if (!pkgJson) {\n throw new errors.BotpressCLIError(`No ${PKGJSON_FILE_NAME} found in path ${workDir}`)\n }\n\n const bpDependencies = pkgJson[BP_DEPENDENCIES_KEY]\n if (!bpDependencies) {\n throw new errors.BotpressCLIError('package')\n }\n\n const bpDependenciesSchema = sdk.z.record(sdk.z.string())\n const parseResult = bpDependenciesSchema.safeParse(bpDependencies)\n if (!parseResult.success) {\n throw new errors.BotpressCLIError(`Invalid ${BP_DEPENDENCIES_KEY} found in ${PKGJSON_FILE_NAME}`)\n }\n\n return { validatedBpDeps: parseResult.data, pkgJson }\n }\n\n private async _removeDepFromBpModules(\n correspondingPackageAlias: string,\n workDir: utils.path.AbsolutePath,\n alias: string\n ) {\n const packageDirName = utils.casing.to.kebabCase(correspondingPackageAlias)\n const installPath = utils.path.join(workDir, consts.installDirName, packageDirName)\n\n await fslib.promises.rm(installPath, { force: true, recursive: true })\n this.logger.log(`Package \"${alias}\" was removed from bp_modules`)\n }\n\n private async _removeDepFromPkgJson(\n correspondingPackageAlias: string,\n validatedBpDeps: Record<string, string>,\n pkgJson: utils.pkgJson.PackageJson,\n workDir: string,\n alias: string\n ) {\n const { [correspondingPackageAlias]: _, ...newBpDependencies } = validatedBpDeps\n pkgJson[BP_DEPENDENCIES_KEY] = newBpDependencies\n\n await utils.pkgJson.writePackageJson(workDir, pkgJson)\n this.logger.log(`Package with alias \"${alias}\" was removed from ${PKGJSON_FILE_NAME}`)\n }\n\n private _findCorrespondingPackage(alias: string, bpDependencies: Record<string, string>): string {\n const correspondingPackage: string | undefined = Object.keys(bpDependencies).find((key) => key === alias)\n\n if (!correspondingPackage) {\n throw new errors.BotpressCLIError(\n `No corresponding package for alias \"${alias}\" was found in ${BP_DEPENDENCIES_KEY}`\n )\n }\n\n return correspondingPackage\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,UAAqB;AACrB,YAAuB;AAEvB,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,2BAAuD;AACvD,6BAA+B;AAGxB,MAAM,sBAAsB,sCAAwC;AAAA,EACzE,MAAgB,MAAqB;AACnC,UAAM,QAAQ,KAAK,KAAK;AACxB,QAAI,CAAC,OAAO;AACV,YAAM,IAAI,OAAO,iBAAiB,wDAAwD;AAAA,IAC5F;AAEA,UAAM,UAAU,MAAM,KAAK,aAAa,MAAM,KAAK,IAAI,GAAG,KAAK,KAAK,OAAO;AAE3E,UAAM,EAAE,iBAAiB,QAAQ,IAAI,MAAM,KAAK,iBAAiB,OAAO;AAExE,UAAM,4BAA4B,KAAK,0BAA0B,OAAO,eAAe;AAEvF,UAAM,KAAK,wBAAwB,2BAA2B,SAAS,KAAK;AAE5E,UAAM,KAAK,sBAAsB,2BAA2B,iBAAiB,SAAS,SAAS,KAAK;AAAA,EACtG;AAAA,EAEA,MAAc,iBAAiB,SAG5B;AACD,UAAM,UAAU,MAAM,MAAM,QAAQ,gBAAgB,OAAO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kB,wCAAmB;AAAA,MACnF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/config.d.ts
CHANGED
|
@@ -1142,11 +1142,6 @@ export declare const schemas: {
|
|
|
1142
1142
|
positional: true;
|
|
1143
1143
|
idx: number;
|
|
1144
1144
|
};
|
|
1145
|
-
packageType: {
|
|
1146
|
-
type: "string";
|
|
1147
|
-
description: string;
|
|
1148
|
-
choices: readonly ["integration", "interface", "plugin"];
|
|
1149
|
-
};
|
|
1150
1145
|
installPath: {
|
|
1151
1146
|
type: "string";
|
|
1152
1147
|
description: string;
|
|
@@ -1201,6 +1196,58 @@ export declare const schemas: {
|
|
|
1201
1196
|
alias: string;
|
|
1202
1197
|
};
|
|
1203
1198
|
};
|
|
1199
|
+
readonly remove: {
|
|
1200
|
+
workDir: {
|
|
1201
|
+
type: "string";
|
|
1202
|
+
description: string;
|
|
1203
|
+
default: string;
|
|
1204
|
+
};
|
|
1205
|
+
alias: {
|
|
1206
|
+
idx: number;
|
|
1207
|
+
positional: true;
|
|
1208
|
+
type: "string";
|
|
1209
|
+
description: string;
|
|
1210
|
+
};
|
|
1211
|
+
apiUrl: {
|
|
1212
|
+
type: "string";
|
|
1213
|
+
description: string;
|
|
1214
|
+
};
|
|
1215
|
+
workspaceId: {
|
|
1216
|
+
type: "string";
|
|
1217
|
+
description: string;
|
|
1218
|
+
};
|
|
1219
|
+
token: {
|
|
1220
|
+
type: "string";
|
|
1221
|
+
description: string;
|
|
1222
|
+
};
|
|
1223
|
+
verbose: {
|
|
1224
|
+
type: "boolean";
|
|
1225
|
+
description: string;
|
|
1226
|
+
alias: string;
|
|
1227
|
+
default: boolean;
|
|
1228
|
+
};
|
|
1229
|
+
confirm: {
|
|
1230
|
+
type: "boolean";
|
|
1231
|
+
description: string;
|
|
1232
|
+
alias: string;
|
|
1233
|
+
default: boolean;
|
|
1234
|
+
};
|
|
1235
|
+
json: {
|
|
1236
|
+
type: "boolean";
|
|
1237
|
+
description: string;
|
|
1238
|
+
default: boolean;
|
|
1239
|
+
};
|
|
1240
|
+
botpressHome: {
|
|
1241
|
+
type: "string";
|
|
1242
|
+
description: string;
|
|
1243
|
+
default: string;
|
|
1244
|
+
};
|
|
1245
|
+
profile: {
|
|
1246
|
+
type: "string";
|
|
1247
|
+
description: string;
|
|
1248
|
+
alias: string;
|
|
1249
|
+
};
|
|
1250
|
+
};
|
|
1204
1251
|
readonly dev: {
|
|
1205
1252
|
sourceMap: {
|
|
1206
1253
|
type: "boolean";
|
package/dist/config.js
CHANGED
|
@@ -77,11 +77,6 @@ const botRef = {
|
|
|
77
77
|
positional: true,
|
|
78
78
|
idx: 0
|
|
79
79
|
};
|
|
80
|
-
const packageType = {
|
|
81
|
-
type: "string",
|
|
82
|
-
description: "Either an integration or an interface; helps disambiguate the package type in case both an integration and an interface have the same reference.",
|
|
83
|
-
choices: ["integration", "interface", "plugin"]
|
|
84
|
-
};
|
|
85
80
|
const packageRef = {
|
|
86
81
|
type: "string",
|
|
87
82
|
description: "The package ID or name with optional version. The package can be either an integration or an interface. Ex: teams, teams@0.2.0, llm@5.1.0",
|
|
@@ -221,7 +216,6 @@ const addSchema = {
|
|
|
221
216
|
...globalSchema,
|
|
222
217
|
...credentialsSchema,
|
|
223
218
|
packageRef,
|
|
224
|
-
packageType,
|
|
225
219
|
installPath: {
|
|
226
220
|
type: "string",
|
|
227
221
|
description: "The path where to install the package",
|
|
@@ -234,9 +228,15 @@ const addSchema = {
|
|
|
234
228
|
},
|
|
235
229
|
alias: {
|
|
236
230
|
type: "string",
|
|
237
|
-
description: "The alias
|
|
231
|
+
description: "The alias to install the package with"
|
|
238
232
|
}
|
|
239
233
|
};
|
|
234
|
+
const removeSchema = {
|
|
235
|
+
...globalSchema,
|
|
236
|
+
...credentialsSchema,
|
|
237
|
+
workDir,
|
|
238
|
+
alias: { idx: 0, positional: true, type: "string", description: "The alias of the package to uninstall" }
|
|
239
|
+
};
|
|
240
240
|
const loginSchema = {
|
|
241
241
|
...globalSchema,
|
|
242
242
|
token,
|
|
@@ -392,6 +392,7 @@ const schemas = {
|
|
|
392
392
|
serve: serveSchema,
|
|
393
393
|
deploy: deploySchema,
|
|
394
394
|
add: addSchema,
|
|
395
|
+
remove: removeSchema,
|
|
395
396
|
dev: devSchema,
|
|
396
397
|
lint: lintSchema,
|
|
397
398
|
chat: chatSchema,
|