@botpress/cli 0.4.2 → 0.4.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/api/client.js +14 -19
- package/dist/api/client.js.map +2 -2
- package/dist/api/paging.js +42 -0
- package/dist/api/paging.js.map +7 -0
- package/dist/command-implementations/deploy-command.js +5 -0
- package/dist/command-implementations/deploy-command.js.map +2 -2
- package/dist/command-implementations/login-command.js +4 -2
- package/dist/command-implementations/login-command.js.map +2 -2
- package/package.json +3 -3
- package/templates/echo-bot/package.json +2 -2
- package/templates/empty-integration/package.json +2 -2
package/dist/api/client.js
CHANGED
|
@@ -27,14 +27,15 @@ __export(client_exports, {
|
|
|
27
27
|
ApiClient: () => ApiClient
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(client_exports);
|
|
30
|
-
var
|
|
30
|
+
var bpclient = __toESM(require("@botpress/client"));
|
|
31
31
|
var import_lodash = __toESM(require("lodash"));
|
|
32
32
|
var import_integration_ref = require("../integration-ref");
|
|
33
|
+
var paging = __toESM(require("./paging"));
|
|
33
34
|
class ApiClient {
|
|
34
35
|
constructor(props, _logger) {
|
|
35
36
|
this._logger = _logger;
|
|
36
37
|
const { apiUrl, token, workspaceId } = props;
|
|
37
|
-
this.client = new
|
|
38
|
+
this.client = new bpclient.Client({ apiUrl, token, workspaceId });
|
|
38
39
|
this.url = apiUrl;
|
|
39
40
|
this.token = token;
|
|
40
41
|
this.workspaceId = workspaceId;
|
|
@@ -59,10 +60,17 @@ class ApiClient {
|
|
|
59
60
|
return;
|
|
60
61
|
}
|
|
61
62
|
async findPrivateIntegration(ref) {
|
|
63
|
+
const { workspaceId } = this;
|
|
62
64
|
if (ref.type === "id") {
|
|
63
|
-
return this.validateStatus(
|
|
65
|
+
return this.validateStatus(
|
|
66
|
+
() => this.client.getIntegration(ref).then((r) => ({ ...r.integration, workspaceId })),
|
|
67
|
+
404
|
|
68
|
+
);
|
|
64
69
|
}
|
|
65
|
-
return this.validateStatus(
|
|
70
|
+
return this.validateStatus(
|
|
71
|
+
() => this.client.getIntegrationByName(ref).then((r) => ({ ...r.integration, workspaceId })),
|
|
72
|
+
404
|
|
73
|
+
);
|
|
66
74
|
}
|
|
67
75
|
async findPublicIntegration(ref) {
|
|
68
76
|
if (ref.type === "id") {
|
|
@@ -73,27 +81,14 @@ class ApiClient {
|
|
|
73
81
|
async testLogin() {
|
|
74
82
|
await this.client.listBots({});
|
|
75
83
|
}
|
|
76
|
-
|
|
77
|
-
let nextToken;
|
|
78
|
-
const all = [];
|
|
79
|
-
do {
|
|
80
|
-
const { meta, ...r } = await lister({ nextToken });
|
|
81
|
-
all.push(r);
|
|
82
|
-
nextToken = meta.nextToken;
|
|
83
|
-
} while (nextToken);
|
|
84
|
-
if (!mapper) {
|
|
85
|
-
return all;
|
|
86
|
-
}
|
|
87
|
-
const mapped = all.flatMap((r) => mapper(r));
|
|
88
|
-
return mapped;
|
|
89
|
-
}
|
|
84
|
+
listAllPages = paging.listAllPages;
|
|
90
85
|
async validateStatus(fn, allowedStatuses) {
|
|
91
86
|
try {
|
|
92
87
|
const v = await fn();
|
|
93
88
|
return v;
|
|
94
89
|
} catch (err) {
|
|
95
90
|
const allowedStatusesArray = import_lodash.default.isArray(allowedStatuses) ? allowedStatuses : [allowedStatuses];
|
|
96
|
-
const isAllowed =
|
|
91
|
+
const isAllowed = bpclient.isApiError(err) && err.code && allowedStatusesArray.includes(err.code);
|
|
97
92
|
if (isAllowed) {
|
|
98
93
|
return;
|
|
99
94
|
}
|
package/dist/api/client.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/api/client.ts"],
|
|
4
|
-
"sourcesContent": ["import
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import * as bpclient from '@botpress/client'\nimport _ from 'lodash'\nimport { formatIntegrationRef, IntegrationRef } from '../integration-ref'\nimport type { Logger } from '../logger'\nimport * as paging from './paging'\n\nexport type PageLister<R extends object> = (t: { nextToken?: string }) => Promise<R & { meta: { nextToken?: string } }>\n\nexport type ApiClientProps = {\n apiUrl: string\n token: string\n workspaceId: string\n}\n\nexport type ApiClientFactory = {\n newClient: (props: ApiClientProps, logger: Logger) => ApiClient\n}\n\ntype PublicIntegration = bpclient.Integration\ntype PrivateIntegration = bpclient.Integration & { workspaceId: string }\ntype Integration = bpclient.Integration & { workspaceId?: string }\n\n/**\n * This class is used to wrap the Botpress API and provide a more convenient way to interact with it.\n */\nexport class ApiClient {\n public readonly client: bpclient.Client\n public readonly url: string\n public readonly token: string\n public readonly workspaceId: string\n\n public static newClient = (props: ApiClientProps, logger: Logger) => new ApiClient(props, logger)\n\n public constructor(props: ApiClientProps, private _logger: Logger) {\n const { apiUrl, token, workspaceId } = props\n this.client = new bpclient.Client({ apiUrl, token, workspaceId })\n this.url = apiUrl\n this.token = token\n this.workspaceId = workspaceId\n }\n\n public async findIntegration(ref: IntegrationRef): Promise<Integration | undefined> {\n const formatted = formatIntegrationRef(ref)\n\n const privateIntegration = await this.findPrivateIntegration(ref)\n if (privateIntegration) {\n this._logger.debug(`Found integration \"${formatted}\" in workspace`)\n return privateIntegration\n }\n\n const publicIntegration = await this.findPublicIntegration(ref)\n if (publicIntegration) {\n this._logger.debug(`Found integration \"${formatted}\" in hub`)\n return publicIntegration\n }\n\n return\n }\n\n public async findPrivateIntegration(ref: IntegrationRef): Promise<PrivateIntegration | undefined> {\n const { workspaceId } = this\n if (ref.type === 'id') {\n return this.validateStatus(\n () => this.client.getIntegration(ref).then((r) => ({ ...r.integration, workspaceId })),\n 404\n )\n }\n return this.validateStatus(\n () => this.client.getIntegrationByName(ref).then((r) => ({ ...r.integration, workspaceId })),\n 404\n )\n }\n\n public async findPublicIntegration(ref: IntegrationRef): Promise<PublicIntegration | undefined> {\n if (ref.type === 'id') {\n return this.validateStatus(() => this.client.getPublicIntegrationById(ref).then((r) => r.integration), 404)\n }\n return this.validateStatus(() => this.client.getPublicIntegration(ref).then((r) => r.integration), 404)\n }\n\n public async testLogin(): Promise<void> {\n await this.client.listBots({})\n }\n\n public listAllPages = paging.listAllPages\n\n public async validateStatus<V>(fn: () => Promise<V>, allowedStatuses: number | number[]): Promise<V | undefined> {\n try {\n const v = await fn()\n return v\n } catch (err) {\n const allowedStatusesArray = _.isArray(allowedStatuses) ? allowedStatuses : [allowedStatuses]\n const isAllowed = bpclient.isApiError(err) && err.code && allowedStatusesArray.includes(err.code)\n if (isAllowed) {\n return\n }\n throw err\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAA0B;AAC1B,oBAAc;AACd,6BAAqD;AAErD,aAAwB;AAqBjB,MAAM,UAAU;AAAA,EAQd,YAAY,OAA+B,SAAiB;AAAjB;AAChD,UAAM,EAAE,QAAQ,OAAO,YAAY,IAAI;AACvC,SAAK,SAAS,IAAI,SAAS,OAAO,EAAE,QAAQ,OAAO,YAAY,CAAC;AAChE,SAAK,MAAM;AACX,SAAK,QAAQ;AACb,SAAK,cAAc;AAAA,EACrB;AAAA,EAbgB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,OAAc,YAAY,CAAC,OAAuB,WAAmB,IAAI,UAAU,OAAO,MAAM;AAAA,EAUhG,MAAa,gBAAgB,KAAuD;AAClF,UAAM,gBAAY,6CAAqB,GAAG;AAE1C,UAAM,qBAAqB,MAAM,KAAK,uBAAuB,GAAG;AAChE,QAAI,oBAAoB;AACtB,WAAK,QAAQ,MAAM,sBAAsB,yBAAyB;AAClE,aAAO;AAAA,IACT;AAEA,UAAM,oBAAoB,MAAM,KAAK,sBAAsB,GAAG;AAC9D,QAAI,mBAAmB;AACrB,WAAK,QAAQ,MAAM,sBAAsB,mBAAmB;AAC5D,aA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,0 +1,42 @@
|
|
|
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 paging_exports = {};
|
|
20
|
+
__export(paging_exports, {
|
|
21
|
+
listAllPages: () => listAllPages
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(paging_exports);
|
|
24
|
+
async function listAllPages(lister, mapper) {
|
|
25
|
+
let nextToken;
|
|
26
|
+
const all = [];
|
|
27
|
+
do {
|
|
28
|
+
const { meta, ...r } = await lister({ nextToken });
|
|
29
|
+
all.push(r);
|
|
30
|
+
nextToken = meta.nextToken;
|
|
31
|
+
} while (nextToken);
|
|
32
|
+
if (!mapper) {
|
|
33
|
+
return all;
|
|
34
|
+
}
|
|
35
|
+
const mapped = all.flatMap((r) => mapper(r));
|
|
36
|
+
return mapped;
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
listAllPages
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=paging.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/api/paging.ts"],
|
|
4
|
+
"sourcesContent": ["export type PageLister<R extends object> = (t: { nextToken?: string }) => Promise<R & { meta: { nextToken?: string } }>\n\nexport async function listAllPages<R extends object>(lister: PageLister<R>): Promise<R[]>\nexport async function listAllPages<R extends object, M>(lister: PageLister<R>, mapper?: (r: R) => M[]): Promise<M[]>\nexport async function listAllPages<R extends object, M>(lister: PageLister<R>, mapper?: (r: R) => M[]) {\n let nextToken: string | undefined\n const all: R[] = []\n\n do {\n const { meta, ...r } = await lister({ nextToken })\n all.push(r as R)\n nextToken = meta.nextToken\n } while (nextToken)\n\n if (!mapper) {\n return all\n }\n\n const mapped: M[] = all.flatMap((r) => mapper(r))\n return mapped\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,eAAsB,aAAkC,QAAuB,QAAwB;AACrG,MAAI;AACJ,QAAM,MAAW,CAAC;AAElB,KAAG;AACD,UAAM,EAAE,SAAS,EAAE,IAAI,MAAM,OAAO,EAAE,UAAU,CAAC;AACjD,QAAI,KAAK,CAAM;AACf,gBAAY,KAAK;AAAA,EACnB,SAAS;AAET,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,QAAM,SAAc,IAAI,QAAQ,CAAC,MAAM,OAAO,CAAC,CAAC;AAChD,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -65,6 +65,11 @@ class DeployCommand extends import_project_command.ProjectCommand {
|
|
|
65
65
|
const iconFileContent = await this._readMediaFile("icon", iconRelativeFilePath);
|
|
66
66
|
const readmeFileContent = await this._readMediaFile("readme", readmeRelativeFilePath);
|
|
67
67
|
const integration = await api.findIntegration({ type: "name", name, version });
|
|
68
|
+
if (integration && !integration.workspaceId) {
|
|
69
|
+
throw new errors.BotpressCLIError(
|
|
70
|
+
`Public integration ${integrationDef.name} v${integrationDef.version} is already deployed in another workspace.`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
68
73
|
let message;
|
|
69
74
|
if (integration) {
|
|
70
75
|
this.logger.warn("Integration already exists. If you decide to deploy, it will overwrite the existing one.");
|
|
@@ -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 * as bpsdk from '@botpress/sdk'\nimport chalk from 'chalk'\nimport * as fs from 'fs'\nimport { prepareUpdateBotBody } from '../api/bot-body'\nimport type { ApiClient } from '../api/client'\nimport { prepareUpdateIntegrationBody, CreateIntegrationBody } from '../api/integration-body'\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.url !== consts.defaultBotpressApiUrl) {\n this.logger.log(`Using custom url ${api.url}`)\n }\n\n if (!this.argv.noBuild) {\n await this._runBuild() // This ensures the bundle is always synced with source code\n }\n\n const integrationDef = await this.readIntegrationDefinitionFromFS()\n if (integrationDef) {\n return this._deployIntegration(api, integrationDef)\n }\n return this._deployBot(api, this.argv.botId, this.argv.createNewBot)\n }\n\n private async _runBuild() {\n return new BuildCommand(this.api, this.prompt, this.logger, this.argv).run()\n }\n\n private async _deployIntegration(api: ApiClient, integrationDef: bpsdk.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 createBody: CreateIntegrationBody = {\n ...this.parseIntegrationDefinition(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 updateBody = prepareUpdateIntegrationBody(\n {\n id: integration.id,\n ...createBody,\n },\n integration\n )\n\n await api.client.updateIntegration(updateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update integration \"${integrationDef.name}\"`)\n })\n } else {\n await api.client.createIntegration(createBody).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: bpsdk.Bot }>(outfile)\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 line = this.logger.line()\n line.started(`Deploying bot ${chalk.bold(bot.name)}...`)\n\n const updateBotBody = prepareUpdateBotBody(\n {\n id: bot.id,\n code,\n ...this.parseBot(botImpl),\n },\n bot\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 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;AACpB,sBAAqC;AAErC,8BAAoE;AAEpE,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,2BAA6B;AAC7B,6BAA+B;AAGxB,MAAM,sBAAsB,sCAAwC;AAAA,EACzE,MAAa,MAAqB;AAChC,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAC3D,QAAI,IAAI,QAAQ,OAAO,uBAAuB;AAC5C,WAAK,OAAO,IAAI,oBAAoB,IAAI,KAAK;AAAA,IAC/C;AAEA,QAAI,CAAC,KAAK,KAAK,SAAS;AACtB,YAAM,KAAK,UAAU;AAAA,IACvB;AAEA,UAAM,iBAAiB,MAAM,KAAK,gCAAgC;AAClE,QAAI,gBAAgB;AAClB,aAAO,KAAK,mBAAmB,KAAK,cAAc;AAAA,IACpD;AACA,WAAO,KAAK,WAAW,KAAK,KAAK,KAAK,OAAO,KAAK,KAAK,YAAY;AAAA,EACrE;AAAA,EAEA,MAAc,YAAY;AACxB,WAAO,IAAI,kCAAa,KAAK,KAAK,KAAK,QAAQ,KAAK,QAAQ,KAAK,IAAI,EAAE,IAAI;AAAA,EAC7E;AAAA,EAEA,MAAc,mBAAmB,KAAgB,gBAA6C;AAC5F,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,OAAO,mBAAmB,cAAc,GAAG,GAAG,IAAI,cAAc;AAAA,IAC1F;AAEA,UAAM,EAAE,MAAM,SAAS,MAAM,sBAAsB,QAAQ,uBAAuB,IAAI;AAEtF,UAAM,kBAAkB,MAAM,KAAK,eAAe,QAAQ,oBAAoB;AAC9E,UAAM,oBAAoB,MAAM,KAAK,eAAe,UAAU,sBAAsB;AAEpF,UAAM,cAAc,MAAM,IAAI,gBAAgB,EAAE,MAAM,QAAQ,MAAM,QAAQ,CAAC;
|
|
4
|
+
"sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport type * as bpsdk from '@botpress/sdk'\nimport chalk from 'chalk'\nimport * as fs from 'fs'\nimport { prepareUpdateBotBody } from '../api/bot-body'\nimport type { ApiClient } from '../api/client'\nimport { prepareUpdateIntegrationBody, CreateIntegrationBody } from '../api/integration-body'\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.url !== consts.defaultBotpressApiUrl) {\n this.logger.log(`Using custom url ${api.url}`)\n }\n\n if (!this.argv.noBuild) {\n await this._runBuild() // This ensures the bundle is always synced with source code\n }\n\n const integrationDef = await this.readIntegrationDefinitionFromFS()\n if (integrationDef) {\n return this._deployIntegration(api, integrationDef)\n }\n return this._deployBot(api, this.argv.botId, this.argv.createNewBot)\n }\n\n private async _runBuild() {\n return new BuildCommand(this.api, this.prompt, this.logger, this.argv).run()\n }\n\n private async _deployIntegration(api: ApiClient, integrationDef: bpsdk.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 if (integration && !integration.workspaceId) {\n throw new errors.BotpressCLIError(\n `Public integration ${integrationDef.name} v${integrationDef.version} is already deployed in another workspace.`\n )\n }\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 createBody: CreateIntegrationBody = {\n ...this.parseIntegrationDefinition(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 updateBody = prepareUpdateIntegrationBody(\n {\n id: integration.id,\n ...createBody,\n },\n integration\n )\n\n await api.client.updateIntegration(updateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update integration \"${integrationDef.name}\"`)\n })\n } else {\n await api.client.createIntegration(createBody).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: bpsdk.Bot }>(outfile)\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 line = this.logger.line()\n line.started(`Deploying bot ${chalk.bold(bot.name)}...`)\n\n const updateBotBody = prepareUpdateBotBody(\n {\n id: bot.id,\n code,\n ...this.parseBot(botImpl),\n },\n bot\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 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;AACpB,sBAAqC;AAErC,8BAAoE;AAEpE,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,2BAA6B;AAC7B,6BAA+B;AAGxB,MAAM,sBAAsB,sCAAwC;AAAA,EACzE,MAAa,MAAqB;AAChC,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAC3D,QAAI,IAAI,QAAQ,OAAO,uBAAuB;AAC5C,WAAK,OAAO,IAAI,oBAAoB,IAAI,KAAK;AAAA,IAC/C;AAEA,QAAI,CAAC,KAAK,KAAK,SAAS;AACtB,YAAM,KAAK,UAAU;AAAA,IACvB;AAEA,UAAM,iBAAiB,MAAM,KAAK,gCAAgC;AAClE,QAAI,gBAAgB;AAClB,aAAO,KAAK,mBAAmB,KAAK,cAAc;AAAA,IACpD;AAC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AW,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
|
}
|
|
@@ -27,6 +27,8 @@ __export(login_command_exports, {
|
|
|
27
27
|
LoginCommand: () => LoginCommand
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(login_command_exports);
|
|
30
|
+
var bpclient = __toESM(require("@botpress/client"));
|
|
31
|
+
var paging = __toESM(require("../api/paging"));
|
|
30
32
|
var errors = __toESM(require("../errors"));
|
|
31
33
|
var import_global_command = require("./global-command");
|
|
32
34
|
class LoginCommand extends import_global_command.GlobalCommand {
|
|
@@ -41,8 +43,8 @@ class LoginCommand extends import_global_command.GlobalCommand {
|
|
|
41
43
|
return prompted;
|
|
42
44
|
});
|
|
43
45
|
const promptedWorkspaceId = await this.globalCache.sync("workspaceId", this.argv.workspaceId, async (defaultId) => {
|
|
44
|
-
const
|
|
45
|
-
const userWorkspaces = await
|
|
46
|
+
const tmpClient = new bpclient.Client({ apiUrl: this.argv.apiUrl, token: promptedToken });
|
|
47
|
+
const userWorkspaces = await paging.listAllPages(tmpClient.listWorkspaces, (r) => r.workspaces).catch((thrown) => {
|
|
46
48
|
throw errors.BotpressCLIError.wrap(thrown, "Could not list workspaces");
|
|
47
49
|
});
|
|
48
50
|
if (userWorkspaces.length === 0) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/command-implementations/login-command.ts"],
|
|
4
|
-
"sourcesContent": ["import type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport { GlobalCommand } from './global-command'\n\nexport type LoginCommandDefinition = typeof commandDefinitions.login\nexport class LoginCommand extends GlobalCommand<LoginCommandDefinition> {\n public async run(): Promise<void> {\n const promptedToken = await this.globalCache.sync('token', this.argv.token, async (previousToken) => {\n const prompted = await this.prompt.password('Enter your Personal Access Token', {\n initial: previousToken,\n })\n\n if (!prompted) {\n throw new errors.ParamRequiredError('Personal Access Token')\n }\n\n return prompted\n })\n\n const promptedWorkspaceId = await this.globalCache.sync('workspaceId', this.argv.workspaceId, async (defaultId) => {\n const
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import * as bpclient from '@botpress/client'\nimport * as paging from '../api/paging'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport { GlobalCommand } from './global-command'\n\nexport type LoginCommandDefinition = typeof commandDefinitions.login\nexport class LoginCommand extends GlobalCommand<LoginCommandDefinition> {\n public async run(): Promise<void> {\n const promptedToken = await this.globalCache.sync('token', this.argv.token, async (previousToken) => {\n const prompted = await this.prompt.password('Enter your Personal Access Token', {\n initial: previousToken,\n })\n\n if (!prompted) {\n throw new errors.ParamRequiredError('Personal Access Token')\n }\n\n return prompted\n })\n\n const promptedWorkspaceId = await this.globalCache.sync('workspaceId', this.argv.workspaceId, async (defaultId) => {\n const tmpClient = new bpclient.Client({ apiUrl: this.argv.apiUrl, token: promptedToken }) // no workspaceId yet\n const userWorkspaces = await paging\n .listAllPages(tmpClient.listWorkspaces, (r) => r.workspaces)\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not list workspaces')\n })\n\n if (userWorkspaces.length === 0) {\n throw new errors.NoWorkspacesFoundError()\n }\n\n const initial = userWorkspaces.find((ws) => ws.id === defaultId)\n\n const prompted = await this.prompt.select('Which workspace do you want to login to?', {\n initial: initial && { title: initial.name, value: initial.id },\n choices: userWorkspaces.map((ws) => ({ title: ws.name, value: ws.id })),\n })\n\n if (!prompted) {\n throw new errors.ParamRequiredError('Workspace Id')\n }\n\n return prompted\n })\n\n await this.globalCache.set('apiUrl', this.argv.apiUrl)\n\n const api = this.api.newClient(\n { apiUrl: this.argv.apiUrl, token: promptedToken, workspaceId: promptedWorkspaceId },\n this.logger\n )\n\n await api.testLogin().catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Login failed. Please check your credentials')\n })\n\n this.logger.success('Logged In')\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAA0B;AAC1B,aAAwB;AAExB,aAAwB;AACxB,4BAA8B;AAGvB,MAAM,qBAAqB,oCAAsC;AAAA,EACtE,MAAa,MAAqB;AAChC,UAAM,gBAAgB,MAAM,KAAK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AEA,UAAM,IAAI,UAAU,EAAE,MAAM,CAAC,WAAW;AACtC,YAAM,OAAO,iBAAiB,KAAK,QAAQ,6CAA6C;AAAA,IAC1F,CAAC;AAED,SAAK,OAAO,QAAQ,WAAW;AAAA,EACjC;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botpress/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Botpress CLI",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "pnpm run bundle && pnpm run template:gen",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"main": "dist/index.js",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@botpress/client": "0.3.
|
|
23
|
+
"@botpress/client": "0.3.7",
|
|
24
24
|
"@bpinternal/tunnel": "^0.1.0",
|
|
25
25
|
"@bpinternal/yargs-extra": "^0.0.3",
|
|
26
26
|
"@bpinternal/zod-to-json-schema": "^3.21.4",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"zod": "^3.20.6"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@botpress/sdk": "0.4.
|
|
50
|
+
"@botpress/sdk": "0.4.3",
|
|
51
51
|
"@bpinternal/log4bot": "^0.0.4",
|
|
52
52
|
"@types/bluebird": "^3.5.38",
|
|
53
53
|
"@types/json-schema": "^7.0.11",
|