@botpress/cli 0.4.3 → 0.4.4

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.
Files changed (27) hide show
  1. package/dist/api/client.js.map +2 -2
  2. package/dist/code-generation/index.js +12 -4
  3. package/dist/code-generation/index.js.map +2 -2
  4. package/dist/code-generation/integration-implementation.js +1 -38
  5. package/dist/code-generation/integration-implementation.js.map +2 -2
  6. package/dist/code-generation/integration-instance.js +2 -1
  7. package/dist/code-generation/integration-instance.js.map +2 -2
  8. package/dist/code-generation/map-integration.js +72 -0
  9. package/dist/code-generation/map-integration.js.map +7 -0
  10. package/dist/code-generation/typings.js.map +1 -1
  11. package/dist/command-implementations/add-command.js +27 -5
  12. package/dist/command-implementations/add-command.js.map +2 -2
  13. package/dist/command-implementations/deploy-command.js +3 -2
  14. package/dist/command-implementations/deploy-command.js.map +2 -2
  15. package/dist/command-implementations/dev-command.js +3 -2
  16. package/dist/command-implementations/dev-command.js.map +2 -2
  17. package/dist/command-implementations/integration-commands.js +6 -0
  18. package/dist/command-implementations/integration-commands.js.map +2 -2
  19. package/dist/command-implementations/project-command.js +35 -6
  20. package/dist/command-implementations/project-command.js.map +3 -3
  21. package/dist/integration-ref.js +10 -0
  22. package/dist/integration-ref.js.map +2 -2
  23. package/dist/integration-ref.test.js +76 -0
  24. package/dist/integration-ref.test.js.map +7 -0
  25. package/package.json +3 -3
  26. package/templates/echo-bot/package.json +2 -2
  27. package/templates/empty-integration/package.json +2 -2
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/api/client.ts"],
4
- "sourcesContent": ["import * as bpclient from '@botpress/client'\nimport _ from 'lodash'\nimport { formatIntegrationRef, IntegrationRef } from '../integration-ref'\nimport type { Logger } from '../logger'\nimport * as paging from './paging'\n\nexport type PageLister<R extends object> = (t: { nextToken?: string }) => Promise<R & { meta: { nextToken?: string } }>\n\nexport type ApiClientProps = {\n apiUrl: string\n token: string\n workspaceId: string\n}\n\nexport type ApiClientFactory = {\n newClient: (props: ApiClientProps, logger: Logger) => ApiClient\n}\n\ntype PublicIntegration = bpclient.Integration\ntype PrivateIntegration = bpclient.Integration & { workspaceId: string }\ntype Integration = bpclient.Integration & { workspaceId?: string }\n\n/**\n * This class is used to wrap the Botpress API and provide a more convenient way to interact with it.\n */\nexport class ApiClient {\n public readonly client: bpclient.Client\n public readonly url: string\n public readonly token: string\n public readonly workspaceId: string\n\n public static newClient = (props: ApiClientProps, logger: Logger) => new ApiClient(props, logger)\n\n public constructor(props: ApiClientProps, private _logger: Logger) {\n const { apiUrl, token, workspaceId } = props\n this.client = new bpclient.Client({ apiUrl, token, workspaceId })\n this.url = apiUrl\n this.token = token\n this.workspaceId = workspaceId\n }\n\n public async findIntegration(ref: IntegrationRef): Promise<Integration | undefined> {\n const formatted = formatIntegrationRef(ref)\n\n const privateIntegration = await this.findPrivateIntegration(ref)\n if (privateIntegration) {\n this._logger.debug(`Found integration \"${formatted}\" in workspace`)\n return privateIntegration\n }\n\n const publicIntegration = await this.findPublicIntegration(ref)\n if (publicIntegration) {\n this._logger.debug(`Found integration \"${formatted}\" in hub`)\n return publicIntegration\n }\n\n return\n }\n\n public async findPrivateIntegration(ref: IntegrationRef): Promise<PrivateIntegration | undefined> {\n const { workspaceId } = this\n if (ref.type === 'id') {\n return this.validateStatus(\n () => this.client.getIntegration(ref).then((r) => ({ ...r.integration, workspaceId })),\n 404\n )\n }\n return this.validateStatus(\n () => this.client.getIntegrationByName(ref).then((r) => ({ ...r.integration, workspaceId })),\n 404\n )\n }\n\n public async findPublicIntegration(ref: IntegrationRef): Promise<PublicIntegration | undefined> {\n if (ref.type === 'id') {\n return this.validateStatus(() => this.client.getPublicIntegrationById(ref).then((r) => r.integration), 404)\n }\n return this.validateStatus(() => this.client.getPublicIntegration(ref).then((r) => r.integration), 404)\n }\n\n public async testLogin(): Promise<void> {\n await this.client.listBots({})\n }\n\n public listAllPages = paging.listAllPages\n\n public async validateStatus<V>(fn: () => Promise<V>, allowedStatuses: number | number[]): Promise<V | undefined> {\n try {\n const v = await fn()\n return v\n } catch (err) {\n const allowedStatusesArray = _.isArray(allowedStatuses) ? allowedStatuses : [allowedStatuses]\n const isAllowed = bpclient.isApiError(err) && err.code && allowedStatusesArray.includes(err.code)\n if (isAllowed) {\n return\n }\n throw err\n }\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAA0B;AAC1B,oBAAc;AACd,6BAAqD;AAErD,aAAwB;AAqBjB,MAAM,UAAU;AAAA,EAQd,YAAY,OAA+B,SAAiB;AAAjB;AAChD,UAAM,EAAE,QAAQ,OAAO,YAAY,IAAI;AACvC,SAAK,SAAS,IAAI,SAAS,OAAO,EAAE,QAAQ,OAAO,YAAY,CAAC;AAChE,SAAK,MAAM;AACX,SAAK,QAAQ;AACb,SAAK,cAAc;AAAA,EACrB;AAAA,EAbgB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,OAAc,YAAY,CAAC,OAAuB,WAAmB,IAAI,UAAU,OAAO,MAAM;AAAA,EAUhG,MAAa,gBAAgB,KAAuD;AAClF,UAAM,gBAAY,6CAAqB,GAAG;AAE1C,UAAM,qBAAqB,MAAM,KAAK,uBAAuB,GAAG;AAChE,QAAI,oBAAoB;AACtB,WAAK,QAAQ,MAAM,sBAAsB,yBAAyB;AAClE,aAAO;AAAA,IACT;AAEA,UAAM,oBAAoB,MAAM,KAAK,sBAAsB,GAAG;AAC9D,QAAI,mBAAmB;AACrB,WAAK,QAAQ,MAAM,sBAAsB,mBAAmB;AAC5D,aAAO;AAAA,IACT;AAEA;AAAA,EACF;AAAA,EAEA,MAAa,uBAAuB,KAA8D;AAChG,UAAM,EAAE,YAAY,IAAI;AACxB,QAAI,IAAI,SAAS,MAAM;AACrB,aAAO,KAAK;AAAA,QACV,MAAM,KAAK,OAAO,eAAe,GAAG,EAAE,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,aAAa,YAAY,EAAE;AAAA,QACrF;AAAA,MACF;AAAA,IACF;AACA,WAAO,KAAK;AAAA,MACV,MAAM,KAAK,OAAO,qBAAqB,GAAG,EAAE,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,aAAa,YAAY,EAAE;AAAA,MAC3F;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAa,sBAAsB,KAA6D;AAC9F,QAAI,IAAI,SAAS,MAAM;AACrB,aAAO,KAAK,eAAe,MAAM,KAAK,OAAO,yBAAyB,GAAG,EAAE,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,GAAG;AAAA,IAC5G;AACA,WAAO,KAAK,eAAe,MAAM,KAAK,OAAO,qBAAqB,GAAG,EAAE,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,GAAG;AAAA,EACxG;AAAA,EAEA,MAAa,YAA2B;AACtC,UAAM,KAAK,OAAO,SAAS,CAAC,CAAC;AAAA,EAC/B;AAAA,EAEO,eAAe,OAAO;AAAA,EAE7B,MAAa,eAAkB,IAAsB,iBAA4D;AAC/G,QAAI;AACF,YAAM,IAAI,MAAM,GAAG;AACnB,aAAO;AAAA,IACT,SAAS,KAAP;AACA,YAAM,uBAAuB,cAAAA,QAAE,QAAQ,eAAe,IAAI,kBAAkB,CAAC,eAAe;AAC5F,YAAM,YAAY,SAAS,WAAW,GAAG,KAAK,IAAI,QAAQ,qBAAqB,SAAS,IAAI,IAAI;AAChG,UAAI,WAAW;AACb;AAAA,MACF;AACA,YAAM;AAAA,IACR;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import * as bpclient from '@botpress/client'\nimport _ from 'lodash'\nimport { formatIntegrationRef, ApiIntegrationRef as IntegrationRef } from '../integration-ref'\nimport type { Logger } from '../logger'\nimport * as paging from './paging'\n\nexport type PageLister<R extends object> = (t: { nextToken?: string }) => Promise<R & { meta: { nextToken?: string } }>\n\nexport type ApiClientProps = {\n apiUrl: string\n token: string\n workspaceId: string\n}\n\nexport type ApiClientFactory = {\n newClient: (props: ApiClientProps, logger: Logger) => ApiClient\n}\n\ntype PublicIntegration = bpclient.Integration\ntype PrivateIntegration = bpclient.Integration & { workspaceId: string }\ntype Integration = bpclient.Integration & { workspaceId?: string }\n\n/**\n * This class is used to wrap the Botpress API and provide a more convenient way to interact with it.\n */\nexport class ApiClient {\n public readonly client: bpclient.Client\n public readonly url: string\n public readonly token: string\n public readonly workspaceId: string\n\n public static newClient = (props: ApiClientProps, logger: Logger) => new ApiClient(props, logger)\n\n public constructor(props: ApiClientProps, private _logger: Logger) {\n const { apiUrl, token, workspaceId } = props\n this.client = new bpclient.Client({ apiUrl, token, workspaceId })\n this.url = apiUrl\n this.token = token\n this.workspaceId = workspaceId\n }\n\n public async findIntegration(ref: IntegrationRef): Promise<Integration | undefined> {\n const formatted = formatIntegrationRef(ref)\n\n const privateIntegration = await this.findPrivateIntegration(ref)\n if (privateIntegration) {\n this._logger.debug(`Found integration \"${formatted}\" in workspace`)\n return privateIntegration\n }\n\n const publicIntegration = await this.findPublicIntegration(ref)\n if (publicIntegration) {\n this._logger.debug(`Found integration \"${formatted}\" in hub`)\n return publicIntegration\n }\n\n return\n }\n\n public async findPrivateIntegration(ref: IntegrationRef): Promise<PrivateIntegration | undefined> {\n const { workspaceId } = this\n if (ref.type === 'id') {\n return this.validateStatus(\n () => this.client.getIntegration(ref).then((r) => ({ ...r.integration, workspaceId })),\n 404\n )\n }\n return this.validateStatus(\n () => this.client.getIntegrationByName(ref).then((r) => ({ ...r.integration, workspaceId })),\n 404\n )\n }\n\n public async findPublicIntegration(ref: IntegrationRef): Promise<PublicIntegration | undefined> {\n if (ref.type === 'id') {\n return this.validateStatus(() => this.client.getPublicIntegrationById(ref).then((r) => r.integration), 404)\n }\n return this.validateStatus(() => this.client.getPublicIntegration(ref).then((r) => r.integration), 404)\n }\n\n public async testLogin(): Promise<void> {\n await this.client.listBots({})\n }\n\n public listAllPages = paging.listAllPages\n\n public async validateStatus<V>(fn: () => Promise<V>, allowedStatuses: number | number[]): Promise<V | undefined> {\n try {\n const v = await fn()\n return v\n } catch (err) {\n const allowedStatusesArray = _.isArray(allowedStatuses) ? allowedStatuses : [allowedStatuses]\n const isAllowed = bpclient.isApiError(err) && err.code && allowedStatusesArray.includes(err.code)\n if (isAllowed) {\n return\n }\n throw err\n }\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAA0B;AAC1B,oBAAc;AACd,6BAA0E;AAE1E,aAAwB;AAqBjB,MAAM,UAAU;AAAA,EAQd,YAAY,OAA+B,SAAiB;AAAjB;AAChD,UAAM,EAAE,QAAQ,OAAO,YAAY,IAAI;AACvC,SAAK,SAAS,IAAI,SAAS,OAAO,EAAE,QAAQ,OAAO,YAAY,CAAC;AAChE,SAAK,MAAM;AACX,SAAK,QAAQ;AACb,SAAK,cAAc;AAAA,EACrB;AAAA,EAbgB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,OAAc,YAAY,CAAC,OAAuB,WAAmB,IAAI,UAAU,OAAO,MAAM;AAAA,EAUhG,MAAa,gBAAgB,KAAuD;AAClF,UAAM,gBAAY,6CAAqB,GAAG;AAE1C,UAAM,qBAAqB,MAAM,KAAK,uBAAuB,GAAG;AAChE,QAAI,oBAAoB;AACtB,WAAK,QAAQ,MAAM,sBAAsB,yBAAyB;AAClE,aAAO;AAAA,IACT;AAEA,UAAM,oBAAoB,MAAM,KAAK,sBAAsB,GAAG;AAC9D,QAAI,mBAAmB;AACrB,WAAK,QAAQ,MAAM,sBAAsB,mBAAmB;AAC5D,aAAO;AAAA,IACT;AAEA;AAAA,EACF;AAAA,EAEA,MAAa,uBAAuB,KAA8D;AAChG,UAAM,EAAE,YAAY,IAAI;AACxB,QAAI,IAAI,SAAS,MAAM;AACrB,aAAO,KAAK;AAAA,QACV,MAAM,KAAK,OAAO,eAAe,GAAG,EAAE,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,aAAa,YAAY,EAAE;AAAA,QACrF;AAAA,MACF;AAAA,IACF;AACA,WAAO,KAAK;AAAA,MACV,MAAM,KAAK,OAAO,qBAAqB,GAAG,EAAE,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,aAAa,YAAY,EAAE;AAAA,MAC3F;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAa,sBAAsB,KAA6D;AAC9F,QAAI,IAAI,SAAS,MAAM;AACrB,aAAO,KAAK,eAAe,MAAM,KAAK,OAAO,yBAAyB,GAAG,EAAE,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,GAAG;AAAA,IAC5G;AACA,WAAO,KAAK,eAAe,MAAM,KAAK,OAAO,qBAAqB,GAAG,EAAE,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,GAAG;AAAA,EACxG;AAAA,EAEA,MAAa,YAA2B;AACtC,UAAM,KAAK,OAAO,SAAS,CAAC,CAAC;AAAA,EAC/B;AAAA,EAEO,eAAe,OAAO;AAAA,EAE7B,MAAa,eAAkB,IAAsB,iBAA4D;AAC/G,QAAI;AACF,YAAM,IAAI,MAAM,GAAG;AACnB,aAAO;AAAA,IACT,SAAS,KAAP;AACA,YAAM,uBAAuB,cAAAA,QAAE,QAAQ,eAAe,IAAI,kBAAkB,CAAC,eAAe;AAC5F,YAAM,YAAY,SAAS,WAAW,GAAG,KAAK,IAAI,QAAQ,qBAAqB,SAAS,IAAI,IAAI;AAChG,UAAI,WAAW;AACb;AAAA,MACF;AACA,YAAM;AAAA,IACR;AAAA,EACF;AACF;",
6
6
  "names": ["_"]
7
7
  }
@@ -40,16 +40,18 @@ var import_const = require("./const");
40
40
  var import_integration_implementation = require("./integration-implementation");
41
41
  var import_integration_instance = require("./integration-instance");
42
42
  var import_integration_secret = require("./integration-secret");
43
+ var mapIntegration = __toESM(require("./map-integration"));
43
44
  var import_typings = require("./typings");
44
45
  var import_integration_secret2 = require("./integration-secret");
45
46
  const INTEGRATION_JSON = "integration.json";
46
- const generateIntegrationImplementationTypings = async (integration, implementationTypingsPath) => {
47
+ const generateIntegrationImplementationTypings = async (sdkIntegration, implementationTypingsPath) => {
48
+ const integration = mapIntegration.from.sdk(sdkIntegration);
47
49
  const indexModule = await import_integration_implementation.IntegrationImplementationIndexModule.create(integration);
48
50
  indexModule.unshift(implementationTypingsPath);
49
51
  return indexModule.flatten();
50
52
  };
51
- const generateIntegrationSecrets = async (integration, secretsPath) => {
52
- const indexModule = await import_integration_secret.IntegrationSecretIndexModule.create(integration);
53
+ const generateIntegrationSecrets = async (sdkIntegration, secretsPath) => {
54
+ const indexModule = await import_integration_secret.IntegrationSecretIndexModule.create(sdkIntegration);
53
55
  indexModule.unshift(secretsPath);
54
56
  return indexModule.flatten();
55
57
  };
@@ -64,7 +66,13 @@ const generateIntegrationIndex = async (implementationTypingsPath, implementatio
64
66
  content
65
67
  };
66
68
  };
67
- const generateIntegrationInstance = async (integration, installPath) => {
69
+ const generateIntegrationInstance = async (anyIntegration, installPath) => {
70
+ let integration;
71
+ if ("id" in anyIntegration) {
72
+ integration = mapIntegration.from.client(anyIntegration);
73
+ } else {
74
+ integration = mapIntegration.from.sdk(anyIntegration);
75
+ }
68
76
  const indexModule = await import_integration_instance.IntegrationInstanceIndexModule.create(integration);
69
77
  const dirname = utils.casing.to.kebabCase(integration.name);
70
78
  indexModule.unshift(installPath, dirname);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/code-generation/index.ts"],
4
- "sourcesContent": ["import type * as client from '@botpress/client'\nimport type { IntegrationDefinition } from '@botpress/sdk'\nimport pathlib from 'path'\nimport * as utils from '../utils'\nimport { GENERATED_HEADER, INDEX_FILE } from './const'\nimport { IntegrationImplementationIndexModule } from './integration-implementation'\nimport { IntegrationInstanceIndexModule } from './integration-instance'\nimport { IntegrationSecretIndexModule } from './integration-secret'\nimport type * as types from './typings'\n\nexport { File } from './typings'\nexport { secretEnvVariableName } from './integration-secret'\nexport const INTEGRATION_JSON = 'integration.json'\n\nexport const generateIntegrationImplementationTypings = async (\n integration: IntegrationDefinition,\n implementationTypingsPath: string\n): Promise<types.File[]> => {\n const indexModule = await IntegrationImplementationIndexModule.create(integration)\n indexModule.unshift(implementationTypingsPath)\n return indexModule.flatten()\n}\n\nexport const generateIntegrationSecrets = async (\n integration: IntegrationDefinition,\n secretsPath: string\n): Promise<types.File[]> => {\n const indexModule = await IntegrationSecretIndexModule.create(integration)\n indexModule.unshift(secretsPath)\n return indexModule.flatten()\n}\n\nexport const generateIntegrationIndex = async (\n implementationTypingsPath: string,\n implementationSecretsPath: string\n): Promise<types.File> => {\n let content = ''\n content += `export * from './${implementationTypingsPath}'\\n`\n content += `export * from './${implementationSecretsPath}'\\n`\n return {\n path: INDEX_FILE,\n content,\n }\n}\n\nexport type IntegrationInstanceJson = {\n name: string\n version: string\n id: string\n}\n\nexport const generateIntegrationInstance = async (\n integration: client.Integration,\n installPath: string\n): Promise<types.File[]> => {\n const indexModule = await IntegrationInstanceIndexModule.create(integration)\n const dirname = utils.casing.to.kebabCase(integration.name)\n indexModule.unshift(installPath, dirname)\n const files = indexModule.flatten()\n\n const { name, version, id } = integration\n const json: IntegrationInstanceJson = {\n name,\n version,\n id,\n }\n files.push({\n path: pathlib.join(installPath, dirname, INTEGRATION_JSON),\n content: JSON.stringify(json, null, 2),\n })\n\n return files\n}\n\nexport const generateBotIndex = async (installPath: string, instances: string[]): Promise<types.File> => {\n const lines: string[] = [\n GENERATED_HEADER,\n \"import * as sdk from '@botpress/sdk'\",\n ...instances.map(\n (instance) => `import * as ${utils.casing.to.camelCase(instance)} from './${installPath}/${instance}'`\n ),\n ...instances.map(\n (instance) => `export * as ${utils.casing.to.camelCase(instance)} from './${installPath}/${instance}'`\n ),\n '',\n 'type TIntegrations = {',\n ...instances.map(\n (instance) =>\n ` ${utils.casing.to.camelCase(instance)}: ${utils.casing.to.camelCase(instance)}.T${utils.casing.to.pascalCase(\n instance\n )}`\n ),\n '}',\n '',\n 'type BaseStates = sdk.Bot extends sdk.Bot<any, infer TStates, any> ? TStates : never',\n 'type BaseEvents = sdk.Bot extends sdk.Bot<any, any, infer TEvents> ? TEvents : never',\n '',\n 'export class Bot<',\n ' TStates extends BaseStates,',\n ' TEvents extends BaseEvents',\n '> extends sdk.Bot<',\n ' TIntegrations,',\n ' TStates,',\n ' TEvents',\n '> {}',\n ]\n\n return {\n path: INDEX_FILE,\n content: lines.join('\\n'),\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,kBAAoB;AACpB,YAAuB;AACvB,mBAA6C;AAC7C,wCAAqD;AACrD,kCAA+C;AAC/C,gCAA6C;AAG7C,qBAAqB;AACrB,IAAAA,6BAAsC;AAC/B,MAAM,mBAAmB;AAEzB,MAAM,2CAA2C,OACtD,aACA,8BAC0B;AAC1B,QAAM,cAAc,MAAM,uEAAqC,OAAO,WAAW;AACjF,cAAY,QAAQ,yBAAyB;AAC7C,SAAO,YAAY,QAAQ;AAC7B;AAEO,MAAM,6BAA6B,OACxC,aACA,gBAC0B;AAC1B,QAAM,cAAc,MAAM,uDAA6B,OAAO,WAAW;AACzE,cAAY,QAAQ,WAAW;AAC/B,SAAO,YAAY,QAAQ;AAC7B;AAEO,MAAM,2BAA2B,OACtC,2BACA,8BACwB;AACxB,MAAI,UAAU;AACd,aAAW,oBAAoB;AAAA;AAC/B,aAAW,oBAAoB;AAAA;AAC/B,SAAO;AAAA,IACL,MAAM;AAAA,IACN;AAAA,EACF;AACF;AAQO,MAAM,8BAA8B,OACzC,aACA,gBAC0B;AAC1B,QAAM,cAAc,MAAM,2DAA+B,OAAO,WAAW;AAC3E,QAAM,UAAU,MAAM,OAAO,GAAG,UAAU,YAAY,IAAI;AAC1D,cAAY,QAAQ,aAAa,OAAO;AACxC,QAAM,QAAQ,YAAY,QAAQ;AAElC,QAAM,EAAE,MAAM,SAAS,GAAG,IAAI;AAC9B,QAAM,OAAgC;AAAA,IACpC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,QAAM,KAAK;AAAA,IACT,MAAM,YAAAC,QAAQ,KAAK,aAAa,SAAS,gBAAgB;AAAA,IACzD,SAAS,KAAK,UAAU,MAAM,MAAM,CAAC;AAAA,EACvC,CAAC;AAED,SAAO;AACT;AAEO,MAAM,mBAAmB,OAAO,aAAqB,cAA6C;AACvG,QAAM,QAAkB;AAAA,IACtB;AAAA,IACA;AAAA,IACA,GAAG,UAAU;AAAA,MACX,CAAC,aAAa,eAAe,MAAM,OAAO,GAAG,UAAU,QAAQ,aAAa,eAAe;AAAA,IAC7F;AAAA,IACA,GAAG,UAAU;AAAA,MACX,CAAC,aAAa,eAAe,MAAM,OAAO,GAAG,UAAU,QAAQ,aAAa,eAAe;AAAA,IAC7F;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG,UAAU;AAAA,MACX,CAAC,aACC,KAAK,MAAM,OAAO,GAAG,UAAU,QAAQ,MAAM,MAAM,OAAO,GAAG,UAAU,QAAQ,MAAM,MAAM,OAAO,GAAG;AAAA,QACnG;AAAA,MACF;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS,MAAM,KAAK,IAAI;AAAA,EAC1B;AACF;",
4
+ "sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport type * as bpsdk from '@botpress/sdk'\nimport pathlib from 'path'\nimport * as utils from '../utils'\nimport { GENERATED_HEADER, INDEX_FILE } from './const'\nimport { IntegrationImplementationIndexModule } from './integration-implementation'\nimport { IntegrationInstanceIndexModule } from './integration-instance'\nimport { IntegrationSecretIndexModule } from './integration-secret'\nimport * as mapIntegration from './map-integration'\nimport type * as types from './typings'\n\nexport { File } from './typings'\nexport { secretEnvVariableName } from './integration-secret'\nexport const INTEGRATION_JSON = 'integration.json'\n\nexport const generateIntegrationImplementationTypings = async (\n sdkIntegration: bpsdk.IntegrationDefinition,\n implementationTypingsPath: string\n): Promise<types.File[]> => {\n const integration = mapIntegration.from.sdk(sdkIntegration)\n const indexModule = await IntegrationImplementationIndexModule.create(integration)\n indexModule.unshift(implementationTypingsPath)\n return indexModule.flatten()\n}\n\nexport const generateIntegrationSecrets = async (\n sdkIntegration: bpsdk.IntegrationDefinition,\n secretsPath: string\n): Promise<types.File[]> => {\n const indexModule = await IntegrationSecretIndexModule.create(sdkIntegration)\n indexModule.unshift(secretsPath)\n return indexModule.flatten()\n}\n\nexport const generateIntegrationIndex = async (\n implementationTypingsPath: string,\n implementationSecretsPath: string\n): Promise<types.File> => {\n let content = ''\n content += `export * from './${implementationTypingsPath}'\\n`\n content += `export * from './${implementationSecretsPath}'\\n`\n return {\n path: INDEX_FILE,\n content,\n }\n}\n\nexport type IntegrationInstanceJson = {\n name: string\n version: string\n id: string | null\n}\n\nexport const generateIntegrationInstance = async (\n anyIntegration: bpclient.Integration | bpsdk.IntegrationDefinition,\n installPath: string\n): Promise<types.File[]> => {\n let integration: types.IntegrationDefinition\n if ('id' in anyIntegration) {\n integration = mapIntegration.from.client(anyIntegration)\n } else {\n integration = mapIntegration.from.sdk(anyIntegration)\n }\n\n const indexModule = await IntegrationInstanceIndexModule.create(integration)\n const dirname = utils.casing.to.kebabCase(integration.name)\n indexModule.unshift(installPath, dirname)\n const files = indexModule.flatten()\n\n const { name, version, id } = integration\n const json: IntegrationInstanceJson = {\n name,\n version,\n id,\n }\n files.push({\n path: pathlib.join(installPath, dirname, INTEGRATION_JSON),\n content: JSON.stringify(json, null, 2),\n })\n\n return files\n}\n\nexport const generateBotIndex = async (installPath: string, instances: string[]): Promise<types.File> => {\n const lines: string[] = [\n GENERATED_HEADER,\n \"import * as sdk from '@botpress/sdk'\",\n ...instances.map(\n (instance) => `import * as ${utils.casing.to.camelCase(instance)} from './${installPath}/${instance}'`\n ),\n ...instances.map(\n (instance) => `export * as ${utils.casing.to.camelCase(instance)} from './${installPath}/${instance}'`\n ),\n '',\n 'type TIntegrations = {',\n ...instances.map(\n (instance) =>\n ` ${utils.casing.to.camelCase(instance)}: ${utils.casing.to.camelCase(instance)}.T${utils.casing.to.pascalCase(\n instance\n )}`\n ),\n '}',\n '',\n 'type BaseStates = sdk.Bot extends sdk.Bot<any, infer TStates, any> ? TStates : never',\n 'type BaseEvents = sdk.Bot extends sdk.Bot<any, any, infer TEvents> ? TEvents : never',\n '',\n 'export class Bot<',\n ' TStates extends BaseStates,',\n ' TEvents extends BaseEvents',\n '> extends sdk.Bot<',\n ' TIntegrations,',\n ' TStates,',\n ' TEvents',\n '> {}',\n ]\n\n return {\n path: INDEX_FILE,\n content: lines.join('\\n'),\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,kBAAoB;AACpB,YAAuB;AACvB,mBAA6C;AAC7C,wCAAqD;AACrD,kCAA+C;AAC/C,gCAA6C;AAC7C,qBAAgC;AAGhC,qBAAqB;AACrB,IAAAA,6BAAsC;AAC/B,MAAM,mBAAmB;AAEzB,MAAM,2CAA2C,OACtD,gBACA,8BAC0B;AAC1B,QAAM,cAAc,eAAe,KAAK,IAAI,cAAc;AAC1D,QAAM,cAAc,MAAM,uEAAqC,OAAO,WAAW;AACjF,cAAY,QAAQ,yBAAyB;AAC7C,SAAO,YAAY,QAAQ;AAC7B;AAEO,MAAM,6BAA6B,OACxC,gBACA,gBAC0B;AAC1B,QAAM,cAAc,MAAM,uDAA6B,OAAO,cAAc;AAC5E,cAAY,QAAQ,WAAW;AAC/B,SAAO,YAAY,QAAQ;AAC7B;AAEO,MAAM,2BAA2B,OACtC,2BACA,8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ACF;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS,MAAM,KAAK,IAAI;AAAA,EAC1B;AACF;",
6
6
  "names": ["import_integration_secret", "pathlib"]
7
7
  }
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,17 +15,12 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
19
  var integration_implementation_exports = {};
26
20
  __export(integration_implementation_exports, {
27
21
  IntegrationImplementationIndexModule: () => IntegrationImplementationIndexModule
28
22
  });
29
23
  module.exports = __toCommonJS(integration_implementation_exports);
30
- var utils = __toESM(require("../utils"));
31
24
  var import_const = require("./const");
32
25
  var import_generators = require("./generators");
33
26
  var import_actions_module = require("./integration-schemas/actions-module");
@@ -46,8 +39,7 @@ class IntegrationImplementationIndexModule extends import_module.Module {
46
39
  this.eventsModule = eventsModule;
47
40
  this.statesModule = statesModule;
48
41
  }
49
- static async create(sdkIntegration) {
50
- const integration = this._mapIntegration(sdkIntegration);
42
+ static async create(integration) {
51
43
  const configModule = await import_configuration_module.ConfigurationModule.create(integration.configuration ?? { schema: {} });
52
44
  configModule.unshift("configuration");
53
45
  const actionsModule = await import_actions_module.ActionsModule.create(integration.actions ?? {});
@@ -120,35 +112,6 @@ class IntegrationImplementationIndexModule extends import_module.Module {
120
112
  ].join("\n");
121
113
  return content;
122
114
  }
123
- static _mapIntegration = (i) => ({
124
- name: i.name,
125
- version: i.version,
126
- user: {
127
- tags: i.user?.tags ?? {},
128
- creation: i.user?.creation ?? { enabled: false, requiredTags: [] }
129
- },
130
- configuration: i.configuration ? this._mapSchema(i.configuration) : { schema: {} },
131
- events: i.events ? utils.records.mapValues(i.events, this._mapSchema) : {},
132
- states: i.states ? utils.records.mapValues(i.states, this._mapSchema) : {},
133
- actions: i.actions ? utils.records.mapValues(i.actions, (a) => ({
134
- input: this._mapSchema(a.input),
135
- output: this._mapSchema(a.output)
136
- })) : {},
137
- channels: i.channels ? utils.records.mapValues(i.channels, (c) => ({
138
- conversation: {
139
- tags: c.conversation?.tags ?? {},
140
- creation: c.conversation?.creation ?? { enabled: false, requiredTags: [] }
141
- },
142
- message: {
143
- tags: c.message?.tags ?? {}
144
- },
145
- messages: utils.records.mapValues(c.messages, this._mapSchema)
146
- })) : {}
147
- });
148
- static _mapSchema = (x) => ({
149
- ...x,
150
- schema: utils.schema.mapZodToJsonSchema(x)
151
- });
152
115
  }
153
116
  // Annotate the CommonJS export names for ESM import in node:
154
117
  0 && (module.exports = {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/code-generation/integration-implementation.ts"],
4
- "sourcesContent": ["import * as bpsdk from '@botpress/sdk'\nimport { z } from 'zod'\nimport * as utils from '../utils'\nimport { GENERATED_HEADER, INDEX_FILE } from './const'\nimport { stringifySingleLine } from './generators'\nimport { ActionsModule } from './integration-schemas/actions-module'\nimport { ChannelsModule } from './integration-schemas/channels-module'\nimport { ConfigurationModule } from './integration-schemas/configuration-module'\nimport { EventsModule } from './integration-schemas/events-module'\nimport { StatesModule } from './integration-schemas/states-module'\nimport { Module, ModuleDef } from './module'\nimport * as types from './typings'\n\nexport class IntegrationImplementationIndexModule extends Module {\n public static async create(\n sdkIntegration: bpsdk.IntegrationDefinition\n ): Promise<IntegrationImplementationIndexModule> {\n const integration = this._mapIntegration(sdkIntegration)\n\n const configModule = await ConfigurationModule.create(integration.configuration ?? { schema: {} })\n configModule.unshift('configuration')\n\n const actionsModule = await ActionsModule.create(integration.actions ?? {})\n actionsModule.unshift('actions')\n\n const channelsModule = await ChannelsModule.create(integration.channels ?? {})\n channelsModule.unshift('channels')\n\n const eventsModule = await EventsModule.create(integration.events ?? {})\n eventsModule.unshift('events')\n\n const statesModule = await StatesModule.create(integration.states ?? {})\n statesModule.unshift('states')\n\n const inst = new IntegrationImplementationIndexModule(\n integration,\n configModule,\n actionsModule,\n channelsModule,\n eventsModule,\n statesModule,\n {\n path: INDEX_FILE,\n exportName: 'Integration',\n content: '',\n }\n )\n\n inst.pushDep(configModule)\n inst.pushDep(actionsModule)\n inst.pushDep(channelsModule)\n inst.pushDep(eventsModule)\n inst.pushDep(statesModule)\n return inst\n }\n\n private constructor(\n private integration: types.IntegrationDefinition,\n private configModule: ConfigurationModule,\n private actionsModule: ActionsModule,\n private channelsModule: ChannelsModule,\n private eventsModule: EventsModule,\n private statesModule: StatesModule,\n def: ModuleDef\n ) {\n super(def)\n }\n\n public override get content(): string {\n let content = GENERATED_HEADER\n\n const { configModule, actionsModule, channelsModule, eventsModule, statesModule, integration } = this\n\n const configImport = configModule.import(this)\n const actionsImport = actionsModule.import(this)\n const channelsImport = channelsModule.import(this)\n const eventsImport = eventsModule.import(this)\n const statesImport = statesModule.import(this)\n\n content += [\n GENERATED_HEADER,\n 'import * as sdk from \"@botpress/sdk\"',\n '',\n `import type * as ${configModule.name} from \"./${configImport}\"`,\n `import type * as ${actionsModule.name} from \"./${actionsImport}\"`,\n `import type * as ${channelsModule.name} from \"./${channelsImport}\"`,\n `import type * as ${eventsModule.name} from \"./${eventsImport}\"`,\n `import type * as ${statesModule.name} from \"./${statesImport}\"`,\n `export * as ${configModule.name} from \"./${configImport}\"`,\n `export * as ${actionsModule.name} from \"./${actionsImport}\"`,\n `export * as ${channelsModule.name} from \"./${channelsImport}\"`,\n `export * as ${eventsModule.name} from \"./${eventsImport}\"`,\n `export * as ${statesModule.name} from \"./${statesImport}\"`,\n '',\n 'type TIntegration = {',\n ` name: \"${integration.name}\"`,\n ` version: \"${integration.version}\"`,\n ` configuration: ${configModule.name}.${configModule.exports}`,\n ` actions: ${actionsModule.name}.${actionsModule.exports}`,\n ` channels: ${channelsModule.name}.${channelsModule.exports}`,\n ` events: ${eventsModule.name}.${eventsModule.exports}`,\n ` states: ${statesModule.name}.${statesModule.exports}`,\n ` user: ${stringifySingleLine(integration.user)}`,\n '}',\n '',\n 'export type IntegrationProps = sdk.IntegrationProps<TIntegration>',\n '',\n 'export class Integration extends sdk.Integration<TIntegration> {}',\n '',\n 'export type Client = sdk.IntegrationSpecificClient<TIntegration>',\n ].join('\\n')\n\n return content\n }\n\n private static _mapIntegration = (i: bpsdk.IntegrationDefinition): types.IntegrationDefinition => ({\n name: i.name,\n version: i.version,\n user: {\n tags: i.user?.tags ?? {},\n creation: i.user?.creation ?? { enabled: false, requiredTags: [] },\n },\n configuration: i.configuration ? this._mapSchema(i.configuration) : { schema: {} },\n events: i.events ? utils.records.mapValues(i.events, this._mapSchema) : {},\n states: i.states ? utils.records.mapValues(i.states, this._mapSchema) : {},\n actions: i.actions\n ? utils.records.mapValues(i.actions, (a) => ({\n input: this._mapSchema(a.input),\n output: this._mapSchema(a.output),\n }))\n : {},\n channels: i.channels\n ? utils.records.mapValues(i.channels, (c) => ({\n conversation: {\n tags: c.conversation?.tags ?? {},\n creation: c.conversation?.creation ?? { enabled: false, requiredTags: [] },\n },\n message: {\n tags: c.message?.tags ?? {},\n },\n messages: utils.records.mapValues(c.messages, this._mapSchema),\n }))\n : {},\n })\n\n private static _mapSchema = <T extends { schema: z.ZodObject<any> }>(\n x: T\n ): utils.types.Merge<T, { schema: ReturnType<typeof utils.schema.mapZodToJsonSchema> }> => ({\n ...x,\n schema: utils.schema.mapZodToJsonSchema(x),\n })\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,YAAuB;AACvB,mBAA6C;AAC7C,wBAAoC;AACpC,4BAA8B;AAC9B,6BAA+B;AAC/B,kCAAoC;AACpC,2BAA6B;AAC7B,2BAA6B;AAC7B,oBAAkC;AAG3B,MAAM,6CAA6C,qBAAO;AAAA,EA2CvD,YACE,aACA,cACA,eACA,gBACA,cACA,cACR,KACA;AACA,UAAM,GAAG;AARD;AACA;AACA;AACA;AACA;AACA;AAAA,EAIV;AAAA,EApDA,aAAoB,OAClB,gBAC+C;AAC/C,UAAM,cAAc,KAAK,gBAAgB,cAAc;AAEvD,UAAM,eAAe,MAAM,gDAAoB,OAAO,YAAY,iBAAiB,EAAE,QAAQ,CAAC,EAAE,CAAC;AACjG,iBAAa,QAAQ,eAAe;AAEpC,UAAM,gBAAgB,MAAM,oCAAc,OAAO,YAAY,WAAW,CAAC,CAAC;AAC1E,kBAAc,QAAQ,SAAS;AAE/B,UAAM,iBAAiB,MAAM,sCAAe,OAAO,YAAY,YAAY,CAAC,CAAC;AAC7E,mBAAe,QAAQ,UAAU;AAEjC,UAAM,eAAe,MAAM,kCAAa,OAAO,YAAY,UAAU,CAAC,CAAC;AACvE,iBAAa,QAAQ,QAAQ;AAE7B,UAAM,eAAe,MAAM,kCAAa,OAAO,YAAY,UAAU,CAAC,CAAC;AACvE,iBAAa,QAAQ,QAAQ;AAE7B,UAAM,OAAO,IAAI;AAAA,MACf;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,YAAY;AAAA,QACZ,SAAS;AAAA,MACX;AAAA,IACF;AAEA,SAAK,QAAQ,YAA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ATED_HEADER, INDEX_FILE } from './const'\nimport { stringifySingleLine } from './generators'\nimport { ActionsModule } from './integration-schemas/actions-module'\nimport { ChannelsModule } from './integration-schemas/channels-module'\nimport { ConfigurationModule } from './integration-schemas/configuration-module'\nimport { EventsModule } from './integration-schemas/events-module'\nimport { StatesModule } from './integration-schemas/states-module'\nimport { Module, ModuleDef } from './module'\nimport * as types from './typings'\n\nexport class IntegrationImplementationIndexModule extends Module {\n public static async create(integration: types.IntegrationDefinition): Promise<IntegrationImplementationIndexModule> {\n const configModule = await ConfigurationModule.create(integration.configuration ?? { schema: {} })\n configModule.unshift('configuration')\n\n const actionsModule = await ActionsModule.create(integration.actions ?? {})\n actionsModule.unshift('actions')\n\n const channelsModule = await ChannelsModule.create(integration.channels ?? {})\n channelsModule.unshift('channels')\n\n const eventsModule = await EventsModule.create(integration.events ?? {})\n eventsModule.unshift('events')\n\n const statesModule = await StatesModule.create(integration.states ?? {})\n statesModule.unshift('states')\n\n const inst = new IntegrationImplementationIndexModule(\n integration,\n configModule,\n actionsModule,\n channelsModule,\n eventsModule,\n statesModule,\n {\n path: INDEX_FILE,\n exportName: 'Integration',\n content: '',\n }\n )\n\n inst.pushDep(configModule)\n inst.pushDep(actionsModule)\n inst.pushDep(channelsModule)\n inst.pushDep(eventsModule)\n inst.pushDep(statesModule)\n return inst\n }\n\n private constructor(\n private integration: types.IntegrationDefinition,\n private configModule: ConfigurationModule,\n private actionsModule: ActionsModule,\n private channelsModule: ChannelsModule,\n private eventsModule: EventsModule,\n private statesModule: StatesModule,\n def: ModuleDef\n ) {\n super(def)\n }\n\n public override get content(): string {\n let content = GENERATED_HEADER\n\n const { configModule, actionsModule, channelsModule, eventsModule, statesModule, integration } = this\n\n const configImport = configModule.import(this)\n const actionsImport = actionsModule.import(this)\n const channelsImport = channelsModule.import(this)\n const eventsImport = eventsModule.import(this)\n const statesImport = statesModule.import(this)\n\n content += [\n GENERATED_HEADER,\n 'import * as sdk from \"@botpress/sdk\"',\n '',\n `import type * as ${configModule.name} from \"./${configImport}\"`,\n `import type * as ${actionsModule.name} from \"./${actionsImport}\"`,\n `import type * as ${channelsModule.name} from \"./${channelsImport}\"`,\n `import type * as ${eventsModule.name} from \"./${eventsImport}\"`,\n `import type * as ${statesModule.name} from \"./${statesImport}\"`,\n `export * as ${configModule.name} from \"./${configImport}\"`,\n `export * as ${actionsModule.name} from \"./${actionsImport}\"`,\n `export * as ${channelsModule.name} from \"./${channelsImport}\"`,\n `export * as ${eventsModule.name} from \"./${eventsImport}\"`,\n `export * as ${statesModule.name} from \"./${statesImport}\"`,\n '',\n 'type TIntegration = {',\n ` name: \"${integration.name}\"`,\n ` version: \"${integration.version}\"`,\n ` configuration: ${configModule.name}.${configModule.exports}`,\n ` actions: ${actionsModule.name}.${actionsModule.exports}`,\n ` channels: ${channelsModule.name}.${channelsModule.exports}`,\n ` events: ${eventsModule.name}.${eventsModule.exports}`,\n ` states: ${statesModule.name}.${statesModule.exports}`,\n ` user: ${stringifySingleLine(integration.user)}`,\n '}',\n '',\n 'export type IntegrationProps = sdk.IntegrationProps<TIntegration>',\n '',\n 'export class Integration extends sdk.Integration<TIntegration> {}',\n '',\n 'export type Client = sdk.IntegrationSpecificClient<TIntegration>',\n ].join('\\n')\n\n return content\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA6C;AAC7C,wBAAoC;AACpC,4BAA8B;AAC9B,6BAA+B;AAC/B,kCAAoC;AACpC,2BAA6B;AAC7B,2BAA6B;AAC7B,oBAAkC;AAG3B,MAAM,6CAA6C,qBAAO;AAAA,EAuCvD,YACE,aACA,cACA,eACA,gBACA,cACA,cACR,KACA;AACA,UAAM,GAAG;AARD;AACA;AACA;AACA;AACA;AACA;AAAA,EAIV;AAAA,EAhDA,aAAoB,OAAO,aAAyF;AAClH,UAAM,eAAe,MAAM,gDAAoB,OAAO,YAAY,iBAAiB,EAAE,QAAQ,CAAC,EAAE,CA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AAgB;AAAA,MACjD,eAAe,aAAa,gBAAgB;AAAA,MAC5C,eAAe,cAAc,gBAAgB;AAAA,MAC7C,eAAe,eAAe,gBAAgB;AAAA,MAC9C,eAAe,aAAa,gBAAgB;AAAA,MAC5C,eAAe,aAAa,gBAAgB;AAAA,MAC5C;AAAA,MACA;AAAA,MACA,YAAY,YAAY;AAAA,MACxB,eAAe,YAAY;AAAA,MAC3B,oBAAoB,aAAa,QAAQ,aAAa;AAAA,MACtD,cAAc,cAAc,QAAQ,cAAc;AAAA,MAClD,eAAe,eAAe,QAAQ,eAAe;AAAA,MACrD,aAAa,aAAa,QAAQ,aAAa;AAAA,MAC/C,aAAa,aAAa,QAAQ,aAAa;AAAA,MAC/C,eAAW,uCAAoB,YAAY,IAAI;AAAA,MAC/C;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,EAAE,KAAK,IAAI;AAEX,WAAO;AAAA,EACT;AACF;",
6
6
  "names": []
7
7
  }
@@ -83,6 +83,7 @@ class IntegrationInstanceIndexModule extends import_module.Module {
83
83
  const { name, version, id } = integration;
84
84
  const className = import_utils.casing.to.pascalCase(name);
85
85
  const propsName = `${className}Props`;
86
+ const integrationId = id === null ? "null" : `'${id}'`;
86
87
  const lines = [
87
88
  import_const.GENERATED_HEADER,
88
89
  "import type { IntegrationInstance } from '@botpress/sdk'",
@@ -118,7 +119,7 @@ class IntegrationInstanceIndexModule extends import_module.Module {
118
119
  "",
119
120
  ` public readonly name = '${name}'`,
120
121
  ` public readonly version = '${version}'`,
121
- ` public readonly id = '${id}'`,
122
+ ` public readonly id = ${integrationId}`,
122
123
  "",
123
124
  " public readonly enabled?: boolean",
124
125
  ` public readonly configuration?: ${configModule.name}.${configModule.exports}`,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/code-generation/integration-instance.ts"],
4
- "sourcesContent": ["import type { Integration } from '@botpress/client'\nimport { casing } from '../utils'\nimport { GENERATED_HEADER, INDEX_FILE } from './const'\nimport { stringifySingleLine } from './generators'\nimport { ActionsModule } from './integration-schemas/actions-module'\nimport { ChannelsModule } from './integration-schemas/channels-module'\nimport { ConfigurationModule } from './integration-schemas/configuration-module'\nimport { EventsModule } from './integration-schemas/events-module'\nimport { StatesModule } from './integration-schemas/states-module'\nimport { Module, ModuleDef } from './module'\n\nexport class IntegrationInstanceIndexModule extends Module {\n public static async create(integration: Integration): Promise<IntegrationInstanceIndexModule> {\n const { name } = integration\n\n const configModule = await ConfigurationModule.create(integration.configuration ?? { schema: {} })\n configModule.unshift('configuration')\n\n const actionsModule = await ActionsModule.create(integration.actions ?? {})\n actionsModule.unshift('actions')\n\n const channelsModule = await ChannelsModule.create(integration.channels ?? {})\n channelsModule.unshift('channels')\n\n const eventsModule = await EventsModule.create(integration.events ?? {})\n eventsModule.unshift('events')\n\n const statesModule = await StatesModule.create(integration.states ?? {})\n statesModule.unshift('states')\n\n const exportName = casing.to.pascalCase(name)\n\n const inst = new IntegrationInstanceIndexModule(\n integration,\n configModule,\n actionsModule,\n channelsModule,\n eventsModule,\n statesModule,\n {\n path: INDEX_FILE,\n content: '',\n exportName,\n }\n )\n\n inst.pushDep(configModule)\n inst.pushDep(actionsModule)\n inst.pushDep(channelsModule)\n inst.pushDep(eventsModule)\n inst.pushDep(statesModule)\n\n return inst\n }\n\n private constructor(\n private integration: Integration,\n private configModule: ConfigurationModule,\n private actionsModule: ActionsModule,\n private channelsModule: ChannelsModule,\n private eventsModule: EventsModule,\n private statesModule: StatesModule,\n def: ModuleDef\n ) {\n super(def)\n }\n\n public override get content(): string {\n const { configModule, actionsModule, channelsModule, eventsModule, statesModule, integration } = this\n\n const configImport = configModule.import(this)\n const actionsImport = actionsModule.import(this)\n const channelsImport = channelsModule.import(this)\n const eventsImport = eventsModule.import(this)\n const statesImport = statesModule.import(this)\n\n const { name, version, id } = integration\n const className = casing.to.pascalCase(name)\n const propsName = `${className}Props`\n\n const lines = [\n GENERATED_HEADER,\n \"import type { IntegrationInstance } from '@botpress/sdk'\",\n '',\n `import type * as ${configModule.name} from \"./${configImport}\"`,\n `import type * as ${actionsModule.name} from \"./${actionsImport}\"`,\n `import type * as ${channelsModule.name} from \"./${channelsImport}\"`,\n `import type * as ${eventsModule.name} from \"./${eventsImport}\"`,\n `import type * as ${statesModule.name} from \"./${statesImport}\"`,\n `export * as ${configModule.name} from \"./${configImport}\"`,\n `export * as ${actionsModule.name} from \"./${actionsImport}\"`,\n `export * as ${channelsModule.name} from \"./${channelsImport}\"`,\n `export * as ${eventsModule.name} from \"./${eventsImport}\"`,\n `export * as ${statesModule.name} from \"./${statesImport}\"`,\n '',\n `export type ${propsName} = {`,\n ' enabled?: boolean',\n ` config?: ${configModule.name}.${configModule.exports}`,\n '}',\n '',\n `export type T${className} = {`,\n ` name: '${name}'`,\n ` version: '${version}'`,\n ` configuration: ${configModule.name}.${configModule.exports}`,\n ` actions: ${actionsModule.name}.${actionsModule.exports}`,\n ` channels: ${channelsModule.name}.${channelsModule.exports}`,\n ` events: ${eventsModule.name}.${eventsModule.exports}`,\n ` states: ${statesModule.name}.${statesModule.exports}`,\n ` user: ${stringifySingleLine(this.integration.user)}`,\n '}',\n '',\n `export class ${className} implements IntegrationInstance<'${name}'> {`,\n '',\n ` public readonly name = '${name}'`,\n ` public readonly version = '${version}'`,\n ` public readonly id = '${id}'`,\n '',\n ' public readonly enabled?: boolean',\n ` public readonly configuration?: ${configModule.name}.${configModule.exports}`,\n '',\n ` constructor(props?: ${propsName}) {`,\n ' this.enabled = props?.enabled',\n ' this.configuration = props?.config',\n ' }',\n '}',\n ]\n\n return `${GENERATED_HEADER}\\n${lines.join('\\n')}`\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAuB;AACvB,mBAA6C;AAC7C,wBAAoC;AACpC,4BAA8B;AAC9B,6BAA+B;AAC/B,kCAAoC;AACpC,2BAA6B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,yBAAyB;AAAA,MACzB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAEA,WAAO,GAAG;AAAA,EAAqB,MAAM,KAAK,IAAI;AAAA,EAChD;AACF;",
4
+ "sourcesContent": ["import { casing } from '../utils'\nimport { GENERATED_HEADER, INDEX_FILE } from './const'\nimport { stringifySingleLine } from './generators'\nimport { ActionsModule } from './integration-schemas/actions-module'\nimport { ChannelsModule } from './integration-schemas/channels-module'\nimport { ConfigurationModule } from './integration-schemas/configuration-module'\nimport { EventsModule } from './integration-schemas/events-module'\nimport { StatesModule } from './integration-schemas/states-module'\nimport { Module, ModuleDef } from './module'\nimport * as types from './typings'\n\nexport class IntegrationInstanceIndexModule extends Module {\n public static async create(integration: types.IntegrationDefinition): Promise<IntegrationInstanceIndexModule> {\n const { name } = integration\n\n const configModule = await ConfigurationModule.create(integration.configuration ?? { schema: {} })\n configModule.unshift('configuration')\n\n const actionsModule = await ActionsModule.create(integration.actions ?? {})\n actionsModule.unshift('actions')\n\n const channelsModule = await ChannelsModule.create(integration.channels ?? {})\n channelsModule.unshift('channels')\n\n const eventsModule = await EventsModule.create(integration.events ?? {})\n eventsModule.unshift('events')\n\n const statesModule = await StatesModule.create(integration.states ?? {})\n statesModule.unshift('states')\n\n const exportName = casing.to.pascalCase(name)\n\n const inst = new IntegrationInstanceIndexModule(\n integration,\n configModule,\n actionsModule,\n channelsModule,\n eventsModule,\n statesModule,\n {\n path: INDEX_FILE,\n content: '',\n exportName,\n }\n )\n\n inst.pushDep(configModule)\n inst.pushDep(actionsModule)\n inst.pushDep(channelsModule)\n inst.pushDep(eventsModule)\n inst.pushDep(statesModule)\n\n return inst\n }\n\n private constructor(\n private integration: types.IntegrationDefinition,\n private configModule: ConfigurationModule,\n private actionsModule: ActionsModule,\n private channelsModule: ChannelsModule,\n private eventsModule: EventsModule,\n private statesModule: StatesModule,\n def: ModuleDef\n ) {\n super(def)\n }\n\n public override get content(): string {\n const { configModule, actionsModule, channelsModule, eventsModule, statesModule, integration } = this\n\n const configImport = configModule.import(this)\n const actionsImport = actionsModule.import(this)\n const channelsImport = channelsModule.import(this)\n const eventsImport = eventsModule.import(this)\n const statesImport = statesModule.import(this)\n\n const { name, version, id } = integration\n const className = casing.to.pascalCase(name)\n const propsName = `${className}Props`\n\n const integrationId = id === null ? 'null' : `'${id}'`\n\n const lines = [\n GENERATED_HEADER,\n \"import type { IntegrationInstance } from '@botpress/sdk'\",\n '',\n `import type * as ${configModule.name} from \"./${configImport}\"`,\n `import type * as ${actionsModule.name} from \"./${actionsImport}\"`,\n `import type * as ${channelsModule.name} from \"./${channelsImport}\"`,\n `import type * as ${eventsModule.name} from \"./${eventsImport}\"`,\n `import type * as ${statesModule.name} from \"./${statesImport}\"`,\n `export * as ${configModule.name} from \"./${configImport}\"`,\n `export * as ${actionsModule.name} from \"./${actionsImport}\"`,\n `export * as ${channelsModule.name} from \"./${channelsImport}\"`,\n `export * as ${eventsModule.name} from \"./${eventsImport}\"`,\n `export * as ${statesModule.name} from \"./${statesImport}\"`,\n '',\n `export type ${propsName} = {`,\n ' enabled?: boolean',\n ` config?: ${configModule.name}.${configModule.exports}`,\n '}',\n '',\n `export type T${className} = {`,\n ` name: '${name}'`,\n ` version: '${version}'`,\n ` configuration: ${configModule.name}.${configModule.exports}`,\n ` actions: ${actionsModule.name}.${actionsModule.exports}`,\n ` channels: ${channelsModule.name}.${channelsModule.exports}`,\n ` events: ${eventsModule.name}.${eventsModule.exports}`,\n ` states: ${statesModule.name}.${statesModule.exports}`,\n ` user: ${stringifySingleLine(this.integration.user)}`,\n '}',\n '',\n `export class ${className} implements IntegrationInstance<'${name}'> {`,\n '',\n ` public readonly name = '${name}'`,\n ` public readonly version = '${version}'`,\n ` public readonly id = ${integrationId}`,\n '',\n ' public readonly enabled?: boolean',\n ` public readonly configuration?: ${configModule.name}.${configModule.exports}`,\n '',\n ` constructor(props?: ${propsName}) {`,\n ' this.enabled = props?.enabled',\n ' this.configuration = props?.config',\n ' }',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a,aAAa,QAAQ,aAAa;AAAA,MAC/C,eAAW,uCAAoB,KAAK,YAAY,IAAI;AAAA,MACpD;AAAA,MACA;AAAA,MACA,gBAAgB,6CAA6C;AAAA,MAC7D;AAAA,MACA,6BAA6B;AAAA,MAC7B,gCAAgC;AAAA,MAChC,0BAA0B;AAAA,MAC1B;AAAA,MACA;AAAA,MACA,qCAAqC,aAAa,QAAQ,aAAa;AAAA,MACvE;AAAA,MACA,yBAAyB;AAAA,MACzB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAEA,WAAO,GAAG;AAAA,EAAqB,MAAM,KAAK,IAAI;AAAA,EAChD;AACF;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from2, except, desc) => {
13
+ if (from2 && typeof from2 === "object" || typeof from2 === "function") {
14
+ for (let key of __getOwnPropNames(from2))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from2[key], enumerable: !(desc = __getOwnPropDesc(from2, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var map_integration_exports = {};
26
+ __export(map_integration_exports, {
27
+ from: () => from
28
+ });
29
+ module.exports = __toCommonJS(map_integration_exports);
30
+ var utils = __toESM(require("../utils"));
31
+ var from;
32
+ ((from2) => {
33
+ from2.sdk = (i) => ({
34
+ id: null,
35
+ name: i.name,
36
+ version: i.version,
37
+ user: {
38
+ tags: i.user?.tags ?? {},
39
+ creation: i.user?.creation ?? { enabled: false, requiredTags: [] }
40
+ },
41
+ configuration: i.configuration ? _mapSchema(i.configuration) : { schema: {} },
42
+ events: i.events ? utils.records.mapValues(i.events, _mapSchema) : {},
43
+ states: i.states ? utils.records.mapValues(i.states, _mapSchema) : {},
44
+ actions: i.actions ? utils.records.mapValues(i.actions, (a) => ({
45
+ input: _mapSchema(a.input),
46
+ output: _mapSchema(a.output)
47
+ })) : {},
48
+ channels: i.channels ? utils.records.mapValues(i.channels, (c) => ({
49
+ conversation: {
50
+ tags: c.conversation?.tags ?? {},
51
+ creation: c.conversation?.creation ?? { enabled: false, requiredTags: [] }
52
+ },
53
+ message: {
54
+ tags: c.message?.tags ?? {}
55
+ },
56
+ messages: utils.records.mapValues(c.messages, _mapSchema)
57
+ })) : {}
58
+ });
59
+ from2.client = (i) => {
60
+ const { id, name, version, configuration, channels, states, events, actions, user } = i;
61
+ return { id, name, version, configuration, channels, states, events, actions, user };
62
+ };
63
+ const _mapSchema = (x) => ({
64
+ ...x,
65
+ schema: utils.schema.mapZodToJsonSchema(x)
66
+ });
67
+ })(from || (from = {}));
68
+ // Annotate the CommonJS export names for ESM import in node:
69
+ 0 && (module.exports = {
70
+ from
71
+ });
72
+ //# sourceMappingURL=map-integration.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/code-generation/map-integration.ts"],
4
+ "sourcesContent": ["import * as bpclient from '@botpress/client'\nimport * as bpsdk from '@botpress/sdk'\nimport { z } from 'zod'\nimport * as utils from '../utils'\nimport * as types from './typings'\n\nexport namespace from {\n export const sdk = (i: bpsdk.IntegrationDefinition): types.IntegrationDefinition => ({\n id: null,\n name: i.name,\n version: i.version,\n user: {\n tags: i.user?.tags ?? {},\n creation: i.user?.creation ?? { enabled: false, requiredTags: [] },\n },\n configuration: i.configuration ? _mapSchema(i.configuration) : { schema: {} },\n events: i.events ? utils.records.mapValues(i.events, _mapSchema) : {},\n states: i.states ? utils.records.mapValues(i.states, _mapSchema) : {},\n actions: i.actions\n ? utils.records.mapValues(i.actions, (a) => ({\n input: _mapSchema(a.input),\n output: _mapSchema(a.output),\n }))\n : {},\n channels: i.channels\n ? utils.records.mapValues(i.channels, (c) => ({\n conversation: {\n tags: c.conversation?.tags ?? {},\n creation: c.conversation?.creation ?? { enabled: false, requiredTags: [] },\n },\n message: {\n tags: c.message?.tags ?? {},\n },\n messages: utils.records.mapValues(c.messages, _mapSchema),\n }))\n : {},\n })\n\n export const client = (i: bpclient.Integration): types.IntegrationDefinition => {\n const { id, name, version, configuration, channels, states, events, actions, user } = i\n return { id, name, version, configuration, channels, states, events, actions, user }\n }\n\n const _mapSchema = <T extends { schema: z.ZodObject<any> }>(\n x: T\n ): utils.types.Merge<T, { schema: ReturnType<typeof utils.schema.mapZodToJsonSchema> }> => ({\n ...x,\n schema: utils.schema.mapZodToJsonSchema(x),\n })\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,YAAuB;AAGhB,IAAU;AAAA,CAAV,CAAUA,UAAV;AACE,EAAMA,MAAA,MAAM,CAAC,OAAiE;AAAA,IACnF,IAAI;AAAA,IACJ,MAAM,EAAE;AAAA,IACR,SAAS,EAAE;AAAA,IACX,MAAM;AAAA,MACJ,MAAM,EAAE,MAAM,QAAQ,CAAC;AAAA,MACvB,UAAU,EAAE,MAAM,YAAY,EAAE,SAAS,OAAO,cAAc,CAAC,EAAE;AAAA,IACnE;AAAA,IACA,eAAe,EAAE,gBAAgB,WAAW,EAAE,aAAa,IAAI,EAAE,QAAQ,CAAC,EAAE;AAAA,IAC5E,QAAQ,EAAE,SAAS,MAAM,QAAQ,UAAU,EAAE,QAAQ,UAAU,IAAI,CAAC;AAAA,IACpE,QAAQ,EAAE,SAAS,MAAM,QAAQ,UAAU,EAAE,QAAQ,UAAU,IAAI,CAAC;AAAA,IACpE,SAAS,EAAE,UACP,MAAM,QAAQ,UAAU,EAAE,SAAS,CAAC,OAAO;AAAA,MACzC,OAAO,WAAW,EAAE,KAAK;AAAA,MACzB,QAAQ,WAAW,EAAE,MAAM;AAAA,IAC7B,EAAE,IACF,CAAC;AAAA,IACL,UAAU,EAAE,WACR,MAAM,QAAQ,UAAU,EAAE,UAAU,CAAC,OAAO;AAAA,MAC1C,cAAc;AAAA,QACZ,MAAM,EAAE,cAAc,QAAQ,CAAC;AAAA,QAC/B,UAAU,EAAE,cAAc,YAAY,EAAE,SAAS,OAAO,cAAc,CAAC,EAAE;AAAA,MAC3E;AAAA,MACA,SAAS;AAAA,QACP,MAAM,EAAE,SAAS,QAAQ,CAAC;AAAA,MAC5B;AAAA,MACA,UAAU,MAAM,QAAQ,UAAU,EAAE,UAAU,UAAU;AAAA,IAC1D,EAAE,IACF,CAAC;AAAA,EACP;AAEO,EAAMA,MAAA,SAAS,CAAC,MAAyD;AAC9E,UAAM,EAAE,IAAI,MAAM,SAAS,eAAe,UAAU,QAAQ,QAAQ,SAAS,KAAK,IAAI;AACtF,WAAO,EAAE,IAAI,MAAM,SAAS,eAAe,UAAU,QAAQ,QAAQ,SAAS,KAAK;AAAA,EACrF;AAEA,QAAM,aAAa,CACjB,OAC0F;AAAA,IAC1F,GAAG;AAAA,IACH,QAAQ,MAAM,OAAO,mBAAmB,CAAC;AAAA,EAC3C;AAAA,GA1Ce;",
6
+ "names": ["from"]
7
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/code-generation/typings.ts"],
4
- "sourcesContent": ["import { Integration } from '@botpress/client'\n\nexport type File = { path: string; content: string }\n\nexport type IntegrationDefinition = Pick<\n Integration,\n 'name' | 'version' | 'configuration' | 'channels' | 'states' | 'events' | 'actions' | 'user'\n>\n\ntype Def<T> = NonNullable<T>\n\nexport type ConfigurationDefinition = Def<IntegrationDefinition['configuration']>\nexport type ChannelDefinition = Def<IntegrationDefinition['channels']>[string]\nexport type MessageDefinition = Def<ChannelDefinition['messages']>[string]\nexport type ActionDefinition = Def<IntegrationDefinition['actions']>[string]\nexport type EventDefinition = Def<IntegrationDefinition['events']>[string]\nexport type StateDefinition = Def<IntegrationDefinition['states']>[string]\nexport type UserDefinition = Def<IntegrationDefinition['user']>\n"],
4
+ "sourcesContent": ["import { Integration } from '@botpress/client'\n\nexport type File = { path: string; content: string }\n\nexport type IntegrationDefinition = Pick<\n Integration,\n 'name' | 'version' | 'configuration' | 'channels' | 'states' | 'events' | 'actions' | 'user'\n> & {\n id: string | null\n}\n\ntype Def<T> = NonNullable<T>\n\nexport type ConfigurationDefinition = Def<IntegrationDefinition['configuration']>\nexport type ChannelDefinition = Def<IntegrationDefinition['channels']>[string]\nexport type MessageDefinition = Def<ChannelDefinition['messages']>[string]\nexport type ActionDefinition = Def<IntegrationDefinition['actions']>[string]\nexport type EventDefinition = Def<IntegrationDefinition['events']>[string]\nexport type StateDefinition = Def<IntegrationDefinition['states']>[string]\nexport type UserDefinition = Def<IntegrationDefinition['user']>\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -32,8 +32,10 @@ var import_chalk = __toESM(require("chalk"));
32
32
  var fs = __toESM(require("fs"));
33
33
  var pathlib = __toESM(require("path"));
34
34
  var codegen = __toESM(require("../code-generation"));
35
+ var consts = __toESM(require("../consts"));
35
36
  var errors = __toESM(require("../errors"));
36
37
  var import_integration_ref = require("../integration-ref");
38
+ var utils = __toESM(require("../utils"));
37
39
  var import_project_command = require("./project-command");
38
40
  class AddCommand extends import_project_command.ProjectCommand {
39
41
  async run() {
@@ -42,15 +44,11 @@ class AddCommand extends import_project_command.ProjectCommand {
42
44
  throw new errors.ExclusiveBotFeatureError();
43
45
  }
44
46
  const integrationRef = this.argv.integrationRef;
45
- const api = await this.ensureLoginAndCreateClient(this.argv);
46
47
  const parsedRef = (0, import_integration_ref.parseIntegrationRef)(integrationRef);
47
48
  if (!parsedRef) {
48
49
  throw new errors.InvalidIntegrationReferenceError(integrationRef);
49
50
  }
50
- const integration = await api.findIntegration(parsedRef);
51
- if (!integration) {
52
- throw new errors.BotpressCLIError(`Integration "${integrationRef}" not found`);
53
- }
51
+ const integration = parsedRef.type === "path" ? await this._fetchLocalIntegration(parsedRef) : await this._fetchApiIntegration(parsedRef);
54
52
  const allInstances = await this._listIntegrationInstances();
55
53
  const existingInstance = allInstances.find((i) => i.name === integration.name);
56
54
  if (existingInstance) {
@@ -64,6 +62,30 @@ class AddCommand extends import_project_command.ProjectCommand {
64
62
  }
65
63
  await this._generateIntegrationInstance(integration);
66
64
  }
65
+ _fetchLocalIntegration = async (integrationRef) => {
66
+ this.logger.warn(
67
+ "Installing integration from a local path. There is no guarantee that the integration is deployed with the expected schemas."
68
+ );
69
+ const workDir = integrationRef.path;
70
+ const pathStore = new utils.path.PathStore({
71
+ workDir,
72
+ definition: utils.path.absoluteFrom(workDir, consts.fromWorkDir.definition)
73
+ });
74
+ const integrationDefinition = await this.readIntegrationDefinitionFromFS(pathStore);
75
+ if (!integrationDefinition) {
76
+ throw new errors.BotpressCLIError(`Integration definition not found at ${workDir}`);
77
+ }
78
+ return integrationDefinition;
79
+ };
80
+ _fetchApiIntegration = async (integrationRef) => {
81
+ const api = await this.ensureLoginAndCreateClient(this.argv);
82
+ const integration = await api.findIntegration(integrationRef);
83
+ if (!integration) {
84
+ const formattedRef = (0, import_integration_ref.formatIntegrationRef)(integrationRef);
85
+ throw new errors.BotpressCLIError(`Integration "${formattedRef}" not found`);
86
+ }
87
+ return integration;
88
+ };
67
89
  async _listIntegrationInstances() {
68
90
  const installPath = this.projectPaths.abs.installDir;
69
91
  if (!fs.existsSync(installPath)) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/command-implementations/add-command.ts"],
4
- "sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport bluebird from 'bluebird'\nimport chalk from 'chalk'\nimport * as fs from 'fs'\nimport * as pathlib from 'path'\nimport * as codegen from '../code-generation'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport { parseIntegrationRef } from '../integration-ref'\nimport { ProjectCommand } from './project-command'\n\ntype IntegrationInstallDir = codegen.IntegrationInstanceJson & {\n dirname: string\n}\n\nexport type AddCommandDefinition = typeof commandDefinitions.add\nexport class AddCommand extends ProjectCommand<AddCommandDefinition> {\n public async run(): Promise<void> {\n const integrationDef = await this.readIntegrationDefinitionFromFS()\n if (integrationDef) {\n throw new errors.ExclusiveBotFeatureError()\n }\n\n const integrationRef = this.argv.integrationRef\n\n const api = await this.ensureLoginAndCreateClient(this.argv)\n const parsedRef = parseIntegrationRef(integrationRef)\n if (!parsedRef) {\n throw new errors.InvalidIntegrationReferenceError(integrationRef)\n }\n\n const integration = await api.findIntegration(parsedRef)\n if (!integration) {\n throw new errors.BotpressCLIError(`Integration \"${integrationRef}\" not found`)\n }\n\n const allInstances = await this._listIntegrationInstances()\n const existingInstance = allInstances.find((i) => i.name === integration.name)\n if (existingInstance) {\n this.logger.warn(`Integration with name \"${integration.name}\" already installed.`)\n const res = await this.prompt.confirm('Do you want to overwrite the existing instance?')\n if (!res) {\n this.logger.log('Aborted')\n return\n }\n\n await this._uninstallIntegration(existingInstance)\n }\n\n await this._generateIntegrationInstance(integration)\n }\n\n private async _listIntegrationInstances(): Promise<IntegrationInstallDir[]> {\n const installPath = this.projectPaths.abs.installDir\n if (!fs.existsSync(installPath)) {\n this.logger.debug('Install path does not exist. Skipping listing of integration instances')\n return []\n }\n\n const allFiles = await fs.promises.readdir(installPath)\n const allPaths = allFiles.map((name) => pathlib.join(installPath, name))\n const directories = await bluebird.filter(allPaths, async (path) => {\n const stat = await fs.promises.stat(path)\n return stat.isDirectory()\n })\n\n let jsons = directories.map((root) => ({ root, json: pathlib.join(root, codegen.INTEGRATION_JSON) }))\n jsons = jsons.filter(({ json: x }) => fs.existsSync(x))\n\n return bluebird.map(jsons, async ({ root, json }) => {\n const content: string = await fs.promises.readFile(json, 'utf-8')\n const { name, version, id } = JSON.parse(content) as codegen.IntegrationInstanceJson\n const dirname = pathlib.basename(root)\n return {\n dirname,\n id,\n name,\n version,\n }\n })\n }\n\n private async _uninstallIntegration(instance: IntegrationInstallDir) {\n const installDir = this.projectPaths.abs.installDir\n const instancePath = pathlib.join(installDir, instance.dirname)\n await fs.promises.rm(instancePath, { recursive: true })\n await this._generateBotIndex()\n }\n\n private async _generateIntegrationInstance(integration: bpclient.Integration) {\n const line = this.logger.line()\n\n const { name, version } = integration\n line.started(`Installing ${chalk.bold(name)} v${version}...`)\n\n const instanceFiles = await codegen.generateIntegrationInstance(\n integration,\n this.projectPaths.rel('outDir').installDir\n )\n await this.writeGeneratedFilesToOutFolder(instanceFiles)\n await this._generateBotIndex()\n\n const rel = this.projectPaths.rel('workDir')\n line.success(`Installed integration available at ${chalk.grey(rel.outDir)}`)\n }\n\n private async _generateBotIndex() {\n const allInstances = await this._listIntegrationInstances()\n const indexFile = await codegen.generateBotIndex(\n this.projectPaths.rel('outDir').installDir,\n allInstances.map((i) => i.dirname)\n )\n await this.writeGeneratedFilesToOutFolder([indexFile])\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAqB;AACrB,mBAAkB;AAClB,SAAoB;AACpB,cAAyB;AACzB,cAAyB;AAEzB,aAAwB;AACxB,6BAAoC;AACpC,6BAA+B;AAOxB,MAAM,mBAAmB,sCAAqC;AAAA,EACnE,MAAa,MAAqB;AAChC,UAAM,iBAAiB,MAAM,KAAK,gCAAgC;AAClE,QAAI,gBAAgB;AAClB,YAAM,IAAI,OAAO,yBAAyB;AAAA,IAC5C;AAEA,UAAM,iBAAiB,KAAK,KAAK;AA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IAAI,CAAC,MAAM,EAAE,OAAO;AAAA,IACnC;AACA,UAAM,KAAK,+BAA+B,CAAC,SAAS,CAAC;AAAA,EACvD;AACF;",
4
+ "sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport type * as bpsdk from '@botpress/sdk'\nimport bluebird from 'bluebird'\nimport chalk from 'chalk'\nimport * as fs from 'fs'\nimport * as pathlib from 'path'\nimport * as codegen from '../code-generation'\nimport type commandDefinitions from '../command-definitions'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport {\n ApiIntegrationRef,\n formatIntegrationRef,\n LocalPathIntegrationRef,\n parseIntegrationRef,\n} from '../integration-ref'\nimport * as utils from '../utils'\nimport { ProjectCommand } from './project-command'\n\ntype IntegrationInstallDir = codegen.IntegrationInstanceJson & {\n dirname: string\n}\n\nexport type AddCommandDefinition = typeof commandDefinitions.add\nexport class AddCommand extends ProjectCommand<AddCommandDefinition> {\n public async run(): Promise<void> {\n const integrationDef = await this.readIntegrationDefinitionFromFS()\n if (integrationDef) {\n throw new errors.ExclusiveBotFeatureError()\n }\n\n const integrationRef = this.argv.integrationRef\n\n const parsedRef = parseIntegrationRef(integrationRef)\n if (!parsedRef) {\n throw new errors.InvalidIntegrationReferenceError(integrationRef)\n }\n\n const integration =\n parsedRef.type === 'path'\n ? await this._fetchLocalIntegration(parsedRef)\n : await this._fetchApiIntegration(parsedRef)\n\n const allInstances = await this._listIntegrationInstances()\n const existingInstance = allInstances.find((i) => i.name === integration.name)\n if (existingInstance) {\n this.logger.warn(`Integration with name \"${integration.name}\" already installed.`)\n const res = await this.prompt.confirm('Do you want to overwrite the existing instance?')\n if (!res) {\n this.logger.log('Aborted')\n return\n }\n\n await this._uninstallIntegration(existingInstance)\n }\n\n await this._generateIntegrationInstance(integration)\n }\n\n private _fetchLocalIntegration = async (\n integrationRef: LocalPathIntegrationRef\n ): Promise<bpsdk.IntegrationDefinition> => {\n this.logger.warn(\n 'Installing integration from a local path. There is no guarantee that the integration is deployed with the expected schemas.'\n )\n\n const workDir = integrationRef.path\n const pathStore = new utils.path.PathStore<'workDir' | 'definition'>({\n workDir,\n definition: utils.path.absoluteFrom(workDir, consts.fromWorkDir.definition),\n })\n const integrationDefinition = await this.readIntegrationDefinitionFromFS(pathStore)\n if (!integrationDefinition) {\n throw new errors.BotpressCLIError(`Integration definition not found at ${workDir}`)\n }\n return integrationDefinition\n }\n\n private _fetchApiIntegration = async (integrationRef: ApiIntegrationRef): Promise<bpclient.Integration> => {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n const integration = await api.findIntegration(integrationRef)\n if (!integration) {\n const formattedRef = formatIntegrationRef(integrationRef)\n throw new errors.BotpressCLIError(`Integration \"${formattedRef}\" not found`)\n }\n return integration\n }\n\n private async _listIntegrationInstances(): Promise<IntegrationInstallDir[]> {\n const installPath = this.projectPaths.abs.installDir\n if (!fs.existsSync(installPath)) {\n this.logger.debug('Install path does not exist. Skipping listing of integration instances')\n return []\n }\n\n const allFiles = await fs.promises.readdir(installPath)\n const allPaths = allFiles.map((name) => pathlib.join(installPath, name))\n const directories = await bluebird.filter(allPaths, async (path) => {\n const stat = await fs.promises.stat(path)\n return stat.isDirectory()\n })\n\n let jsons = directories.map((root) => ({ root, json: pathlib.join(root, codegen.INTEGRATION_JSON) }))\n jsons = jsons.filter(({ json: x }) => fs.existsSync(x))\n\n return bluebird.map(jsons, async ({ root, json }) => {\n const content: string = await fs.promises.readFile(json, 'utf-8')\n const { name, version, id } = JSON.parse(content) as codegen.IntegrationInstanceJson\n const dirname = pathlib.basename(root)\n return {\n dirname,\n id,\n name,\n version,\n }\n })\n }\n\n private async _uninstallIntegration(instance: IntegrationInstallDir) {\n const installDir = this.projectPaths.abs.installDir\n const instancePath = pathlib.join(installDir, instance.dirname)\n await fs.promises.rm(instancePath, { recursive: true })\n await this._generateBotIndex()\n }\n\n private async _generateIntegrationInstance(integration: bpclient.Integration | bpsdk.IntegrationDefinition) {\n const line = this.logger.line()\n\n const { name, version } = integration\n line.started(`Installing ${chalk.bold(name)} v${version}...`)\n\n const instanceFiles = await codegen.generateIntegrationInstance(\n integration,\n this.projectPaths.rel('outDir').installDir\n )\n await this.writeGeneratedFilesToOutFolder(instanceFiles)\n await this._generateBotIndex()\n\n const rel = this.projectPaths.rel('workDir')\n line.success(`Installed integration available at ${chalk.grey(rel.outDir)}`)\n }\n\n private async _generateBotIndex() {\n const allInstances = await this._listIntegrationInstances()\n const indexFile = await codegen.generateBotIndex(\n this.projectPaths.rel('outDir').installDir,\n allInstances.map((i) => i.dirname)\n )\n await this.writeGeneratedFilesToOutFolder([indexFile])\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAAqB;AACrB,mBAAkB;AAClB,SAAoB;AACpB,cAAyB;AACzB,cAAyB;AAEzB,aAAwB;AACxB,aAAwB;AACxB,6BAKO;AACP,YAAuB;AACvB,6BAA+B;AAOxB,MAAM,mBAAmB,sCAAqC;AAAA,EACnE,MAAa,MAAqB;AAChC,UAAM,iBAAiB,MAAM,KAAK,gCAAgC;AAClE,QAAI,gBAAgB;AAClB,YAAM,IAAI,OAAO,yBAAyB;AAAA,IAC5C;AAEA,UAAM,iBAAiB,KAAK,KAAK;AAEjC,UAAM,gBAAY,4CAAoB,cAAc;AACpD,QAAI,CAAC,WAAW;AACd,YAAM,IAAI,OAAO,iCAAiC,cAAc;AAAA,IAClE;AAEA,UAAM,cACJ,UAAU,SAAS,SACf,MAAM,KAAK,uBAAuB,SAAS,IAC3C,MAAM,KAAK,qBAAqB,SAAS;AAE/C,UAAM,eAAe,MAAM,KAAK,0BAA0B;AAC1D,UAAM,mBAAmB,aAAa,KAAK,CAAC,MAAM,EAAE,SAAS,YAAY,IAAI;AAC7E,QAAI,kBAAkB;AACpB,WAAK,OAAO,KAAK,0BAA0B,YAAY,0BAA0B;AACjF,YAAM,MAAM,MAAM,KAAK,OAAO,QAAQ,iDAAiD;AACvF,UAAI,CAAC,K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UAAM,eAAe,MAAM,KAAK,0BAA0B;AAC1D,UAAM,YAAY,MAAM,QAAQ;AAAA,MAC9B,KAAK,aAAa,IAAI,QAAQ,EAAE;AAAA,MAChC,aAAa,IAAI,CAAC,MAAM,EAAE,OAAO;AAAA,IACnC;AACA,UAAM,KAAK,+BAA+B,CAAC,SAAS,CAAC;AAAA,EACvD;AACF;",
6
6
  "names": ["bluebird", "chalk"]
7
7
  }
@@ -83,7 +83,7 @@ class DeployCommand extends import_project_command.ProjectCommand {
83
83
  return;
84
84
  }
85
85
  const createBody = {
86
- ...this.parseIntegrationDefinition(integrationDef),
86
+ ...this.prepareIntegrationDefinition(integrationDef),
87
87
  icon: iconFileContent,
88
88
  readme: readmeFileContent,
89
89
  code
@@ -145,7 +145,8 @@ class DeployCommand extends import_project_command.ProjectCommand {
145
145
  {
146
146
  id: bot.id,
147
147
  code,
148
- ...this.parseBot(botImpl)
148
+ ...this.prepareBot(botImpl),
149
+ ...await this.prepareBotIntegrationInstances(botImpl, api)
149
150
  },
150
151
  bot
151
152
  );
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/command-implementations/deploy-command.ts"],
4
- "sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport type * as bpsdk from '@botpress/sdk'\nimport chalk from 'chalk'\nimport * as fs from 'fs'\nimport { prepareUpdateBotBody } from '../api/bot-body'\nimport type { ApiClient } from '../api/client'\nimport { prepareUpdateIntegrationBody, CreateIntegrationBody } from '../api/integration-body'\nimport type commandDefinitions from '../command-definitions'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport * as utils from '../utils'\nimport { BuildCommand } from './build-command'\nimport { ProjectCommand } from './project-command'\n\nexport type DeployCommandDefinition = typeof commandDefinitions.deploy\nexport class DeployCommand extends ProjectCommand<DeployCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n if (api.url !== consts.defaultBotpressApiUrl) {\n this.logger.log(`Using custom url ${api.url}`)\n }\n\n if (!this.argv.noBuild) {\n await this._runBuild() // This ensures the bundle is always synced with source code\n }\n\n const integrationDef = await this.readIntegrationDefinitionFromFS()\n if (integrationDef) {\n return this._deployIntegration(api, integrationDef)\n }\n return this._deployBot(api, this.argv.botId, this.argv.createNewBot)\n }\n\n private async _runBuild() {\n return new BuildCommand(this.api, this.prompt, this.logger, this.argv).run()\n }\n\n private async _deployIntegration(api: ApiClient, integrationDef: bpsdk.IntegrationDefinition) {\n const outfile = this.projectPaths.abs.outFile\n let code = await fs.promises.readFile(outfile, 'utf-8')\n\n const secrets = await this.promptSecrets(integrationDef, this.argv)\n // TODO: provide these secrets to the backend by API and remove this string replacement hack\n for (const [secretName, secretValue] of Object.entries(secrets)) {\n code = code.replace(new RegExp(`process\\\\.env\\\\.${secretName}`, 'g'), `\"${secretValue}\"`)\n }\n\n const { name, version, icon: iconRelativeFilePath, readme: readmeRelativeFilePath } = integrationDef\n\n const iconFileContent = await this._readMediaFile('icon', iconRelativeFilePath)\n const readmeFileContent = await this._readMediaFile('readme', readmeRelativeFilePath)\n\n const integration = await api.findIntegration({ type: 'name', name, version })\n if (integration && !integration.workspaceId) {\n throw new errors.BotpressCLIError(\n `Public integration ${integrationDef.name} v${integrationDef.version} is already deployed in another workspace.`\n )\n }\n\n let message: string\n if (integration) {\n this.logger.warn('Integration already exists. If you decide to deploy, it will overwrite the existing one.')\n message = `Are you sure you want to override integration ${integrationDef.name} v${integrationDef.version}?`\n } else {\n message = `Are you sure you want to deploy integration ${integrationDef.name} v${integrationDef.version}?`\n }\n\n const confirm = await this.prompt.confirm(message)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n const createBody: CreateIntegrationBody = {\n ...this.parseIntegrationDefinition(integrationDef),\n icon: iconFileContent,\n readme: readmeFileContent,\n code,\n }\n\n const line = this.logger.line()\n line.started(`Deploying integration ${chalk.bold(integrationDef.name)} v${integrationDef.version}...`)\n if (integration) {\n const updateBody = prepareUpdateIntegrationBody(\n {\n id: integration.id,\n ...createBody,\n },\n integration\n )\n\n await api.client.updateIntegration(updateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update integration \"${integrationDef.name}\"`)\n })\n } else {\n await api.client.createIntegration(createBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not create integration \"${integrationDef.name}\"`)\n })\n }\n line.success('Integration deployed')\n }\n\n private _readMediaFile = async (\n filePurpose: 'icon' | 'readme',\n filePath: string | undefined\n ): Promise<string | undefined> => {\n if (!filePath) {\n return undefined\n }\n\n const absoluteFilePath = utils.path.absoluteFrom(this.projectPaths.abs.workDir, filePath)\n return fs.promises.readFile(absoluteFilePath, 'base64').catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not read ${filePurpose} file \"${absoluteFilePath}\"`)\n })\n }\n\n private async _deployBot(api: ApiClient, argvBotId: string | undefined, argvCreateNew: boolean | undefined) {\n const outfile = this.projectPaths.abs.outFile\n const code = await fs.promises.readFile(outfile, 'utf-8')\n const { default: botImpl } = utils.require.requireJsFile<{ default: bpsdk.Bot }>(outfile)\n\n let bot: bpclient.Bot\n if (argvBotId && argvCreateNew) {\n throw new errors.BotpressCLIError('Cannot specify both --botId and --createNew')\n } else if (argvCreateNew) {\n const confirm = await this.prompt.confirm('Are you sure you want to create a new bot ?')\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n bot = await this._createNewBot(api)\n } else {\n bot = await this._getExistingBot(api, argvBotId)\n\n const confirm = await this.prompt.confirm(`Are you sure you want to deploy the bot \"${bot.name}\"?`)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n }\n\n const line = this.logger.line()\n line.started(`Deploying bot ${chalk.bold(bot.name)}...`)\n\n const updateBotBody = prepareUpdateBotBody(\n {\n id: bot.id,\n code,\n ...this.parseBot(botImpl),\n },\n bot\n )\n\n const { bot: updatedBot } = await api.client.updateBot(updateBotBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update bot \"${bot.name}\"`)\n })\n line.success('Bot deployed')\n this.displayWebhookUrls(updatedBot)\n }\n\n private async _createNewBot(api: ApiClient): Promise<bpclient.Bot> {\n const line = this.logger.line()\n const { bot: createdBot } = await api.client.createBot({}).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not create bot')\n })\n line.success(`Bot created with ID \"${createdBot.id}\" and name \"${createdBot.name}\"`)\n await this.projectCache.set('botId', createdBot.id)\n return createdBot\n }\n\n private async _getExistingBot(api: ApiClient, botId: string | undefined): Promise<bpclient.Bot> {\n const promptedBotId = await this.projectCache.sync('botId', botId, async (defaultId) => {\n const userBots = await api\n .listAllPages(api.client.listBots, (r) => r.bots)\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not fetch existing bots')\n })\n\n if (!userBots.length) {\n throw new errors.NoBotsFoundError()\n }\n\n const initial = userBots.find((bot) => bot.id === defaultId)\n\n const prompted = await this.prompt.select('Which bot do you want to deploy?', {\n initial: initial && { title: initial.name, value: initial.id },\n choices: userBots.map((bot) => ({ title: bot.name, value: bot.id })),\n })\n\n if (!prompted) {\n throw new errors.ParamRequiredError('Bot Id')\n }\n\n return prompted\n })\n\n const { bot: fetchedBot } = await api.client.getBot({ id: promptedBotId }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not get bot info')\n })\n\n return fetchedBot\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAkB;AAClB,SAAoB;AACpB,sBAAqC;AAErC,8BAAoE;AAEpE,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,2BAA6B;AAC7B,6BAA+B;AAGxB,MAAM,sBAAsB,sCAAwC;AAAA,EACzE,MAAa,MAAqB;AAChC,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAC3D,QAAI,IAAI,QAAQ,OAAO,uBAAuB;AAC5C,WAAK,OAAO,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import type * as bpclient from '@botpress/client'\nimport type * as bpsdk from '@botpress/sdk'\nimport chalk from 'chalk'\nimport * as fs from 'fs'\nimport { prepareUpdateBotBody } from '../api/bot-body'\nimport type { ApiClient } from '../api/client'\nimport { prepareUpdateIntegrationBody, CreateIntegrationBody } from '../api/integration-body'\nimport type commandDefinitions from '../command-definitions'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport * as utils from '../utils'\nimport { BuildCommand } from './build-command'\nimport { ProjectCommand } from './project-command'\n\nexport type DeployCommandDefinition = typeof commandDefinitions.deploy\nexport class DeployCommand extends ProjectCommand<DeployCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n if (api.url !== consts.defaultBotpressApiUrl) {\n this.logger.log(`Using custom url ${api.url}`)\n }\n\n if (!this.argv.noBuild) {\n await this._runBuild() // This ensures the bundle is always synced with source code\n }\n\n const integrationDef = await this.readIntegrationDefinitionFromFS()\n if (integrationDef) {\n return this._deployIntegration(api, integrationDef)\n }\n return this._deployBot(api, this.argv.botId, this.argv.createNewBot)\n }\n\n private async _runBuild() {\n return new BuildCommand(this.api, this.prompt, this.logger, this.argv).run()\n }\n\n private async _deployIntegration(api: ApiClient, integrationDef: bpsdk.IntegrationDefinition) {\n const outfile = this.projectPaths.abs.outFile\n let code = await fs.promises.readFile(outfile, 'utf-8')\n\n const secrets = await this.promptSecrets(integrationDef, this.argv)\n // TODO: provide these secrets to the backend by API and remove this string replacement hack\n for (const [secretName, secretValue] of Object.entries(secrets)) {\n code = code.replace(new RegExp(`process\\\\.env\\\\.${secretName}`, 'g'), `\"${secretValue}\"`)\n }\n\n const { name, version, icon: iconRelativeFilePath, readme: readmeRelativeFilePath } = integrationDef\n\n const iconFileContent = await this._readMediaFile('icon', iconRelativeFilePath)\n const readmeFileContent = await this._readMediaFile('readme', readmeRelativeFilePath)\n\n const integration = await api.findIntegration({ type: 'name', name, version })\n if (integration && !integration.workspaceId) {\n throw new errors.BotpressCLIError(\n `Public integration ${integrationDef.name} v${integrationDef.version} is already deployed in another workspace.`\n )\n }\n\n let message: string\n if (integration) {\n this.logger.warn('Integration already exists. If you decide to deploy, it will overwrite the existing one.')\n message = `Are you sure you want to override integration ${integrationDef.name} v${integrationDef.version}?`\n } else {\n message = `Are you sure you want to deploy integration ${integrationDef.name} v${integrationDef.version}?`\n }\n\n const confirm = await this.prompt.confirm(message)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n const createBody: CreateIntegrationBody = {\n ...this.prepareIntegrationDefinition(integrationDef),\n icon: iconFileContent,\n readme: readmeFileContent,\n code,\n }\n\n const line = this.logger.line()\n line.started(`Deploying integration ${chalk.bold(integrationDef.name)} v${integrationDef.version}...`)\n if (integration) {\n const updateBody = prepareUpdateIntegrationBody(\n {\n id: integration.id,\n ...createBody,\n },\n integration\n )\n\n await api.client.updateIntegration(updateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update integration \"${integrationDef.name}\"`)\n })\n } else {\n await api.client.createIntegration(createBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not create integration \"${integrationDef.name}\"`)\n })\n }\n line.success('Integration deployed')\n }\n\n private _readMediaFile = async (\n filePurpose: 'icon' | 'readme',\n filePath: string | undefined\n ): Promise<string | undefined> => {\n if (!filePath) {\n return undefined\n }\n\n const absoluteFilePath = utils.path.absoluteFrom(this.projectPaths.abs.workDir, filePath)\n return fs.promises.readFile(absoluteFilePath, 'base64').catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not read ${filePurpose} file \"${absoluteFilePath}\"`)\n })\n }\n\n private async _deployBot(api: ApiClient, argvBotId: string | undefined, argvCreateNew: boolean | undefined) {\n const outfile = this.projectPaths.abs.outFile\n const code = await fs.promises.readFile(outfile, 'utf-8')\n const { default: botImpl } = utils.require.requireJsFile<{ default: bpsdk.Bot }>(outfile)\n\n let bot: bpclient.Bot\n if (argvBotId && argvCreateNew) {\n throw new errors.BotpressCLIError('Cannot specify both --botId and --createNew')\n } else if (argvCreateNew) {\n const confirm = await this.prompt.confirm('Are you sure you want to create a new bot ?')\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n bot = await this._createNewBot(api)\n } else {\n bot = await this._getExistingBot(api, argvBotId)\n\n const confirm = await this.prompt.confirm(`Are you sure you want to deploy the bot \"${bot.name}\"?`)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n }\n\n const line = this.logger.line()\n line.started(`Deploying bot ${chalk.bold(bot.name)}...`)\n\n const updateBotBody = prepareUpdateBotBody(\n {\n id: bot.id,\n code,\n ...this.prepareBot(botImpl),\n ...(await this.prepareBotIntegrationInstances(botImpl, api)),\n },\n bot\n )\n\n const { bot: updatedBot } = await api.client.updateBot(updateBotBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update bot \"${bot.name}\"`)\n })\n line.success('Bot deployed')\n this.displayWebhookUrls(updatedBot)\n }\n\n private async _createNewBot(api: ApiClient): Promise<bpclient.Bot> {\n const line = this.logger.line()\n const { bot: createdBot } = await api.client.createBot({}).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not create bot')\n })\n line.success(`Bot created with ID \"${createdBot.id}\" and name \"${createdBot.name}\"`)\n await this.projectCache.set('botId', createdBot.id)\n return createdBot\n }\n\n private async _getExistingBot(api: ApiClient, botId: string | undefined): Promise<bpclient.Bot> {\n const promptedBotId = await this.projectCache.sync('botId', botId, async (defaultId) => {\n const userBots = await api\n .listAllPages(api.client.listBots, (r) => r.bots)\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not fetch existing bots')\n })\n\n if (!userBots.length) {\n throw new errors.NoBotsFoundError()\n }\n\n const initial = userBots.find((bot) => bot.id === defaultId)\n\n const prompted = await this.prompt.select('Which bot do you want to deploy?', {\n initial: initial && { title: initial.name, value: initial.id },\n choices: userBots.map((bot) => ({ title: bot.name, value: bot.id })),\n })\n\n if (!prompted) {\n throw new errors.ParamRequiredError('Bot Id')\n }\n\n return prompted\n })\n\n const { bot: fetchedBot } = await api.client.getBot({ id: promptedBotId }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not get bot info')\n })\n\n return fetchedBot\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAkB;AAClB,SAAoB;AACpB,sBAAqC;AAErC,8BAAoE;AAEpE,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,2BAA6B;AAC7B,6BAA+B;AAGxB,MAAM,sBAAsB,sCAAwC;AAAA,EACzE,MAAa,MAAqB;AAChC,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAC3D,QAAI,IAAI,QAAQ,OAAO,uBAAuB;AAC5C,WAAK,OAAO,IAAI,oBAAoB,IAAI,KAAK;AAAA,IAC/C;AAEA,QAAI,CAAC,KAAK,KAAK,SAAS;AACtB,YAAM,KAAK,UAAU;AAAA,IACvB;AAEA,UAAM,iBAAiB,MAAM,KAAK,gCAAgC;AAClE,QAAI,gBAAgB;AAClB,aAAO,KAAK,mBAAmB,KAAK,cAAc;AAAA,IACpD;AACA,WAAO,KAAK,WAAW,KAAK,KAAK,KAAK,OAAO,KAAK,KAAK,YAAY;AAAA,EACrE;AAAA,EAEA,MAAc,YAAY;AACxB,WAAO,IAAI,kCAAa,KAAK,KAAK,KAAK,QAAQ,KAAK,QAAQ,KAAK,IAAI,EAAE,IAAI;AAAA,EAC7E;AAAA,EAEA,MAAc,mBAAmB,KAAgB,gBAA6C;AAC5F,UAAM,UAAU,KAAK,aAAa,IAAI;AACtC,QAAI,OAAO,MAAM,GAAG,SAAS,SAAS,SAAS,OAAO;AAEtD,UAAM,UAAU,MAAM,KAAK,cAAc,gBAAgB,KAAK,IAAI;AAElE,eAAW,CAAC,YAAY,WAAW,KAAK,OAAO,QAAQ,OAAO,GAAG;AAC/D,aAAO,KAAK,QAAQ,IAA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,IAAI,OAAO,SAAS;AAE3D,YAAM,WAAW,MAAM,KAAK,OAAO,OAAO,oCAAoC;AAAA,QAC5E,SAAS,WAAW,EAAE,OAAO,QAAQ,MAAM,OAAO,QAAQ,GAAG;AAAA,QAC7D,SAAS,SAAS,IAAI,CAAC,SAAS,EAAE,OAAO,IAAI,MAAM,OAAO,IAAI,GAAG,EAAE;AAAA,MACrE,CAAC;AAED,UAAI,CAAC,UAAU;AACb,cAAM,IAAI,OAAO,mBAAmB,QAAQ;AAAA,MAC9C;AAEA,aAAO;AAAA,IACT,CAAC;AAED,UAAM,EAAE,KAAK,WAAW,IAAI,MAAM,IAAI,OAAO,OAAO,EAAE,IAAI,cAAc,CAAC,EAAE,MAAM,CAAC,WAAW;AAC3F,YAAM,OAAO,iBAAiB,KAAK,QAAQ,wBAAwB;AAAA,IACrE,CAAC;AAED,WAAO;AAAA,EACT;AACF;",
6
6
  "names": ["chalk"]
7
7
  }
@@ -199,7 +199,7 @@ class DevCommand extends import_project_command.ProjectCommand {
199
199
  const line = this.logger.line();
200
200
  line.started(`Deploying dev integration ${import_chalk.default.bold(integrationDef.name)}...`);
201
201
  const integrationBody = {
202
- ...this.parseIntegrationDefinition(integrationDef),
202
+ ...this.prepareIntegrationDefinition(integrationDef),
203
203
  url: externalUrl
204
204
  };
205
205
  if (integration) {
@@ -258,7 +258,8 @@ class DevCommand extends import_project_command.ProjectCommand {
258
258
  {
259
259
  id: bot.id,
260
260
  url: externalUrl,
261
- ...this.parseBot(botImpl)
261
+ ...this.prepareBot(botImpl),
262
+ ...await this.prepareBotIntegrationInstances(botImpl, api)
262
263
  },
263
264
  bot
264
265
  );
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/command-implementations/dev-command.ts"],
4
- "sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport type * as bpsdk from '@botpress/sdk'\nimport { TunnelRequest, TunnelResponse } from '@bpinternal/tunnel'\nimport axios, { AxiosRequestConfig, AxiosResponse } from 'axios'\nimport chalk from 'chalk'\nimport * as pathlib from 'path'\nimport * as uuid from 'uuid'\nimport { prepareUpdateBotBody } from '../api/bot-body'\nimport type { ApiClient } from '../api/client'\nimport { prepareUpdateIntegrationBody, CreateIntegrationBody } from '../api/integration-body'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport * as utils from '../utils'\nimport { Worker } from '../worker'\nimport { BuildCommand } from './build-command'\nimport { ProjectCommand } from './project-command'\n\nconst DEFAULT_BOT_PORT = 8075\nconst DEFAULT_INTEGRATION_PORT = 8076\nconst TUNNEL_HELLO_INTERVAL = 5000\n\nexport type DevCommandDefinition = typeof commandDefinitions.dev\nexport class DevCommand extends ProjectCommand<DevCommandDefinition> {\n private _initialDef: bpsdk.IntegrationDefinition | undefined = undefined\n\n public async run(): Promise<void> {\n this.logger.warn('This command is experimental and subject to breaking changes without notice.')\n\n const api = await this.ensureLoginAndCreateClient(this.argv)\n\n this._initialDef = await this.readIntegrationDefinitionFromFS()\n\n let env: Record<string, string> = {\n ...process.env,\n BP_API_URL: api.url,\n BP_TOKEN: api.token,\n }\n\n let defaultPort = DEFAULT_BOT_PORT\n if (this._initialDef) {\n defaultPort = DEFAULT_INTEGRATION_PORT\n const secrets = await this.promptSecrets(this._initialDef, this.argv)\n env = { ...env, ...secrets }\n }\n\n const port = this.argv.port ?? defaultPort\n\n const urlParseResult = utils.url.parse(this.argv.tunnelUrl)\n if (urlParseResult.status === 'error') {\n throw new errors.BotpressCLIError(`Invalid tunnel URL: ${urlParseResult.error}`)\n }\n\n const tunnelId = uuid.v4()\n\n const { url: parsedTunnelUrl } = urlParseResult\n const isSecured = parsedTunnelUrl.protocol === 'https' || parsedTunnelUrl.protocol === 'wss'\n\n const wsTunnelUrl: string = utils.url.format({ ...parsedTunnelUrl, protocol: isSecured ? 'wss' : 'ws' })\n const httpTunnelUrl: string = utils.url.format({\n ...parsedTunnelUrl,\n protocol: isSecured ? 'https' : 'http',\n path: `/${tunnelId}`,\n })\n\n 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(() => tunnel.hello(), TUNNEL_HELLO_INTERVAL)\n tunnel.events.on('close', () => clearInterval(timer))\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 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.filter((e) => pathlib.extname(e.path) === '.ts')\n if (typescriptEvents.length === 0) {\n return\n }\n\n this.logger.log('Changes detected, rebuilding')\n await this._restart(api, worker, httpTunnelUrl)\n },\n {\n ignore: [this.projectPaths.abs.outDir],\n }\n )\n\n await Promise.race([worker.wait(), watcher.wait(), supervisor.wait()])\n\n if (worker.running) {\n await worker.kill()\n }\n await watcher.close()\n supervisor.close()\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, 'An error occurred while running the dev server')\n } finally {\n if (worker.running) {\n await worker.kill()\n }\n }\n }\n\n private _restart = async (api: ApiClient, worker: Worker, tunnelUrl: string) => {\n 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: ApiClient, tunnelUrl: string) => {\n const integrationDef = await this.readIntegrationDefinitionFromFS()\n if (integrationDef) {\n this._checkSecrets(integrationDef)\n await this._deployDevIntegration(api, tunnelUrl, integrationDef)\n } else {\n await this._deployDevBot(api, tunnelUrl)\n }\n }\n\n private _checkSecrets(integrationDef: bpsdk.IntegrationDefinition) {\n const initialSecrets = this._initialDef?.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.outFile\n const importPath = utils.path.toUnix(outfile)\n const requireFrom = utils.path.rmExtension(importPath)\n const code = `require('${requireFrom}').default.start(${port})`\n const worker = await Worker.spawn(\n {\n type: 'code',\n code,\n env,\n },\n this.logger\n ).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not start dev worker')\n })\n\n return worker\n }\n\n private _runBuild() {\n return new BuildCommand(this.api, this.prompt, this.logger, this.argv).run()\n }\n\n private async _deployDevIntegration(\n api: ApiClient,\n externalUrl: string,\n integrationDef: bpsdk.IntegrationDefinition\n ): Promise<void> {\n const devId = await this.projectCache.get('devId')\n\n let integration: bpclient.Integration | undefined = undefined\n\n if (devId) {\n const resp = await api.client.getIntegration({ id: devId }).catch(async (thrown) => {\n const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev integration with id \"${devId}\"`)\n this.logger.warn(err.message)\n return { integration: undefined }\n })\n\n if (resp.integration?.dev) {\n integration = resp.integration\n } else {\n await this.projectCache.rm('devId')\n }\n }\n\n const line = this.logger.line()\n line.started(`Deploying dev integration ${chalk.bold(integrationDef.name)}...`)\n\n const integrationBody: CreateIntegrationBody = {\n ...this.parseIntegrationDefinition(integrationDef),\n url: externalUrl,\n }\n\n if (integration) {\n const updateIntegrationBody = prepareUpdateIntegrationBody(\n { ...integrationBody, 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({ ...integrationBody, 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}\"`)\n line.commit()\n\n await this.projectCache.set('devId', integration.id)\n }\n\n private async _deployDevBot(api: ApiClient, externalUrl: string): Promise<void> {\n const devId = await this.projectCache.get('devId')\n\n let bot: bpclient.Bot | undefined = undefined\n\n if (devId) {\n const resp = await api.client.getBot({ id: devId }).catch(async (thrown) => {\n const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev bot with id \"${devId}\"`)\n this.logger.warn(err.message)\n return { bot: undefined }\n })\n\n if (resp.bot?.dev) {\n bot = resp.bot\n } else {\n await this.projectCache.rm('devId')\n }\n }\n\n if (!bot) {\n const createLine = this.logger.line()\n createLine.started('Creating dev bot...')\n const resp = await api.client\n .createBot({\n dev: true,\n url: externalUrl,\n })\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not deploy dev bot')\n })\n\n bot = resp.bot\n createLine.success(`Dev Bot created with id \"${bot.id}\"`)\n createLine.commit()\n await this.projectCache.set('devId', bot.id)\n }\n\n const outfile = this.projectPaths.abs.outFile\n const { default: botImpl } = utils.require.requireJsFile<{ default: bpsdk.Bot }>(outfile)\n\n const updateLine = this.logger.line()\n updateLine.started('Deploying dev bot...')\n\n const updateBotBody = prepareUpdateBotBody(\n {\n id: bot.id,\n url: externalUrl,\n ...this.parseBot(botImpl),\n },\n bot\n )\n\n const { bot: updatedBot } = await api.client.updateBot(updateBotBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not deploy dev bot')\n })\n updateLine.success(`Dev Bot deployed with id \"${updatedBot.id}\"`)\n updateLine.commit()\n\n this.displayWebhookUrls(updatedBot)\n }\n\n private _forwardTunnelRequest = async (baseUrl: string, request: TunnelRequest): Promise<TunnelResponse> => {\n const axiosConfig = {\n method: request.method,\n url: this._formatLocalUrl(baseUrl, request),\n headers: request.headers,\n data: request.body,\n responseType: 'text',\n validateStatus: () => true,\n } satisfies AxiosRequestConfig\n\n this.logger.debug(`Forwarding request to ${axiosConfig.url}`)\n const response = await axios(axiosConfig)\n this.logger.debug('Sending back response up the tunnel')\n\n return {\n requestId: request.id,\n status: response.status,\n headers: this._getHeaders(response.headers),\n body: response.data,\n }\n }\n\n private _formatLocalUrl = (baseUrl: string, req: TunnelRequest): string => {\n if (req.query) {\n return `${baseUrl}${req.path}?${req.query}`\n }\n return `${baseUrl}${req.path}`\n }\n\n private _getHeaders = (res: AxiosResponse['headers']): TunnelResponse['headers'] => {\n const headers: TunnelResponse['headers'] = {}\n for (const key in res) {\n if (typeof res[key] === 'string' || typeof res[key] === 'number') {\n headers[key] = res[key]\n }\n }\n return headers\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAyD;AACzD,mBAAkB;AAClB,cAAyB;AACzB,WAAsB;AACtB,sBAAqC;AAErC,8BAAoE;AAEpE,aAAwB;AACxB,YAAuB;AACvB,oBAAuB;AACvB,2BAA6B;AAC7B,6BAA+B;AAE/B,MAAM,mBAAmB;AACzB,MAAM,2BAA2B;AACjC,MAAM,wBAAwB;AAGvB,MAAM,mBAAmB,sCAAqC;AAAA,EAC3D,cAAuD;AAAA,EAE/D,MAAa,MAAqB;AAChC,SAAK,OAAO,KAAK,8EAA8E;AAE/F,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAE3D,SAAK,cAAc,MAAM,KAAK,gCAAgC;AAE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AACA,WAAO,GAAG,UAAU,IAAI;AAAA,EAC1B;AAAA,EAEQ,cAAc,CAAC,QAA6D;AAClF,UAAM,UAAqC,CAAC;AAC5C,eAAW,OAAO,KAAK;AACrB,UAAI,OAAO,IAAI,SAAS,YAAY,OAAO,IAAI,SAAS,UAAU;AAChE,gBAAQ,OAAO,IAAI;AAAA,MACrB;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;",
4
+ "sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport type * as bpsdk from '@botpress/sdk'\nimport { TunnelRequest, TunnelResponse } from '@bpinternal/tunnel'\nimport axios, { AxiosRequestConfig, AxiosResponse } from 'axios'\nimport chalk from 'chalk'\nimport * as pathlib from 'path'\nimport * as uuid from 'uuid'\nimport { prepareUpdateBotBody } from '../api/bot-body'\nimport type { ApiClient } from '../api/client'\nimport { prepareUpdateIntegrationBody, CreateIntegrationBody } from '../api/integration-body'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport * as utils from '../utils'\nimport { Worker } from '../worker'\nimport { BuildCommand } from './build-command'\nimport { ProjectCommand } from './project-command'\n\nconst DEFAULT_BOT_PORT = 8075\nconst DEFAULT_INTEGRATION_PORT = 8076\nconst TUNNEL_HELLO_INTERVAL = 5000\n\nexport type DevCommandDefinition = typeof commandDefinitions.dev\nexport class DevCommand extends ProjectCommand<DevCommandDefinition> {\n private _initialDef: bpsdk.IntegrationDefinition | undefined = undefined\n\n public async run(): Promise<void> {\n this.logger.warn('This command is experimental and subject to breaking changes without notice.')\n\n const api = await this.ensureLoginAndCreateClient(this.argv)\n\n this._initialDef = await this.readIntegrationDefinitionFromFS()\n\n let env: Record<string, string> = {\n ...process.env,\n BP_API_URL: api.url,\n BP_TOKEN: api.token,\n }\n\n let defaultPort = DEFAULT_BOT_PORT\n if (this._initialDef) {\n defaultPort = DEFAULT_INTEGRATION_PORT\n const secrets = await this.promptSecrets(this._initialDef, this.argv)\n env = { ...env, ...secrets }\n }\n\n const port = this.argv.port ?? defaultPort\n\n const urlParseResult = utils.url.parse(this.argv.tunnelUrl)\n if (urlParseResult.status === 'error') {\n throw new errors.BotpressCLIError(`Invalid tunnel URL: ${urlParseResult.error}`)\n }\n\n const tunnelId = uuid.v4()\n\n const { url: parsedTunnelUrl } = urlParseResult\n const isSecured = parsedTunnelUrl.protocol === 'https' || parsedTunnelUrl.protocol === 'wss'\n\n const wsTunnelUrl: string = utils.url.format({ ...parsedTunnelUrl, protocol: isSecured ? 'wss' : 'ws' })\n const httpTunnelUrl: string = utils.url.format({\n ...parsedTunnelUrl,\n protocol: isSecured ? 'https' : 'http',\n path: `/${tunnelId}`,\n })\n\n 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(() => tunnel.hello(), TUNNEL_HELLO_INTERVAL)\n tunnel.events.on('close', () => clearInterval(timer))\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 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.filter((e) => pathlib.extname(e.path) === '.ts')\n if (typescriptEvents.length === 0) {\n return\n }\n\n this.logger.log('Changes detected, rebuilding')\n await this._restart(api, worker, httpTunnelUrl)\n },\n {\n ignore: [this.projectPaths.abs.outDir],\n }\n )\n\n await Promise.race([worker.wait(), watcher.wait(), supervisor.wait()])\n\n if (worker.running) {\n await worker.kill()\n }\n await watcher.close()\n supervisor.close()\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, 'An error occurred while running the dev server')\n } finally {\n if (worker.running) {\n await worker.kill()\n }\n }\n }\n\n private _restart = async (api: ApiClient, worker: Worker, tunnelUrl: string) => {\n 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: ApiClient, tunnelUrl: string) => {\n const integrationDef = await this.readIntegrationDefinitionFromFS()\n if (integrationDef) {\n this._checkSecrets(integrationDef)\n await this._deployDevIntegration(api, tunnelUrl, integrationDef)\n } else {\n await this._deployDevBot(api, tunnelUrl)\n }\n }\n\n private _checkSecrets(integrationDef: bpsdk.IntegrationDefinition) {\n const initialSecrets = this._initialDef?.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.outFile\n const importPath = utils.path.toUnix(outfile)\n const requireFrom = utils.path.rmExtension(importPath)\n const code = `require('${requireFrom}').default.start(${port})`\n const worker = await Worker.spawn(\n {\n type: 'code',\n code,\n env,\n },\n this.logger\n ).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not start dev worker')\n })\n\n return worker\n }\n\n private _runBuild() {\n return new BuildCommand(this.api, this.prompt, this.logger, this.argv).run()\n }\n\n private async _deployDevIntegration(\n api: ApiClient,\n externalUrl: string,\n integrationDef: bpsdk.IntegrationDefinition\n ): Promise<void> {\n const devId = await this.projectCache.get('devId')\n\n let integration: bpclient.Integration | undefined = undefined\n\n if (devId) {\n const resp = await api.client.getIntegration({ id: devId }).catch(async (thrown) => {\n const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev integration with id \"${devId}\"`)\n this.logger.warn(err.message)\n return { integration: undefined }\n })\n\n if (resp.integration?.dev) {\n integration = resp.integration\n } else {\n await this.projectCache.rm('devId')\n }\n }\n\n const line = this.logger.line()\n line.started(`Deploying dev integration ${chalk.bold(integrationDef.name)}...`)\n\n const integrationBody: CreateIntegrationBody = {\n ...this.prepareIntegrationDefinition(integrationDef),\n url: externalUrl,\n }\n\n if (integration) {\n const updateIntegrationBody = prepareUpdateIntegrationBody(\n { ...integrationBody, 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({ ...integrationBody, 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}\"`)\n line.commit()\n\n await this.projectCache.set('devId', integration.id)\n }\n\n private async _deployDevBot(api: ApiClient, externalUrl: string): Promise<void> {\n const devId = await this.projectCache.get('devId')\n\n let bot: bpclient.Bot | undefined = undefined\n\n if (devId) {\n const resp = await api.client.getBot({ id: devId }).catch(async (thrown) => {\n const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev bot with id \"${devId}\"`)\n this.logger.warn(err.message)\n return { bot: undefined }\n })\n\n if (resp.bot?.dev) {\n bot = resp.bot\n } else {\n await this.projectCache.rm('devId')\n }\n }\n\n if (!bot) {\n const createLine = this.logger.line()\n createLine.started('Creating dev bot...')\n const resp = await api.client\n .createBot({\n dev: true,\n url: externalUrl,\n })\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not deploy dev bot')\n })\n\n bot = resp.bot\n createLine.success(`Dev Bot created with id \"${bot.id}\"`)\n createLine.commit()\n await this.projectCache.set('devId', bot.id)\n }\n\n const outfile = this.projectPaths.abs.outFile\n const { default: botImpl } = utils.require.requireJsFile<{ default: bpsdk.Bot }>(outfile)\n\n const updateLine = this.logger.line()\n updateLine.started('Deploying dev bot...')\n\n const updateBotBody = prepareUpdateBotBody(\n {\n id: bot.id,\n url: externalUrl,\n ...this.prepareBot(botImpl),\n ...(await this.prepareBotIntegrationInstances(botImpl, api)),\n },\n bot\n )\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 updateLine.success(`Dev Bot deployed with id \"${updatedBot.id}\"`)\n updateLine.commit()\n\n this.displayWebhookUrls(updatedBot)\n }\n\n private _forwardTunnelRequest = async (baseUrl: string, request: TunnelRequest): Promise<TunnelResponse> => {\n const axiosConfig = {\n method: request.method,\n url: this._formatLocalUrl(baseUrl, request),\n headers: request.headers,\n data: request.body,\n responseType: 'text',\n validateStatus: () => true,\n } satisfies AxiosRequestConfig\n\n this.logger.debug(`Forwarding request to ${axiosConfig.url}`)\n const response = await axios(axiosConfig)\n this.logger.debug('Sending back response up the tunnel')\n\n return {\n requestId: request.id,\n status: response.status,\n headers: this._getHeaders(response.headers),\n body: response.data,\n }\n }\n\n private _formatLocalUrl = (baseUrl: string, req: TunnelRequest): string => {\n if (req.query) {\n return `${baseUrl}${req.path}?${req.query}`\n }\n return `${baseUrl}${req.path}`\n }\n\n private _getHeaders = (res: AxiosResponse['headers']): TunnelResponse['headers'] => {\n const headers: TunnelResponse['headers'] = {}\n for (const key in res) {\n if (typeof res[key] === 'string' || typeof res[key] === 'number') {\n headers[key] = res[key]\n }\n }\n return headers\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;A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AAS,QAAQ;AAAA,MACjB,MAAM,QAAQ;AAAA,MACd,cAAc;AAAA,MACd,gBAAgB,MAAM;AAAA,IACxB;AAEA,SAAK,OAAO,MAAM,yBAAyB,YAAY,KAAK;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,UAAU,IAAI,QAAQ,IAAI;AAAA,IACtC;AACA,WAAO,GAAG,UAAU,IAAI;AAAA,EAC1B;AAAA,EAEQ,cAAc,CAAC,QAA6D;AAClF,UAAM,UAAqC,CAAC;AAC5C,eAAW,OAAO,KAAK;AACrB,UAAI,OAAO,IAAI,SAAS,YAAY,OAAO,IAAI,SAAS,UAAU;AAChE,gBAAQ,OAAO,IAAI;AAAA,MACrB;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;",
6
6
  "names": ["chalk", "axios"]
7
7
  }
@@ -41,6 +41,9 @@ class GetIntegrationCommand extends import_global_command.GlobalCommand {
41
41
  if (!parsedRef) {
42
42
  throw new errors.InvalidIntegrationReferenceError(this.argv.integrationRef);
43
43
  }
44
+ if (parsedRef.type === "path") {
45
+ throw new errors.BotpressCLIError("Cannot get local integration");
46
+ }
44
47
  try {
45
48
  const integration = await api.findIntegration(parsedRef);
46
49
  if (integration) {
@@ -77,6 +80,9 @@ class DeleteIntegrationCommand extends import_global_command.GlobalCommand {
77
80
  if (!parsedRef) {
78
81
  throw new errors.InvalidIntegrationReferenceError(this.argv.integrationRef);
79
82
  }
83
+ if (parsedRef.type === "path") {
84
+ throw new errors.BotpressCLIError("Cannot delete local integration");
85
+ }
80
86
  let integration;
81
87
  try {
82
88
  integration = await api.findPrivateIntegration(parsedRef);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/command-implementations/integration-commands.ts"],
4
- "sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport chalk from 'chalk'\nimport _ from 'lodash'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport { parseIntegrationRef } from '../integration-ref'\nimport { GlobalCommand } from './global-command'\n\nexport type GetIntegrationCommandDefinition = typeof commandDefinitions.integrations.subcommands.get\nexport class GetIntegrationCommand extends GlobalCommand<GetIntegrationCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n const parsedRef = parseIntegrationRef(this.argv.integrationRef)\n if (!parsedRef) {\n throw new errors.InvalidIntegrationReferenceError(this.argv.integrationRef)\n }\n\n try {\n const integration = await api.findIntegration(parsedRef)\n if (integration) {\n this.logger.success(`Integration ${chalk.bold(this.argv.integrationRef)}:`)\n this.logger.json(integration)\n return\n }\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, `Could not get integration ${this.argv.integrationRef}`)\n }\n\n throw new errors.BotpressCLIError(`Integration ${this.argv.integrationRef} not found`)\n }\n}\n\nexport type ListIntegrationsCommandDefinition = typeof commandDefinitions.integrations.subcommands.list\nexport class ListIntegrationsCommand extends GlobalCommand<ListIntegrationsCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n\n const privateLister = (req: { nextToken?: string }) =>\n api.client.listIntegrations({ nextToken: req.nextToken, name: this.argv.name, version: this.argv.version })\n\n const publicLister = (req: { nextToken?: string }) =>\n api.client.listPublicIntegrations({ nextToken: req.nextToken, name: this.argv.name, version: this.argv.version })\n\n try {\n const privateIntegrations = await api.listAllPages(privateLister, (r) => r.integrations)\n const publicIntegrations = await api.listAllPages(publicLister, (r) => r.integrations)\n const integrations = _.uniqBy([...privateIntegrations, ...publicIntegrations], (i) => i.id)\n\n this.logger.success('Integrations:')\n this.logger.json(integrations)\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not list integrations')\n }\n }\n}\n\nexport type DeleteIntegrationCommandDefinition = typeof commandDefinitions.integrations.subcommands.delete\nexport class DeleteIntegrationCommand extends GlobalCommand<DeleteIntegrationCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n const parsedRef = parseIntegrationRef(this.argv.integrationRef)\n if (!parsedRef) {\n throw new errors.InvalidIntegrationReferenceError(this.argv.integrationRef)\n }\n\n let integration: bpclient.Integration | undefined\n try {\n integration = await api.findPrivateIntegration(parsedRef)\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, `Could not get integration ${this.argv.integrationRef}`)\n }\n\n if (!integration) {\n const publicIntegration = await api.findPublicIntegration(parsedRef)\n if (publicIntegration) {\n throw new errors.BotpressCLIError(`Integration ${this.argv.integrationRef} does not belong to your workspace`)\n }\n\n throw new errors.BotpressCLIError(`Integration ${this.argv.integrationRef} not found`)\n }\n\n try {\n await api.client.deleteIntegration({ id: integration.id })\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, `Could not delete integration ${this.argv.integrationRef}`)\n }\n\n this.logger.success(`Integration ${chalk.bold(this.argv.integrationRef)} deleted`)\n return\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAClB,oBAAc;AAEd,aAAwB;AACxB,6BAAoC;AACpC,4BAA8B;AAGvB,MAAM,8BAA8B,oCAA+C;AAAA,EACxF,MAAa,MAAqB;AAChC,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAC3D,UAAM,gBAAY,4CAAoB,KAAK,KAAK,cAAc;AAC9D,QAAI,CAAC,WAAW;AACd,YAAM,IAAI,OAAO,iCAAiC,KAAK,KAAK,cAAc;AAAA,IAC5E;AAEA,Q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AAK,2BAA2B,KAAK,IAAI;AAC3D,UAAM,gBAAY,4CAAoB,KAAK,KAAK,cAAc;AAC9D,QAAI,CAAC,WAAW;AACd,YAAM,IAAI,OAAO,iCAAiC,KAAK,KAAK,cAAc;AAAA,IAC5E;AAEA,QAAI;AACJ,QAAI;AACF,oBAAc,MAAM,IAAI,uBAAuB,SAAS;AAAA,IAC1D,SAAS,QAAP;AACA,YAAM,OAAO,iBAAiB,KAAK,QAAQ,6BAA6B,KAAK,KAAK,gBAAgB;AAAA,IACpG;AAEA,QAAI,CAAC,aAAa;AAChB,YAAM,oBAAoB,MAAM,IAAI,sBAAsB,SAAS;AACnE,UAAI,mBAAmB;AACrB,cAAM,IAAI,OAAO,iBAAiB,eAAe,KAAK,KAAK,kDAAkD;AAAA,MAC/G;AAEA,YAAM,IAAI,OAAO,iBAAiB,eAAe,KAAK,KAAK,0BAA0B;AAAA,IACvF;AAEA,QAAI;AACF,YAAM,IAAI,OAAO,kBAAkB,EAAE,IAAI,YAAY,GAAG,CAAC;AAAA,IAC3D,SAAS,QAAP;AACA,YAAM,OAAO,iBAAiB,KAAK,QAAQ,gCAAgC,KAAK,KAAK,gBAAgB;AAAA,IACvG;AAEA,SAAK,OAAO,QAAQ,eAAe,aAAAD,QAAM,KAAK,KAAK,KAAK,cAAc,WAAW;AACjF;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport chalk from 'chalk'\nimport _ from 'lodash'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport { parseIntegrationRef } from '../integration-ref'\nimport { GlobalCommand } from './global-command'\n\nexport type GetIntegrationCommandDefinition = typeof commandDefinitions.integrations.subcommands.get\nexport class GetIntegrationCommand extends GlobalCommand<GetIntegrationCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n const parsedRef = parseIntegrationRef(this.argv.integrationRef)\n if (!parsedRef) {\n throw new errors.InvalidIntegrationReferenceError(this.argv.integrationRef)\n }\n if (parsedRef.type === 'path') {\n throw new errors.BotpressCLIError('Cannot get local integration')\n }\n\n try {\n const integration = await api.findIntegration(parsedRef)\n if (integration) {\n this.logger.success(`Integration ${chalk.bold(this.argv.integrationRef)}:`)\n this.logger.json(integration)\n return\n }\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, `Could not get integration ${this.argv.integrationRef}`)\n }\n\n throw new errors.BotpressCLIError(`Integration ${this.argv.integrationRef} not found`)\n }\n}\n\nexport type ListIntegrationsCommandDefinition = typeof commandDefinitions.integrations.subcommands.list\nexport class ListIntegrationsCommand extends GlobalCommand<ListIntegrationsCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n\n const privateLister = (req: { nextToken?: string }) =>\n api.client.listIntegrations({ nextToken: req.nextToken, name: this.argv.name, version: this.argv.version })\n\n const publicLister = (req: { nextToken?: string }) =>\n api.client.listPublicIntegrations({ nextToken: req.nextToken, name: this.argv.name, version: this.argv.version })\n\n try {\n const privateIntegrations = await api.listAllPages(privateLister, (r) => r.integrations)\n const publicIntegrations = await api.listAllPages(publicLister, (r) => r.integrations)\n const integrations = _.uniqBy([...privateIntegrations, ...publicIntegrations], (i) => i.id)\n\n this.logger.success('Integrations:')\n this.logger.json(integrations)\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not list integrations')\n }\n }\n}\n\nexport type DeleteIntegrationCommandDefinition = typeof commandDefinitions.integrations.subcommands.delete\nexport class DeleteIntegrationCommand extends GlobalCommand<DeleteIntegrationCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n const parsedRef = parseIntegrationRef(this.argv.integrationRef)\n if (!parsedRef) {\n throw new errors.InvalidIntegrationReferenceError(this.argv.integrationRef)\n }\n if (parsedRef.type === 'path') {\n throw new errors.BotpressCLIError('Cannot delete local integration')\n }\n\n let integration: bpclient.Integration | undefined\n try {\n integration = await api.findPrivateIntegration(parsedRef)\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, `Could not get integration ${this.argv.integrationRef}`)\n }\n\n if (!integration) {\n const publicIntegration = await api.findPublicIntegration(parsedRef)\n if (publicIntegration) {\n throw new errors.BotpressCLIError(`Integration ${this.argv.integrationRef} does not belong to your workspace`)\n }\n\n throw new errors.BotpressCLIError(`Integration ${this.argv.integrationRef} not found`)\n }\n\n try {\n await api.client.deleteIntegration({ id: integration.id })\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, `Could not delete integration ${this.argv.integrationRef}`)\n }\n\n this.logger.success(`Integration ${chalk.bold(this.argv.integrationRef)} deleted`)\n return\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAClB,oBAAc;AAEd,aAAwB;AACxB,6BAAoC;AACpC,4BAA8B;AAGvB,MAAM,8BAA8B,oCAA+C;AAAA,EACxF,MAAa,MAAqB;AAChC,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAC3D,UAAM,gBAAY,4CAAoB,KAAK,KAAK,cAAc;AAC9D,QAAI,CAAC,WAAW;AACd,YAAM,IAAI,OAAO,iCAAiC,KAAK,KAAK,cAAc;AAAA,IAC5E;AACA,QAAI,UAAU,SAAS,QAAQ;AAC7B,YAAM,IAAI,OAAO,iBAAiB,8BAA8B;AAAA,IAClE;AAEA,QAAI;AACF,YAAM,cAAc,MAAM,IAAI,gBAAgB,SAAS;AACvD,UAAI,aAAa;AACf,aAAK,OAAO,QAAQ,eAAe,aAAAA,QAAM,KAAK,KAAK,KAAK,cAAc,IAAI;AAC1E,aAAK,OAAO,KAAK,WAAW;AAC5B;AAAA,MACF;AAAA,IACF,SAAS,QAAP;AACA,YAAM,OAAO,iBAAiB,KAAK,QAAQ,6BAA6B,KAAK,KAAK,gBAAgB;AAAA,IACpG;AAEA,UAAM,IAAI,OAAO,iBAAi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AAS,QAAP;AACA,YAAM,OAAO,iBAAiB,KAAK,QAAQ,6BAA6B,KAAK,KAAK,gBAAgB;AAAA,IACpG;AAEA,QAAI,CAAC,aAAa;AAChB,YAAM,oBAAoB,MAAM,IAAI,sBAAsB,SAAS;AACnE,UAAI,mBAAmB;AACrB,cAAM,IAAI,OAAO,iBAAiB,eAAe,KAAK,KAAK,kDAAkD;AAAA,MAC/G;AAEA,YAAM,IAAI,OAAO,iBAAiB,eAAe,KAAK,KAAK,0BAA0B;AAAA,IACvF;AAEA,QAAI;AACF,YAAM,IAAI,OAAO,kBAAkB,EAAE,IAAI,YAAY,GAAG,CAAC;AAAA,IAC3D,SAAS,QAAP;AACA,YAAM,OAAO,iBAAiB,KAAK,QAAQ,gCAAgC,KAAK,KAAK,gBAAgB;AAAA,IACvG;AAEA,SAAK,OAAO,QAAQ,eAAe,aAAAD,QAAM,KAAK,KAAK,KAAK,cAAc,WAAW;AACjF;AAAA,EACF;AACF;",
6
6
  "names": ["chalk", "_"]
7
7
  }
@@ -27,6 +27,7 @@ __export(project_command_exports, {
27
27
  ProjectCommand: () => ProjectCommand
28
28
  });
29
29
  module.exports = __toCommonJS(project_command_exports);
30
+ var import_bluebird = __toESM(require("bluebird"));
30
31
  var import_chalk = __toESM(require("chalk"));
31
32
  var import_fs = __toESM(require("fs"));
32
33
  var import_lodash = __toESM(require("lodash"));
@@ -34,6 +35,7 @@ var import_path = __toESM(require("path"));
34
35
  var codegen = __toESM(require("../code-generation"));
35
36
  var consts = __toESM(require("../consts"));
36
37
  var errors = __toESM(require("../errors"));
38
+ var import_integration_ref = require("../integration-ref");
37
39
  var utils = __toESM(require("../utils"));
38
40
  var import_global_command = require("./global-command");
39
41
  class ProjectPaths extends utils.path.PathStore {
@@ -57,10 +59,37 @@ class ProjectCommand extends import_global_command.GlobalCommand {
57
59
  get projectCache() {
58
60
  return new utils.cache.FSKeyValueCache(this.projectPaths.abs.projectCacheFile);
59
61
  }
60
- parseBot(bot) {
62
+ async prepareBotIntegrationInstances(bot, api) {
63
+ const integrationList = (0, import_lodash.default)(bot.props.integrations).values().filter(utils.guards.is.defined).value();
64
+ const { apiInstances, localInstances } = this._splitApiAndLocalIntegrationInstances(integrationList);
65
+ const fetchedInstances = await import_bluebird.default.map(localInstances, async (instance) => {
66
+ const ref = { type: "name", name: instance.name, version: instance.version };
67
+ const integration = await api.findIntegration(ref);
68
+ if (!integration) {
69
+ const formattedRef = (0, import_integration_ref.formatIntegrationRef)(ref);
70
+ throw new errors.BotpressCLIError(`Integration "${formattedRef}" not found`);
71
+ }
72
+ return { ...instance, id: integration.id };
73
+ });
74
+ return {
75
+ integrations: (0, import_lodash.default)([...fetchedInstances, ...apiInstances]).keyBy((i) => i.id).mapValues(({ enabled, configuration }) => ({ enabled, configuration })).value()
76
+ };
77
+ }
78
+ _splitApiAndLocalIntegrationInstances(instances) {
79
+ const apiInstances = [];
80
+ const localInstances = [];
81
+ for (const { id, ...instance } of instances) {
82
+ if (id) {
83
+ apiInstances.push({ ...instance, id });
84
+ } else {
85
+ localInstances.push({ ...instance, id: null });
86
+ }
87
+ }
88
+ return { apiInstances, localInstances };
89
+ }
90
+ prepareBot(bot) {
61
91
  return {
62
92
  ...bot.props,
63
- integrations: (0, import_lodash.default)(bot.props.integrations).values().filter(utils.guards.is.defined).keyBy((i) => i.id).mapValues(({ enabled, configuration }) => ({ enabled, configuration })).value(),
64
93
  configuration: bot.props.configuration ? {
65
94
  ...bot.props.configuration,
66
95
  schema: utils.schema.mapZodToJsonSchema(bot.props.configuration)
@@ -75,7 +104,7 @@ class ProjectCommand extends import_global_command.GlobalCommand {
75
104
  })) : void 0
76
105
  };
77
106
  }
78
- parseIntegrationDefinition(integration) {
107
+ prepareIntegrationDefinition(integration) {
79
108
  return {
80
109
  ...integration,
81
110
  configuration: integration.configuration ? {
@@ -110,9 +139,9 @@ class ProjectCommand extends import_global_command.GlobalCommand {
110
139
  })) : void 0
111
140
  };
112
141
  }
113
- async readIntegrationDefinitionFromFS() {
114
- const abs = this.projectPaths.abs;
115
- const rel = this.projectPaths.rel("workDir");
142
+ async readIntegrationDefinitionFromFS(projectPaths = this.projectPaths) {
143
+ const abs = projectPaths.abs;
144
+ const rel = projectPaths.rel("workDir");
116
145
  if (!import_fs.default.existsSync(abs.definition)) {
117
146
  this.logger.debug(`Integration definition not found at ${rel.definition}`);
118
147
  return;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/command-implementations/project-command.ts"],
4
- "sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport type * as bpsdk from '@botpress/sdk'\nimport type { YargsConfig } from '@bpinternal/yargs-extra'\nimport chalk from 'chalk'\nimport fs from 'fs'\nimport _ from 'lodash'\nimport pathlib from 'path'\nimport * as codegen from '../code-generation'\nimport type * as config from '../config'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport type { CommandArgv, CommandDefinition } from '../typings'\nimport * as utils from '../utils'\nimport { GlobalCommand } from './global-command'\n\nexport type ProjectCommandDefinition = CommandDefinition<typeof config.schemas.project>\nexport type ProjectCache = { botId: string; devId: string }\n\ntype ConfigurableProjectPaths = { entryPoint: string; outDir: string; workDir: string }\ntype ConstantProjectPaths = typeof consts.fromOutDir & typeof consts.fromWorkDir\ntype AllProjectPaths = ConfigurableProjectPaths & ConstantProjectPaths\n\nclass ProjectPaths extends utils.path.PathStore<keyof AllProjectPaths> {\n public constructor(argv: CommandArgv<ProjectCommandDefinition>) {\n const absWorkDir = utils.path.absoluteFrom(utils.path.cwd(), argv.workDir)\n const absEntrypoint = utils.path.absoluteFrom(absWorkDir, argv.entryPoint)\n const absOutDir = utils.path.absoluteFrom(absWorkDir, argv.outDir)\n super({\n workDir: absWorkDir,\n entryPoint: absEntrypoint,\n outDir: absOutDir,\n ..._.mapValues(consts.fromOutDir, (p) => utils.path.absoluteFrom(absOutDir, p)),\n ..._.mapValues(consts.fromWorkDir, (p) => utils.path.absoluteFrom(absWorkDir, p)),\n })\n }\n}\n\nexport abstract class ProjectCommand<C extends ProjectCommandDefinition> extends GlobalCommand<C> {\n protected get projectPaths() {\n return new ProjectPaths(this.argv)\n }\n\n protected get projectCache() {\n return new utils.cache.FSKeyValueCache<ProjectCache>(this.projectPaths.abs.projectCacheFile)\n }\n\n protected parseBot(bot: bpsdk.Bot) {\n return {\n ...bot.props,\n integrations: _(bot.props.integrations)\n .values()\n .filter(utils.guards.is.defined)\n .keyBy((i) => i.id)\n .mapValues(({ enabled, configuration }) => ({ enabled, configuration }))\n .value(),\n configuration: bot.props.configuration\n ? {\n ...bot.props.configuration,\n schema: utils.schema.mapZodToJsonSchema(bot.props.configuration),\n }\n : undefined,\n events: bot.props.events\n ? _.mapValues(bot.props.events, (event) => ({\n ...event,\n schema: utils.schema.mapZodToJsonSchema(event),\n }))\n : undefined,\n states: bot.props.states\n ? _.mapValues(bot.props.states, (state) => ({\n ...state,\n schema: utils.schema.mapZodToJsonSchema(state),\n }))\n : undefined,\n }\n }\n\n protected parseIntegrationDefinition(integration: bpsdk.IntegrationDefinition) {\n return {\n ...integration,\n configuration: integration.configuration\n ? {\n ...integration.configuration,\n schema: utils.schema.mapZodToJsonSchema(integration.configuration),\n }\n : undefined,\n events: integration.events\n ? _.mapValues(integration.events, (event) => ({\n ...event,\n schema: utils.schema.mapZodToJsonSchema(event),\n }))\n : undefined,\n actions: integration.actions\n ? _.mapValues(integration.actions, (action) => ({\n ...action,\n input: {\n ...action.input,\n schema: utils.schema.mapZodToJsonSchema(action.input),\n },\n output: {\n ...action.output,\n schema: utils.schema.mapZodToJsonSchema(action.output),\n },\n }))\n : undefined,\n channels: integration.channels\n ? _.mapValues(integration.channels, (channel) => ({\n ...channel,\n messages: _.mapValues(channel.messages, (message) => ({\n ...message,\n schema: utils.schema.mapZodToJsonSchema(message),\n })),\n }))\n : undefined,\n states: integration.states\n ? _.mapValues(integration.states, (state) => ({\n ...state,\n schema: utils.schema.mapZodToJsonSchema(state),\n }))\n : undefined,\n }\n }\n\n protected async readIntegrationDefinitionFromFS(): Promise<bpsdk.IntegrationDefinition | undefined> {\n const abs = this.projectPaths.abs\n const rel = this.projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.definition)) {\n this.logger.debug(`Integration definition not found at ${rel.definition}`)\n return\n }\n\n const { outputFiles } = await utils.esbuild.buildEntrypoint({\n cwd: abs.workDir,\n outfile: '',\n entrypoint: rel.definition,\n write: false,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read integration definition')\n }\n\n const { default: definition } = utils.require.requireJsCode<{ default: bpsdk.IntegrationDefinition }>(artifact.text)\n return definition\n }\n\n protected async writeGeneratedFilesToOutFolder(files: codegen.File[]) {\n for (const file of files) {\n const filePath = utils.path.absoluteFrom(this.projectPaths.abs.outDir, file.path)\n const dirPath = pathlib.dirname(filePath)\n await fs.promises.mkdir(dirPath, { recursive: true })\n await fs.promises.writeFile(filePath, file.content)\n }\n }\n\n protected displayWebhookUrls(bot: bpclient.Bot) {\n if (!_.keys(bot.integrations).length) {\n this.logger.debug('No integrations in bot')\n return\n }\n\n this.logger.log('Integrations:')\n for (const integration of Object.values(bot.integrations).filter(utils.guards.is.defined)) {\n if (!integration.enabled) {\n this.logger.log(`${chalk.grey(integration.name)} ${chalk.italic('(disabled)')}: ${integration.webhookUrl}`, {\n prefix: { symbol: '\u25CB', indent: 2 },\n })\n } else {\n this.logger.log(`${chalk.bold(integration.name)} : ${integration.webhookUrl}`, {\n prefix: { symbol: '\u25CF', indent: 2 },\n })\n }\n }\n }\n\n protected async promptSecrets(\n integrationDef: bpsdk.IntegrationDefinition,\n argv: YargsConfig<typeof config.schemas.secrets>\n ): Promise<Record<string, string>> {\n const { secrets: secretDefinitions } = integrationDef\n if (!secretDefinitions) {\n return {}\n }\n\n const secretArgv = this._parseArgvSecrets(argv.secrets)\n const invalidSecret = Object.keys(secretArgv).find((s) => !secretDefinitions[s])\n if (invalidSecret) {\n throw new errors.BotpressCLIError(`Secret ${invalidSecret} is not defined in integration definition`)\n }\n\n const values: Record<string, string> = {}\n for (const [secretName, { optional }] of Object.entries(secretDefinitions)) {\n const argvSecret = secretArgv[secretName]\n if (argvSecret) {\n this.logger.debug(`Using secret \"${secretName}\" from argv`)\n values[secretName] = argvSecret\n continue\n }\n\n const mode = optional ? 'optional' : 'required'\n const prompted = await this.prompt.text(`Enter value for secret \"${secretName}\" (${mode})`)\n if (prompted) {\n values[secretName] = prompted\n continue\n }\n\n if (optional) {\n this.logger.warn(`Secret \"${secretName}\" is unassigned`)\n continue\n }\n\n throw new errors.BotpressCLIError(`Secret \"${secretName}\" is required`)\n }\n\n const envVariables = _.mapKeys(values, (_v, k) => codegen.secretEnvVariableName(k))\n return envVariables\n }\n\n private _parseArgvSecrets(argvSecrets: string[]): Record<string, string> {\n const parsed: Record<string, string> = {}\n for (const secret of argvSecrets) {\n const [key, value] = this._splitOnce(secret, '=')\n if (!value) {\n throw new errors.BotpressCLIError(\n `Secret \"${key}\" is missing a value. Expected format: \"SECRET_NAME=secretValue\"`\n )\n }\n parsed[key!] = value\n }\n\n return parsed\n }\n\n private _splitOnce = (text: string, separator: string): [string, string | undefined] => {\n const index = text.indexOf(separator)\n if (index === -1) {\n return [text, undefined]\n }\n return [text.slice(0, index), text.slice(index + 1)]\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAkB;AAClB,gBAAe;AACf,oBAAc;AACd,kBAAoB;AACpB,cAAyB;AAEzB,aAAwB;AACxB,aAAwB;AAExB,YAAuB;AACvB,4BAA8B;AAS9B,MAAM,qBAAqB,MAAM,KAAK,UAAiC;AAAA,EAC9D,YAAY,MAA6C;AAC9D,UAAM,aAAa,MAAM,KAAK,aAAa,MAAM,KAAK,IAAI,GAAG,KAAK,OAAO;AACzE,UAAM,gBAAgB,MAAM,KAAK,aAAa,YAAY,KAAK,UAAU;AACzE,UAAM,YAAY,MAAM,KAAK,aAAa,YAA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BAAkB,aAA+C;AACvE,UAAM,SAAiC,CAAC;AACxC,eAAW,UAAU,aAAa;AAChC,YAAM,CAAC,KAAK,KAAK,IAAI,KAAK,WAAW,QAAQ,GAAG;AAChD,UAAI,CAAC,OAAO;AACV,cAAM,IAAI,OAAO;AAAA,UACf,WAAW;AAAA,QACb;AAAA,MACF;AACA,aAAO,OAAQ;AAAA,IACjB;AAEA,WAAO;AAAA,EACT;AAAA,EAEQ,aAAa,CAAC,MAAc,cAAoD;AACtF,UAAM,QAAQ,KAAK,QAAQ,SAAS;AACpC,QAAI,UAAU,IAAI;AAChB,aAAO,CAAC,MAAM,MAAS;AAAA,IACzB;AACA,WAAO,CAAC,KAAK,MAAM,GAAG,KAAK,GAAG,KAAK,MAAM,QAAQ,CAAC,CAAC;AAAA,EACrD;AACF;",
6
- "names": ["_", "fs", "pathlib", "chalk"]
4
+ "sourcesContent": ["import type * as bpclient from '@botpress/client'\nimport type * as bpsdk from '@botpress/sdk'\nimport type { YargsConfig } from '@bpinternal/yargs-extra'\nimport bluebird from 'bluebird'\nimport chalk from 'chalk'\nimport fs from 'fs'\nimport _ from 'lodash'\nimport pathlib from 'path'\nimport { ApiClient } from '../api/client'\nimport * as codegen from '../code-generation'\nimport type * as config from '../config'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport { formatIntegrationRef, IntegrationRef } from '../integration-ref'\nimport type { CommandArgv, CommandDefinition } from '../typings'\nimport * as utils from '../utils'\nimport { GlobalCommand } from './global-command'\n\nexport type ProjectCommandDefinition = CommandDefinition<typeof config.schemas.project>\nexport type ProjectCache = { botId: string; devId: string }\n\ntype ConfigurableProjectPaths = { entryPoint: string; outDir: string; workDir: string }\ntype ConstantProjectPaths = typeof consts.fromOutDir & typeof consts.fromWorkDir\ntype AllProjectPaths = ConfigurableProjectPaths & ConstantProjectPaths\n\ntype ApiIntegrationInstance = utils.types.Merge<bpsdk.IntegrationInstance<string>, { id: string }>\ntype LocalIntegrationInstance = utils.types.Merge<bpsdk.IntegrationInstance<string>, { id: null }>\n\nclass ProjectPaths extends utils.path.PathStore<keyof AllProjectPaths> {\n public constructor(argv: CommandArgv<ProjectCommandDefinition>) {\n const absWorkDir = utils.path.absoluteFrom(utils.path.cwd(), argv.workDir)\n const absEntrypoint = utils.path.absoluteFrom(absWorkDir, argv.entryPoint)\n const absOutDir = utils.path.absoluteFrom(absWorkDir, argv.outDir)\n super({\n workDir: absWorkDir,\n entryPoint: absEntrypoint,\n outDir: absOutDir,\n ..._.mapValues(consts.fromOutDir, (p) => utils.path.absoluteFrom(absOutDir, p)),\n ..._.mapValues(consts.fromWorkDir, (p) => utils.path.absoluteFrom(absWorkDir, p)),\n })\n }\n}\n\nexport abstract class ProjectCommand<C extends ProjectCommandDefinition> extends GlobalCommand<C> {\n protected get projectPaths() {\n return new ProjectPaths(this.argv)\n }\n\n protected get projectCache() {\n return new utils.cache.FSKeyValueCache<ProjectCache>(this.projectPaths.abs.projectCacheFile)\n }\n\n protected async prepareBotIntegrationInstances(bot: bpsdk.Bot, api: ApiClient) {\n const integrationList = _(bot.props.integrations).values().filter(utils.guards.is.defined).value()\n\n const { apiInstances, localInstances } = this._splitApiAndLocalIntegrationInstances(integrationList)\n\n const fetchedInstances: ApiIntegrationInstance[] = await bluebird.map(localInstances, async (instance) => {\n const ref: IntegrationRef = { type: 'name', name: instance.name, version: instance.version }\n const integration = await api.findIntegration(ref)\n if (!integration) {\n const formattedRef = formatIntegrationRef(ref)\n throw new errors.BotpressCLIError(`Integration \"${formattedRef}\" not found`)\n }\n return { ...instance, id: integration.id }\n })\n\n return {\n integrations: _([...fetchedInstances, ...apiInstances])\n .keyBy((i) => i.id)\n .mapValues(({ enabled, configuration }) => ({ enabled, configuration }))\n .value(),\n }\n }\n\n private _splitApiAndLocalIntegrationInstances(instances: bpsdk.IntegrationInstance<string>[]): {\n apiInstances: ApiIntegrationInstance[]\n localInstances: LocalIntegrationInstance[]\n } {\n const apiInstances: ApiIntegrationInstance[] = []\n const localInstances: LocalIntegrationInstance[] = []\n for (const { id, ...instance } of instances) {\n if (id) {\n apiInstances.push({ ...instance, id })\n } else {\n localInstances.push({ ...instance, id: null })\n }\n }\n\n return { apiInstances, localInstances }\n }\n\n protected prepareBot(bot: bpsdk.Bot) {\n return {\n ...bot.props,\n configuration: bot.props.configuration\n ? {\n ...bot.props.configuration,\n schema: utils.schema.mapZodToJsonSchema(bot.props.configuration),\n }\n : undefined,\n events: bot.props.events\n ? _.mapValues(bot.props.events, (event) => ({\n ...event,\n schema: utils.schema.mapZodToJsonSchema(event),\n }))\n : undefined,\n states: bot.props.states\n ? _.mapValues(bot.props.states, (state) => ({\n ...state,\n schema: utils.schema.mapZodToJsonSchema(state),\n }))\n : undefined,\n }\n }\n\n protected prepareIntegrationDefinition(integration: bpsdk.IntegrationDefinition) {\n return {\n ...integration,\n configuration: integration.configuration\n ? {\n ...integration.configuration,\n schema: utils.schema.mapZodToJsonSchema(integration.configuration),\n }\n : undefined,\n events: integration.events\n ? _.mapValues(integration.events, (event) => ({\n ...event,\n schema: utils.schema.mapZodToJsonSchema(event),\n }))\n : undefined,\n actions: integration.actions\n ? _.mapValues(integration.actions, (action) => ({\n ...action,\n input: {\n ...action.input,\n schema: utils.schema.mapZodToJsonSchema(action.input),\n },\n output: {\n ...action.output,\n schema: utils.schema.mapZodToJsonSchema(action.output),\n },\n }))\n : undefined,\n channels: integration.channels\n ? _.mapValues(integration.channels, (channel) => ({\n ...channel,\n messages: _.mapValues(channel.messages, (message) => ({\n ...message,\n schema: utils.schema.mapZodToJsonSchema(message),\n })),\n }))\n : undefined,\n states: integration.states\n ? _.mapValues(integration.states, (state) => ({\n ...state,\n schema: utils.schema.mapZodToJsonSchema(state),\n }))\n : undefined,\n }\n }\n\n protected async readIntegrationDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'definition'> = this.projectPaths\n ): Promise<bpsdk.IntegrationDefinition | undefined> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.definition)) {\n this.logger.debug(`Integration definition not found at ${rel.definition}`)\n return\n }\n\n const { outputFiles } = await utils.esbuild.buildEntrypoint({\n cwd: abs.workDir,\n outfile: '',\n entrypoint: rel.definition,\n write: false,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read integration definition')\n }\n\n const { default: definition } = utils.require.requireJsCode<{ default: bpsdk.IntegrationDefinition }>(artifact.text)\n return definition\n }\n\n protected async writeGeneratedFilesToOutFolder(files: codegen.File[]) {\n for (const file of files) {\n const filePath = utils.path.absoluteFrom(this.projectPaths.abs.outDir, file.path)\n const dirPath = pathlib.dirname(filePath)\n await fs.promises.mkdir(dirPath, { recursive: true })\n await fs.promises.writeFile(filePath, file.content)\n }\n }\n\n protected displayWebhookUrls(bot: bpclient.Bot) {\n if (!_.keys(bot.integrations).length) {\n this.logger.debug('No integrations in bot')\n return\n }\n\n this.logger.log('Integrations:')\n for (const integration of Object.values(bot.integrations).filter(utils.guards.is.defined)) {\n if (!integration.enabled) {\n this.logger.log(`${chalk.grey(integration.name)} ${chalk.italic('(disabled)')}: ${integration.webhookUrl}`, {\n prefix: { symbol: '\u25CB', indent: 2 },\n })\n } else {\n this.logger.log(`${chalk.bold(integration.name)} : ${integration.webhookUrl}`, {\n prefix: { symbol: '\u25CF', indent: 2 },\n })\n }\n }\n }\n\n protected async promptSecrets(\n integrationDef: bpsdk.IntegrationDefinition,\n argv: YargsConfig<typeof config.schemas.secrets>\n ): Promise<Record<string, string>> {\n const { secrets: secretDefinitions } = integrationDef\n if (!secretDefinitions) {\n return {}\n }\n\n const secretArgv = this._parseArgvSecrets(argv.secrets)\n const invalidSecret = Object.keys(secretArgv).find((s) => !secretDefinitions[s])\n if (invalidSecret) {\n throw new errors.BotpressCLIError(`Secret ${invalidSecret} is not defined in integration definition`)\n }\n\n const values: Record<string, string> = {}\n for (const [secretName, { optional }] of Object.entries(secretDefinitions)) {\n const argvSecret = secretArgv[secretName]\n if (argvSecret) {\n this.logger.debug(`Using secret \"${secretName}\" from argv`)\n values[secretName] = argvSecret\n continue\n }\n\n const mode = optional ? 'optional' : 'required'\n const prompted = await this.prompt.text(`Enter value for secret \"${secretName}\" (${mode})`)\n if (prompted) {\n values[secretName] = prompted\n continue\n }\n\n if (optional) {\n this.logger.warn(`Secret \"${secretName}\" is unassigned`)\n continue\n }\n\n throw new errors.BotpressCLIError(`Secret \"${secretName}\" is required`)\n }\n\n const envVariables = _.mapKeys(values, (_v, k) => codegen.secretEnvVariableName(k))\n return envVariables\n }\n\n private _parseArgvSecrets(argvSecrets: string[]): Record<string, string> {\n const parsed: Record<string, string> = {}\n for (const secret of argvSecrets) {\n const [key, value] = this._splitOnce(secret, '=')\n if (!value) {\n throw new errors.BotpressCLIError(\n `Secret \"${key}\" is missing a value. Expected format: \"SECRET_NAME=secretValue\"`\n )\n }\n parsed[key!] = value\n }\n\n return parsed\n }\n\n private _splitOnce = (text: string, separator: string): [string, string | undefined] => {\n const index = text.indexOf(separator)\n if (index === -1) {\n return [text, undefined]\n }\n return [text.slice(0, index), text.slice(index + 1)]\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAAqB;AACrB,mBAAkB;AAClB,gBAAe;AACf,oBAAc;AACd,kBAAoB;AAEpB,cAAyB;AAEzB,aAAwB;AACxB,aAAwB;AACxB,6BAAqD;AAErD,YAAuB;AACvB,4BAA8B;AAY9B,MAAM,qBAAqB,MAAM,KAAK,UAAiC;AAAA,EAC9D,YAAY,MAA6C;AAC9D,UAAM,aAAa,MAAM,KAAK,aAAa,MAAM,KAAK,IAAI,GAAG,KAAK,OAAO;AACzE,UAAM,gBAAgB,MAAM,KAAK,aAAa,YAAY,KAAK,UAAU;AACzE,UAAM,YAAY,MAAM,KAAK,aAAa,YAAY,KAAK,MAAM;AACjE,UAAM;AAAA,MACJ,SAAS;AAAA,MACT,YAAY;AAAA,MACZ,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AAC,MAAM,MAAS;AAAA,IACzB;AACA,WAAO,CAAC,KAAK,MAAM,GAAG,KAAK,GAAG,KAAK,MAAM,QAAQ,CAAC,CAAC;AAAA,EACrD;AACF;",
6
+ "names": ["_", "bluebird", "fs", "pathlib", "chalk"]
7
7
  }
@@ -30,17 +30,27 @@ __export(integration_ref_exports, {
30
30
  module.exports = __toCommonJS(integration_ref_exports);
31
31
  var import_semver = __toESM(require("semver"));
32
32
  var uuid = __toESM(require("uuid"));
33
+ var utils = __toESM(require("./utils"));
33
34
  const LATEST_TAG = "latest";
34
35
  const formatIntegrationRef = (ref) => {
36
+ if (ref.type === "path") {
37
+ return ref.path;
38
+ }
35
39
  if (ref.type === "id") {
36
40
  return ref.id;
37
41
  }
38
42
  return `${ref.name}@${ref.version}`;
39
43
  };
40
44
  const parseIntegrationRef = (ref) => {
45
+ if (!ref) {
46
+ return;
47
+ }
41
48
  if (uuid.validate(ref)) {
42
49
  return { type: "id", id: ref };
43
50
  }
51
+ if (utils.path.isAbsolute(ref)) {
52
+ return { type: "path", path: ref };
53
+ }
44
54
  if (!ref.includes("@")) {
45
55
  return { type: "name", name: ref, version: LATEST_TAG };
46
56
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/integration-ref.ts"],
4
- "sourcesContent": ["import semver from 'semver'\nimport * as uuid from 'uuid'\n\nexport type UUIDIntegrationRef = {\n type: 'id'\n id: string\n}\n\nexport type NameIntegrationRef = {\n type: 'name'\n name: string\n version: string\n}\n\nexport type IntegrationRef = UUIDIntegrationRef | NameIntegrationRef\n\nconst LATEST_TAG = 'latest'\n\nexport const formatIntegrationRef = (ref: IntegrationRef): string => {\n if (ref.type === 'id') {\n return ref.id\n }\n return `${ref.name}@${ref.version}`\n}\n\nexport const parseIntegrationRef = (ref: string): IntegrationRef | undefined => {\n if (uuid.validate(ref)) {\n return { type: 'id', id: ref }\n }\n\n if (!ref.includes('@')) {\n return { type: 'name', name: ref, version: LATEST_TAG }\n }\n\n const [name, version] = ref.split('@')\n if (!name || !version) {\n return\n }\n\n const cleanedVersion = version === LATEST_TAG ? version : semver.clean(version)\n if (!cleanedVersion) {\n return\n }\n\n return { type: 'name', name, version: cleanedVersion }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmB;AACnB,WAAsB;AAetB,MAAM,aAAa;AAEZ,MAAM,uBAAuB,CAAC,QAAgC;AACnE,MAAI,IAAI,SAAS,MAAM;AACrB,WAAO,IAAI;AAAA,EACb;AACA,SAAO,GAAG,IAAI,QAAQ,IAAI;AAC5B;AAEO,MAAM,sBAAsB,CAAC,QAA4C;AAC9E,MAAI,KAAK,SAAS,GAAG,GAAG;AACtB,WAAO,EAAE,MAAM,MAAM,IAAI,IAAI;AAAA,EAC/B;AAEA,MAAI,CAAC,IAAI,SAAS,GAAG,GAAG;AACtB,WAAO,EAAE,MAAM,QAAQ,MAAM,KAAK,SAAS,WAAW;AAAA,EACxD;AAEA,QAAM,CAAC,MAAM,OAAO,IAAI,IAAI,MAAM,GAAG;AACrC,MAAI,CAAC,QAAQ,CAAC,SAAS;AACrB;AAAA,EACF;AAEA,QAAM,iBAAiB,YAAY,aAAa,UAAU,cAAAA,QAAO,MAAM,OAAO;AAC9E,MAAI,CAAC,gBAAgB;AACnB;AAAA,EACF;AAEA,SAAO,EAAE,MAAM,QAAQ,MAAM,SAAS,eAAe;AACvD;",
4
+ "sourcesContent": ["import semver from 'semver'\nimport * as uuid from 'uuid'\nimport * as utils from './utils'\n\nexport type UUIDIntegrationRef = {\n type: 'id'\n id: string\n}\n\nexport type NameIntegrationRef = {\n type: 'name'\n name: string\n version: string\n}\n\nexport type LocalPathIntegrationRef = {\n type: 'path'\n path: utils.path.AbsolutePath\n}\n\nexport type ApiIntegrationRef = UUIDIntegrationRef | NameIntegrationRef\nexport type IntegrationRef = ApiIntegrationRef | LocalPathIntegrationRef\n\nconst LATEST_TAG = 'latest'\n\nexport const formatIntegrationRef = (ref: IntegrationRef): string => {\n if (ref.type === 'path') {\n return ref.path\n }\n if (ref.type === 'id') {\n return ref.id\n }\n return `${ref.name}@${ref.version}`\n}\n\nexport const parseIntegrationRef = (ref: string): IntegrationRef | undefined => {\n if (!ref) {\n return\n }\n\n if (uuid.validate(ref)) {\n return { type: 'id', id: ref }\n }\n\n if (utils.path.isAbsolute(ref)) {\n return { type: 'path', path: ref }\n }\n\n if (!ref.includes('@')) {\n return { type: 'name', name: ref, version: LATEST_TAG }\n }\n\n const [name, version] = ref.split('@')\n if (!name || !version) {\n return\n }\n\n const cleanedVersion = version === LATEST_TAG ? version : semver.clean(version)\n if (!cleanedVersion) {\n return\n }\n\n return { type: 'name', name, version: cleanedVersion }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmB;AACnB,WAAsB;AACtB,YAAuB;AAqBvB,MAAM,aAAa;AAEZ,MAAM,uBAAuB,CAAC,QAAgC;AACnE,MAAI,IAAI,SAAS,QAAQ;AACvB,WAAO,IAAI;AAAA,EACb;AACA,MAAI,IAAI,SAAS,MAAM;AACrB,WAAO,IAAI;AAAA,EACb;AACA,SAAO,GAAG,IAAI,QAAQ,IAAI;AAC5B;AAEO,MAAM,sBAAsB,CAAC,QAA4C;AAC9E,MAAI,CAAC,KAAK;AACR;AAAA,EACF;AAEA,MAAI,KAAK,SAAS,GAAG,GAAG;AACtB,WAAO,EAAE,MAAM,MAAM,IAAI,IAAI;AAAA,EAC/B;AAEA,MAAI,MAAM,KAAK,WAAW,GAAG,GAAG;AAC9B,WAAO,EAAE,MAAM,QAAQ,MAAM,IAAI;AAAA,EACnC;AAEA,MAAI,CAAC,IAAI,SAAS,GAAG,GAAG;AACtB,WAAO,EAAE,MAAM,QAAQ,MAAM,KAAK,SAAS,WAAW;AAAA,EACxD;AAEA,QAAM,CAAC,MAAM,OAAO,IAAI,IAAI,MAAM,GAAG;AACrC,MAAI,CAAC,QAAQ,CAAC,SAAS;AACrB;AAAA,EACF;AAEA,QAAM,iBAAiB,YAAY,aAAa,UAAU,cAAAA,QAAO,MAAM,OAAO;AAC9E,MAAI,CAAC,gBAAgB;AACnB;AAAA,EACF;AAEA,SAAO,EAAE,MAAM,QAAQ,MAAM,SAAS,eAAe;AACvD;",
6
6
  "names": ["semver"]
7
7
  }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ var import_node_test = require("node:test");
3
+ var import_vitest = require("vitest");
4
+ var import_integration_ref = require("./integration-ref");
5
+ const path = "/my/path";
6
+ const uuid = "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11";
7
+ const name = "myintegration";
8
+ (0, import_node_test.describe)("parseIntegrationRef", () => {
9
+ (0, import_vitest.test)("parse empty string should return undefined", () => {
10
+ const ref = "";
11
+ const result = (0, import_integration_ref.parseIntegrationRef)(ref);
12
+ (0, import_vitest.expect)(result).toBeUndefined();
13
+ });
14
+ (0, import_vitest.test)("parse with invalid version should return undefined", () => {
15
+ const ref0 = `${name}@lol`;
16
+ const ref1 = `${name}@1`;
17
+ const ref2 = `${name}@1.0`;
18
+ const result0 = (0, import_integration_ref.parseIntegrationRef)(ref0);
19
+ const result1 = (0, import_integration_ref.parseIntegrationRef)(ref1);
20
+ const result2 = (0, import_integration_ref.parseIntegrationRef)(ref2);
21
+ (0, import_vitest.expect)(result0).toBeUndefined();
22
+ (0, import_vitest.expect)(result1).toBeUndefined();
23
+ (0, import_vitest.expect)(result2).toBeUndefined();
24
+ });
25
+ (0, import_vitest.test)("parse with an absolute path should return path", () => {
26
+ const ref = path;
27
+ const result = (0, import_integration_ref.parseIntegrationRef)(ref);
28
+ const expected = { type: "path", path: ref };
29
+ (0, import_vitest.expect)(result).toEqual(expected);
30
+ });
31
+ (0, import_vitest.test)("parse with a uuid return uuid", () => {
32
+ const ref = uuid;
33
+ const result = (0, import_integration_ref.parseIntegrationRef)(ref);
34
+ const expected = { type: "id", id: ref };
35
+ (0, import_vitest.expect)(result).toEqual(expected);
36
+ });
37
+ (0, import_vitest.test)("parse with a name and version should return name and version", () => {
38
+ const version = "1.0.0";
39
+ const ref = `${name}@${version}`;
40
+ const result = (0, import_integration_ref.parseIntegrationRef)(ref);
41
+ const expected = { type: "name", name, version };
42
+ (0, import_vitest.expect)(result).toEqual(expected);
43
+ });
44
+ (0, import_vitest.test)("parse with a name and latest should return name and latest", () => {
45
+ const version = "latest";
46
+ const ref = `${name}@${version}`;
47
+ const result = (0, import_integration_ref.parseIntegrationRef)(ref);
48
+ const expected = { type: "name", name, version };
49
+ (0, import_vitest.expect)(result).toEqual(expected);
50
+ });
51
+ (0, import_vitest.test)("parse with only a name should return name and latest", () => {
52
+ const ref = name;
53
+ const result = (0, import_integration_ref.parseIntegrationRef)(ref);
54
+ const expected = { type: "name", name, version: "latest" };
55
+ (0, import_vitest.expect)(result).toEqual(expected);
56
+ });
57
+ });
58
+ (0, import_node_test.describe)("formatIntegrationRef", () => {
59
+ (0, import_vitest.test)("format with a path should return path", () => {
60
+ const ref = { type: "path", path };
61
+ const result = (0, import_integration_ref.formatIntegrationRef)(ref);
62
+ (0, import_vitest.expect)(result).toEqual(ref.path);
63
+ });
64
+ (0, import_vitest.test)("format with a uuid should return uuid", () => {
65
+ const ref = { type: "id", id: uuid };
66
+ const result = (0, import_integration_ref.formatIntegrationRef)(ref);
67
+ (0, import_vitest.expect)(result).toEqual(ref.id);
68
+ });
69
+ (0, import_vitest.test)("format with a name and version should return name and version", () => {
70
+ const version = "1.0.0";
71
+ const ref = { type: "name", name, version };
72
+ const result = (0, import_integration_ref.formatIntegrationRef)(ref);
73
+ (0, import_vitest.expect)(result).toEqual(`${name}@${version}`);
74
+ });
75
+ });
76
+ //# sourceMappingURL=integration-ref.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/integration-ref.test.ts"],
4
+ "sourcesContent": ["import { describe } from 'node:test'\nimport { test, expect } from 'vitest'\nimport { formatIntegrationRef, IntegrationRef, parseIntegrationRef } from './integration-ref'\n\nconst path = '/my/path'\nconst uuid = 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'\nconst name = 'myintegration'\n\ndescribe('parseIntegrationRef', () => {\n test('parse empty string should return undefined', () => {\n // arrange\n const ref = ''\n // act\n const result = parseIntegrationRef(ref)\n // assert\n expect(result).toBeUndefined()\n })\n\n test('parse with invalid version should return undefined', () => {\n // arrange\n const ref0 = `${name}@lol`\n const ref1 = `${name}@1`\n const ref2 = `${name}@1.0`\n // act\n const result0 = parseIntegrationRef(ref0)\n const result1 = parseIntegrationRef(ref1)\n const result2 = parseIntegrationRef(ref2)\n // assert\n expect(result0).toBeUndefined()\n expect(result1).toBeUndefined()\n expect(result2).toBeUndefined()\n })\n\n test('parse with an absolute path should return path', () => {\n // arrange\n const ref = path\n // act\n const result = parseIntegrationRef(ref)\n // assert\n const expected: IntegrationRef = { type: 'path', path: ref }\n expect(result).toEqual(expected)\n })\n\n test('parse with a uuid return uuid', () => {\n // arrange\n const ref = uuid\n // act\n const result = parseIntegrationRef(ref)\n // assert\n const expected: IntegrationRef = { type: 'id', id: ref }\n expect(result).toEqual(expected)\n })\n\n test('parse with a name and version should return name and version', () => {\n // arrange\n const version = '1.0.0'\n const ref = `${name}@${version}`\n // act\n const result = parseIntegrationRef(ref)\n // assert\n const expected: IntegrationRef = { type: 'name', name, version }\n expect(result).toEqual(expected)\n })\n\n test('parse with a name and latest should return name and latest', () => {\n // arrange\n const version = 'latest'\n const ref = `${name}@${version}`\n // act\n const result = parseIntegrationRef(ref)\n // assert\n const expected: IntegrationRef = { type: 'name', name, version }\n expect(result).toEqual(expected)\n })\n\n test('parse with only a name should return name and latest', () => {\n // arrange\n const ref = name\n // act\n const result = parseIntegrationRef(ref)\n // assert\n const expected: IntegrationRef = { type: 'name', name, version: 'latest' }\n expect(result).toEqual(expected)\n })\n})\n\ndescribe('formatIntegrationRef', () => {\n test('format with a path should return path', () => {\n // arrange\n const ref: IntegrationRef = { type: 'path', path }\n // act\n const result = formatIntegrationRef(ref)\n // assert\n expect(result).toEqual(ref.path)\n })\n\n test('format with a uuid should return uuid', () => {\n // arrange\n const ref: IntegrationRef = { type: 'id', id: uuid }\n // act\n const result = formatIntegrationRef(ref)\n // assert\n expect(result).toEqual(ref.id)\n })\n\n test('format with a name and version should return name and version', () => {\n // arrange\n const version = '1.0.0'\n const ref: IntegrationRef = { type: 'name', name, version }\n // act\n const result = formatIntegrationRef(ref)\n // assert\n expect(result).toEqual(`${name}@${version}`)\n })\n})\n"],
5
+ "mappings": ";AAAA,uBAAyB;AACzB,oBAA6B;AAC7B,6BAA0E;AAE1E,MAAM,OAAO;AACb,MAAM,OAAO;AACb,MAAM,OAAO;AAAA,IAEb,2BAAS,uBAAuB,MAAM;AACpC,0BAAK,8CAA8C,MAAM;AAEvD,UAAM,MAAM;AAEZ,UAAM,aAAS,4CAAoB,GAAG;AAEtC,8BAAO,MAAM,EAAE,cAAc;AAAA,EAC/B,CAAC;AAED,0BAAK,sDAAsD,MAAM;AAE/D,UAAM,OAAO,GAAG;AAChB,UAAM,OAAO,GAAG;AAChB,UAAM,OAAO,GAAG;AAEhB,UAAM,cAAU,4CAAoB,IAAI;AACxC,UAAM,cAAU,4CAAoB,IAAI;AACxC,UAAM,cAAU,4CAAoB,IAAI;AAExC,8BAAO,OAAO,EAAE,cAAc;AAC9B,8BAAO,OAAO,EAAE,cAAc;AAC9B,8BAAO,OAAO,EAAE,cAAc;AAAA,EAChC,CAAC;AAED,0BAAK,kDAAkD,MAAM;AAE3D,UAAM,MAAM;AAEZ,UAAM,aAAS,4CAAoB,GAAG;AAEtC,UAAM,WAA2B,EAAE,MAAM,QAAQ,MAAM,IAAI;AAC3D,8BAAO,MAAM,EAAE,QAAQ,QAAQ;AAAA,EACjC,CAAC;AAED,0BAAK,iCAAiC,MAAM;AAE1C,UAAM,MAAM;AAEZ,UAAM,aAAS,4CAAoB,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QAAQ;AAE1D,UAAM,aAAS,6CAAqB,GAAG;AAEvC,8BAAO,MAAM,EAAE,QAAQ,GAAG,QAAQ,SAAS;AAAA,EAC7C,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botpress/cli",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "Botpress CLI",
5
5
  "scripts": {
6
6
  "build": "pnpm run bundle && pnpm run template:gen",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "main": "dist/index.js",
22
22
  "dependencies": {
23
- "@botpress/client": "0.3.7",
23
+ "@botpress/client": "0.3.8",
24
24
  "@bpinternal/tunnel": "^0.1.0",
25
25
  "@bpinternal/yargs-extra": "^0.0.3",
26
26
  "@bpinternal/zod-to-json-schema": "^3.21.4",
@@ -47,7 +47,7 @@
47
47
  "zod": "^3.20.6"
48
48
  },
49
49
  "devDependencies": {
50
- "@botpress/sdk": "0.4.3",
50
+ "@botpress/sdk": "0.4.4",
51
51
  "@bpinternal/log4bot": "^0.0.4",
52
52
  "@types/bluebird": "^3.5.38",
53
53
  "@types/json-schema": "^7.0.11",
@@ -8,8 +8,8 @@
8
8
  "author": "",
9
9
  "license": "MIT",
10
10
  "dependencies": {
11
- "@botpress/client": "0.3.7",
12
- "@botpress/sdk": "0.4.3",
11
+ "@botpress/client": "0.3.8",
12
+ "@botpress/sdk": "0.4.4",
13
13
  "zod": "^3.20.6"
14
14
  },
15
15
  "devDependencies": {
@@ -8,8 +8,8 @@
8
8
  "author": "",
9
9
  "license": "MIT",
10
10
  "dependencies": {
11
- "@botpress/client": "0.3.7",
12
- "@botpress/sdk": "0.4.3",
11
+ "@botpress/client": "0.3.8",
12
+ "@botpress/sdk": "0.4.4",
13
13
  "zod": "^3.20.6"
14
14
  },
15
15
  "devDependencies": {