@botpress/cli 0.11.5 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/.turbo/turbo-build.log +9 -9
  2. package/dist/api/bot-body.js.map +2 -2
  3. package/dist/api/client.js +14 -28
  4. package/dist/api/client.js.map +3 -3
  5. package/dist/api/find-previous-version.js +1 -1
  6. package/dist/api/find-previous-version.js.map +2 -2
  7. package/dist/api/index.js +23 -0
  8. package/dist/api/index.js.map +7 -0
  9. package/dist/api/interface-body.js +25 -10
  10. package/dist/api/interface-body.js.map +2 -2
  11. package/dist/code-generation/bot-implementation/bot-implementation.js +92 -0
  12. package/dist/code-generation/bot-implementation/bot-implementation.js.map +7 -0
  13. package/dist/code-generation/{integration-schemas → bot-implementation/bot-typings}/events-module.js +15 -22
  14. package/dist/code-generation/bot-implementation/bot-typings/events-module.js.map +7 -0
  15. package/dist/code-generation/bot-implementation/bot-typings/index.js +96 -0
  16. package/dist/code-generation/bot-implementation/bot-typings/index.js.map +7 -0
  17. package/dist/code-generation/{integration-schemas → bot-implementation/bot-typings}/states-module.js +17 -22
  18. package/dist/code-generation/bot-implementation/bot-typings/states-module.js.map +7 -0
  19. package/dist/code-generation/bot-implementation/index.js +56 -0
  20. package/dist/code-generation/bot-implementation/index.js.map +7 -0
  21. package/dist/code-generation/{const.js → consts.js} +9 -4
  22. package/dist/code-generation/consts.js.map +7 -0
  23. package/dist/code-generation/generators.js +37 -7
  24. package/dist/code-generation/generators.js.map +2 -2
  25. package/dist/code-generation/index.js +15 -105
  26. package/dist/code-generation/index.js.map +3 -3
  27. package/dist/code-generation/integration-implementation/index.js +66 -0
  28. package/dist/code-generation/integration-implementation/index.js.map +7 -0
  29. package/dist/code-generation/integration-implementation/integration-implementation.js +110 -0
  30. package/dist/code-generation/integration-implementation/integration-implementation.js.map +7 -0
  31. package/dist/code-generation/{integration-secret.js → integration-implementation/integration-secret.js} +17 -7
  32. package/dist/code-generation/integration-implementation/integration-secret.js.map +7 -0
  33. package/dist/code-generation/{integration-schemas → integration-implementation/integration-typings}/actions-module.js +28 -40
  34. package/dist/code-generation/integration-implementation/integration-typings/actions-module.js.map +7 -0
  35. package/dist/code-generation/integration-implementation/integration-typings/channels-module.js +103 -0
  36. package/dist/code-generation/integration-implementation/integration-typings/channels-module.js.map +7 -0
  37. package/dist/code-generation/{integration-schemas → integration-implementation/integration-typings}/configuration-module.js +18 -20
  38. package/dist/code-generation/integration-implementation/integration-typings/configuration-module.js.map +7 -0
  39. package/dist/code-generation/{integration-schemas → integration-implementation/integration-typings}/configurations-module.js +21 -27
  40. package/dist/code-generation/integration-implementation/integration-typings/configurations-module.js.map +7 -0
  41. package/dist/code-generation/{integration-schemas → integration-implementation/integration-typings}/entities-module.js +15 -22
  42. package/dist/code-generation/integration-implementation/integration-typings/entities-module.js.map +7 -0
  43. package/dist/code-generation/integration-implementation/integration-typings/events-module.js +59 -0
  44. package/dist/code-generation/integration-implementation/integration-typings/events-module.js.map +7 -0
  45. package/dist/code-generation/integration-implementation/integration-typings/index.js +128 -0
  46. package/dist/code-generation/integration-implementation/integration-typings/index.js.map +7 -0
  47. package/dist/code-generation/integration-implementation/integration-typings/states-module.js +60 -0
  48. package/dist/code-generation/integration-implementation/integration-typings/states-module.js.map +7 -0
  49. package/dist/code-generation/integration-package/index.js +81 -0
  50. package/dist/code-generation/integration-package/index.js.map +7 -0
  51. package/dist/code-generation/integration-package/integration-package-definition/actions-module.js +84 -0
  52. package/dist/code-generation/integration-package/integration-package-definition/actions-module.js.map +7 -0
  53. package/dist/code-generation/integration-package/integration-package-definition/channels-module.js +103 -0
  54. package/dist/code-generation/integration-package/integration-package-definition/channels-module.js.map +7 -0
  55. package/dist/code-generation/integration-package/integration-package-definition/configuration-module.js +58 -0
  56. package/dist/code-generation/integration-package/integration-package-definition/configuration-module.js.map +7 -0
  57. package/dist/code-generation/integration-package/integration-package-definition/configurations-module.js +66 -0
  58. package/dist/code-generation/integration-package/integration-package-definition/configurations-module.js.map +7 -0
  59. package/dist/code-generation/integration-package/integration-package-definition/entities-module.js +59 -0
  60. package/dist/code-generation/integration-package/integration-package-definition/entities-module.js.map +7 -0
  61. package/dist/code-generation/integration-package/integration-package-definition/events-module.js +62 -0
  62. package/dist/code-generation/integration-package/integration-package-definition/events-module.js.map +7 -0
  63. package/dist/code-generation/integration-package/integration-package-definition/index.js +136 -0
  64. package/dist/code-generation/integration-package/integration-package-definition/index.js.map +7 -0
  65. package/dist/code-generation/integration-package/integration-package-definition/states-module.js +62 -0
  66. package/dist/code-generation/integration-package/integration-package-definition/states-module.js.map +7 -0
  67. package/dist/code-generation/integration-package/integration-package-definition/typings.js +17 -0
  68. package/dist/code-generation/integration-package/integration-package-definition/typings.js.map +7 -0
  69. package/dist/code-generation/interface-package/index.js +81 -0
  70. package/dist/code-generation/interface-package/index.js.map +7 -0
  71. package/dist/code-generation/interface-package/interface-package-definition/actions-module.js +84 -0
  72. package/dist/code-generation/interface-package/interface-package-definition/actions-module.js.map +7 -0
  73. package/dist/code-generation/interface-package/interface-package-definition/channels-module.js +94 -0
  74. package/dist/code-generation/interface-package/interface-package-definition/channels-module.js.map +7 -0
  75. package/dist/code-generation/interface-package/interface-package-definition/entities-module.js +59 -0
  76. package/dist/code-generation/interface-package/interface-package-definition/entities-module.js.map +7 -0
  77. package/dist/code-generation/interface-package/interface-package-definition/events-module.js +62 -0
  78. package/dist/code-generation/interface-package/interface-package-definition/events-module.js.map +7 -0
  79. package/dist/code-generation/interface-package/interface-package-definition/index.js +100 -0
  80. package/dist/code-generation/interface-package/interface-package-definition/index.js.map +7 -0
  81. package/dist/code-generation/interface-package/interface-package-definition/typings.js +17 -0
  82. package/dist/code-generation/interface-package/interface-package-definition/typings.js.map +7 -0
  83. package/dist/code-generation/module.js +60 -16
  84. package/dist/code-generation/module.js.map +2 -2
  85. package/dist/code-generation/strings.js +5 -2
  86. package/dist/code-generation/strings.js.map +2 -2
  87. package/dist/code-generation/typings.js.map +1 -1
  88. package/dist/command-implementations/add-command.js +102 -91
  89. package/dist/command-implementations/add-command.js.map +3 -3
  90. package/dist/command-implementations/bundle-command.js +16 -9
  91. package/dist/command-implementations/bundle-command.js.map +2 -2
  92. package/dist/command-implementations/deploy-command.js +34 -19
  93. package/dist/command-implementations/deploy-command.js.map +2 -2
  94. package/dist/command-implementations/dev-command.js +15 -12
  95. package/dist/command-implementations/dev-command.js.map +2 -2
  96. package/dist/command-implementations/gen-command.js +31 -12
  97. package/dist/command-implementations/gen-command.js.map +3 -3
  98. package/dist/command-implementations/init-command.js +2 -2
  99. package/dist/command-implementations/init-command.js.map +2 -2
  100. package/dist/command-implementations/integration-commands.js +5 -5
  101. package/dist/command-implementations/integration-commands.js.map +2 -2
  102. package/dist/command-implementations/interface-commands.js +5 -5
  103. package/dist/command-implementations/interface-commands.js.map +2 -2
  104. package/dist/command-implementations/lint-command.js +3 -1
  105. package/dist/command-implementations/lint-command.js.map +3 -3
  106. package/dist/command-implementations/project-command.js +40 -23
  107. package/dist/command-implementations/project-command.js.map +3 -3
  108. package/dist/command-implementations/read-command.js +0 -5
  109. package/dist/command-implementations/read-command.js.map +2 -2
  110. package/dist/config.js +22 -7
  111. package/dist/config.js.map +2 -2
  112. package/dist/consts.js +15 -6
  113. package/dist/consts.js.map +2 -2
  114. package/dist/errors.js +19 -11
  115. package/dist/errors.js.map +2 -2
  116. package/dist/logger/index.js +4 -2
  117. package/dist/logger/index.js.map +2 -2
  118. package/dist/{integration-ref.js → package-ref.js} +11 -11
  119. package/dist/package-ref.js.map +7 -0
  120. package/dist/{integration-ref.test.js → package-ref.test.js} +18 -18
  121. package/dist/package-ref.test.js.map +7 -0
  122. package/dist/sdk/index.js +21 -0
  123. package/dist/sdk/index.js.map +7 -0
  124. package/dist/sdk/resolve-bot-interfaces.js +38 -0
  125. package/dist/sdk/resolve-bot-interfaces.js.map +7 -0
  126. package/dist/sdk/resolve-integration-interfaces.js +148 -0
  127. package/dist/sdk/resolve-integration-interfaces.js.map +7 -0
  128. package/dist/utils/index.js +3 -0
  129. package/dist/utils/index.js.map +2 -2
  130. package/dist/utils/path-utils.js +25 -8
  131. package/dist/utils/path-utils.js.map +3 -3
  132. package/dist/utils/path-utils.test.js +69 -0
  133. package/dist/utils/path-utils.test.js.map +7 -0
  134. package/dist/utils/record-utils.js +25 -0
  135. package/dist/utils/record-utils.js.map +3 -3
  136. package/dist/utils/schema-utils.js +11 -0
  137. package/dist/utils/schema-utils.js.map +2 -2
  138. package/dist/utils/schema-utils.test.js +51 -0
  139. package/dist/utils/schema-utils.test.js.map +7 -0
  140. package/dist/utils/template-utils.js +47 -0
  141. package/dist/utils/template-utils.js.map +7 -0
  142. package/dist/utils/type-utils.js.map +1 -1
  143. package/e2e/index.ts +2 -0
  144. package/e2e/tests/install-package.ts +163 -0
  145. package/e2e/utils.ts +25 -2
  146. package/package.json +5 -4
  147. package/templates/empty-bot/.botpress/implementation/index.ts +41 -0
  148. package/templates/empty-bot/.botpress/implementation/typings/index.ts +17 -0
  149. package/templates/empty-bot/.botpress/implementation/typings/integrations/index.ts +6 -0
  150. package/templates/empty-bot/.botpress/index.ts +1 -0
  151. package/templates/empty-bot/bot.definition.ts +2 -0
  152. package/templates/{echo-bot → empty-bot}/package.json +2 -2
  153. package/templates/empty-bot/src/index.ts +5 -0
  154. package/templates/empty-integration/.botpress/implementation/index.ts +7 -35
  155. package/templates/empty-integration/.botpress/implementation/typings/configuration/index.ts +2 -0
  156. package/templates/empty-integration/.botpress/implementation/typings/index.ts +31 -0
  157. package/templates/empty-integration/package.json +1 -1
  158. package/templates/hello-world/.botpress/implementation/index.ts +7 -35
  159. package/templates/hello-world/.botpress/implementation/typings/actions/helloWorld/input.ts +5 -0
  160. package/templates/hello-world/.botpress/implementation/typings/actions/helloWorld/output.ts +5 -0
  161. package/templates/hello-world/.botpress/implementation/typings/configuration/index.ts +2 -0
  162. package/templates/hello-world/.botpress/implementation/typings/index.ts +31 -0
  163. package/templates/hello-world/package.json +1 -1
  164. package/templates/webhook-message/.botpress/implementation/index.ts +7 -35
  165. package/templates/webhook-message/.botpress/implementation/typings/channels/webhook/messages/text.ts +5 -0
  166. package/templates/webhook-message/.botpress/implementation/typings/configuration/index.ts +8 -0
  167. package/templates/webhook-message/.botpress/implementation/typings/events/index.ts +6 -0
  168. package/templates/webhook-message/.botpress/implementation/typings/index.ts +31 -0
  169. package/templates/webhook-message/.botpress/implementation/typings/states/index.ts +6 -0
  170. package/templates/webhook-message/package.json +1 -1
  171. package/dist/code-generation/const.js.map +0 -7
  172. package/dist/code-generation/integration-implementation.js +0 -192
  173. package/dist/code-generation/integration-implementation.js.map +0 -7
  174. package/dist/code-generation/integration-instance.js +0 -185
  175. package/dist/code-generation/integration-instance.js.map +0 -7
  176. package/dist/code-generation/integration-schemas/actions-module.js.map +0 -7
  177. package/dist/code-generation/integration-schemas/channels-module.js +0 -117
  178. package/dist/code-generation/integration-schemas/channels-module.js.map +0 -7
  179. package/dist/code-generation/integration-schemas/configuration-module.js.map +0 -7
  180. package/dist/code-generation/integration-schemas/configurations-module.js.map +0 -7
  181. package/dist/code-generation/integration-schemas/entities-module.js.map +0 -7
  182. package/dist/code-generation/integration-schemas/events-module.js.map +0 -7
  183. package/dist/code-generation/integration-schemas/states-module.js.map +0 -7
  184. package/dist/code-generation/integration-secret.js.map +0 -7
  185. package/dist/code-generation/map-integration.js +0 -76
  186. package/dist/code-generation/map-integration.js.map +0 -7
  187. package/dist/integration-ref.js.map +0 -7
  188. package/dist/integration-ref.test.js.map +0 -7
  189. package/templates/echo-bot/src/index.ts +0 -30
  190. package/templates/empty-integration/.botpress/implementation/configuration/index.ts +0 -10
  191. package/templates/hello-world/.botpress/implementation/actions/helloWorld/input.ts +0 -10
  192. package/templates/hello-world/.botpress/implementation/actions/helloWorld/output.ts +0 -10
  193. package/templates/hello-world/.botpress/implementation/configuration/index.ts +0 -10
  194. package/templates/webhook-message/.botpress/implementation/channels/webhook/messages/text.ts +0 -10
  195. package/templates/webhook-message/.botpress/implementation/configuration/index.ts +0 -13
  196. /package/templates/{empty-integration/.botpress/implementation → empty-bot/.botpress/implementation/typings}/events/index.ts +0 -0
  197. /package/templates/{empty-integration/.botpress/implementation → empty-bot/.botpress/implementation/typings}/states/index.ts +0 -0
  198. /package/templates/{echo-bot → empty-bot}/tsconfig.json +0 -0
  199. /package/templates/empty-integration/.botpress/implementation/{actions → typings/actions}/index.ts +0 -0
  200. /package/templates/empty-integration/.botpress/implementation/{channels → typings/channels}/index.ts +0 -0
  201. /package/templates/empty-integration/.botpress/implementation/{configurations → typings/configurations}/index.ts +0 -0
  202. /package/templates/empty-integration/.botpress/implementation/{entities → typings/entities}/index.ts +0 -0
  203. /package/templates/{hello-world/.botpress/implementation → empty-integration/.botpress/implementation/typings}/events/index.ts +0 -0
  204. /package/templates/{hello-world/.botpress/implementation → empty-integration/.botpress/implementation/typings}/states/index.ts +0 -0
  205. /package/templates/hello-world/.botpress/implementation/{actions → typings/actions}/helloWorld/index.ts +0 -0
  206. /package/templates/hello-world/.botpress/implementation/{actions → typings/actions}/index.ts +0 -0
  207. /package/templates/hello-world/.botpress/implementation/{channels → typings/channels}/index.ts +0 -0
  208. /package/templates/hello-world/.botpress/implementation/{configurations → typings/configurations}/index.ts +0 -0
  209. /package/templates/hello-world/.botpress/implementation/{entities → typings/entities}/index.ts +0 -0
  210. /package/templates/{webhook-message/.botpress/implementation → hello-world/.botpress/implementation/typings}/events/index.ts +0 -0
  211. /package/templates/{webhook-message/.botpress/implementation → hello-world/.botpress/implementation/typings}/states/index.ts +0 -0
  212. /package/templates/webhook-message/.botpress/implementation/{actions → typings/actions}/index.ts +0 -0
  213. /package/templates/webhook-message/.botpress/implementation/{channels → typings/channels}/index.ts +0 -0
  214. /package/templates/webhook-message/.botpress/implementation/{channels → typings/channels}/webhook/index.ts +0 -0
  215. /package/templates/webhook-message/.botpress/implementation/{channels → typings/channels}/webhook/messages/index.ts +0 -0
  216. /package/templates/webhook-message/.botpress/implementation/{configurations → typings/configurations}/index.ts +0 -0
  217. /package/templates/webhook-message/.botpress/implementation/{entities → typings/entities}/index.ts +0 -0
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/code-generation/module.ts"],
4
- "sourcesContent": ["import { posix as pathlib } from 'path'\nimport * as utils from '../utils'\nimport { GENERATED_HEADER, INDEX_FILE } from './const'\nimport * as strings from './strings'\nimport type { File } from './typings'\n\nexport type ModuleDef = File & {\n exportName: string\n}\n\nexport abstract class Module implements File {\n private _localDependencies: Module[] = []\n\n public get path(): string {\n return this._def.path\n }\n\n public get content(): string {\n return this._def.content\n }\n\n /**\n * @returns file name without extension\n */\n public get name(): string {\n const basename = pathlib.basename(this.path)\n if (basename === INDEX_FILE) {\n const dirname = pathlib.basename(pathlib.dirname(this.path))\n return dirname\n }\n const withoutExtension = utils.path.rmExtension(basename)\n return withoutExtension\n }\n\n public get exports(): string {\n return this._def.exportName\n }\n\n public get deps(): Module[] {\n return [...this._localDependencies]\n }\n\n protected constructor(private _def: ModuleDef) {}\n\n public pushDep(...dependencies: Module[]): this {\n this._localDependencies.push(...dependencies)\n return this\n }\n\n public unshift(...basePath: string[]): this {\n this._def = {\n ...this._def,\n path: pathlib.join(...basePath, this._def.path),\n }\n this._localDependencies = this._localDependencies.map((d) => d.unshift(...basePath))\n return this\n }\n\n public flatten(): File[] {\n return [this, ...this._localDependencies.flatMap((d) => d.flatten())]\n }\n\n public import(base: Module): string {\n let relativePath = pathlib.relative(pathlib.dirname(base.path), this.path)\n relativePath = pathlib.join('.', relativePath)\n return utils.path.rmExtension(relativePath)\n }\n}\n\nexport class ReExportTypeModule extends Module {\n protected constructor(def: { exportName: string }) {\n super({\n ...def,\n path: INDEX_FILE,\n content: '',\n })\n }\n\n public override get content(): string {\n let content = GENERATED_HEADER\n\n for (const m of this.deps) {\n const { name } = m\n const importAlias = strings.importAlias(name)\n const importFrom = m.import(this)\n content += `import * as ${importAlias} from \"./${importFrom}\";\\n`\n content += `export * as ${importAlias} from \"./${importFrom}\";\\n`\n }\n\n content += '\\n'\n\n content += `export type ${this.exports} = {\\n`\n for (const { name, exports } of this.deps) {\n const importAlias = strings.importAlias(name)\n content += ` \"${name}\": ${importAlias}.${exports};\\n`\n }\n content += '}'\n\n content += '\\n'\n\n return content\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiC;AACjC,YAAuB;AACvB,mBAA6C;AAC7C,cAAyB;AAOlB,MAAe,OAAuB;AAAA,EAgCjC,YAAoB,MAAiB;AAAjB;AAAA,EAAkB;AAAA,EA/BxC,qBAA+B,CAAC;AAAA,EAExC,IAAW,OAAe;AACxB,WAAO,KAAK,KAAK;AAAA,EACnB;AAAA,EAEA,IAAW,UAAkB;AAC3B,WAAO,KAAK,KAAK;AAAA,EACnB;AAAA,EAKA,IAAW,OAAe;AACxB,UAAM,WAAW,YAAAA,MAAQ,SAAS,KAAK,IAAI;AAC3C,QAAI,aAAa,yBAAY;AAC3B,YAAM,UAAU,YAAAA,MAAQ,SAAS,YAAAA,MAAQ,QAAQ,KAAK,IAAI,CAAC;AAC3D,aAAO;AAAA,IACT;AACA,UAAM,mBAAmB,MAAM,KAAK,YAAY,QAAQ;AACxD,WAAO;AAAA,EACT;AAAA,EAEA,IAAW,UAAkB;AAC3B,WAAO,KAAK,KAAK;AAAA,EACnB;AAAA,EAEA,IAAW,OAAiB;AAC1B,WAAO,CAAC,GAAG,KAAK,kBAAkB;AAAA,EACpC;AAAA,EAIO,WAAW,cAA8B;AAC9C,SAAK,mBAAmB,KAAK,GAAG,YAAY;AAC5C,WAAO;AAAA,EACT;AAAA,EAEO,WAAW,UAA0B;AAC1C,SAAK,OAAO;AAAA,MACV,GAAG,KAAK;AAAA,MACR,MAAM,YAAAA,MAAQ,KAAK,GAAG,UAAU,KAAK,KAAK,IAAI;AAAA,IAChD;AACA,SAAK,qBAAqB,KAAK,mBAAmB,IAAI,CAAC,MAAM,EAAE,QAAQ,GAAG,QAAQ,CAAC;AACnF,WAAO;AAAA,EACT;AAAA,EAEO,UAAkB;AACvB,WAAO,CAAC,MAAM,GAAG,KAAK,mBAAmB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAAA,EACtE;AAAA,EAEO,OAAO,MAAsB;AAClC,QAAI,eAAe,YAAAA,MAAQ,SAAS,YAAAA,MAAQ,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI;AACzE,mBAAe,YAAAA,MAAQ,KAAK,KAAK,YAAY;AAC7C,WAAO,MAAM,KAAK,YAAY,YAAY;AAAA,EAC5C;AACF;AAEO,MAAM,2BAA2B,OAAO;AAAA,EACnC,YAAY,KAA6B;AACjD,UAAM;AAAA,MACJ,GAAG;AAAA,MACH,MAAM;AAAA,MACN,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAAA,EAEA,IAAoB,UAAkB;AACpC,QAAI,UAAU;AAEd,eAAW,KAAK,KAAK,MAAM;AACzB,YAAM,EAAE,KAAK,IAAI;AACjB,YAAM,cAAc,QAAQ,YAAY,IAAI;AAC5C,YAAM,aAAa,EAAE,OAAO,IAAI;AAChC,iBAAW,eAAe,uBAAuB;AAAA;AACjD,iBAAW,eAAe,uBAAuB;AAAA;AAAA,IACnD;AAEA,eAAW;AAEX,eAAW,eAAe,KAAK;AAAA;AAC/B,eAAW,EAAE,MAAM,QAAQ,KAAK,KAAK,MAAM;AACzC,YAAM,cAAc,QAAQ,YAAY,IAAI;AAC5C,iBAAW,MAAM,UAAU,eAAe;AAAA;AAAA,IAC5C;AACA,eAAW;AAEX,eAAW;AAEX,WAAO;AAAA,EACT;AACF;",
4
+ "sourcesContent": ["import { posix as pathlib } from 'path'\nimport * as utils from '../utils'\nimport * as consts from './consts'\nimport * as strings from './strings'\nimport { File } from './typings'\n\nexport type ModuleProps = {\n path: string\n exportName: string\n}\n\nexport abstract class Module {\n private _localDependencies: Module[] = []\n\n public get path(): string {\n return this._def.path\n }\n\n /**\n * @returns file name without extension\n */\n public get name(): string {\n const basename = pathlib.basename(this.path)\n if (basename === consts.INDEX_FILE) {\n const dirname = pathlib.basename(pathlib.dirname(this.path))\n return dirname\n }\n const withoutExtension = utils.path.rmExtension(basename)\n return withoutExtension\n }\n\n public get isDefaultExport(): boolean {\n return this._def.exportName === consts.DEFAULT_EXPORT_NAME\n }\n\n public get exportName(): string {\n return this._def.exportName\n }\n\n public get deps(): Module[] {\n return [...this._localDependencies]\n }\n\n protected constructor(private _def: ModuleProps) {}\n\n public abstract getContent(): Promise<string>\n\n public pushDep(...dependencies: Module[]): this {\n this._localDependencies.push(...dependencies)\n return this\n }\n\n public unshift(...basePath: string[]): this {\n this._def = {\n ...this._def,\n path: pathlib.join(...basePath, this._def.path),\n }\n this._localDependencies = this._localDependencies.map((d) => d.unshift(...basePath))\n return this\n }\n\n public async toFile(): Promise<File> {\n return {\n path: this.path,\n content: await this.getContent(),\n }\n }\n\n public async flatten(): Promise<File[]> {\n const self = await this.toFile()\n const allFiles: File[] = [self]\n for (const dep of this._localDependencies) {\n const depFiles = await dep.flatten()\n allFiles.push(...depFiles)\n }\n return allFiles\n }\n\n public import(base: Module): string {\n let relativePath = pathlib.relative(pathlib.dirname(base.path), this.path)\n relativePath = pathlib.join('.', relativePath)\n return utils.path.rmExtension(relativePath)\n }\n}\n\nexport class ReExportTypeModule extends Module {\n protected constructor(def: { exportName: string }) {\n super({\n ...def,\n path: consts.INDEX_FILE,\n })\n }\n\n public async getContent(): Promise<string> {\n let content = consts.GENERATED_HEADER\n\n for (const m of this.deps) {\n const { name } = m\n const importAlias = strings.importAlias(name)\n const importFrom = m.import(this)\n content += `import * as ${importAlias} from \"./${importFrom}\";\\n`\n content += `export * as ${importAlias} from \"./${importFrom}\";\\n`\n }\n\n content += '\\n'\n\n content += `export type ${this.exportName} = {\\n`\n for (const { name, exportName: exports } of this.deps) {\n const importAlias = strings.importAlias(name)\n content += ` \"${name}\": ${importAlias}.${exports};\\n`\n }\n content += '}'\n\n content += '\\n'\n\n return content\n }\n}\n\nexport class ReExportVariableModule extends Module {\n protected constructor(def: { exportName: string }) {\n super({\n ...def,\n path: consts.INDEX_FILE,\n })\n }\n\n public async getContent(): Promise<string> {\n let content = consts.GENERATED_HEADER\n\n for (const m of this.deps) {\n const { name } = m\n const importAlias = strings.importAlias(name)\n const importFrom = m.import(this)\n content += `import * as ${importAlias} from \"./${importFrom}\";\\n`\n content += `export * as ${importAlias} from \"./${importFrom}\";\\n`\n }\n\n content += '\\n'\n\n content += `export const ${this.exportName} = {\\n`\n for (const { name, exportName: exports } of this.deps) {\n const importAlias = strings.importAlias(name)\n content += ` \"${name}\": ${importAlias}.${exports},\\n`\n }\n content += '}'\n\n content += '\\n'\n\n return content\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiC;AACjC,YAAuB;AACvB,aAAwB;AACxB,cAAyB;AAQlB,MAAe,OAAO;AAAA,EAgCjB,YAAoB,MAAmB;AAAnB;AAAA,EAAoB;AAAA,EA/B1C,qBAA+B,CAAC;AAAA,EAExC,IAAW,OAAe;AACxB,WAAO,KAAK,KAAK;AAAA,EACnB;AAAA,EAKA,IAAW,OAAe;AACxB,UAAM,WAAW,YAAAA,MAAQ,SAAS,KAAK,IAAI;AAC3C,QAAI,aAAa,OAAO,YAAY;AAClC,YAAM,UAAU,YAAAA,MAAQ,SAAS,YAAAA,MAAQ,QAAQ,KAAK,IAAI,CAAC;AAC3D,aAAO;AAAA,IACT;AACA,UAAM,mBAAmB,MAAM,KAAK,YAAY,QAAQ;AACxD,WAAO;AAAA,EACT;AAAA,EAEA,IAAW,kBAA2B;AACpC,WAAO,KAAK,KAAK,eAAe,OAAO;AAAA,EACzC;AAAA,EAEA,IAAW,aAAqB;AAC9B,WAAO,KAAK,KAAK;AAAA,EACnB;AAAA,EAEA,IAAW,OAAiB;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,IAAI;AAC5C,YAAM,aAAa,EAAE,OAAO,IAAI;AAChC,iBAAW,eAAe,uBAAuB;AAAA;AACjD,iBAAW,eAAe,uBAAuB;AAAA;AAAA,IACnD;AAEA,eAAW;AAEX,eAAW,eAAe,KAAK;AAAA;AAC/B,eAAW,EAAE,MAAM,YAAY,QAAQ,KAAK,KAAK,MAAM;AACrD,YAAM,cAAc,QAAQ,YAAY,IAAI;AAC5C,iBAAW,MAAM,UAAU,eAAe;AAAA;AAAA,IAC5C;AACA,eAAW;AAEX,eAAW;AAEX,WAAO;AAAA,EACT;AACF;AAEO,MAAM,+BAA+B,OAAO;AAAA,EACvC,YAAY,KAA6B;AACjD,UAAM;AAAA,MACJ,GAAG;AAAA,MACH,MAAM,OAAO;AAAA,IACf,CAAC;AAAA,EACH;AAAA,EAEA,MAAa,aAA8B;AACzC,QAAI,UAAU,OAAO;AAErB,eAAW,KAAK,KAAK,MAAM;AACzB,YAAM,EAAE,KAAK,IAAI;AACjB,YAAM,cAAc,QAAQ,YAAY,IAAI;AAC5C,YAAM,aAAa,EAAE,OAAO,IAAI;AAChC,iBAAW,eAAe,uBAAuB;AAAA;AACjD,iBAAW,eAAe,uBAAuB;AAAA;AAAA,IACnD;AAEA,eAAW;AAEX,eAAW,gBAAgB,KAAK;AAAA;AAChC,eAAW,EAAE,MAAM,YAAY,QAAQ,KAAK,KAAK,MAAM;AACrD,YAAM,cAAc,QAAQ,YAAY,IAAI;AAC5C,iBAAW,MAAM,UAAU,eAAe;AAAA;AAAA,IAC5C;AACA,eAAW;AAEX,eAAW;AAEX,WAAO;AAAA,EACT;AACF;",
6
6
  "names": ["pathlib"]
7
7
  }
@@ -25,16 +25,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
25
25
  var strings_exports = {};
26
26
  __export(strings_exports, {
27
27
  importAlias: () => importAlias,
28
- typeName: () => typeName
28
+ typeName: () => typeName,
29
+ varName: () => varName
29
30
  });
30
31
  module.exports = __toCommonJS(strings_exports);
31
32
  var utils = __toESM(require("../utils"));
32
33
  const apply = (str, ...transforms) => transforms.reduce((acc, transform) => transform(acc), str);
33
34
  const typeName = (name) => apply(name, utils.casing.to.pascalCase);
34
35
  const importAlias = (name) => apply(name, utils.casing.to.camelCase);
36
+ const varName = (name) => apply(name, utils.casing.to.camelCase);
35
37
  // Annotate the CommonJS export names for ESM import in node:
36
38
  0 && (module.exports = {
37
39
  importAlias,
38
- typeName
40
+ typeName,
41
+ varName
39
42
  });
40
43
  //# sourceMappingURL=strings.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/code-generation/strings.ts"],
4
- "sourcesContent": ["import * as utils from '../utils'\ntype StrTransform = (str: string) => string\n\nconst apply = (str: string, ...transforms: StrTransform[]) => transforms.reduce((acc, transform) => transform(acc), str)\n\nexport const typeName = (name: string) => apply(name, utils.casing.to.pascalCase)\nexport const importAlias = (name: string) => apply(name, utils.casing.to.camelCase)\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAAuB;AAGvB,MAAM,QAAQ,CAAC,QAAgB,eAA+B,WAAW,OAAO,CAAC,KAAK,cAAc,UAAU,GAAG,GAAG,GAAG;AAEhH,MAAM,WAAW,CAAC,SAAiB,MAAM,MAAM,MAAM,OAAO,GAAG,UAAU;AACzE,MAAM,cAAc,CAAC,SAAiB,MAAM,MAAM,MAAM,OAAO,GAAG,SAAS;",
4
+ "sourcesContent": ["import * as utils from '../utils'\ntype StrTransform = (str: string) => string\n\nconst apply = (str: string, ...transforms: StrTransform[]) => transforms.reduce((acc, transform) => transform(acc), str)\n\nexport const typeName = (name: string) => apply(name, utils.casing.to.pascalCase)\nexport const importAlias = (name: string) => apply(name, utils.casing.to.camelCase)\nexport const varName = (name: string) => apply(name, utils.casing.to.camelCase)\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAAuB;AAGvB,MAAM,QAAQ,CAAC,QAAgB,eAA+B,WAAW,OAAO,CAAC,KAAK,cAAc,UAAU,GAAG,GAAG,GAAG;AAEhH,MAAM,WAAW,CAAC,SAAiB,MAAM,MAAM,MAAM,OAAO,GAAG,UAAU;AACzE,MAAM,cAAc,CAAC,SAAiB,MAAM,MAAM,MAAM,OAAO,GAAG,SAAS;AAC3E,MAAM,UAAU,CAAC,SAAiB,MAAM,MAAM,MAAM,OAAO,GAAG,SAAS;",
6
6
  "names": []
7
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' | 'channels' | 'states' | 'events' | 'actions' | 'user' | 'entities'\n> & {\n id: string | null\n configuration: Pick<Integration['configuration'], 'schema'>\n configurations: Record<string, Pick<Integration['configuration'], 'schema'>>\n}\n\ntype Def<T> = NonNullable<T>\n\nexport type ConfigurationDefinition = Def<IntegrationDefinition['configuration']>\nexport type ConfigurationsDefinition = Def<IntegrationDefinition['configurations']>\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']>\nexport type EntityDefinition = Def<IntegrationDefinition['entities']>[string]\n"],
4
+ "sourcesContent": ["import * as client from '@botpress/client'\nimport * as utils from '../utils'\n\nexport type File = { path: string; content: string }\n\nexport type IntegrationInstallablePackage =\n | {\n source: 'remote'\n integration: client.Integration\n }\n | {\n source: 'local'\n path: utils.path.AbsolutePath\n }\n\nexport type InterfaceInstallablePackage =\n | {\n source: 'remote'\n interface: client.Interface\n }\n | {\n source: 'local'\n path: utils.path.AbsolutePath\n }\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -27,122 +27,133 @@ __export(add_command_exports, {
27
27
  AddCommand: () => AddCommand
28
28
  });
29
29
  module.exports = __toCommonJS(add_command_exports);
30
- var import_bluebird = __toESM(require("bluebird"));
31
- var import_chalk = __toESM(require("chalk"));
32
- var fs = __toESM(require("fs"));
30
+ var fslib = __toESM(require("fs"));
33
31
  var pathlib = __toESM(require("path"));
32
+ var import_api = require("../api");
34
33
  var codegen = __toESM(require("../code-generation"));
35
34
  var consts = __toESM(require("../consts"));
36
35
  var errors = __toESM(require("../errors"));
37
- var import_integration_ref = require("../integration-ref");
36
+ var pkgRef = __toESM(require("../package-ref"));
38
37
  var utils = __toESM(require("../utils"));
38
+ var import_global_command = require("./global-command");
39
39
  var import_project_command = require("./project-command");
40
- class AddCommand extends import_project_command.ProjectCommand {
40
+ class AddCommand extends import_global_command.GlobalCommand {
41
41
  async run() {
42
- const projectDef = await this.readProjectDefinitionFromFS();
43
- if (projectDef.type !== "bot") {
44
- throw new errors.ExclusiveBotFeatureError();
45
- }
46
- const integrationRef = this.argv.integrationRef;
47
- const parsedRef = (0, import_integration_ref.parseIntegrationRef)(integrationRef);
42
+ const parsedRef = pkgRef.parsePackageRef(this.argv.packageRef);
48
43
  if (!parsedRef) {
49
- throw new errors.InvalidIntegrationReferenceError(integrationRef);
44
+ throw new errors.InvalidPackageReferenceError(this.argv.packageRef);
45
+ }
46
+ const targetPackage = parsedRef.type === "path" ? await this._findLocalPackage(parsedRef) : await this._findRemotePackage(parsedRef);
47
+ if (!targetPackage) {
48
+ const notFoundMessage = this.argv.packageType ? `Could not find package "${this.argv.packageRef}" of type "${this.argv.packageType}"` : `Could not find package "${this.argv.packageRef}"`;
49
+ throw new errors.BotpressCLIError(notFoundMessage);
50
50
  }
51
- const integration = parsedRef.type === "path" ? await this._fetchLocalIntegrationOrInterface(parsedRef) : await this._fetchApiIntegration(parsedRef);
52
- const allInstances = await this._listIntegrationInstances();
53
- const existingInstance = allInstances.find((i) => i.name === integration.name);
54
- if (existingInstance) {
55
- this.logger.warn(`Integration with name "${integration.name}" already installed.`);
56
- const res = await this.prompt.confirm("Do you want to overwrite the existing instance?");
51
+ const packageName = targetPackage.name;
52
+ const baseInstallPath = utils.path.absoluteFrom(utils.path.cwd(), this.argv.installPath);
53
+ const packageDirName = utils.casing.to.kebabCase(packageName);
54
+ const installPath = utils.path.join(baseInstallPath, consts.installDirName, packageDirName);
55
+ const alreadyInstalled = fslib.existsSync(installPath);
56
+ if (alreadyInstalled) {
57
+ this.logger.warn(`Package with name "${packageName}" already installed.`);
58
+ const res = await this.prompt.confirm("Do you want to overwrite the existing package?");
57
59
  if (!res) {
58
60
  this.logger.log("Aborted");
59
61
  return;
60
62
  }
61
- await this._uninstallIntegration(existingInstance);
63
+ await this._uninstall(installPath);
62
64
  }
63
- await this._generateIntegrationInstance(integration);
64
- }
65
- _fetchLocalIntegrationOrInterface = async (integrationOrInterfaceRef) => {
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 = integrationOrInterfaceRef.path;
70
- const pathStore = new utils.path.PathStore({
71
- workDir,
72
- integrationDefinition: utils.path.absoluteFrom(workDir, consts.fromWorkDir.integrationDefinition),
73
- interfaceDefinition: utils.path.absoluteFrom(workDir, consts.fromWorkDir.interfaceDefinition)
74
- });
75
- const projectDef = await this.readProjectDefinitionFromFS(pathStore);
76
- if (projectDef.type === "bot") {
77
- throw new errors.BotpressCLIError(`Integration definition not found at ${workDir}`);
78
- } else if (projectDef.type === "interface") {
79
- throw new errors.BotpressCLIError("Installing interfaces is not supported yet");
65
+ let files;
66
+ if (targetPackage.type === "integration") {
67
+ files = await codegen.generateIntegrationPackage(targetPackage.pkg);
68
+ } else {
69
+ files = await codegen.generateInterfacePackage(targetPackage.pkg);
80
70
  }
81
- return projectDef.definition;
82
- };
83
- _fetchApiIntegration = async (integrationRef) => {
71
+ await this._install(installPath, files);
72
+ }
73
+ async _findRemotePackage(ref) {
84
74
  const api = await this.ensureLoginAndCreateClient(this.argv);
85
- const integration = await api.findIntegration(integrationRef);
86
- if (integration) {
87
- return integration;
75
+ if (this._pkgCouldBe("integration")) {
76
+ const integration = await api.findIntegration(ref);
77
+ if (integration) {
78
+ return { type: "integration", name: integration.name, pkg: { source: "remote", integration } };
79
+ }
88
80
  }
89
- const intrface = await api.findPublicInterface(integrationRef);
90
- if (intrface) {
91
- throw new errors.BotpressCLIError("Installing interfaces is not supported yet");
81
+ if (this._pkgCouldBe("interface")) {
82
+ const intrface = await api.findPublicInterface(ref);
83
+ if (intrface) {
84
+ return { type: "interface", name: intrface.name, pkg: { source: "remote", interface: intrface } };
85
+ }
92
86
  }
93
- const formattedRef = (0, import_integration_ref.formatIntegrationRef)(integrationRef);
94
- throw new errors.BotpressCLIError(`Integration "${formattedRef}" not found`);
95
- };
96
- async _listIntegrationInstances() {
97
- const installPath = this.projectPaths.abs.installDir;
98
- if (!fs.existsSync(installPath)) {
99
- this.logger.debug("Install path does not exist. Skipping listing of integration instances");
100
- return [];
87
+ return;
88
+ }
89
+ async _findLocalPackage(ref) {
90
+ const absPath = utils.path.absoluteFrom(utils.path.cwd(), ref.path);
91
+ const projectDefinition = await this._readProject(absPath);
92
+ if (this._pkgCouldBe("integration") && projectDefinition?.type === "integration") {
93
+ return {
94
+ type: "integration",
95
+ name: projectDefinition.definition.name,
96
+ pkg: { source: "local", path: absPath }
97
+ };
101
98
  }
102
- const allFiles = await fs.promises.readdir(installPath);
103
- const allPaths = allFiles.map((name) => pathlib.join(installPath, name));
104
- const directories = await import_bluebird.default.filter(allPaths, async (path) => {
105
- const stat = await fs.promises.stat(path);
106
- return stat.isDirectory();
107
- });
108
- let jsons = directories.map((root) => ({ root, json: pathlib.join(root, codegen.INTEGRATION_JSON) }));
109
- jsons = jsons.filter(({ json: x }) => fs.existsSync(x));
110
- return import_bluebird.default.map(jsons, async ({ root, json }) => {
111
- const content = await fs.promises.readFile(json, "utf-8");
112
- const { name, version, id } = JSON.parse(content);
113
- const dirname = pathlib.basename(root);
99
+ if (this._pkgCouldBe("interface") && projectDefinition?.type === "interface") {
114
100
  return {
115
- dirname,
116
- id,
117
- name,
118
- version
101
+ type: "interface",
102
+ name: projectDefinition.definition.name,
103
+ pkg: { source: "local", path: absPath }
119
104
  };
120
- });
121
- }
122
- async _uninstallIntegration(instance) {
123
- const installDir = this.projectPaths.abs.installDir;
124
- const instancePath = pathlib.join(installDir, instance.dirname);
125
- await fs.promises.rm(instancePath, { recursive: true });
126
- await this._generateBotIndex();
105
+ }
106
+ if (projectDefinition?.type === "bot") {
107
+ throw new errors.BotpressCLIError("Cannot install a bot as a package");
108
+ }
109
+ return;
127
110
  }
128
- async _generateIntegrationInstance(integration) {
111
+ async _install(installPath, files) {
129
112
  const line = this.logger.line();
130
- const { name, version } = integration;
131
- line.started(`Installing ${import_chalk.default.bold(name)} v${version}...`);
132
- const instanceFiles = await codegen.generateIntegrationInstance(
133
- integration,
134
- this.projectPaths.rel("outDir").installDir
135
- );
136
- await this.writeGeneratedFilesToOutFolder(instanceFiles);
137
- await this._generateBotIndex();
138
- const rel = this.projectPaths.rel("workDir");
139
- line.success(`Installed integration available at ${import_chalk.default.grey(rel.outDir)}`);
113
+ line.started(`Installing ${files.length} files to "${installPath}"`);
114
+ try {
115
+ for (const file of files) {
116
+ const filePath = utils.path.absoluteFrom(installPath, file.path);
117
+ const dirPath = pathlib.dirname(filePath);
118
+ await fslib.promises.mkdir(dirPath, { recursive: true });
119
+ await fslib.promises.writeFile(filePath, file.content);
120
+ }
121
+ line.success(`Installed ${files.length} files to "${installPath}"`);
122
+ } finally {
123
+ line.commit();
124
+ }
125
+ }
126
+ async _uninstall(installPath) {
127
+ await fslib.promises.rm(installPath, { recursive: true });
140
128
  }
141
- async _generateBotIndex() {
142
- const allInstances = await this._listIntegrationInstances();
143
- const indexFile = await codegen.generateBotIndex(this.projectPaths.rel("outDir").installDir, allInstances);
144
- await this.writeGeneratedFilesToOutFolder([indexFile]);
129
+ async _readProject(workDir) {
130
+ class AnyProjectCommand extends import_project_command.ProjectCommand {
131
+ async run() {
132
+ throw new errors.BotpressCLIError("Not implemented");
133
+ }
134
+ async readProjectDefinitionFromFS() {
135
+ return super.readProjectDefinitionFromFS();
136
+ }
137
+ }
138
+ const cmd = new AnyProjectCommand(import_api.ApiClient, this.prompt, this.logger, {
139
+ ...this.argv,
140
+ entryPoint: consts.defaultEntrypoint,
141
+ outDir: consts.defaultOutputFolder,
142
+ workDir
143
+ });
144
+ return cmd.readProjectDefinitionFromFS().catch((thrown) => {
145
+ if (thrown instanceof errors.ProjectDefinitionNotFoundError) {
146
+ return void 0;
147
+ }
148
+ throw thrown;
149
+ });
145
150
  }
151
+ _pkgCouldBe = (pkgType) => {
152
+ if (!this.argv.packageType) {
153
+ return true;
154
+ }
155
+ return this.argv.packageType === pkgType;
156
+ };
146
157
  }
147
158
  // Annotate the CommonJS export names for ESM import in node:
148
159
  0 && (module.exports = {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/command-implementations/add-command.ts"],
4
- "sourcesContent": ["import type * as client from '@botpress/client'\nimport type * as sdk 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 projectDef = await this.readProjectDefinitionFromFS()\n if (projectDef.type !== 'bot') {\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._fetchLocalIntegrationOrInterface(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 _fetchLocalIntegrationOrInterface = async (\n integrationOrInterfaceRef: LocalPathIntegrationRef\n ): Promise<sdk.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 = integrationOrInterfaceRef.path\n const pathStore = new utils.path.PathStore<'workDir' | 'integrationDefinition' | 'interfaceDefinition'>({\n workDir,\n integrationDefinition: utils.path.absoluteFrom(workDir, consts.fromWorkDir.integrationDefinition),\n interfaceDefinition: utils.path.absoluteFrom(workDir, consts.fromWorkDir.interfaceDefinition),\n })\n\n const projectDef = await this.readProjectDefinitionFromFS(pathStore)\n if (projectDef.type === 'bot') {\n throw new errors.BotpressCLIError(`Integration definition not found at ${workDir}`)\n } else if (projectDef.type === 'interface') {\n throw new errors.BotpressCLIError('Installing interfaces is not supported yet')\n }\n\n return projectDef.definition\n }\n\n private _fetchApiIntegration = async (integrationRef: ApiIntegrationRef): Promise<client.Integration> => {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n const integration = await api.findIntegration(integrationRef)\n if (integration) {\n return integration\n }\n\n const intrface = await api.findPublicInterface(integrationRef)\n if (intrface) {\n throw new errors.BotpressCLIError('Installing interfaces is not supported yet')\n }\n\n const formattedRef = formatIntegrationRef(integrationRef)\n throw new errors.BotpressCLIError(`Integration \"${formattedRef}\" not found`)\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: client.Integration | sdk.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(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AA0B;AAC1D,UAAM,YAAY,MAAM,QAAQ,iBAAiB,KAAK,aAAa,IAAI,QAAQ,EAAE,YAAY,YAAY;AACzG,UAAM,KAAK,+BAA+B,CAAC,SAAS,CAAC;AAAA,EACvD;AACF;",
6
- "names": ["bluebird", "chalk"]
4
+ "sourcesContent": ["import * as fslib from 'fs'\nimport * as pathlib from 'path'\nimport { ApiClient } from '../api'\nimport * as codegen from '../code-generation'\nimport type commandDefinitions from '../command-definitions'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport * as pkgRef from '../package-ref'\nimport * as utils from '../utils'\nimport { GlobalCommand } from './global-command'\nimport { ProjectCommand, ProjectCommandDefinition, ProjectDefinition } from './project-command'\n\ntype InstallablePackage =\n | {\n type: 'integration'\n name: string\n pkg: codegen.IntegrationInstallablePackage\n }\n | {\n type: 'interface'\n name: string\n pkg: codegen.InterfaceInstallablePackage\n }\n\nexport type AddCommandDefinition = typeof commandDefinitions.add\nexport class AddCommand extends GlobalCommand<AddCommandDefinition> {\n public async run(): Promise<void> {\n const parsedRef = pkgRef.parsePackageRef(this.argv.packageRef)\n if (!parsedRef) {\n throw new errors.InvalidPackageReferenceError(this.argv.packageRef)\n }\n\n const targetPackage =\n parsedRef.type === 'path' ? await this._findLocalPackage(parsedRef) : await this._findRemotePackage(parsedRef)\n\n if (!targetPackage) {\n const notFoundMessage = this.argv.packageType\n ? `Could not find package \"${this.argv.packageRef}\" of type \"${this.argv.packageType}\"`\n : `Could not find package \"${this.argv.packageRef}\"`\n throw new errors.BotpressCLIError(notFoundMessage)\n }\n\n const packageName = targetPackage.name // TODO: eventually replace name by alias (with argv --alias)\n const baseInstallPath = utils.path.absoluteFrom(utils.path.cwd(), this.argv.installPath)\n const packageDirName = utils.casing.to.kebabCase(packageName)\n const installPath = utils.path.join(baseInstallPath, consts.installDirName, packageDirName)\n\n const alreadyInstalled = fslib.existsSync(installPath)\n if (alreadyInstalled) {\n this.logger.warn(`Package with name \"${packageName}\" already installed.`)\n const res = await this.prompt.confirm('Do you want to overwrite the existing package?')\n if (!res) {\n this.logger.log('Aborted')\n return\n }\n\n await this._uninstall(installPath)\n }\n\n let files: codegen.File[]\n if (targetPackage.type === 'integration') {\n files = await codegen.generateIntegrationPackage(targetPackage.pkg)\n } else {\n files = await codegen.generateInterfacePackage(targetPackage.pkg)\n }\n\n await this._install(installPath, files)\n }\n\n private async _findRemotePackage(ref: pkgRef.ApiPackageRef): Promise<InstallablePackage | undefined> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n if (this._pkgCouldBe('integration')) {\n const integration = await api.findIntegration(ref)\n if (integration) {\n return { type: 'integration', name: integration.name, pkg: { source: 'remote', integration } }\n }\n }\n if (this._pkgCouldBe('interface')) {\n const intrface = await api.findPublicInterface(ref)\n if (intrface) {\n return { type: 'interface', name: intrface.name, pkg: { source: 'remote', interface: intrface } }\n }\n }\n return\n }\n\n private async _findLocalPackage(ref: pkgRef.LocalPackageRef): Promise<InstallablePackage | undefined> {\n const absPath = utils.path.absoluteFrom(utils.path.cwd(), ref.path)\n const projectDefinition = await this._readProject(absPath)\n if (this._pkgCouldBe('integration') && projectDefinition?.type === 'integration') {\n return {\n type: 'integration',\n name: projectDefinition.definition.name,\n pkg: { source: 'local', path: absPath },\n }\n }\n if (this._pkgCouldBe('interface') && projectDefinition?.type === 'interface') {\n return {\n type: 'interface',\n name: projectDefinition.definition.name,\n pkg: { source: 'local', path: absPath },\n }\n }\n if (projectDefinition?.type === 'bot') {\n throw new errors.BotpressCLIError('Cannot install a bot as a package')\n }\n return\n }\n\n private async _install(installPath: utils.path.AbsolutePath, files: codegen.File[]): Promise<void> {\n const line = this.logger.line()\n line.started(`Installing ${files.length} files to \"${installPath}\"`)\n try {\n for (const file of files) {\n const filePath = utils.path.absoluteFrom(installPath, file.path)\n const dirPath = pathlib.dirname(filePath)\n await fslib.promises.mkdir(dirPath, { recursive: true })\n await fslib.promises.writeFile(filePath, file.content)\n }\n line.success(`Installed ${files.length} files to \"${installPath}\"`)\n } finally {\n line.commit()\n }\n }\n\n private async _uninstall(installPath: utils.path.AbsolutePath): Promise<void> {\n await fslib.promises.rm(installPath, { recursive: true })\n }\n\n private async _readProject(workDir: utils.path.AbsolutePath): Promise<ProjectDefinition | undefined> {\n // this is a hack to avoid refactoring the project command class\n class AnyProjectCommand extends ProjectCommand<ProjectCommandDefinition> {\n public async run(): Promise<void> {\n throw new errors.BotpressCLIError('Not implemented')\n }\n\n public async readProjectDefinitionFromFS(): Promise<ProjectDefinition> {\n return super.readProjectDefinitionFromFS()\n }\n }\n\n const cmd = new AnyProjectCommand(ApiClient, this.prompt, this.logger, {\n ...this.argv,\n entryPoint: consts.defaultEntrypoint,\n outDir: consts.defaultOutputFolder,\n workDir,\n })\n\n return cmd.readProjectDefinitionFromFS().catch((thrown) => {\n if (thrown instanceof errors.ProjectDefinitionNotFoundError) {\n return undefined\n }\n throw thrown\n })\n }\n\n private _pkgCouldBe = (pkgType: InstallablePackage['type']) => {\n if (!this.argv.packageType) {\n return true\n }\n return this.argv.packageType === pkgType\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAAuB;AACvB,cAAyB;AACzB,iBAA0B;AAC1B,cAAyB;AAEzB,aAAwB;AACxB,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,4BAA8B;AAC9B,6BAA4E;AAerE,MAAM,mBAAmB,oCAAoC;AAAA,EAClE,MAAa,MAAqB;AAChC,UAAM,YAAY,OAAO,gBAAgB,KAAK,KAAK,UAAU;AAC7D,QAAI,CAAC,WAAW;AACd,YAAM,IAAI,OAAO,6BAA6B,KAAK,KAAK,UAAU;AAAA,IACpE;AAEA,UAAM,gBACJ,UAAU,SAAS,SAAS,MAAM,KAAK,kBAAkB,SAAS,IAAI,MAAM,KAAK,mBAAmB,SAAS;AAE/G,QAAI,CAAC,eAAe;AAClB,YAAM,kBAAkB,KAAK,KAAK,cAC9B,2BAA2B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qD;AAC5E,UAAM,MAAM,SAAS,GAAG,aAAa,EAAE,WAAW,KAAK,CAAC;AAAA,EAC1D;AAAA,EAEA,MAAc,aAAa,SAA0E;AAEnG,UAAM,0BAA0B,sCAAyC;AAAA,MACvE,MAAa,MAAqB;AAChC,cAAM,IAAI,OAAO,iBAAiB,iBAAiB;AAAA,MACrD;AAAA,MAEA,MAAa,8BAA0D;AACrE,eAAO,MAAM,4BAA4B;AAAA,MAC3C;AAAA,IACF;AAEA,UAAM,MAAM,IAAI,kBAAkB,sBAAW,KAAK,QAAQ,KAAK,QAAQ;AAAA,MACrE,GAAG,KAAK;AAAA,MACR,YAAY,OAAO;AAAA,MACnB,QAAQ,OAAO;AAAA,MACf;AAAA,IACF,CAAC;AAED,WAAO,IAAI,4BAA4B,EAAE,MAAM,CAAC,WAAW;AACzD,UAAI,kBAAkB,OAAO,gCAAgC;AAC3D,eAAO;AAAA,MACT;AACA,YAAM;AAAA,IACR,CAAC;AAAA,EACH;AAAA,EAEQ,cAAc,CAAC,YAAwC;AAC7D,QAAI,CAAC,KAAK,KAAK,aAAa;AAC1B,aAAO;AAAA,IACT;AACA,WAAO,KAAK,KAAK,gBAAgB;AAAA,EACnC;AACF;",
6
+ "names": []
7
7
  }
@@ -28,25 +28,32 @@ __export(bundle_command_exports, {
28
28
  });
29
29
  module.exports = __toCommonJS(bundle_command_exports);
30
30
  var import_chalk = __toESM(require("chalk"));
31
+ var errors = __toESM(require("../errors"));
31
32
  var utils = __toESM(require("../utils"));
32
33
  var import_project_command = require("./project-command");
33
34
  class BundleCommand extends import_project_command.ProjectCommand {
34
35
  async run() {
35
- const { type: projectType, definition: integrationDef } = await this.readProjectDefinitionFromFS();
36
- if (projectType === "interface") {
37
- this.logger.success("Interface projects have nothing to bundle.");
36
+ const projectDef = await this.readProjectDefinitionFromFS();
37
+ if (projectDef.type === "interface") {
38
+ this.logger.success("Interface projects have no implementation to bundle.");
38
39
  return;
39
40
  }
40
- const abs = this.projectPaths.abs;
41
- const rel = this.projectPaths.rel("workDir");
42
41
  const line = this.logger.line();
43
- const logLevel = this.argv.verbose ? "info" : "silent";
44
- if (integrationDef) {
45
- const { name } = integrationDef;
42
+ if (projectDef.type === "integration") {
43
+ const { name } = projectDef.definition;
46
44
  line.started(`Bundling integration ${import_chalk.default.bold(name)}...`);
47
- } else {
45
+ return await this._bundle(line);
46
+ }
47
+ if (projectDef.type === "bot") {
48
48
  line.started("Bundling bot...");
49
+ return await this._bundle(line);
49
50
  }
51
+ throw new errors.UnsupportedProjectType();
52
+ }
53
+ async _bundle(line) {
54
+ const logLevel = this.argv.verbose ? "info" : "silent";
55
+ const abs = this.projectPaths.abs;
56
+ const rel = this.projectPaths.rel("workDir");
50
57
  const unixPath = utils.path.toUnix(rel.entryPoint);
51
58
  const importFrom = utils.path.rmExtension(unixPath);
52
59
  const code = `import x from './${importFrom}'; export default x; export const handler = x.handler;`;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/command-implementations/bundle-command.ts"],
4
- "sourcesContent": ["import chalk from 'chalk'\nimport type commandDefinitions from '../command-definitions'\nimport * as utils from '../utils'\nimport { ProjectCommand } from './project-command'\n\nexport type BundleCommandDefinition = typeof commandDefinitions.bundle\nexport class BundleCommand extends ProjectCommand<BundleCommandDefinition> {\n public async run(): Promise<void> {\n const { type: projectType, definition: integrationDef } = await this.readProjectDefinitionFromFS()\n\n if (projectType === 'interface') {\n this.logger.success('Interface projects have nothing to bundle.')\n return\n }\n\n const abs = this.projectPaths.abs\n const rel = this.projectPaths.rel('workDir')\n\n const line = this.logger.line()\n\n const logLevel = this.argv.verbose ? 'info' : 'silent'\n\n if (integrationDef) {\n const { name } = integrationDef\n line.started(`Bundling integration ${chalk.bold(name)}...`)\n } else {\n line.started('Bundling bot...')\n }\n\n const unixPath = utils.path.toUnix(rel.entryPoint)\n const importFrom = utils.path.rmExtension(unixPath)\n const code = `import x from './${importFrom}'; export default x; export const handler = x.handler;`\n\n const outfile = abs.outFile // TODO: ensure dir exists\n line.debug(`Writing bundle to ${outfile}`)\n\n await utils.esbuild.buildCode({\n code,\n cwd: abs.workDir,\n outfile,\n logLevel,\n write: true,\n sourcemap: this.argv.sourceMap,\n minify: this.argv.minify,\n })\n\n line.success(`Bundle available at ${chalk.grey(rel.outDir)}`)\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAElB,YAAuB;AACvB,6BAA+B;AAGxB,MAAM,sBAAsB,sCAAwC;AAAA,EACzE,MAAa,MAAqB;AAChC,UAAM,EAAE,MAAM,aAAa,YAAY,eAAe,IAAI,MAAM,KAAK,4BAA4B;AAEjG,QAAI,gBAAgB,aAAa;AAC/B,WAAK,OAAO,QAAQ,4CAA4C;AAChE;AAAA,IACF;AAEA,UAAM,MAAM,KAAK,aAAa;AAC9B,UAAM,MAAM,KAAK,aAAa,IAAI,SAAS;AAE3C,UAAM,OAAO,KAAK,OAAO,KAAK;AAE9B,UAAM,WAAW,KAAK,KAAK,UAAU,SAAS;AAE9C,QAAI,gBAAgB;AAClB,YAAM,EAAE,KAAK,IAAI;AACjB,WAAK,QAAQ,wBAAwB,aAAAA,QAAM,KAAK,IAAI,MAAM;AAAA,IAC5D,OAAO;AACL,WAAK,QAAQ,iBAAiB;AAAA,IAChC;AAEA,UAAM,WAAW,MAAM,KAAK,OAAO,IAAI,UAAU;AACjD,UAAM,aAAa,MAAM,KAAK,YAAY,QAAQ;AAClD,UAAM,OAAO,oBAAoB;AAEjC,UAAM,UAAU,IAAI;AACpB,SAAK,MAAM,qBAAqB,SAAS;AAEzC,UAAM,MAAM,QAAQ,UAAU;AAAA,MAC5B;AAAA,MACA,KAAK,IAAI;AAAA,MACT;AAAA,MACA;AAAA,MACA,OAAO;AAAA,MACP,WAAW,KAAK,KAAK;AAAA,MACrB,QAAQ,KAAK,KAAK;AAAA,IACpB,CAAC;AAED,SAAK,QAAQ,uBAAuB,aAAAA,QAAM,KAAK,IAAI,MAAM,GAAG;AAAA,EAC9D;AACF;",
4
+ "sourcesContent": ["import chalk from 'chalk'\nimport { SingleLineLogger } from 'src/logger'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport * as utils from '../utils'\nimport { ProjectCommand } from './project-command'\n\nexport type BundleCommandDefinition = typeof commandDefinitions.bundle\nexport class BundleCommand extends ProjectCommand<BundleCommandDefinition> {\n public async run(): Promise<void> {\n const projectDef = await this.readProjectDefinitionFromFS()\n\n if (projectDef.type === 'interface') {\n this.logger.success('Interface projects have no implementation to bundle.')\n return\n }\n\n const line = this.logger.line()\n\n if (projectDef.type === 'integration') {\n const { name } = projectDef.definition\n line.started(`Bundling integration ${chalk.bold(name)}...`)\n return await this._bundle(line)\n }\n\n if (projectDef.type === 'bot') {\n line.started('Bundling bot...')\n return await this._bundle(line)\n }\n\n throw new errors.UnsupportedProjectType()\n }\n\n private async _bundle(line: SingleLineLogger) {\n const logLevel = this.argv.verbose ? 'info' : 'silent'\n const abs = this.projectPaths.abs\n const rel = this.projectPaths.rel('workDir')\n\n const unixPath = utils.path.toUnix(rel.entryPoint)\n const importFrom = utils.path.rmExtension(unixPath)\n const code = `import x from './${importFrom}'; export default x; export const handler = x.handler;`\n\n const outfile = abs.outFile // TODO: ensure dir exists\n line.debug(`Writing bundle to ${outfile}`)\n\n await utils.esbuild.buildCode({\n code,\n cwd: abs.workDir,\n outfile,\n logLevel,\n write: true,\n sourcemap: this.argv.sourceMap,\n minify: this.argv.minify,\n })\n\n line.success(`Bundle available at ${chalk.grey(rel.outDir)}`)\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAGlB,aAAwB;AACxB,YAAuB;AACvB,6BAA+B;AAGxB,MAAM,sBAAsB,sCAAwC;AAAA,EACzE,MAAa,MAAqB;AAChC,UAAM,aAAa,MAAM,KAAK,4BAA4B;AAE1D,QAAI,WAAW,SAAS,aAAa;AACnC,WAAK,OAAO,QAAQ,sDAAsD;AAC1E;AAAA,IACF;AAEA,UAAM,OAAO,KAAK,OAAO,KAAK;AAE9B,QAAI,WAAW,SAAS,eAAe;AACrC,YAAM,EAAE,KAAK,IAAI,WAAW;AAC5B,WAAK,QAAQ,wBAAwB,aAAAA,QAAM,KAAK,IAAI,MAAM;AAC1D,aAAO,MAAM,KAAK,QAAQ,IAAI;AAAA,IAChC;AAEA,QAAI,WAAW,SAAS,OAAO;AAC7B,WAAK,QAAQ,iBAAiB;AAC9B,aAAO,MAAM,KAAK,QAAQ,IAAI;AAAA,IAChC;AAEA,UAAM,IAAI,OAAO,uBAAuB;AAAA,EAC1C;AAAA,EAEA,MAAc,QAAQ,MAAwB;AAC5C,UAAM,WAAW,KAAK,KAAK,UAAU,SAAS;AAC9C,UAAM,MAAM,KAAK,aAAa;AAC9B,UAAM,MAAM,KAAK,aAAa,IAAI,SAAS;AAE3C,UAAM,WAAW,MAAM,KAAK,OAAO,IAAI,UAAU;AACjD,UAAM,aAAa,MAAM,KAAK,YAAY,QAAQ;AAClD,UAAM,OAAO,oBAAoB;AAEjC,UAAM,UAAU,IAAI;AACpB,SAAK,MAAM,qBAAqB,SAAS;AAEzC,UAAM,MAAM,QAAQ,UAAU;AAAA,MAC5B;AAAA,MACA,KAAK,IAAI;AAAA,MACT;AAAA,MACA;AAAA,MACA,OAAO;AAAA,MACP,WAAW,KAAK,KAAK;AAAA,MACrB,QAAQ,KAAK,KAAK;AAAA,IACpB,CAAC;AAED,SAAK,QAAQ,uBAAuB,aAAAA,QAAM,KAAK,IAAI,MAAM,GAAG;AAAA,EAC9D;AACF;",
6
6
  "names": ["chalk"]
7
7
  }
@@ -27,6 +27,7 @@ __export(deploy_command_exports, {
27
27
  DeployCommand: () => DeployCommand
28
28
  });
29
29
  module.exports = __toCommonJS(deploy_command_exports);
30
+ var sdk = __toESM(require("@botpress/sdk"));
30
31
  var import_chalk = __toESM(require("chalk"));
31
32
  var fs = __toESM(require("fs"));
32
33
  var import_semver = __toESM(require("semver"));
@@ -34,6 +35,7 @@ var import_bot_body = require("../api/bot-body");
34
35
  var import_integration_body = require("../api/integration-body");
35
36
  var import_interface_body = require("../api/interface-body");
36
37
  var errors = __toESM(require("../errors"));
38
+ var import_sdk = require("../sdk");
37
39
  var utils = __toESM(require("../utils"));
38
40
  var import_build_command = require("./build-command");
39
41
  var import_project_command = require("./project-command");
@@ -50,7 +52,10 @@ class DeployCommand extends import_project_command.ProjectCommand {
50
52
  if (projectDef.type === "interface") {
51
53
  return this._deployInterface(api, projectDef.definition);
52
54
  }
53
- return this._deployBot(api, this.argv.botId, this.argv.createNewBot);
55
+ if (projectDef.type === "bot") {
56
+ return this._deployBot(api, projectDef.definition, this.argv.botId, this.argv.createNewBot);
57
+ }
58
+ throw new errors.UnsupportedProjectType();
54
59
  }
55
60
  async _runBuild() {
56
61
  return new import_build_command.BuildCommand(this.api, this.prompt, this.logger, this.argv).run();
@@ -90,6 +95,7 @@ class DeployCommand extends import_project_command.ProjectCommand {
90
95
  this.logger.log("Aborted");
91
96
  return;
92
97
  }
98
+ this.logger.debug("Preparing integration request body...");
93
99
  let createBody = await (0, import_integration_body.prepareCreateIntegrationBody)(integrationDef);
94
100
  createBody = {
95
101
  ...createBody,
@@ -128,7 +134,13 @@ class DeployCommand extends import_project_command.ProjectCommand {
128
134
  });
129
135
  line.success(successMessage);
130
136
  } else {
137
+ this.logger.debug(`looking for previous version of integration "${name}"`);
131
138
  const previousVersion = await api.findPreviousIntegrationVersion({ type: "name", name, version });
139
+ if (previousVersion) {
140
+ this.logger.debug(`previous version found: ${previousVersion.version}`);
141
+ } else {
142
+ this.logger.debug("no previous version found");
143
+ }
132
144
  const knownSecrets = previousVersion?.secrets;
133
145
  const createSecrets = await this.promptSecrets(integrationDef, this.argv, { knownSecrets });
134
146
  createBody.secrets = utils.records.filterValues(createSecrets, utils.guards.is.notNull);
@@ -232,10 +244,9 @@ class DeployCommand extends import_project_command.ProjectCommand {
232
244
  throw errors.BotpressCLIError.wrap(thrown, `Could not read ${filePurpose} file "${absoluteFilePath}"`);
233
245
  });
234
246
  };
235
- async _deployBot(api, argvBotId, argvCreateNew) {
247
+ async _deployBot(api, botDefinition, argvBotId, argvCreateNew) {
236
248
  const outfile = this.projectPaths.abs.outFile;
237
249
  const code = await fs.promises.readFile(outfile, "utf-8");
238
- const { default: botImpl } = utils.require.requireJsFile(outfile);
239
250
  let bot;
240
251
  if (argvBotId && argvCreateNew) {
241
252
  throw new errors.BotpressCLIError("Cannot specify both --botId and --createNew");
@@ -256,10 +267,11 @@ class DeployCommand extends import_project_command.ProjectCommand {
256
267
  }
257
268
  const line = this.logger.line();
258
269
  line.started(`Deploying bot ${import_chalk.default.bold(bot.name)}...`);
259
- const integrationInstances = await this.fetchBotIntegrationInstances(botImpl, api);
270
+ const integrationInstances = await this.fetchBotIntegrationInstances(botDefinition, api);
271
+ const createBotBody = await (0, import_bot_body.prepareCreateBotBody)(botDefinition);
260
272
  const updateBotBody = (0, import_bot_body.prepareUpdateBotBody)(
261
273
  {
262
- ...await (0, import_bot_body.prepareCreateBotBody)(botImpl),
274
+ ...createBotBody,
263
275
  id: bot.id,
264
276
  code,
265
277
  integrations: integrationInstances
@@ -330,7 +342,7 @@ class DeployCommand extends import_project_command.ProjectCommand {
330
342
  throw new errors.BotpressCLIError(workspaceHandleIsMandatoryMsg);
331
343
  }
332
344
  const newName2 = `${remoteHandle}/${localName}`;
333
- return integration.clone({ name: newName2 });
345
+ return new sdk.IntegrationDefinition({ ...integration, name: newName2 });
334
346
  }
335
347
  if (localHandle && !remoteHandle) {
336
348
  const { available } = await api.client.checkHandleAvailability({ handle: localHandle }).catch((thrown) => {
@@ -370,7 +382,7 @@ class DeployCommand extends import_project_command.ProjectCommand {
370
382
  } while (!claimedHandle);
371
383
  this.logger.success(`Handle "${claimedHandle}" is yours!`);
372
384
  const newName = `${claimedHandle}/${localName}`;
373
- return integration.clone({ name: newName });
385
+ return new sdk.IntegrationDefinition({ ...integration, name: newName });
374
386
  }
375
387
  _parseIntegrationName = (integrationName) => {
376
388
  const parts = integrationName.split("/");
@@ -387,22 +399,25 @@ class DeployCommand extends import_project_command.ProjectCommand {
387
399
  return { name };
388
400
  };
389
401
  _formatInterfacesImplStatements = async (api, integration) => {
390
- const interfacesEntries = Object.entries(integration.interfaces);
391
- if (!interfacesEntries.length) {
392
- return void 0;
393
- }
402
+ const interfacesStatements = (0, import_sdk.getImplementationStatements)(integration);
394
403
  const interfaces = {};
395
- for (const [key, i] of interfacesEntries) {
396
- const { name, version, entities, actions, events } = i;
397
- const intrface = await api.findPublicInterface({ type: "name", name, version });
398
- if (!intrface) {
399
- throw new errors.BotpressCLIError(`Could not find interface "${name}@${version}"`);
400
- }
401
- const { id } = intrface;
402
- interfaces[key] = { id, entities, actions, events };
404
+ for (const [key, i] of Object.entries(interfacesStatements)) {
405
+ const { name, version, entities, actions, events, channels } = i;
406
+ const id = await this._getInterfaceId(api, { id: i.id, name, version });
407
+ interfaces[key] = { id, entities, actions, events, channels };
403
408
  }
404
409
  return interfaces;
405
410
  };
411
+ _getInterfaceId = async (api, ref) => {
412
+ if (ref.id) {
413
+ return ref.id;
414
+ }
415
+ const intrface = await api.findPublicInterface({ type: "name", name: ref.name, version: ref.version });
416
+ if (!intrface) {
417
+ throw new errors.BotpressCLIError(`Could not find interface "${ref.name}@${ref.version}"`);
418
+ }
419
+ return intrface.id;
420
+ };
406
421
  }
407
422
  // Annotate the CommonJS export names for ESM import in node:
408
423
  0 && (module.exports = {