@botpress/cli 4.20.2 → 4.21.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.
@@ -1,36 +1,36 @@
1
1
 
2
- > @botpress/cli@4.20.2 build /home/runner/work/botpress/botpress/packages/cli
2
+ > @botpress/cli@4.21.0 build /home/runner/work/botpress/botpress/packages/cli
3
3
  > pnpm run build:types && pnpm run bundle && pnpm run template:gen
4
4
 
5
5
 
6
- > @botpress/cli@4.20.2 build:types /home/runner/work/botpress/botpress/packages/cli
6
+ > @botpress/cli@4.21.0 build:types /home/runner/work/botpress/botpress/packages/cli
7
7
  > tsc -p ./tsconfig.build.json
8
8
 
9
9
 
10
- > @botpress/cli@4.20.2 bundle /home/runner/work/botpress/botpress/packages/cli
10
+ > @botpress/cli@4.21.0 bundle /home/runner/work/botpress/botpress/packages/cli
11
11
  > ts-node -T build.ts
12
12
 
13
13
 
14
- > @botpress/cli@4.20.2 template:gen /home/runner/work/botpress/botpress/packages/cli
14
+ > @botpress/cli@4.21.0 template:gen /home/runner/work/botpress/botpress/packages/cli
15
15
  > pnpm -r --stream -F @bp-templates/* exec bp gen
16
16
 
17
- 🤖 Botpress CLI v4.20.2
18
- 🤖 Botpress CLI v4.20.2
19
- 🤖 Botpress CLI v4.20.2
20
- 🤖 Botpress CLI v4.20.2
21
- ○ Generating typings for integration hello-world...
17
+ 🤖 Botpress CLI v4.21.0
18
+ 🤖 Botpress CLI v4.21.0
19
+ 🤖 Botpress CLI v4.21.0
20
+ 🤖 Botpress CLI v4.21.0
22
21
  ○ Generating typings for bot...
23
22
  ✓ Typings available at .botpress
24
23
 
25
- ○ Generating typings for integration empty-integration...
24
+ ○ Generating typings for plugin empty-plugin...
25
+ ○ Generating typings for integration hello-world...
26
26
  ✓ Typings available at .botpress
27
27
 
28
28
  ✓ Typings available at .botpress
29
29
 
30
- ○ Generating typings for plugin empty-plugin...
30
+ ○ Generating typings for integration empty-integration...
31
31
  ✓ Typings available at .botpress
32
32
 
33
- 🤖 Botpress CLI v4.20.2
33
+ 🤖 Botpress CLI v4.21.0
34
34
  ○ Generating typings for integration webhook-message...
35
35
  ✓ Typings available at .botpress
36
36
 
@@ -47,4 +47,5 @@ export declare class ApiClient {
47
47
  findPreviousIntegrationVersion(ref: NamePackageRef): Promise<PublicOrPrivateIntegration | undefined>;
48
48
  findBotByName(name: string): Promise<BotSummary | undefined>;
49
49
  private _returnUndefinedOnError;
50
+ getOrGenerateShareableId(botId: string, integrationId: string, integrationAlias: string): Promise<string>;
50
51
  }
@@ -225,6 +225,22 @@ class ApiClient {
225
225
  }
226
226
  throw thrown;
227
227
  };
228
+ async getOrGenerateShareableId(botId, integrationId, integrationAlias) {
229
+ const { shareableId, isExpired } = await this.client.getIntegrationShareableId({
230
+ botId,
231
+ integrationId,
232
+ integrationInstanceAlias: integrationAlias
233
+ }).catch(() => ({ shareableId: void 0, isExpired: true }));
234
+ if (shareableId && !isExpired) {
235
+ return shareableId;
236
+ }
237
+ const { shareableId: newShareableId } = await this.client.createIntegrationShareableId({
238
+ botId,
239
+ integrationId,
240
+ integrationInstanceAlias: integrationAlias
241
+ });
242
+ return newShareableId;
243
+ }
228
244
  }
229
245
  // Annotate the CommonJS export names for ESM import in node:
230
246
  0 && (module.exports = {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/api/client.ts"],
4
- "sourcesContent": ["import * as client from '@botpress/client'\nimport semver from 'semver'\nimport yn from 'yn'\nimport * as errors from '../errors'\nimport type { Logger } from '../logger'\nimport { formatPackageRef, ApiPackageRef, NamePackageRef } from '../package-ref'\nimport * as utils from '../utils'\nimport * as paging from './paging'\nimport * as retry from './retry'\n\nimport {\n ApiClientProps,\n PublicOrUnlistedIntegration,\n PrivateIntegration,\n PublicOrPrivateIntegration,\n PublicInterface,\n PrivateInterface,\n PublicOrPrivateInterface,\n PrivatePlugin,\n PublicPlugin,\n PublicOrPrivatePlugin,\n BotSummary,\n} from './types'\n\nexport * from './types'\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: client.Client\n public readonly url: string\n public readonly token: string\n public readonly workspaceId: string\n public readonly botId?: string\n\n public static newClient = (props: ApiClientProps, logger: Logger) => new ApiClient(props, logger)\n\n public constructor(\n props: ApiClientProps,\n private _logger: Logger\n ) {\n const { apiUrl, token, workspaceId, botId } = props\n this.client = new client.Client({\n apiUrl,\n token,\n workspaceId,\n botId,\n retry: retry.config,\n headers: { 'x-multiple-integrations': 'true' },\n })\n this.url = apiUrl\n this.token = token\n this.workspaceId = workspaceId\n this.botId = botId\n }\n\n public get isBotpressWorkspace(): boolean {\n // this environment variable is undocumented and only used internally for dev purposes\n const isBotpressWorkspace = yn(process.env.BP_IS_BOTPRESS_WORKSPACE)\n if (isBotpressWorkspace !== undefined) {\n return isBotpressWorkspace\n }\n return [\n '6a76fa10-e150-4ff6-8f59-a300feec06c1',\n '95de33eb-1551-4af9-9088-e5dcb02efd09',\n '11111111-1111-1111-aaaa-111111111111',\n ].includes(this.workspaceId)\n }\n\n public async safeListTables(req: client.ClientInputs['listTables']): Promise<\n | {\n success: true\n tables: client.ClientOutputs['listTables']['tables']\n }\n | {\n success: false\n error: Error\n }\n > {\n try {\n const result = await this.client.listTables(req)\n return { success: true, tables: result.tables }\n } catch (thrown) {\n const error = thrown instanceof Error ? thrown : new Error(String(thrown))\n return { success: false, error }\n }\n }\n\n public async getWorkspace(): Promise<client.ClientOutputs['getWorkspace']> {\n return this.client.getWorkspace({ id: this.workspaceId })\n }\n\n public async findWorkspaceByHandle(handle: string): Promise<client.ClientOutputs['getWorkspace'] | undefined> {\n const { workspaces } = await this.client.listWorkspaces({ handle })\n return workspaces[0] // There should be only one workspace with a given handle\n }\n\n public switchWorkspace(workspaceId: string): ApiClient {\n return ApiClient.newClient({ apiUrl: this.url, token: this.token, workspaceId }, this._logger)\n }\n\n public switchBot(botId: string): ApiClient {\n return ApiClient.newClient(\n { apiUrl: this.url, token: this.token, botId, workspaceId: this.workspaceId },\n this._logger\n )\n }\n\n public async updateWorkspace(\n props: utils.types.SafeOmit<client.ClientInputs['updateWorkspace'], 'id'>\n ): Promise<client.ClientOutputs['updateWorkspace']> {\n return this.client.updateWorkspace({ id: this.workspaceId, ...props })\n }\n\n public async getPublicOrPrivateIntegration(ref: ApiPackageRef): Promise<PublicOrPrivateIntegration> {\n const integration = await this.findPublicOrPrivateIntegration(ref)\n if (!integration) {\n throw new Error(`Integration \"${formatPackageRef(ref)}\" not found`)\n }\n return integration\n }\n\n public async findPublicOrPrivateIntegration(ref: ApiPackageRef): Promise<PublicOrPrivateIntegration | undefined> {\n const formatted = formatPackageRef(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: ApiPackageRef): Promise<PrivateIntegration | undefined> {\n const { workspaceId } = this\n if (ref.type === 'id') {\n return this.client\n .getIntegration(ref)\n .then((r) => ({ ...r.integration, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n return this.client\n .getIntegrationByName(ref)\n .then((r) => ({ ...r.integration, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async findPublicIntegration(ref: ApiPackageRef): Promise<PublicOrUnlistedIntegration | undefined> {\n if (ref.type === 'id') {\n return this.client\n .getPublicIntegrationById(ref)\n .then((r) => ({ ...r.integration, visibility: r.integration.visibility as 'public' | 'unlisted' }) as const)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n return this.client\n .getPublicIntegration(ref)\n .then((r) => ({ ...r.integration, visibility: r.integration.visibility as 'public' | 'unlisted' }) as const)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async findPublicOrPrivateInterface(ref: ApiPackageRef): Promise<PublicOrPrivateInterface | undefined> {\n const formatted = formatPackageRef(ref)\n\n const privateInterface = await this.findPrivateInterface(ref)\n if (privateInterface) {\n this._logger.debug(`Found interface \"${formatted}\" in workspace`)\n return privateInterface\n }\n\n const publicInterface = await this.findPublicInterface(ref)\n if (publicInterface) {\n this._logger.debug(`Found interface \"${formatted}\" in hub`)\n return publicInterface\n }\n\n return\n }\n\n public async findPrivateInterface(ref: ApiPackageRef): Promise<PrivateInterface | undefined> {\n const { workspaceId } = this\n if (ref.type === 'id') {\n return this.client\n .getInterface(ref)\n .then((r) => ({ ...r.interface, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n return this.client\n .getInterfaceByName(ref)\n .then((r) => ({ ...r.interface, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async getPublicInterface(ref: ApiPackageRef): Promise<PublicInterface> {\n const intrface = await this.findPublicInterface(ref)\n if (!intrface) {\n throw new Error(`Interface \"${formatPackageRef(ref)}\" not found`)\n }\n return intrface\n }\n\n public async findPublicInterface(ref: ApiPackageRef): Promise<PublicInterface | undefined> {\n if (ref.type === 'id') {\n return this.client\n .getPublicInterfaceById(ref)\n .then((r) => ({ ...r.interface, public: true }) as const)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n return this.client\n .getPublicInterface(ref)\n .then((r) => ({ ...r.interface, public: true }) as const)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async findPublicPlugin(ref: ApiPackageRef): Promise<PublicPlugin | undefined> {\n if (ref.type === 'id') {\n return this.client\n .getPublicPluginById(ref)\n .then((r) => ({ ...r.plugin, public: true }) as const)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n return this.client\n .getPublicPlugin(ref)\n .then((r) => ({ ...r.plugin, public: true }) as const)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async getPublicOrPrivatePlugin(ref: ApiPackageRef): Promise<PublicOrPrivatePlugin> {\n const plugin = await this.findPublicOrPrivatePlugin(ref)\n if (!plugin) {\n throw new Error(`Plugin \"${formatPackageRef(ref)}\" not found`)\n }\n return plugin\n }\n\n public async findPublicOrPrivatePlugin(ref: ApiPackageRef): Promise<PublicOrPrivatePlugin | undefined> {\n const formatted = formatPackageRef(ref)\n\n const privatePlugin = await this.findPrivatePlugin(ref)\n if (privatePlugin) {\n this._logger.debug(`Found plugin \"${formatted}\" in workspace`)\n return privatePlugin\n }\n\n const publicPlugin = await this.findPublicPlugin(ref)\n if (publicPlugin) {\n this._logger.debug(`Found plugin \"${formatted}\" in hub`)\n return publicPlugin\n }\n\n return\n }\n\n public async findPrivatePlugin(ref: ApiPackageRef): Promise<PrivatePlugin | undefined> {\n const { workspaceId } = this\n if (ref.type === 'id') {\n return this.client\n .getPlugin(ref)\n .then((r) => ({ ...r.plugin, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n return this.client\n .getPluginByName(ref)\n .then((r) => ({ ...r.plugin, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async testLogin(): Promise<void> {\n await this.client.listBots({})\n }\n\n public listAllPages = paging.listAllPages\n\n public async findPreviousIntegrationVersion(ref: NamePackageRef): Promise<PublicOrPrivateIntegration | undefined> {\n const isValidSemverVersion = semver.valid(ref.version)\n\n // Sanity check (this should never happen):\n if (!isValidSemverVersion) {\n throw new errors.BotpressCLIError(`Invalid version \"${ref.version}\" for integration \"${ref.name}\"`)\n }\n\n return this.findPublicOrPrivateIntegration({ ...ref, version: `<${ref.version}` })\n }\n\n public async findBotByName(name: string): Promise<BotSummary | undefined> {\n // api does not allow filtering bots by name\n const allBots = await this.listAllPages(this.client.listBots, (r) => r.bots)\n return allBots.find((b) => b.name === name)\n }\n\n private _returnUndefinedOnError =\n (type: client.ApiError['type']) =>\n (thrown: any): undefined => {\n if (client.isApiError(thrown) && thr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AoB,IAAI,OAAO,sBAAsB,IAAI,IAAI,GAAG;AAAA,IACpG;AAEA,WAAO,KAAK,+BAA+B,EAAE,GAAG,KAAK,SAAS,IAAI,IAAI,OAAO,GAAG,CAAC;AAAA,EACnF;AAAA,EAEA,MAAa,cAAc,MAA+C;AAExE,UAAM,UAAU,MAAM,KAAK,aAAa,KAAK,OAAO,UAAU,CAAC,MAAM,EAAE,IAAI;AAC3E,WAAO,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,IAAI;AAAA,EAC5C;AAAA,EAEQ,0BACN,CAAC,SACD,CAAC,WAA2B;AAC1B,QAAI,OAAO,WAAW,MAAM,KAAK,OAAO,SAAS,MAAM;AACrD;AAAA,IACF;AACA,UAAM;AAAA,EACR;AACJ;",
4
+ "sourcesContent": ["import * as client from '@botpress/client'\nimport semver from 'semver'\nimport yn from 'yn'\nimport * as errors from '../errors'\nimport type { Logger } from '../logger'\nimport { formatPackageRef, ApiPackageRef, NamePackageRef } from '../package-ref'\nimport * as utils from '../utils'\nimport * as paging from './paging'\nimport * as retry from './retry'\n\nimport {\n ApiClientProps,\n PublicOrUnlistedIntegration,\n PrivateIntegration,\n PublicOrPrivateIntegration,\n PublicInterface,\n PrivateInterface,\n PublicOrPrivateInterface,\n PrivatePlugin,\n PublicPlugin,\n PublicOrPrivatePlugin,\n BotSummary,\n} from './types'\n\nexport * from './types'\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: client.Client\n public readonly url: string\n public readonly token: string\n public readonly workspaceId: string\n public readonly botId?: string\n\n public static newClient = (props: ApiClientProps, logger: Logger) => new ApiClient(props, logger)\n\n public constructor(\n props: ApiClientProps,\n private _logger: Logger\n ) {\n const { apiUrl, token, workspaceId, botId } = props\n this.client = new client.Client({\n apiUrl,\n token,\n workspaceId,\n botId,\n retry: retry.config,\n headers: { 'x-multiple-integrations': 'true' },\n })\n this.url = apiUrl\n this.token = token\n this.workspaceId = workspaceId\n this.botId = botId\n }\n\n public get isBotpressWorkspace(): boolean {\n // this environment variable is undocumented and only used internally for dev purposes\n const isBotpressWorkspace = yn(process.env.BP_IS_BOTPRESS_WORKSPACE)\n if (isBotpressWorkspace !== undefined) {\n return isBotpressWorkspace\n }\n return [\n '6a76fa10-e150-4ff6-8f59-a300feec06c1',\n '95de33eb-1551-4af9-9088-e5dcb02efd09',\n '11111111-1111-1111-aaaa-111111111111',\n ].includes(this.workspaceId)\n }\n\n public async safeListTables(req: client.ClientInputs['listTables']): Promise<\n | {\n success: true\n tables: client.ClientOutputs['listTables']['tables']\n }\n | {\n success: false\n error: Error\n }\n > {\n try {\n const result = await this.client.listTables(req)\n return { success: true, tables: result.tables }\n } catch (thrown) {\n const error = thrown instanceof Error ? thrown : new Error(String(thrown))\n return { success: false, error }\n }\n }\n\n public async getWorkspace(): Promise<client.ClientOutputs['getWorkspace']> {\n return this.client.getWorkspace({ id: this.workspaceId })\n }\n\n public async findWorkspaceByHandle(handle: string): Promise<client.ClientOutputs['getWorkspace'] | undefined> {\n const { workspaces } = await this.client.listWorkspaces({ handle })\n return workspaces[0] // There should be only one workspace with a given handle\n }\n\n public switchWorkspace(workspaceId: string): ApiClient {\n return ApiClient.newClient({ apiUrl: this.url, token: this.token, workspaceId }, this._logger)\n }\n\n public switchBot(botId: string): ApiClient {\n return ApiClient.newClient(\n { apiUrl: this.url, token: this.token, botId, workspaceId: this.workspaceId },\n this._logger\n )\n }\n\n public async updateWorkspace(\n props: utils.types.SafeOmit<client.ClientInputs['updateWorkspace'], 'id'>\n ): Promise<client.ClientOutputs['updateWorkspace']> {\n return this.client.updateWorkspace({ id: this.workspaceId, ...props })\n }\n\n public async getPublicOrPrivateIntegration(ref: ApiPackageRef): Promise<PublicOrPrivateIntegration> {\n const integration = await this.findPublicOrPrivateIntegration(ref)\n if (!integration) {\n throw new Error(`Integration \"${formatPackageRef(ref)}\" not found`)\n }\n return integration\n }\n\n public async findPublicOrPrivateIntegration(ref: ApiPackageRef): Promise<PublicOrPrivateIntegration | undefined> {\n const formatted = formatPackageRef(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: ApiPackageRef): Promise<PrivateIntegration | undefined> {\n const { workspaceId } = this\n if (ref.type === 'id') {\n return this.client\n .getIntegration(ref)\n .then((r) => ({ ...r.integration, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n return this.client\n .getIntegrationByName(ref)\n .then((r) => ({ ...r.integration, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async findPublicIntegration(ref: ApiPackageRef): Promise<PublicOrUnlistedIntegration | undefined> {\n if (ref.type === 'id') {\n return this.client\n .getPublicIntegrationById(ref)\n .then((r) => ({ ...r.integration, visibility: r.integration.visibility as 'public' | 'unlisted' }) as const)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n return this.client\n .getPublicIntegration(ref)\n .then((r) => ({ ...r.integration, visibility: r.integration.visibility as 'public' | 'unlisted' }) as const)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async findPublicOrPrivateInterface(ref: ApiPackageRef): Promise<PublicOrPrivateInterface | undefined> {\n const formatted = formatPackageRef(ref)\n\n const privateInterface = await this.findPrivateInterface(ref)\n if (privateInterface) {\n this._logger.debug(`Found interface \"${formatted}\" in workspace`)\n return privateInterface\n }\n\n const publicInterface = await this.findPublicInterface(ref)\n if (publicInterface) {\n this._logger.debug(`Found interface \"${formatted}\" in hub`)\n return publicInterface\n }\n\n return\n }\n\n public async findPrivateInterface(ref: ApiPackageRef): Promise<PrivateInterface | undefined> {\n const { workspaceId } = this\n if (ref.type === 'id') {\n return this.client\n .getInterface(ref)\n .then((r) => ({ ...r.interface, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n return this.client\n .getInterfaceByName(ref)\n .then((r) => ({ ...r.interface, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async getPublicInterface(ref: ApiPackageRef): Promise<PublicInterface> {\n const intrface = await this.findPublicInterface(ref)\n if (!intrface) {\n throw new Error(`Interface \"${formatPackageRef(ref)}\" not found`)\n }\n return intrface\n }\n\n public async findPublicInterface(ref: ApiPackageRef): Promise<PublicInterface | undefined> {\n if (ref.type === 'id') {\n return this.client\n .getPublicInterfaceById(ref)\n .then((r) => ({ ...r.interface, public: true }) as const)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n return this.client\n .getPublicInterface(ref)\n .then((r) => ({ ...r.interface, public: true }) as const)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async findPublicPlugin(ref: ApiPackageRef): Promise<PublicPlugin | undefined> {\n if (ref.type === 'id') {\n return this.client\n .getPublicPluginById(ref)\n .then((r) => ({ ...r.plugin, public: true }) as const)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n return this.client\n .getPublicPlugin(ref)\n .then((r) => ({ ...r.plugin, public: true }) as const)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async getPublicOrPrivatePlugin(ref: ApiPackageRef): Promise<PublicOrPrivatePlugin> {\n const plugin = await this.findPublicOrPrivatePlugin(ref)\n if (!plugin) {\n throw new Error(`Plugin \"${formatPackageRef(ref)}\" not found`)\n }\n return plugin\n }\n\n public async findPublicOrPrivatePlugin(ref: ApiPackageRef): Promise<PublicOrPrivatePlugin | undefined> {\n const formatted = formatPackageRef(ref)\n\n const privatePlugin = await this.findPrivatePlugin(ref)\n if (privatePlugin) {\n this._logger.debug(`Found plugin \"${formatted}\" in workspace`)\n return privatePlugin\n }\n\n const publicPlugin = await this.findPublicPlugin(ref)\n if (publicPlugin) {\n this._logger.debug(`Found plugin \"${formatted}\" in hub`)\n return publicPlugin\n }\n\n return\n }\n\n public async findPrivatePlugin(ref: ApiPackageRef): Promise<PrivatePlugin | undefined> {\n const { workspaceId } = this\n if (ref.type === 'id') {\n return this.client\n .getPlugin(ref)\n .then((r) => ({ ...r.plugin, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n return this.client\n .getPluginByName(ref)\n .then((r) => ({ ...r.plugin, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async testLogin(): Promise<void> {\n await this.client.listBots({})\n }\n\n public listAllPages = paging.listAllPages\n\n public async findPreviousIntegrationVersion(ref: NamePackageRef): Promise<PublicOrPrivateIntegration | undefined> {\n const isValidSemverVersion = semver.valid(ref.version)\n\n // Sanity check (this should never happen):\n if (!isValidSemverVersion) {\n throw new errors.BotpressCLIError(`Invalid version \"${ref.version}\" for integration \"${ref.name}\"`)\n }\n\n return this.findPublicOrPrivateIntegration({ ...ref, version: `<${ref.version}` })\n }\n\n public async findBotByName(name: string): Promise<BotSummary | undefined> {\n // api does not allow filtering bots by name\n const allBots = await this.listAllPages(this.client.listBots, (r) => r.bots)\n return allBots.find((b) => b.name === name)\n }\n\n private _returnUndefinedOnError =\n (type: client.ApiError['type']) =>\n (thrown: any): undefined => {\n if (client.isApiError(thrown) && thrown.type === type) {\n return\n }\n throw thrown\n }\n\n public async getOrGenerateShareableId(\n botId: string,\n integrationId: string,\n integrationAlias: string\n ): Promise<string> {\n const { shareableId, isExpired } = await this.client\n .getIntegrationShareableId({\n botId,\n integrationId,\n integrationInstanceAlias: integrationAlias,\n })\n .catch(() => ({ shareableId: undefined, isExpired: true }))\n if (shareableId && !isExpired) {\n return shareableId\n }\n const { shareableId: newShareableId } = await this.client.createIntegrationShareableId({\n botId,\n integrationId,\n integrationInstanceAlias: integrationAlias,\n })\n return newShareableId\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAA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,GAAG,KAAK,SAAS,IAAI,IAAI,OAAO,GAAG,CAAC;AAAA,EACnF;AAAA,EAEA,MAAa,cAAc,MAA+C;AAExE,UAAM,UAAU,MAAM,KAAK,aAAa,KAAK,OAAO,UAAU,CAAC,MAAM,EAAE,IAAI;AAC3E,WAAO,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,IAAI;AAAA,EAC5C;AAAA,EAEQ,0BACN,CAAC,SACD,CAAC,WAA2B;AAC1B,QAAI,OAAO,WAAW,MAAM,KAAK,OAAO,SAAS,MAAM;AACrD;AAAA,IACF;AACA,UAAM;AAAA,EACR;AAAA,EAEF,MAAa,yBACX,OACA,eACA,kBACiB;AACjB,UAAM,EAAE,aAAa,UAAU,IAAI,MAAM,KAAK,OAC3C,0BAA0B;AAAA,MACzB;AAAA,MACA;AAAA,MACA,0BAA0B;AAAA,IAC5B,CAAC,EACA,MAAM,OAAO,EAAE,aAAa,QAAW,WAAW,KAAK,EAAE;AAC5D,QAAI,eAAe,CAAC,WAAW;AAC7B,aAAO;AAAA,IACT;AACA,UAAM,EAAE,aAAa,eAAe,IAAI,MAAM,KAAK,OAAO,6BAA6B;AAAA,MACrF;AAAA,MACA;AAAA,MACA,0BAA0B;AAAA,IAC5B,CAAC;AACD,WAAO;AAAA,EACT;AACF;",
6
6
  "names": ["yn", "semver"]
7
7
  }
@@ -409,7 +409,7 @@ ${Object.entries(failedIntegrations).map(([key, int]) => `\u2022 ${key}: ${int.s
409
409
  const tablesPublisher = new tables.TablesPublisher({ api, logger: this.logger, prompt: this.prompt });
410
410
  await tablesPublisher.deployTables({ botId: updatedBot.id, botDefinition });
411
411
  line.success("Bot deployed");
412
- this.displayWebhookUrls(updatedBot);
412
+ await this.displayIntegrationUrls({ api, bot: updatedBot });
413
413
  }
414
414
  async _createNewBot(api) {
415
415
  const line = this.logger.line();
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/command-implementations/deploy-command.ts"],
4
- "sourcesContent": ["import type * as client from '@botpress/client'\nimport * as sdk from '@botpress/sdk'\nimport chalk from 'chalk'\nimport * as fs from 'fs'\nimport semver from 'semver'\nimport * as apiUtils from '../api'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport * as tables from '../tables'\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\n if (!this.argv.noBuild) {\n await this._runBuild() // This ensures the bundle is always synced with source code\n }\n\n const { projectType, resolveProjectDefinition } = this.readProjectDefinitionFromFS()\n\n if (projectType === 'integration') {\n const projectDef = await resolveProjectDefinition()\n return this._deployIntegration(api, projectDef.definition)\n }\n if (projectType === 'interface') {\n const projectDef = await resolveProjectDefinition()\n return this._deployInterface(api, projectDef.definition)\n }\n if (projectType === 'plugin') {\n const projectDef = await resolveProjectDefinition()\n return this._deployPlugin(api, projectDef.definition)\n }\n if (projectType === 'bot') {\n const projectDef = await resolveProjectDefinition()\n return this._deployBot(api, projectDef.definition, this.argv.botId, this.argv.createNewBot)\n }\n throw new errors.UnsupportedProjectType()\n }\n\n private async _runBuild() {\n return new BuildCommand(this.api, this.prompt, this.logger, this.argv).setProjectContext(this.projectContext).run()\n }\n\n private get _visibility(): 'public' | 'private' | 'unlisted' {\n if (this.argv.public && this.argv.visibility === 'private') {\n this.logger.warn('The --public flag is deprecated. Please use \"--visibility public\" instead.')\n return 'public'\n }\n\n if (this.argv.public && this.argv.visibility !== 'private') {\n this.logger.warn('The --public flag and --visibility option are both present. Ignoring the --public flag...')\n }\n\n return this.argv.visibility\n }\n\n private async _deployIntegration(api: apiUtils.ApiClient, integrationDef: sdk.IntegrationDefinition) {\n const res = await this._manageWorkspaceHandle(api, integrationDef)\n if (!res) return\n const { integration: updatedIntegrationDef, workspaceId } = res\n integrationDef = updatedIntegrationDef\n if (workspaceId) {\n api = api.switchWorkspace(workspaceId)\n }\n\n const { name, version } = integrationDef\n\n if (integrationDef.icon && !integrationDef.icon.toLowerCase().endsWith('.svg')) {\n throw new errors.BotpressCLIError('Icon must be an SVG file')\n }\n\n if (integrationDef.readme && !integrationDef.readme.toLowerCase().endsWith('.md')) {\n throw new errors.BotpressCLIError('Readme must be a Markdown file')\n }\n\n const integration = await api.findPublicOrPrivateIntegration({ type: 'name', name, version })\n if (integration && integration.workspaceId !== api.workspaceId) {\n throw new errors.BotpressCLIError(\n `Public integration ${name} v${version} is already deployed in another workspace.`\n )\n }\n\n if (integration && integration.visibility !== 'private' && !api.isBotpressWorkspace) {\n throw new errors.BotpressCLIError(\n `Integration ${name} v${version} is already deployed publicly and cannot be updated. Please bump the version.`\n )\n }\n\n let message: string\n if (integration) {\n this.logger.warn('Integration already exists. If you decide to deploy, it will override the existing one.')\n message = `Are you sure you want to override integration ${name} v${version}?`\n } else {\n message = `Are you sure you want to deploy integration ${name} v${version}?`\n }\n\n const confirm = await this.prompt.confirm(message)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n this.logger.debug('Preparing integration request body...')\n\n const createBody = {\n ...(await this.prepareCreateIntegrationBody(integrationDef)),\n ...(await this.prepareIntegrationDependencies(integrationDef, api)),\n visibility: this._visibility,\n }\n\n const startedMessage = `Deploying integration ${chalk.bold(name)} v${version}...`\n const successMessage = 'Integration deployed'\n if (integration) {\n const updateBody = apiUtils.prepareUpdateIntegrationBody(\n {\n id: integration.id,\n ...createBody,\n },\n integration\n )\n\n const { secrets: knownSecrets } = integration\n updateBody.secrets = await this.promptSecrets(integrationDef, this.argv, { knownSecrets })\n this._detectDeprecatedFeatures(integrationDef, { allowDeprecated: true })\n\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.log('Dry-run mode is active. Simulating integration update...')\n\n await api.client.validateIntegrationUpdate(updateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update integration \"${name}\"`)\n })\n } else {\n await api.client.updateIntegration(updateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update integration \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n } else {\n this.logger.debug(`looking for previous version of integration \"${name}\"`)\n const previousVersion = await api.findPreviousIntegrationVersion({ type: 'name', name, version })\n\n if (previousVersion) {\n this.logger.debug(`previous version found: ${previousVersion.version}`)\n } else {\n this.logger.debug('no previous version found')\n }\n\n const knownSecrets = previousVersion?.secrets\n\n createBody.secrets = await this.promptSecrets(integrationDef, this.argv, { knownSecrets })\n this._detectDeprecatedFeatures(integrationDef, {\n allowDeprecated: this._allowDeprecatedFeatures(integrationDef, previousVersion),\n })\n\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.log('Dry-run mode is active. Simulating integration creation...')\n\n await api.client.validateIntegrationCreation(createBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not create integration \"${name}\"`)\n })\n } else {\n await api.client.createIntegration(createBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not create integration \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n }\n }\n\n private async _deployInterface(api: apiUtils.ApiClient, interfaceDeclaration: sdk.InterfaceDefinition) {\n if (this._visibility === 'unlisted') {\n throw new errors.BotpressCLIError(\n 'Unlisted visibility is not supported for interfaces. Please use \"public\" or \"private\".'\n )\n }\n\n if (interfaceDeclaration.icon && !interfaceDeclaration.icon.toLowerCase().endsWith('.svg')) {\n throw new errors.BotpressCLIError('Icon must be an SVG file')\n }\n\n if (interfaceDeclaration.readme && !interfaceDeclaration.readme.toLowerCase().endsWith('.md')) {\n throw new errors.BotpressCLIError('Readme must be a Markdown file')\n }\n\n const { name, version } = interfaceDeclaration\n const intrface = await api.findPublicOrPrivateInterface({ type: 'name', name, version })\n\n let message: string\n if (intrface) {\n this.logger.warn('Interface already exists. If you decide to deploy, it will override the existing one.')\n message = `Are you sure you want to override interface ${name} v${version}?`\n } else {\n message = `Are you sure you want to deploy interface ${name} v${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 icon = await this.readProjectFile(interfaceDeclaration.icon, 'base64')\n const readme = await this.readProjectFile(interfaceDeclaration.readme, 'base64')\n\n if (this._visibility !== 'public') {\n this.logger.warn(\n 'You are currently publishing a private interface, which cannot be used by integrations and plugins. To fix this, change the visibility to \"public\"'\n )\n }\n\n const createBody = {\n ...(await apiUtils.prepareCreateInterfaceBody(interfaceDeclaration)),\n public: this._visibility === 'public',\n icon,\n readme,\n }\n\n const startedMessage = `Deploying interface ${chalk.bold(name)} v${version}...`\n const successMessage = 'Interface deployed'\n if (intrface) {\n const updateBody = apiUtils.prepareUpdateInterfaceBody(\n {\n id: intrface.id,\n ...createBody,\n },\n intrface\n )\n\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.warn('Dry-run mode is not supported for interface updates. Skipping deployment...')\n } else {\n await api.client.updateInterface(updateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update interface \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n } else {\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.warn('Dry-run mode is not supported for interface creation. Skipping deployment...')\n } else {\n await api.client.createInterface(createBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not create interface \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n }\n }\n\n private async _deployPlugin(api: apiUtils.ApiClient, pluginDef: sdk.PluginDefinition) {\n if (this._visibility === 'unlisted') {\n throw new errors.BotpressCLIError(\n 'Unlisted visibility is not supported for plugins. Please use \"public\" or \"private\".'\n )\n }\n\n const codeCJS = await fs.promises.readFile(this.projectPaths.abs.outFileCJS, 'utf-8')\n const codeESM = await fs.promises.readFile(this.projectPaths.abs.outFileESM, 'utf-8')\n\n const { name, version } = pluginDef\n\n if (pluginDef.icon && !pluginDef.icon.toLowerCase().endsWith('.svg')) {\n throw new errors.BotpressCLIError('Icon must be an SVG file')\n }\n\n if (pluginDef.readme && !pluginDef.readme.toLowerCase().endsWith('.md')) {\n throw new errors.BotpressCLIError('Readme must be a Markdown file')\n }\n\n const plugin = await api.findPublicOrPrivatePlugin({ type: 'name', name, version })\n\n let message: string\n if (plugin) {\n this.logger.warn('Plugin already exists. If you decide to deploy, it will override the existing one.')\n message = `Are you sure you want to override plugin ${name} v${version}?`\n } else {\n message = `Are you sure you want to deploy plugin ${name} v${version}?`\n }\n\n const confirm = await this.prompt.confirm(message)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n this.logger.debug('Preparing plugin request body...')\n\n const icon = await this.readProjectFile(pluginDef.icon, 'base64')\n const readme = await this.readProjectFile(pluginDef.readme, 'base64')\n\n const createBody = {\n ...(await apiUtils.prepareCreatePluginBody(pluginDef)),\n ...(await this.preparePluginDependencies(pluginDef, api)),\n public: this._visibility === 'public',\n icon,\n readme,\n code: {\n node: codeCJS,\n browser: codeESM,\n },\n }\n\n const startedMessage = `Deploying plugin ${chalk.bold(name)} v${version}...`\n const successMessage = 'Plugin deployed'\n if (plugin) {\n const updateBody = apiUtils.prepareUpdatePluginBody(\n {\n id: plugin.id,\n ...createBody,\n },\n plugin\n )\n\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.warn('Dry-run mode is not supported for plugin updates. Skipping deployment...')\n } else {\n await api.client.updatePlugin(updateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update plugin \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n } else {\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.warn('Dry-run mode is not supported for plugin creation. Skipping deployment...')\n } else {\n await api.client.createPlugin(createBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not create plugin \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n }\n }\n\n private _allowDeprecatedFeatures(\n integrationDef: sdk.IntegrationDefinition,\n previousVersion: client.Integration | undefined\n ): boolean {\n if (this.argv.allowDeprecated) {\n return true\n }\n\n if (!previousVersion) {\n return false\n }\n\n const versionDiff = semver.diff(integrationDef.version, previousVersion.version)\n if (!versionDiff) {\n return false\n }\n\n return utils.semver.releases.lt(versionDiff, 'major')\n }\n\n private _detectDeprecatedFeatures(\n integrationDef: sdk.IntegrationDefinition,\n opts: { allowDeprecated?: boolean } = {}\n ) {\n const deprecatedFields: string[] = []\n const { user, channels } = integrationDef\n if (user?.creation?.enabled) {\n deprecatedFields.push('user.creation')\n }\n\n for (const [channelName, channel] of Object.entries(channels ?? {})) {\n if (channel?.conversation?.creation?.enabled) {\n deprecatedFields.push(`channels.${channelName}.creation`)\n }\n }\n\n if (!deprecatedFields.length) {\n return\n }\n\n const errorMessage = `The following fields of the integration's definition are deprecated: ${deprecatedFields.join(\n ', '\n )}`\n\n if (opts.allowDeprecated) {\n this.logger.warn(errorMessage)\n } else {\n throw new errors.BotpressCLIError(errorMessage)\n }\n }\n\n private async _deployBot(\n api: apiUtils.ApiClient,\n botDefinition: sdk.BotDefinition,\n argvBotId: string | undefined,\n argvCreateNew: boolean | undefined\n ) {\n if (this.argv.dryRun) {\n this.logger.warn('Dry-run mode is not supported for bot deployments. Skipping deployment...')\n return\n }\n\n const outfile = this.projectPaths.abs.outFileCJS\n const code = await fs.promises.readFile(outfile, 'utf-8')\n\n let bot: client.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 = apiUtils.prepareUpdateBotBody(\n {\n ...(await apiUtils.prepareCreateBotBody(botDefinition)),\n ...(await this.prepareBotDependencies(botDefinition, api)),\n id: bot.id,\n code,\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\n this.validateIntegrationRegistration(updatedBot, (failedIntegrations) =>\n this.logger.warn(\n `Some integrations failed to register:\\n${Object.entries(failedIntegrations)\n .map(([key, int]) => `\u2022 ${key}: ${int.statusReason}`)\n .join('\\n')}`\n )\n )\n\n const tablesPublisher = new tables.TablesPublisher({ api, logger: this.logger, prompt: this.prompt })\n await tablesPublisher.deployTables({ botId: updatedBot.id, botDefinition })\n\n line.success('Bot deployed')\n this.displayWebhookUrls(updatedBot)\n }\n\n private async _createNewBot(api: apiUtils.ApiClient): Promise<client.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: apiUtils.ApiClient, botId: string | undefined): Promise<client.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 private async _manageWorkspaceHandle(\n api: apiUtils.ApiClient,\n integration: sdk.IntegrationDefinition\n ): Promise<\n | {\n integration: sdk.IntegrationDefinition\n workspaceId?: string // Set if user opted to deploy on another available workspace\n }\n | undefined\n > {\n const { name: localName, workspaceHandle: localHandle } = this._parseIntegrationName(integration.name)\n if (!localHandle && api.isBotpressWorkspace) {\n this.logger.debug('Botpress workspace detected; workspace handle omitted')\n return { integration } // botpress has the right to omit workspace handle\n }\n\n const { handle: remoteHandle, name: workspaceName } = await api.getWorkspace().catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not fetch workspace')\n })\n\n if (localHandle && remoteHandle) {\n let workspaceId: string | undefined = undefined\n if (localHandle !== remoteHandle) {\n const remoteWorkspace = await api.findWorkspaceByHandle(localHandle).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not list workspaces')\n })\n if (!remoteWorkspace) {\n throw new errors.BotpressCLIError(\n `The integration handle \"${localHandle}\" is not associated with any of your workspaces.`\n )\n }\n this.logger.warn(\n `Your are logged in to workspace \"${workspaceName}\" but integration handle \"${localHandle}\" belongs to \"${remoteWorkspace.name}\".`\n )\n const confirmUseAlternateWorkspace = await this.prompt.confirm(\n 'Do you want to deploy integration on this workspace instead?'\n )\n if (!confirmUseAlternateWorkspace) {\n throw new errors.BotpressCLIError(\n `Cannot deploy integration with handle \"${localHandle}\" on workspace \"${workspaceName}\"`\n )\n }\n\n workspaceId = remoteWorkspace.id\n }\n return { integration, workspaceId }\n }\n\n const workspaceHandleIsMandatoryMsg = 'Cannot deploy integration without workspace handle'\n\n if (!localHandle && remoteHandle) {\n const confirmAddHandle = await this.prompt.confirm(\n `Your current workspace handle is \"${remoteHandle}\". Do you want to use the name \"${remoteHandle}/${localName}\"?`\n )\n if (!confirmAddHandle) {\n this.logger.log('Aborted')\n return\n }\n const newName = `${remoteHandle}/${localName}`\n return { integration: new sdk.IntegrationDefinition({ ...integration, name: newName }) }\n }\n\n if (localHandle && !remoteHandle) {\n const { available } = await api.client.checkHandleAvailability({ handle: localHandle }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not check handle availability')\n })\n\n if (!available) {\n throw new errors.BotpressCLIError(`Handle \"${localHandle}\" is not yours and is not available`)\n }\n\n const confirmClaimHandle = await this.prompt.confirm(\n `Handle \"${localHandle}\" is available. Do you want to claim it for your workspace ${workspaceName}?`\n )\n if (!confirmClaimHandle) {\n throw new errors.BotpressCLIError(workspaceHandleIsMandatoryMsg)\n }\n\n await api.updateWorkspace({ handle: localHandle }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not claim handle \"${localHandle}\"`)\n })\n\n this.logger.success(`Handle \"${localHandle}\" is now yours!`)\n return { integration }\n }\n\n this.logger.warn(\"It seems you don't have a workspace handle yet.\")\n let claimedHandle: string | undefined = undefined\n do {\n const prompted = await this.prompt.text('Please enter a workspace handle')\n if (!prompted) {\n throw new errors.BotpressCLIError(workspaceHandleIsMandatoryMsg)\n }\n\n const { available, suggestions } = await api.client.checkHandleAvailability({ handle: prompted })\n if (!available) {\n this.logger.warn(`Handle \"${prompted}\" is not available. Suggestions: ${suggestions.join(', ')}`)\n continue\n }\n\n claimedHandle = prompted\n await api.updateWorkspace({ handle: claimedHandle }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not claim handle \"${claimedHandle}\"`)\n })\n } while (!claimedHandle)\n\n this.logger.success(`Handle \"${claimedHandle}\" is yours!`)\n const newName = `${claimedHandle}/${localName}`\n return { integration: new sdk.IntegrationDefinition({ ...integration, name: newName }) }\n }\n\n private _parseIntegrationName = (integrationName: string): { name: string; workspaceHandle?: string } => {\n const parts = integrationName.split('/')\n if (parts.length > 2) {\n throw new errors.BotpressCLIError(\n `Invalid integration name \"${integrationName}\": a single forward slash is allowed`\n )\n }\n if (parts.length === 2) {\n const [workspaceHandle, name] = parts as [string, string]\n return { name, workspaceHandle }\n }\n const [name] = parts as [string]\n return { name }\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,UAAqB;AACrB,mBAAkB;AAClB,SAAoB;AACpB,oBAAmB;AACnB,eAA0B;AAE1B,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;AAE3D,QAAI,CAAC,KAAK,KAAK,SAAS;AACtB,YAAM,KAAK,UAAU;AAAA,IACvB;AAEA,UAAM,EAAE,aAAa,yBAAyB,IAAI,KAAK,4BAA4B;AAEnF,QAAI,gBAAgB,eAAe;AACjC,YAAM,aAAa,MAAM,yBAAyB;AAClD,aAAO,KAAK,mBAAmB,KAAK,WAAW,UAAU;AAAA,IAC3D;AACA,QAAI,gBAAgB,aAAa;AAC/B,YAAM,aAAa,MAAM,yBAAyB;AAClD,aAAO,KAAK,iBAAiB,KAAK,WAAW,UAAU;AAAA,IACzD;AACA,QAAI,gBAAgB,UAAU;AAC5B,YAAM,aAAa,MAAM,yBAAyB;AAClD,aAAO,KAAK,cAAc,KAAK,WAAW,UAAU;AAAA,IACtD;AACA,QAAI,gBAAgB,OAAO;AACzB,YAAM,aAAa,MAAM,yBAAyB;AAClD,aAAO,KAAK,WAAW,KAAK,WAAW,YAAY,KAAK,KAAK,OAAO,KAAK,KAAK,YAAY;AAAA,IAC5F;AACA,UAAM,IAAI,OAAO,uBAAuB;AAAA,EAC1C;AAAA,EAEA,MAAc,YAAY;AACxB,WAAO,IA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AACtB,YAAM,CAAC,iBAAiBC,KAAI,IAAI;AAChC,aAAO,EAAE,MAAAA,OAAM,gBAAgB;AAAA,IACjC;AACA,UAAM,CAAC,IAAI,IAAI;AACf,WAAO,EAAE,KAAK;AAAA,EAChB;AACF;",
4
+ "sourcesContent": ["import type * as client from '@botpress/client'\nimport * as sdk from '@botpress/sdk'\nimport chalk from 'chalk'\nimport * as fs from 'fs'\nimport semver from 'semver'\nimport * as apiUtils from '../api'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport * as tables from '../tables'\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\n if (!this.argv.noBuild) {\n await this._runBuild() // This ensures the bundle is always synced with source code\n }\n\n const { projectType, resolveProjectDefinition } = this.readProjectDefinitionFromFS()\n\n if (projectType === 'integration') {\n const projectDef = await resolveProjectDefinition()\n return this._deployIntegration(api, projectDef.definition)\n }\n if (projectType === 'interface') {\n const projectDef = await resolveProjectDefinition()\n return this._deployInterface(api, projectDef.definition)\n }\n if (projectType === 'plugin') {\n const projectDef = await resolveProjectDefinition()\n return this._deployPlugin(api, projectDef.definition)\n }\n if (projectType === 'bot') {\n const projectDef = await resolveProjectDefinition()\n return this._deployBot(api, projectDef.definition, this.argv.botId, this.argv.createNewBot)\n }\n throw new errors.UnsupportedProjectType()\n }\n\n private async _runBuild() {\n return new BuildCommand(this.api, this.prompt, this.logger, this.argv).setProjectContext(this.projectContext).run()\n }\n\n private get _visibility(): 'public' | 'private' | 'unlisted' {\n if (this.argv.public && this.argv.visibility === 'private') {\n this.logger.warn('The --public flag is deprecated. Please use \"--visibility public\" instead.')\n return 'public'\n }\n\n if (this.argv.public && this.argv.visibility !== 'private') {\n this.logger.warn('The --public flag and --visibility option are both present. Ignoring the --public flag...')\n }\n\n return this.argv.visibility\n }\n\n private async _deployIntegration(api: apiUtils.ApiClient, integrationDef: sdk.IntegrationDefinition) {\n const res = await this._manageWorkspaceHandle(api, integrationDef)\n if (!res) return\n const { integration: updatedIntegrationDef, workspaceId } = res\n integrationDef = updatedIntegrationDef\n if (workspaceId) {\n api = api.switchWorkspace(workspaceId)\n }\n\n const { name, version } = integrationDef\n\n if (integrationDef.icon && !integrationDef.icon.toLowerCase().endsWith('.svg')) {\n throw new errors.BotpressCLIError('Icon must be an SVG file')\n }\n\n if (integrationDef.readme && !integrationDef.readme.toLowerCase().endsWith('.md')) {\n throw new errors.BotpressCLIError('Readme must be a Markdown file')\n }\n\n const integration = await api.findPublicOrPrivateIntegration({ type: 'name', name, version })\n if (integration && integration.workspaceId !== api.workspaceId) {\n throw new errors.BotpressCLIError(\n `Public integration ${name} v${version} is already deployed in another workspace.`\n )\n }\n\n if (integration && integration.visibility !== 'private' && !api.isBotpressWorkspace) {\n throw new errors.BotpressCLIError(\n `Integration ${name} v${version} is already deployed publicly and cannot be updated. Please bump the version.`\n )\n }\n\n let message: string\n if (integration) {\n this.logger.warn('Integration already exists. If you decide to deploy, it will override the existing one.')\n message = `Are you sure you want to override integration ${name} v${version}?`\n } else {\n message = `Are you sure you want to deploy integration ${name} v${version}?`\n }\n\n const confirm = await this.prompt.confirm(message)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n this.logger.debug('Preparing integration request body...')\n\n const createBody = {\n ...(await this.prepareCreateIntegrationBody(integrationDef)),\n ...(await this.prepareIntegrationDependencies(integrationDef, api)),\n visibility: this._visibility,\n }\n\n const startedMessage = `Deploying integration ${chalk.bold(name)} v${version}...`\n const successMessage = 'Integration deployed'\n if (integration) {\n const updateBody = apiUtils.prepareUpdateIntegrationBody(\n {\n id: integration.id,\n ...createBody,\n },\n integration\n )\n\n const { secrets: knownSecrets } = integration\n updateBody.secrets = await this.promptSecrets(integrationDef, this.argv, { knownSecrets })\n this._detectDeprecatedFeatures(integrationDef, { allowDeprecated: true })\n\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.log('Dry-run mode is active. Simulating integration update...')\n\n await api.client.validateIntegrationUpdate(updateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update integration \"${name}\"`)\n })\n } else {\n await api.client.updateIntegration(updateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update integration \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n } else {\n this.logger.debug(`looking for previous version of integration \"${name}\"`)\n const previousVersion = await api.findPreviousIntegrationVersion({ type: 'name', name, version })\n\n if (previousVersion) {\n this.logger.debug(`previous version found: ${previousVersion.version}`)\n } else {\n this.logger.debug('no previous version found')\n }\n\n const knownSecrets = previousVersion?.secrets\n\n createBody.secrets = await this.promptSecrets(integrationDef, this.argv, { knownSecrets })\n this._detectDeprecatedFeatures(integrationDef, {\n allowDeprecated: this._allowDeprecatedFeatures(integrationDef, previousVersion),\n })\n\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.log('Dry-run mode is active. Simulating integration creation...')\n\n await api.client.validateIntegrationCreation(createBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not create integration \"${name}\"`)\n })\n } else {\n await api.client.createIntegration(createBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not create integration \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n }\n }\n\n private async _deployInterface(api: apiUtils.ApiClient, interfaceDeclaration: sdk.InterfaceDefinition) {\n if (this._visibility === 'unlisted') {\n throw new errors.BotpressCLIError(\n 'Unlisted visibility is not supported for interfaces. Please use \"public\" or \"private\".'\n )\n }\n\n if (interfaceDeclaration.icon && !interfaceDeclaration.icon.toLowerCase().endsWith('.svg')) {\n throw new errors.BotpressCLIError('Icon must be an SVG file')\n }\n\n if (interfaceDeclaration.readme && !interfaceDeclaration.readme.toLowerCase().endsWith('.md')) {\n throw new errors.BotpressCLIError('Readme must be a Markdown file')\n }\n\n const { name, version } = interfaceDeclaration\n const intrface = await api.findPublicOrPrivateInterface({ type: 'name', name, version })\n\n let message: string\n if (intrface) {\n this.logger.warn('Interface already exists. If you decide to deploy, it will override the existing one.')\n message = `Are you sure you want to override interface ${name} v${version}?`\n } else {\n message = `Are you sure you want to deploy interface ${name} v${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 icon = await this.readProjectFile(interfaceDeclaration.icon, 'base64')\n const readme = await this.readProjectFile(interfaceDeclaration.readme, 'base64')\n\n if (this._visibility !== 'public') {\n this.logger.warn(\n 'You are currently publishing a private interface, which cannot be used by integrations and plugins. To fix this, change the visibility to \"public\"'\n )\n }\n\n const createBody = {\n ...(await apiUtils.prepareCreateInterfaceBody(interfaceDeclaration)),\n public: this._visibility === 'public',\n icon,\n readme,\n }\n\n const startedMessage = `Deploying interface ${chalk.bold(name)} v${version}...`\n const successMessage = 'Interface deployed'\n if (intrface) {\n const updateBody = apiUtils.prepareUpdateInterfaceBody(\n {\n id: intrface.id,\n ...createBody,\n },\n intrface\n )\n\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.warn('Dry-run mode is not supported for interface updates. Skipping deployment...')\n } else {\n await api.client.updateInterface(updateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update interface \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n } else {\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.warn('Dry-run mode is not supported for interface creation. Skipping deployment...')\n } else {\n await api.client.createInterface(createBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not create interface \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n }\n }\n\n private async _deployPlugin(api: apiUtils.ApiClient, pluginDef: sdk.PluginDefinition) {\n if (this._visibility === 'unlisted') {\n throw new errors.BotpressCLIError(\n 'Unlisted visibility is not supported for plugins. Please use \"public\" or \"private\".'\n )\n }\n\n const codeCJS = await fs.promises.readFile(this.projectPaths.abs.outFileCJS, 'utf-8')\n const codeESM = await fs.promises.readFile(this.projectPaths.abs.outFileESM, 'utf-8')\n\n const { name, version } = pluginDef\n\n if (pluginDef.icon && !pluginDef.icon.toLowerCase().endsWith('.svg')) {\n throw new errors.BotpressCLIError('Icon must be an SVG file')\n }\n\n if (pluginDef.readme && !pluginDef.readme.toLowerCase().endsWith('.md')) {\n throw new errors.BotpressCLIError('Readme must be a Markdown file')\n }\n\n const plugin = await api.findPublicOrPrivatePlugin({ type: 'name', name, version })\n\n let message: string\n if (plugin) {\n this.logger.warn('Plugin already exists. If you decide to deploy, it will override the existing one.')\n message = `Are you sure you want to override plugin ${name} v${version}?`\n } else {\n message = `Are you sure you want to deploy plugin ${name} v${version}?`\n }\n\n const confirm = await this.prompt.confirm(message)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n this.logger.debug('Preparing plugin request body...')\n\n const icon = await this.readProjectFile(pluginDef.icon, 'base64')\n const readme = await this.readProjectFile(pluginDef.readme, 'base64')\n\n const createBody = {\n ...(await apiUtils.prepareCreatePluginBody(pluginDef)),\n ...(await this.preparePluginDependencies(pluginDef, api)),\n public: this._visibility === 'public',\n icon,\n readme,\n code: {\n node: codeCJS,\n browser: codeESM,\n },\n }\n\n const startedMessage = `Deploying plugin ${chalk.bold(name)} v${version}...`\n const successMessage = 'Plugin deployed'\n if (plugin) {\n const updateBody = apiUtils.prepareUpdatePluginBody(\n {\n id: plugin.id,\n ...createBody,\n },\n plugin\n )\n\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.warn('Dry-run mode is not supported for plugin updates. Skipping deployment...')\n } else {\n await api.client.updatePlugin(updateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update plugin \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n } else {\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.warn('Dry-run mode is not supported for plugin creation. Skipping deployment...')\n } else {\n await api.client.createPlugin(createBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not create plugin \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n }\n }\n\n private _allowDeprecatedFeatures(\n integrationDef: sdk.IntegrationDefinition,\n previousVersion: client.Integration | undefined\n ): boolean {\n if (this.argv.allowDeprecated) {\n return true\n }\n\n if (!previousVersion) {\n return false\n }\n\n const versionDiff = semver.diff(integrationDef.version, previousVersion.version)\n if (!versionDiff) {\n return false\n }\n\n return utils.semver.releases.lt(versionDiff, 'major')\n }\n\n private _detectDeprecatedFeatures(\n integrationDef: sdk.IntegrationDefinition,\n opts: { allowDeprecated?: boolean } = {}\n ) {\n const deprecatedFields: string[] = []\n const { user, channels } = integrationDef\n if (user?.creation?.enabled) {\n deprecatedFields.push('user.creation')\n }\n\n for (const [channelName, channel] of Object.entries(channels ?? {})) {\n if (channel?.conversation?.creation?.enabled) {\n deprecatedFields.push(`channels.${channelName}.creation`)\n }\n }\n\n if (!deprecatedFields.length) {\n return\n }\n\n const errorMessage = `The following fields of the integration's definition are deprecated: ${deprecatedFields.join(\n ', '\n )}`\n\n if (opts.allowDeprecated) {\n this.logger.warn(errorMessage)\n } else {\n throw new errors.BotpressCLIError(errorMessage)\n }\n }\n\n private async _deployBot(\n api: apiUtils.ApiClient,\n botDefinition: sdk.BotDefinition,\n argvBotId: string | undefined,\n argvCreateNew: boolean | undefined\n ) {\n if (this.argv.dryRun) {\n this.logger.warn('Dry-run mode is not supported for bot deployments. Skipping deployment...')\n return\n }\n\n const outfile = this.projectPaths.abs.outFileCJS\n const code = await fs.promises.readFile(outfile, 'utf-8')\n\n let bot: client.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 = apiUtils.prepareUpdateBotBody(\n {\n ...(await apiUtils.prepareCreateBotBody(botDefinition)),\n ...(await this.prepareBotDependencies(botDefinition, api)),\n id: bot.id,\n code,\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\n this.validateIntegrationRegistration(updatedBot, (failedIntegrations) =>\n this.logger.warn(\n `Some integrations failed to register:\\n${Object.entries(failedIntegrations)\n .map(([key, int]) => `\u2022 ${key}: ${int.statusReason}`)\n .join('\\n')}`\n )\n )\n\n const tablesPublisher = new tables.TablesPublisher({ api, logger: this.logger, prompt: this.prompt })\n await tablesPublisher.deployTables({ botId: updatedBot.id, botDefinition })\n\n line.success('Bot deployed')\n await this.displayIntegrationUrls({ api, bot: updatedBot })\n }\n\n private async _createNewBot(api: apiUtils.ApiClient): Promise<client.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: apiUtils.ApiClient, botId: string | undefined): Promise<client.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 private async _manageWorkspaceHandle(\n api: apiUtils.ApiClient,\n integration: sdk.IntegrationDefinition\n ): Promise<\n | {\n integration: sdk.IntegrationDefinition\n workspaceId?: string // Set if user opted to deploy on another available workspace\n }\n | undefined\n > {\n const { name: localName, workspaceHandle: localHandle } = this._parseIntegrationName(integration.name)\n if (!localHandle && api.isBotpressWorkspace) {\n this.logger.debug('Botpress workspace detected; workspace handle omitted')\n return { integration } // botpress has the right to omit workspace handle\n }\n\n const { handle: remoteHandle, name: workspaceName } = await api.getWorkspace().catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not fetch workspace')\n })\n\n if (localHandle && remoteHandle) {\n let workspaceId: string | undefined = undefined\n if (localHandle !== remoteHandle) {\n const remoteWorkspace = await api.findWorkspaceByHandle(localHandle).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not list workspaces')\n })\n if (!remoteWorkspace) {\n throw new errors.BotpressCLIError(\n `The integration handle \"${localHandle}\" is not associated with any of your workspaces.`\n )\n }\n this.logger.warn(\n `Your are logged in to workspace \"${workspaceName}\" but integration handle \"${localHandle}\" belongs to \"${remoteWorkspace.name}\".`\n )\n const confirmUseAlternateWorkspace = await this.prompt.confirm(\n 'Do you want to deploy integration on this workspace instead?'\n )\n if (!confirmUseAlternateWorkspace) {\n throw new errors.BotpressCLIError(\n `Cannot deploy integration with handle \"${localHandle}\" on workspace \"${workspaceName}\"`\n )\n }\n\n workspaceId = remoteWorkspace.id\n }\n return { integration, workspaceId }\n }\n\n const workspaceHandleIsMandatoryMsg = 'Cannot deploy integration without workspace handle'\n\n if (!localHandle && remoteHandle) {\n const confirmAddHandle = await this.prompt.confirm(\n `Your current workspace handle is \"${remoteHandle}\". Do you want to use the name \"${remoteHandle}/${localName}\"?`\n )\n if (!confirmAddHandle) {\n this.logger.log('Aborted')\n return\n }\n const newName = `${remoteHandle}/${localName}`\n return { integration: new sdk.IntegrationDefinition({ ...integration, name: newName }) }\n }\n\n if (localHandle && !remoteHandle) {\n const { available } = await api.client.checkHandleAvailability({ handle: localHandle }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not check handle availability')\n })\n\n if (!available) {\n throw new errors.BotpressCLIError(`Handle \"${localHandle}\" is not yours and is not available`)\n }\n\n const confirmClaimHandle = await this.prompt.confirm(\n `Handle \"${localHandle}\" is available. Do you want to claim it for your workspace ${workspaceName}?`\n )\n if (!confirmClaimHandle) {\n throw new errors.BotpressCLIError(workspaceHandleIsMandatoryMsg)\n }\n\n await api.updateWorkspace({ handle: localHandle }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not claim handle \"${localHandle}\"`)\n })\n\n this.logger.success(`Handle \"${localHandle}\" is now yours!`)\n return { integration }\n }\n\n this.logger.warn(\"It seems you don't have a workspace handle yet.\")\n let claimedHandle: string | undefined = undefined\n do {\n const prompted = await this.prompt.text('Please enter a workspace handle')\n if (!prompted) {\n throw new errors.BotpressCLIError(workspaceHandleIsMandatoryMsg)\n }\n\n const { available, suggestions } = await api.client.checkHandleAvailability({ handle: prompted })\n if (!available) {\n this.logger.warn(`Handle \"${prompted}\" is not available. Suggestions: ${suggestions.join(', ')}`)\n continue\n }\n\n claimedHandle = prompted\n await api.updateWorkspace({ handle: claimedHandle }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not claim handle \"${claimedHandle}\"`)\n })\n } while (!claimedHandle)\n\n this.logger.success(`Handle \"${claimedHandle}\" is yours!`)\n const newName = `${claimedHandle}/${localName}`\n return { integration: new sdk.IntegrationDefinition({ ...integration, name: newName }) }\n }\n\n private _parseIntegrationName = (integrationName: string): { name: string; workspaceHandle?: string } => {\n const parts = integrationName.split('/')\n if (parts.length > 2) {\n throw new errors.BotpressCLIError(\n `Invalid integration name \"${integrationName}\": a single forward slash is allowed`\n )\n }\n if (parts.length === 2) {\n const [workspaceHandle, name] = parts as [string, string]\n return { name, workspaceHandle }\n }\n const [name] = parts as [string]\n return { name }\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,UAAqB;AACrB,mBAAkB;AAClB,SAAoB;AACpB,oBAAmB;AACnB,eAA0B;AAE1B,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;AAE3D,QAAI,CAAC,KAAK,KAAK,SAAS;AACtB,YAAM,KAAK,UAAU;AAAA,IACvB;AAEA,UAAM,EAAE,aAAa,yBAAyB,IAAI,KAAK,4BAA4B;AAEnF,QAAI,gBAAgB,eAAe;AACjC,YAAM,aAAa,MAAM,yBAAyB;AAClD,aAAO,KAAK,mBAAmB,KAAK,WAAW,UAAU;AAAA,IAC3D;AACA,QAAI,gBAAgB,aAAa;AAC/B,YAAM,aAAa,MAAM,yBAAyB;AAClD,aAAO,KAAK,iBAAiB,KAAK,WAAW,UAAU;AAAA,IACzD;AACA,QAAI,gBAAgB,UAAU;AAC5B,YAAM,aAAa,MAAM,yBAAyB;AAClD,aAAO,KAAK,cAAc,KAAK,WAAW,UAAU;AAAA,IACtD;AACA,QAAI,gBAAgB,OAAO;AACzB,YAAM,aAAa,MAA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A,EACzF;AAAA,EAEQ,wBAAwB,CAAC,oBAAwE;AACvG,UAAM,QAAQ,gBAAgB,MAAM,GAAG;AACvC,QAAI,MAAM,SAAS,GAAG;AACpB,YAAM,IAAI,OAAO;AAAA,QACf,6BAA6B,eAAe;AAAA,MAC9C;AAAA,IACF;AACA,QAAI,MAAM,WAAW,GAAG;AACtB,YAAM,CAAC,iBAAiBC,KAAI,IAAI;AAChC,aAAO,EAAE,MAAAA,OAAM,gBAAgB;AAAA,IACjC;AACA,UAAM,CAAC,IAAI,IAAI;AACf,WAAO,EAAE,KAAK;AAAA,EAChB;AACF;",
6
6
  "names": ["chalk", "semver", "newName", "name"]
7
7
  }
@@ -329,7 +329,7 @@ ${Object.entries(failedIntegrations).map(([key, int]) => `\u2022 ${key}: ${int.s
329
329
  updateLine.commit();
330
330
  const tablesPublisher = new tables.TablesPublisher({ api, logger: this.logger, prompt: this.prompt });
331
331
  await tablesPublisher.deployTables({ botId: updatedBot.id, botDefinition: botDef });
332
- this.displayWebhookUrls(updatedBot);
332
+ await this.displayIntegrationUrls({ api, bot: updatedBot });
333
333
  }
334
334
  async _didDefinitionChange(body) {
335
335
  const didChange = !(0, import_lodash.isEqual)(body, this._cacheDevRequestBody);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/command-implementations/dev-command.ts"],
4
- "sourcesContent": ["import type * as client from '@botpress/client'\nimport type * as sdk from '@botpress/sdk'\nimport { TunnelRequest, TunnelResponse } from '@bpinternal/tunnel'\nimport axios, { AxiosRequestConfig, AxiosResponse } from 'axios'\nimport chalk from 'chalk'\nimport { isEqual } from 'lodash'\nimport * as pathlib from 'path'\nimport * as uuid from 'uuid'\nimport * as apiUtils from '../api'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport * as tables from '../tables'\nimport * as utils from '../utils'\nimport { Worker } from '../worker'\nimport { BuildCommand } from './build-command'\nimport { ProjectCommand, ProjectDefinition } from './project-command'\n\nconst DEFAULT_BOT_PORT = 8075\nconst DEFAULT_INTEGRATION_PORT = 8076\nconst TUNNEL_HELLO_INTERVAL = 5000\nconst FILEWATCHER_DEBOUNCE_MS = 500\n\nexport type DevCommandDefinition = typeof commandDefinitions.dev\nexport class DevCommand extends ProjectCommand<DevCommandDefinition> {\n private _initialDef: ProjectDefinition | undefined = undefined\n private _cacheDevRequestBody: apiUtils.UpdateBotRequestBody | apiUtils.UpdateIntegrationRequestBody | undefined\n private _buildContext: utils.esbuild.BuildCodeContext\n\n public constructor(...args: ConstructorParameters<typeof ProjectCommand<DevCommandDefinition>>) {\n super(...args)\n this._buildContext = new utils.esbuild.BuildCodeContext()\n }\n\n public async run(): Promise<void> {\n this.logger.warn('This command is experimental and subject to breaking changes without notice.')\n\n const api = await this.ensureLoginAndCreateClient(this.argv)\n\n const { projectType, resolveProjectDefinition } = this.readProjectDefinitionFromFS()\n if (projectType === 'interface') {\n throw new errors.BotpressCLIError('This feature is not available for interfaces.')\n }\n const projectDef = await resolveProjectDefinition()\n this._initialDef = projectDef\n\n let env: Record<string, string> = {\n ...process.env,\n BP_API_URL: api.url,\n BP_TOKEN: api.token,\n }\n\n let defaultPort = DEFAULT_BOT_PORT\n if (this._initialDef.type === 'integration') {\n defaultPort = DEFAULT_INTEGRATION_PORT\n // TODO: store secrets in local cache to avoid prompting every time\n const secretEnvVariables = await this.promptSecrets(this._initialDef.definition, this.argv, { formatEnv: true })\n const nonNullSecretEnvVariables = utils.records.filterValues(secretEnvVariables, utils.guards.is.notNull)\n env = { ...env, ...nonNullSecretEnvVariables }\n }\n\n const port = this.argv.port ?? defaultPort\n\n const urlParseResult = utils.url.parse(this.argv.tunnelUrl)\n if (urlParseResult.status === 'error') {\n throw new errors.BotpressCLIError(`Invalid tunnel URL: ${urlParseResult.error}`)\n }\n\n const cachedTunnelId = await this.projectCache.get('tunnelId')\n\n let tunnelId: string\n if (this.argv.tunnelId) {\n tunnelId = this.argv.tunnelId\n } else if (cachedTunnelId) {\n tunnelId = cachedTunnelId\n } else {\n tunnelId = uuid.v4()\n }\n\n if (cachedTunnelId !== tunnelId) {\n await this.projectCache.set('tunnelId', tunnelId)\n }\n\n const { url: parsedTunnelUrl } = urlParseResult\n const isSecured = parsedTunnelUrl.protocol === 'https' || parsedTunnelUrl.protocol === 'wss'\n\n const wsTunnelUrl: string = utils.url.format({ ...parsedTunnelUrl, protocol: isSecured ? 'wss' : 'ws' })\n const httpTunnelUrl: string = utils.url.format({\n ...parsedTunnelUrl,\n protocol: isSecured ? 'https' : 'http',\n path: `/${tunnelId}`,\n })\n\n let worker: Worker | undefined = undefined\n\n const supervisor = new utils.tunnel.TunnelSupervisor(wsTunnelUrl, tunnelId, this.logger)\n supervisor.events.on('connected', ({ tunnel }) => {\n // prevents the tunnel from closing due to inactivity\n const timer = setInterval(() => {\n if (tunnel.closed) {\n return handleClose()\n }\n tunnel.hello()\n }, TUNNEL_HELLO_INTERVAL)\n const handleClose = (): void => clearInterval(timer)\n tunnel.events.on('close', handleClose)\n\n tunnel.events.on('request', (req) => {\n if (!worker) {\n this.logger.debug('Worker not ready yet, ignoring request')\n tunnel.send({ requestId: req.id, status: 503, body: 'Worker not ready yet' })\n return\n }\n\n void this._forwardTunnelRequest(`http://localhost:${port}`, req)\n .then((res) => {\n tunnel.send(res)\n })\n .catch((thrown) => {\n const err = errors.BotpressCLIError.wrap(thrown, 'An error occurred while handling request')\n this.logger.error(err.message)\n tunnel.send({\n requestId: req.id,\n status: 500,\n body: err.message,\n })\n })\n })\n })\n\n supervisor.events.on('manuallyClosed', () => {\n this.logger.debug('Tunnel manually closed')\n })\n\n await supervisor.start()\n\n await this._runBuild()\n await this._deploy(api, httpTunnelUrl)\n worker = await this._spawnWorker(env, port)\n\n try {\n const watcher = await utils.filewatcher.FileWatcher.watch(\n this.argv.workDir,\n async (events) => {\n if (!worker) {\n this.logger.debug('Worker not ready yet, ignoring file change event')\n return\n }\n\n const typescriptEvents = events\n .filter((e) => !e.path.startsWith(this.projectPaths.abs.outDir))\n .filter((e) => pathlib.extname(e.path) === '.ts')\n\n const distEvents = events.filter((e) => e.path.startsWith(this.projectPaths.abs.distDir))\n\n if (typescriptEvents.length > 0) {\n this.logger.log('Changes detected, rebuilding')\n await this._restart(api, worker, httpTunnelUrl)\n } else if (distEvents.length > 0) {\n this.logger.log('Changes detected in output directory, reloading worker')\n await worker.reload()\n }\n },\n {\n debounceMs: FILEWATCHER_DEBOUNCE_MS,\n }\n )\n\n await Promise.race([worker.wait(), watcher.wait(), supervisor.wait()])\n\n if (worker.running) {\n await worker.kill()\n }\n await watcher.close()\n supervisor.close()\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, 'An error occurred while running the dev server')\n } finally {\n if (worker.running) {\n await worker.kill()\n }\n }\n }\n\n private _restart = async (api: apiUtils.ApiClient, worker: Worker, tunnelUrl: string) => {\n try {\n await this._runBuild()\n } catch (thrown) {\n const error = errors.BotpressCLIError.wrap(thrown, 'Build failed')\n this.logger.error(error.message)\n return\n }\n\n await this._deploy(api, tunnelUrl)\n await worker.reload()\n }\n\n private _deploy = async (api: apiUtils.ApiClient, tunnelUrl: string) => {\n const { projectType, resolveProjectDefinition } = this.readProjectDefinitionFromFS()\n\n if (projectType === 'interface') {\n throw new errors.BotpressCLIError('This feature is not available for interfaces.')\n }\n if (projectType === 'integration') {\n const projectDef = await resolveProjectDefinition()\n this._checkSecrets(projectDef.definition)\n return await this._deployDevIntegration(api, tunnelUrl, projectDef.definition)\n }\n if (projectType === 'bot') {\n const projectDef = await resolveProjectDefinition()\n return await this._deployDevBot(api, tunnelUrl, projectDef.definition)\n }\n throw new errors.UnsupportedProjectType()\n }\n\n private _checkSecrets(integrationDef: sdk.IntegrationDefinition) {\n if (this._initialDef?.type !== 'integration') {\n return\n }\n const initialSecrets = this._initialDef?.definition.secrets ?? {}\n const currentSecrets = integrationDef.secrets ?? {}\n const newSecrets = Object.keys(currentSecrets).filter((s) => !initialSecrets[s])\n if (newSecrets.length > 0) {\n throw new errors.BotpressCLIError('Secrets were added while the server was running. A restart is required.')\n }\n }\n\n private _spawnWorker = async (env: Record<string, string>, port: number) => {\n const outfile = this.projectPaths.abs.outFileCJS\n const importPath = utils.path.toUnix(outfile)\n const code = `require('${importPath}').default.start(${port})`\n const worker = await Worker.spawn(\n {\n type: 'code',\n code,\n env,\n },\n this.logger\n ).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not start dev worker')\n })\n\n return worker\n }\n\n private _runBuild() {\n return new BuildCommand(this.api, this.prompt, this.logger, this.argv)\n .setProjectContext(this.projectContext)\n .run(this._buildContext)\n }\n\n private async _deployDevIntegration(\n api: apiUtils.ApiClient,\n externalUrl: string,\n integrationDef: sdk.IntegrationDefinition\n ): Promise<void> {\n const devId = await this.projectCache.get('devId')\n\n let integration: client.Integration | undefined = undefined\n\n if (devId) {\n const resp = await api.client.getIntegration({ id: devId }).catch(async (thrown) => {\n const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev integration with id \"${devId}\"`)\n this.logger.warn(err.message)\n return { integration: undefined }\n })\n\n if (resp.integration?.dev) {\n integration = resp.integration\n } else {\n await this.projectCache.rm('devId')\n }\n }\n\n const line = this.logger.line()\n line.started(`Deploying dev integration ${chalk.bold(integrationDef.name)}...`)\n\n const createIntegrationBody = {\n ...(await this.prepareCreateIntegrationBody(integrationDef)),\n ...(await this.prepareIntegrationDependencies(integrationDef, api)),\n url: externalUrl,\n }\n\n if (integration) {\n const updateIntegrationBody = apiUtils.prepareUpdateIntegrationBody(\n { ...createIntegrationBody, id: integration.id },\n integration\n )\n\n const resp = await api.client.updateIntegration(updateIntegrationBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update dev integration \"${integrationDef.name}\"`)\n })\n integration = resp.integration\n } else {\n const resp = await api.client.createIntegration({ ...createIntegrationBody, dev: true }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not deploy dev integration \"${integrationDef.name}\"`)\n })\n integration = resp.integration\n }\n\n line.success(`Dev Integration deployed with id \"${integration.id}\" at \"${externalUrl}\"`)\n line.commit()\n\n await this.projectCache.set('devId', integration.id)\n }\n\n private async _deployDevBot(api: apiUtils.ApiClient, externalUrl: string, botDef: sdk.BotDefinition): Promise<void> {\n const devId = await this.projectCache.get('devId')\n\n let bot: client.Bot | undefined = undefined\n\n if (devId) {\n const resp = await api.client.getBot({ id: devId }).catch(async (thrown) => {\n const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev bot with id \"${devId}\"`)\n this.logger.warn(err.message)\n return { bot: undefined }\n })\n\n if (resp.bot?.dev) {\n bot = resp.bot\n } else {\n await this.projectCache.rm('devId')\n }\n }\n\n if (!bot) {\n const createLine = this.logger.line()\n createLine.started('Creating dev bot...')\n const resp = await api.client\n .createBot({\n dev: true,\n url: externalUrl,\n })\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not deploy dev bot')\n })\n\n bot = resp.bot\n createLine.log('Dev Bot created')\n createLine.commit()\n await this.projectCache.set('devId', bot.id)\n }\n\n const updateBotBody = apiUtils.prepareUpdateBotBody(\n {\n ...(await apiUtils.prepareCreateBotBody(botDef)),\n ...(await this.prepareBotDependencies(botDef, api)),\n id: bot.id,\n url: externalUrl,\n },\n bot\n )\n\n if (!(await this._didDefinitionChange(updateBotBody))) {\n this.logger.log('Skipping deployment step. No changes found in bot.definition.ts')\n return\n }\n const updateLine = this.logger.line()\n updateLine.started('Deploying dev bot...')\n\n const { bot: updatedBot } = await api.client.updateBot(updateBotBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not deploy dev bot')\n })\n\n this.validateIntegrationRegistration(updatedBot, (failedIntegrations) => {\n throw new errors.BotpressCLIError(\n `Some integrations failed to register:\\n${Object.entries(failedIntegrations)\n .map(([key, int]) => `\u2022 ${key}: ${int.statusReason}`)\n .join('\\n')}`\n )\n })\n\n updateLine.success(`Dev Bot deployed with id \"${updatedBot.id}\" at \"${externalUrl}\"`)\n updateLine.commit()\n\n const tablesPublisher = new tables.TablesPublisher({ api, logger: this.logger, prompt: this.prompt })\n await tablesPublisher.deployTables({ botId: updatedBot.id, botDefinition: botDef })\n\n this.displayWebhookUrls(updatedBot)\n }\n\n private async _didDefinitionChange(body: apiUtils.UpdateBotRequestBody | apiUtils.UpdateIntegrationRequestBody) {\n const didChange = !isEqual(body, this._cacheDevRequestBody)\n this._cacheDevRequestBody = { ...body }\n return didChange\n }\n\n private _forwardTunnelRequest = async (baseUrl: string, request: TunnelRequest): Promise<TunnelResponse> => {\n const axiosConfig = {\n method: request.method,\n url: this._formatLocalUrl(baseUrl, request),\n headers: request.headers,\n data: request.body,\n responseType: 'text',\n validateStatus: () => true,\n } satisfies AxiosRequestConfig\n\n this.logger.debug(`Forwarding request to ${axiosConfig.url}`)\n const response = await axios(axiosConfig)\n this.logger.debug('Sending back response up the tunnel')\n\n return {\n requestId: request.id,\n status: response.status,\n headers: this._getHeaders(response.headers),\n body: response.data,\n }\n }\n\n private _formatLocalUrl = (baseUrl: string, req: TunnelRequest): string => {\n if (req.query) {\n return `${baseUrl}${req.path}?${req.query}`\n }\n return `${baseUrl}${req.path}`\n }\n\n private _getHeaders = (res: AxiosResponse['headers']): TunnelResponse['headers'] => {\n const headers: TunnelResponse['headers'] = {}\n for (const key in res) {\n if (typeof res[key] === 'string' || typeof res[key] === 'number') {\n headers[key] = String(res[key])\n }\n }\n return headers\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAyD;AACzD,mBAAkB;AAClB,oBAAwB;AACxB,cAAyB;AACzB,WAAsB;AACtB,eAA0B;AAE1B,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,oBAAuB;AACvB,2BAA6B;AAC7B,6BAAkD;AAElD,MAAM,mBAAmB;AACzB,MAAM,2BAA2B;AACjC,MAAM,wBAAwB;AAC9B,MAAM,0BAA0B;AAGzB,MAAM,mB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AClF,UAAM,UAAqC,CAAC;AAC5C,eAAW,OAAO,KAAK;AACrB,UAAI,OAAO,IAAI,GAAG,MAAM,YAAY,OAAO,IAAI,GAAG,MAAM,UAAU;AAChE,gBAAQ,GAAG,IAAI,OAAO,IAAI,GAAG,CAAC;AAAA,MAChC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;",
4
+ "sourcesContent": ["import type * as client from '@botpress/client'\nimport type * as sdk from '@botpress/sdk'\nimport { TunnelRequest, TunnelResponse } from '@bpinternal/tunnel'\nimport axios, { AxiosRequestConfig, AxiosResponse } from 'axios'\nimport chalk from 'chalk'\nimport { isEqual } from 'lodash'\nimport * as pathlib from 'path'\nimport * as uuid from 'uuid'\nimport * as apiUtils from '../api'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport * as tables from '../tables'\nimport * as utils from '../utils'\nimport { Worker } from '../worker'\nimport { BuildCommand } from './build-command'\nimport { ProjectCommand, ProjectDefinition } from './project-command'\n\nconst DEFAULT_BOT_PORT = 8075\nconst DEFAULT_INTEGRATION_PORT = 8076\nconst TUNNEL_HELLO_INTERVAL = 5000\nconst FILEWATCHER_DEBOUNCE_MS = 500\n\nexport type DevCommandDefinition = typeof commandDefinitions.dev\nexport class DevCommand extends ProjectCommand<DevCommandDefinition> {\n private _initialDef: ProjectDefinition | undefined = undefined\n private _cacheDevRequestBody: apiUtils.UpdateBotRequestBody | apiUtils.UpdateIntegrationRequestBody | undefined\n private _buildContext: utils.esbuild.BuildCodeContext\n\n public constructor(...args: ConstructorParameters<typeof ProjectCommand<DevCommandDefinition>>) {\n super(...args)\n this._buildContext = new utils.esbuild.BuildCodeContext()\n }\n\n public async run(): Promise<void> {\n this.logger.warn('This command is experimental and subject to breaking changes without notice.')\n\n const api = await this.ensureLoginAndCreateClient(this.argv)\n\n const { projectType, resolveProjectDefinition } = this.readProjectDefinitionFromFS()\n if (projectType === 'interface') {\n throw new errors.BotpressCLIError('This feature is not available for interfaces.')\n }\n const projectDef = await resolveProjectDefinition()\n this._initialDef = projectDef\n\n let env: Record<string, string> = {\n ...process.env,\n BP_API_URL: api.url,\n BP_TOKEN: api.token,\n }\n\n let defaultPort = DEFAULT_BOT_PORT\n if (this._initialDef.type === 'integration') {\n defaultPort = DEFAULT_INTEGRATION_PORT\n // TODO: store secrets in local cache to avoid prompting every time\n const secretEnvVariables = await this.promptSecrets(this._initialDef.definition, this.argv, { formatEnv: true })\n const nonNullSecretEnvVariables = utils.records.filterValues(secretEnvVariables, utils.guards.is.notNull)\n env = { ...env, ...nonNullSecretEnvVariables }\n }\n\n const port = this.argv.port ?? defaultPort\n\n const urlParseResult = utils.url.parse(this.argv.tunnelUrl)\n if (urlParseResult.status === 'error') {\n throw new errors.BotpressCLIError(`Invalid tunnel URL: ${urlParseResult.error}`)\n }\n\n const cachedTunnelId = await this.projectCache.get('tunnelId')\n\n let tunnelId: string\n if (this.argv.tunnelId) {\n tunnelId = this.argv.tunnelId\n } else if (cachedTunnelId) {\n tunnelId = cachedTunnelId\n } else {\n tunnelId = uuid.v4()\n }\n\n if (cachedTunnelId !== tunnelId) {\n await this.projectCache.set('tunnelId', tunnelId)\n }\n\n const { url: parsedTunnelUrl } = urlParseResult\n const isSecured = parsedTunnelUrl.protocol === 'https' || parsedTunnelUrl.protocol === 'wss'\n\n const wsTunnelUrl: string = utils.url.format({ ...parsedTunnelUrl, protocol: isSecured ? 'wss' : 'ws' })\n const httpTunnelUrl: string = utils.url.format({\n ...parsedTunnelUrl,\n protocol: isSecured ? 'https' : 'http',\n path: `/${tunnelId}`,\n })\n\n let worker: Worker | undefined = undefined\n\n const supervisor = new utils.tunnel.TunnelSupervisor(wsTunnelUrl, tunnelId, this.logger)\n supervisor.events.on('connected', ({ tunnel }) => {\n // prevents the tunnel from closing due to inactivity\n const timer = setInterval(() => {\n if (tunnel.closed) {\n return handleClose()\n }\n tunnel.hello()\n }, TUNNEL_HELLO_INTERVAL)\n const handleClose = (): void => clearInterval(timer)\n tunnel.events.on('close', handleClose)\n\n tunnel.events.on('request', (req) => {\n if (!worker) {\n this.logger.debug('Worker not ready yet, ignoring request')\n tunnel.send({ requestId: req.id, status: 503, body: 'Worker not ready yet' })\n return\n }\n\n void this._forwardTunnelRequest(`http://localhost:${port}`, req)\n .then((res) => {\n tunnel.send(res)\n })\n .catch((thrown) => {\n const err = errors.BotpressCLIError.wrap(thrown, 'An error occurred while handling request')\n this.logger.error(err.message)\n tunnel.send({\n requestId: req.id,\n status: 500,\n body: err.message,\n })\n })\n })\n })\n\n supervisor.events.on('manuallyClosed', () => {\n this.logger.debug('Tunnel manually closed')\n })\n\n await supervisor.start()\n\n await this._runBuild()\n await this._deploy(api, httpTunnelUrl)\n worker = await this._spawnWorker(env, port)\n\n try {\n const watcher = await utils.filewatcher.FileWatcher.watch(\n this.argv.workDir,\n async (events) => {\n if (!worker) {\n this.logger.debug('Worker not ready yet, ignoring file change event')\n return\n }\n\n const typescriptEvents = events\n .filter((e) => !e.path.startsWith(this.projectPaths.abs.outDir))\n .filter((e) => pathlib.extname(e.path) === '.ts')\n\n const distEvents = events.filter((e) => e.path.startsWith(this.projectPaths.abs.distDir))\n\n if (typescriptEvents.length > 0) {\n this.logger.log('Changes detected, rebuilding')\n await this._restart(api, worker, httpTunnelUrl)\n } else if (distEvents.length > 0) {\n this.logger.log('Changes detected in output directory, reloading worker')\n await worker.reload()\n }\n },\n {\n debounceMs: FILEWATCHER_DEBOUNCE_MS,\n }\n )\n\n await Promise.race([worker.wait(), watcher.wait(), supervisor.wait()])\n\n if (worker.running) {\n await worker.kill()\n }\n await watcher.close()\n supervisor.close()\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, 'An error occurred while running the dev server')\n } finally {\n if (worker.running) {\n await worker.kill()\n }\n }\n }\n\n private _restart = async (api: apiUtils.ApiClient, worker: Worker, tunnelUrl: string) => {\n try {\n await this._runBuild()\n } catch (thrown) {\n const error = errors.BotpressCLIError.wrap(thrown, 'Build failed')\n this.logger.error(error.message)\n return\n }\n\n await this._deploy(api, tunnelUrl)\n await worker.reload()\n }\n\n private _deploy = async (api: apiUtils.ApiClient, tunnelUrl: string) => {\n const { projectType, resolveProjectDefinition } = this.readProjectDefinitionFromFS()\n\n if (projectType === 'interface') {\n throw new errors.BotpressCLIError('This feature is not available for interfaces.')\n }\n if (projectType === 'integration') {\n const projectDef = await resolveProjectDefinition()\n this._checkSecrets(projectDef.definition)\n return await this._deployDevIntegration(api, tunnelUrl, projectDef.definition)\n }\n if (projectType === 'bot') {\n const projectDef = await resolveProjectDefinition()\n return await this._deployDevBot(api, tunnelUrl, projectDef.definition)\n }\n throw new errors.UnsupportedProjectType()\n }\n\n private _checkSecrets(integrationDef: sdk.IntegrationDefinition) {\n if (this._initialDef?.type !== 'integration') {\n return\n }\n const initialSecrets = this._initialDef?.definition.secrets ?? {}\n const currentSecrets = integrationDef.secrets ?? {}\n const newSecrets = Object.keys(currentSecrets).filter((s) => !initialSecrets[s])\n if (newSecrets.length > 0) {\n throw new errors.BotpressCLIError('Secrets were added while the server was running. A restart is required.')\n }\n }\n\n private _spawnWorker = async (env: Record<string, string>, port: number) => {\n const outfile = this.projectPaths.abs.outFileCJS\n const importPath = utils.path.toUnix(outfile)\n const code = `require('${importPath}').default.start(${port})`\n const worker = await Worker.spawn(\n {\n type: 'code',\n code,\n env,\n },\n this.logger\n ).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not start dev worker')\n })\n\n return worker\n }\n\n private _runBuild() {\n return new BuildCommand(this.api, this.prompt, this.logger, this.argv)\n .setProjectContext(this.projectContext)\n .run(this._buildContext)\n }\n\n private async _deployDevIntegration(\n api: apiUtils.ApiClient,\n externalUrl: string,\n integrationDef: sdk.IntegrationDefinition\n ): Promise<void> {\n const devId = await this.projectCache.get('devId')\n\n let integration: client.Integration | undefined = undefined\n\n if (devId) {\n const resp = await api.client.getIntegration({ id: devId }).catch(async (thrown) => {\n const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev integration with id \"${devId}\"`)\n this.logger.warn(err.message)\n return { integration: undefined }\n })\n\n if (resp.integration?.dev) {\n integration = resp.integration\n } else {\n await this.projectCache.rm('devId')\n }\n }\n\n const line = this.logger.line()\n line.started(`Deploying dev integration ${chalk.bold(integrationDef.name)}...`)\n\n const createIntegrationBody = {\n ...(await this.prepareCreateIntegrationBody(integrationDef)),\n ...(await this.prepareIntegrationDependencies(integrationDef, api)),\n url: externalUrl,\n }\n\n if (integration) {\n const updateIntegrationBody = apiUtils.prepareUpdateIntegrationBody(\n { ...createIntegrationBody, id: integration.id },\n integration\n )\n\n const resp = await api.client.updateIntegration(updateIntegrationBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update dev integration \"${integrationDef.name}\"`)\n })\n integration = resp.integration\n } else {\n const resp = await api.client.createIntegration({ ...createIntegrationBody, dev: true }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not deploy dev integration \"${integrationDef.name}\"`)\n })\n integration = resp.integration\n }\n\n line.success(`Dev Integration deployed with id \"${integration.id}\" at \"${externalUrl}\"`)\n line.commit()\n\n await this.projectCache.set('devId', integration.id)\n }\n\n private async _deployDevBot(api: apiUtils.ApiClient, externalUrl: string, botDef: sdk.BotDefinition): Promise<void> {\n const devId = await this.projectCache.get('devId')\n\n let bot: client.Bot | undefined = undefined\n\n if (devId) {\n const resp = await api.client.getBot({ id: devId }).catch(async (thrown) => {\n const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev bot with id \"${devId}\"`)\n this.logger.warn(err.message)\n return { bot: undefined }\n })\n\n if (resp.bot?.dev) {\n bot = resp.bot\n } else {\n await this.projectCache.rm('devId')\n }\n }\n\n if (!bot) {\n const createLine = this.logger.line()\n createLine.started('Creating dev bot...')\n const resp = await api.client\n .createBot({\n dev: true,\n url: externalUrl,\n })\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not deploy dev bot')\n })\n\n bot = resp.bot\n createLine.log('Dev Bot created')\n createLine.commit()\n await this.projectCache.set('devId', bot.id)\n }\n\n const updateBotBody = apiUtils.prepareUpdateBotBody(\n {\n ...(await apiUtils.prepareCreateBotBody(botDef)),\n ...(await this.prepareBotDependencies(botDef, api)),\n id: bot.id,\n url: externalUrl,\n },\n bot\n )\n\n if (!(await this._didDefinitionChange(updateBotBody))) {\n this.logger.log('Skipping deployment step. No changes found in bot.definition.ts')\n return\n }\n const updateLine = this.logger.line()\n updateLine.started('Deploying dev bot...')\n\n const { bot: updatedBot } = await api.client.updateBot(updateBotBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not deploy dev bot')\n })\n\n this.validateIntegrationRegistration(updatedBot, (failedIntegrations) => {\n throw new errors.BotpressCLIError(\n `Some integrations failed to register:\\n${Object.entries(failedIntegrations)\n .map(([key, int]) => `\u2022 ${key}: ${int.statusReason}`)\n .join('\\n')}`\n )\n })\n\n updateLine.success(`Dev Bot deployed with id \"${updatedBot.id}\" at \"${externalUrl}\"`)\n updateLine.commit()\n\n const tablesPublisher = new tables.TablesPublisher({ api, logger: this.logger, prompt: this.prompt })\n await tablesPublisher.deployTables({ botId: updatedBot.id, botDefinition: botDef })\n\n await this.displayIntegrationUrls({ api, bot: updatedBot })\n }\n\n private async _didDefinitionChange(body: apiUtils.UpdateBotRequestBody | apiUtils.UpdateIntegrationRequestBody) {\n const didChange = !isEqual(body, this._cacheDevRequestBody)\n this._cacheDevRequestBody = { ...body }\n return didChange\n }\n\n private _forwardTunnelRequest = async (baseUrl: string, request: TunnelRequest): Promise<TunnelResponse> => {\n const axiosConfig = {\n method: request.method,\n url: this._formatLocalUrl(baseUrl, request),\n headers: request.headers,\n data: request.body,\n responseType: 'text',\n validateStatus: () => true,\n } satisfies AxiosRequestConfig\n\n this.logger.debug(`Forwarding request to ${axiosConfig.url}`)\n const response = await axios(axiosConfig)\n this.logger.debug('Sending back response up the tunnel')\n\n return {\n requestId: request.id,\n status: response.status,\n headers: this._getHeaders(response.headers),\n body: response.data,\n }\n }\n\n private _formatLocalUrl = (baseUrl: string, req: TunnelRequest): string => {\n if (req.query) {\n return `${baseUrl}${req.path}?${req.query}`\n }\n return `${baseUrl}${req.path}`\n }\n\n private _getHeaders = (res: AxiosResponse['headers']): TunnelResponse['headers'] => {\n const headers: TunnelResponse['headers'] = {}\n for (const key in res) {\n if (typeof res[key] === 'string' || typeof res[key] === 'number') {\n headers[key] = String(res[key])\n }\n }\n return headers\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAyD;AACzD,mBAAkB;AAClB,oBAAwB;AACxB,cAAyB;AACzB,WAAsB;AACtB,eAA0B;AAE1B,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,oBAAuB;AACvB,2BAA6B;AAC7B,6BAAkD;AAElD,MAAM,mBAAmB;AACzB,MAAM,2BAA2B;AACjC,MAAM,wBAAwB;AAC9B,MAAM,0BAA0B;AAGzB,MAAM,mBAAmB,sCAAqC;AAAA,EAC3D,cAA6C;AAAA,EAC7C;AAAA,EACA;AAAA,EAED,eAAe,MAA0E;AAC9F,UAAM,GAAG,IAAI;AACb,SAAK,gBAAgB,IAAI,MAAM,QAAQ,iBAAiB;AAAA,EAC1D;AAAA,EAEA,MAAa,MAAqB;AAChC,SAAK,OAAO,KAAK,8EAA8E;AAE/F,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAE3D,UAAM,EAAE,aAAa,yBAAyB,IAAI,KAAK,4BAA4B;AACnF,QAAI,gBAAgB,aAAa;AAC/B,YAAM,IAAI,OAAO,iBAAiB,+CAA+C;AAAA,IACnF;AACA,UAAM,aAAa,MAAM,yBAAyB;AAClD,SAAK,cAAc;AAEnB,QAAI,MAA8B;AAAA,MAChC,GAAG,QAAQ;AAAA,MACX,YAAY,IAAI;AAAA,MAChB,UAAU,IAAI;AAAA,IAChB;AAEA,QAAI,cAAc;AAClB,QAAI,KAAK,YA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;AAAA,MAChB,KAAK,KAAK,gBAAgB,SAAS,OAAO;AAAA,MAC1C,SAAS,QAAQ;AAAA,MACjB,MAAM,QAAQ;AAAA,MACd,cAAc;AAAA,MACd,gBAAgB,MAAM;AAAA,IACxB;AAEA,SAAK,OAAO,MAAM,yBAAyB,YAAY,GAAG,EAAE;AAC5D,UAAM,WAAW,UAAM,aAAAC,SAAM,WAAW;AACxC,SAAK,OAAO,MAAM,qCAAqC;AAEvD,WAAO;AAAA,MACL,WAAW,QAAQ;AAAA,MACnB,QAAQ,SAAS;AAAA,MACjB,SAAS,KAAK,YAAY,SAAS,OAAO;AAAA,MAC1C,MAAM,SAAS;AAAA,IACjB;AAAA,EACF;AAAA,EAEQ,kBAAkB,CAAC,SAAiB,QAA+B;AACzE,QAAI,IAAI,OAAO;AACb,aAAO,GAAG,OAAO,GAAG,IAAI,IAAI,IAAI,IAAI,KAAK;AAAA,IAC3C;AACA,WAAO,GAAG,OAAO,GAAG,IAAI,IAAI;AAAA,EAC9B;AAAA,EAEQ,cAAc,CAAC,QAA6D;AAClF,UAAM,UAAqC,CAAC;AAC5C,eAAW,OAAO,KAAK;AACrB,UAAI,OAAO,IAAI,GAAG,MAAM,YAAY,OAAO,IAAI,GAAG,MAAM,UAAU;AAChE,gBAAQ,GAAG,IAAI,OAAO,IAAI,GAAG,CAAC;AAAA,MAChC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;",
6
6
  "names": ["chalk", "axios"]
7
7
  }
@@ -84,7 +84,17 @@ export declare abstract class ProjectCommand<C extends ProjectCommandDefinition>
84
84
  private _readBotDefinitionFromFS;
85
85
  private _readPluginDefinitionFromFS;
86
86
  private _isBpLintDisabled;
87
- protected displayWebhookUrls(bot: client.Bot): void;
87
+ protected displayIntegrationUrls({ api, bot }: {
88
+ api: apiUtils.ApiClient;
89
+ bot: client.Bot;
90
+ }): Promise<void>;
91
+ private _getLinkTemplateScript;
92
+ private _displayWebhookUrl;
93
+ private _displayAuthorizationLink;
94
+ private _getLinkTemplateArgs;
95
+ private _getAuthorizationLink;
96
+ private _getSandboxLink;
97
+ private _displaySandboxLinkAndCode;
88
98
  protected promptSecrets(integrationDef: sdk.IntegrationDefinition, argv: YargsConfig<typeof config.schemas.secrets>, opts?: {
89
99
  formatEnv?: boolean;
90
100
  knownSecrets?: string[];