@apimatic/cli 1.1.0-alpha.8 → 1.1.0-beta.1

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 (345) hide show
  1. package/README.md +436 -374
  2. package/bin/run.js +5 -0
  3. package/lib/actions/action-result.d.ts +13 -0
  4. package/lib/actions/action-result.js +44 -0
  5. package/lib/actions/action-result.js.map +1 -0
  6. package/lib/actions/api/transform.d.ts +15 -0
  7. package/lib/actions/api/transform.js +48 -0
  8. package/lib/actions/api/transform.js.map +1 -0
  9. package/lib/actions/api/validate.d.ts +12 -0
  10. package/lib/actions/api/validate.js +41 -0
  11. package/lib/actions/api/validate.js.map +1 -0
  12. package/lib/actions/auth/login.d.ts +13 -0
  13. package/lib/actions/auth/login.js +55 -0
  14. package/lib/actions/auth/login.js.map +1 -0
  15. package/lib/actions/auth/logout.d.ts +8 -0
  16. package/lib/actions/auth/logout.js +15 -0
  17. package/lib/actions/auth/logout.js.map +1 -0
  18. package/lib/actions/auth/status.d.ts +11 -0
  19. package/lib/actions/auth/status.js +26 -0
  20. package/lib/actions/auth/status.js.map +1 -0
  21. package/lib/actions/portal/copilot.d.ts +16 -0
  22. package/lib/actions/portal/copilot.js +89 -0
  23. package/lib/actions/portal/copilot.js.map +1 -0
  24. package/lib/actions/portal/generate.d.ts +11 -5
  25. package/lib/actions/portal/generate.js +60 -55
  26. package/lib/actions/portal/generate.js.map +1 -0
  27. package/lib/actions/portal/quickstart.d.ts +16 -0
  28. package/lib/actions/portal/quickstart.js +146 -0
  29. package/lib/actions/portal/quickstart.js.map +1 -0
  30. package/lib/actions/portal/recipe/new-recipe.d.ts +15 -0
  31. package/lib/actions/portal/recipe/new-recipe.js +177 -0
  32. package/lib/actions/portal/recipe/new-recipe.js.map +1 -0
  33. package/lib/actions/portal/serve.d.ts +15 -0
  34. package/lib/actions/portal/serve.js +118 -0
  35. package/lib/actions/portal/serve.js.map +1 -0
  36. package/lib/actions/portal/toc/new-toc.d.ts +21 -0
  37. package/lib/actions/portal/toc/new-toc.js +97 -0
  38. package/lib/actions/portal/toc/new-toc.js.map +1 -0
  39. package/lib/actions/quickstart.d.ts +10 -0
  40. package/lib/actions/quickstart.js +30 -0
  41. package/lib/actions/quickstart.js.map +1 -0
  42. package/lib/actions/sdk/generate.d.ts +13 -0
  43. package/lib/actions/sdk/generate.js +47 -0
  44. package/lib/actions/sdk/generate.js.map +1 -0
  45. package/lib/actions/sdk/quickstart.d.ts +14 -0
  46. package/lib/actions/sdk/quickstart.js +149 -0
  47. package/lib/actions/sdk/quickstart.js.map +1 -0
  48. package/lib/application/portal/recipe/portal-recipe.d.ts +8 -0
  49. package/lib/application/portal/recipe/portal-recipe.js +33 -0
  50. package/lib/application/portal/recipe/portal-recipe.js.map +1 -0
  51. package/lib/application/portal/recipe/recipe-generator.d.ts +21 -0
  52. package/lib/application/portal/recipe/recipe-generator.js +145 -0
  53. package/lib/application/portal/recipe/recipe-generator.js.map +1 -0
  54. package/lib/application/portal/{new/toc → toc}/toc-content-parser.d.ts +1 -1
  55. package/lib/application/portal/toc/toc-content-parser.js +44 -0
  56. package/lib/application/portal/toc/toc-content-parser.js.map +1 -0
  57. package/lib/application/portal/{new/toc → toc}/toc-structure-generator.d.ts +1 -1
  58. package/lib/application/portal/toc/toc-structure-generator.js +84 -0
  59. package/lib/application/portal/toc/toc-structure-generator.js.map +1 -0
  60. package/lib/client-utils/auth-manager.d.ts +7 -2
  61. package/lib/client-utils/auth-manager.js +26 -14
  62. package/lib/client-utils/auth-manager.js.map +1 -0
  63. package/lib/commands/api/transform.d.ts +10 -7
  64. package/lib/commands/api/transform.js +51 -111
  65. package/lib/commands/api/transform.js.map +1 -0
  66. package/lib/commands/api/validate.d.ts +7 -4
  67. package/lib/commands/api/validate.js +31 -74
  68. package/lib/commands/api/validate.js.map +1 -0
  69. package/lib/commands/auth/login.d.ts +3 -1
  70. package/lib/commands/auth/login.js +26 -68
  71. package/lib/commands/auth/login.js.map +1 -0
  72. package/lib/commands/auth/logout.d.ts +3 -1
  73. package/lib/commands/auth/logout.js +14 -21
  74. package/lib/commands/auth/logout.js.map +1 -0
  75. package/lib/commands/auth/status.d.ts +1 -0
  76. package/lib/commands/auth/status.js +18 -21
  77. package/lib/commands/auth/status.js.map +1 -0
  78. package/lib/commands/portal/copilot.d.ts +13 -0
  79. package/lib/commands/portal/copilot.js +34 -0
  80. package/lib/commands/portal/copilot.js.map +1 -0
  81. package/lib/commands/portal/generate.d.ts +7 -11
  82. package/lib/commands/portal/generate.js +26 -89
  83. package/lib/commands/portal/generate.js.map +1 -0
  84. package/lib/commands/portal/recipe/new.d.ts +12 -0
  85. package/lib/commands/portal/recipe/new.js +45 -0
  86. package/lib/commands/portal/recipe/new.js.map +1 -0
  87. package/lib/commands/portal/serve.d.ts +8 -8
  88. package/lib/commands/portal/serve.js +41 -125
  89. package/lib/commands/portal/serve.js.map +1 -0
  90. package/lib/commands/portal/toc/new.d.ts +14 -0
  91. package/lib/commands/portal/toc/new.js +60 -0
  92. package/lib/commands/portal/toc/new.js.map +1 -0
  93. package/lib/commands/quickstart.d.ts +9 -0
  94. package/lib/commands/quickstart.js +37 -0
  95. package/lib/commands/quickstart.js.map +1 -0
  96. package/lib/commands/sdk/generate.d.ts +10 -8
  97. package/lib/commands/sdk/generate.js +46 -131
  98. package/lib/commands/sdk/generate.js.map +1 -0
  99. package/lib/config/axios-config.js +4 -6
  100. package/lib/config/axios-config.js.map +1 -0
  101. package/lib/hooks/not-found.d.ts +3 -0
  102. package/lib/hooks/not-found.js +52 -0
  103. package/lib/hooks/not-found.js.map +1 -0
  104. package/lib/hooks/utils.d.ts +5 -0
  105. package/lib/hooks/utils.js +51 -0
  106. package/lib/hooks/utils.js.map +1 -0
  107. package/lib/index.js +2 -5
  108. package/lib/index.js.map +1 -0
  109. package/lib/infrastructure/debounce-service.d.ts +10 -0
  110. package/lib/infrastructure/debounce-service.js +52 -0
  111. package/lib/infrastructure/debounce-service.js.map +1 -0
  112. package/lib/infrastructure/env-info.d.ts +12 -0
  113. package/lib/infrastructure/env-info.js +58 -0
  114. package/lib/infrastructure/env-info.js.map +1 -0
  115. package/lib/infrastructure/file-service.d.ts +24 -0
  116. package/lib/infrastructure/file-service.js +120 -0
  117. package/lib/infrastructure/file-service.js.map +1 -0
  118. package/lib/infrastructure/launcher-service.d.ts +9 -0
  119. package/lib/infrastructure/launcher-service.js +72 -0
  120. package/lib/infrastructure/launcher-service.js.map +1 -0
  121. package/lib/infrastructure/network-service.d.ts +3 -0
  122. package/lib/infrastructure/network-service.js +7 -0
  123. package/lib/infrastructure/network-service.js.map +1 -0
  124. package/lib/infrastructure/service-error.d.ts +16 -0
  125. package/lib/infrastructure/service-error.js +49 -0
  126. package/lib/infrastructure/service-error.js.map +1 -0
  127. package/lib/infrastructure/services/api-client-factory.d.ts +6 -0
  128. package/lib/infrastructure/services/api-client-factory.js +20 -0
  129. package/lib/infrastructure/services/api-client-factory.js.map +1 -0
  130. package/lib/infrastructure/services/api-service.d.ts +12 -0
  131. package/lib/infrastructure/services/api-service.js +79 -0
  132. package/lib/infrastructure/services/api-service.js.map +1 -0
  133. package/lib/infrastructure/services/auth-service.d.ts +11 -0
  134. package/lib/infrastructure/services/auth-service.js +37 -0
  135. package/lib/infrastructure/services/auth-service.js.map +1 -0
  136. package/lib/infrastructure/services/file-download-service.d.ts +15 -0
  137. package/lib/infrastructure/services/file-download-service.js +104 -0
  138. package/lib/infrastructure/services/file-download-service.js.map +1 -0
  139. package/lib/infrastructure/services/portal-service.d.ts +17 -12
  140. package/lib/infrastructure/services/portal-service.js +134 -99
  141. package/lib/infrastructure/services/portal-service.js.map +1 -0
  142. package/lib/infrastructure/services/telemetry-service.d.ts +9 -0
  143. package/lib/infrastructure/services/telemetry-service.js +38 -0
  144. package/lib/infrastructure/services/telemetry-service.js.map +1 -0
  145. package/lib/infrastructure/services/transformation-service.d.ts +23 -0
  146. package/lib/infrastructure/services/transformation-service.js +56 -0
  147. package/lib/infrastructure/services/transformation-service.js.map +1 -0
  148. package/lib/infrastructure/services/validation-service.d.ts +17 -0
  149. package/lib/infrastructure/services/validation-service.js +49 -0
  150. package/lib/infrastructure/services/validation-service.js.map +1 -0
  151. package/lib/infrastructure/tmp-extensions.d.ts +2 -0
  152. package/lib/infrastructure/tmp-extensions.js +6 -0
  153. package/lib/infrastructure/tmp-extensions.js.map +1 -0
  154. package/lib/infrastructure/zip-service.d.ts +6 -0
  155. package/lib/infrastructure/zip-service.js +39 -0
  156. package/lib/infrastructure/zip-service.js.map +1 -0
  157. package/lib/prompts/api/transform.d.ts +11 -0
  158. package/lib/prompts/api/transform.js +29 -0
  159. package/lib/prompts/api/transform.js.map +1 -0
  160. package/lib/prompts/api/validate.d.ts +12 -0
  161. package/lib/prompts/api/validate.js +40 -0
  162. package/lib/prompts/api/validate.js.map +1 -0
  163. package/lib/prompts/auth/login.d.ts +10 -0
  164. package/lib/prompts/auth/login.js +22 -0
  165. package/lib/prompts/auth/login.js.map +1 -0
  166. package/lib/prompts/auth/logout.d.ts +3 -0
  167. package/lib/prompts/auth/logout.js +7 -0
  168. package/lib/prompts/auth/logout.js.map +1 -0
  169. package/lib/prompts/auth/status.d.ts +8 -0
  170. package/lib/prompts/auth/status.js +22 -0
  171. package/lib/prompts/auth/status.js.map +1 -0
  172. package/lib/prompts/format.d.ts +31 -0
  173. package/lib/prompts/format.js +89 -0
  174. package/lib/prompts/format.js.map +1 -0
  175. package/lib/prompts/portal/copilot.d.ts +18 -0
  176. package/lib/prompts/portal/copilot.js +82 -0
  177. package/lib/prompts/portal/copilot.js.map +1 -0
  178. package/lib/prompts/portal/generate.d.ts +13 -8
  179. package/lib/prompts/portal/generate.js +36 -53
  180. package/lib/prompts/portal/generate.js.map +1 -0
  181. package/lib/prompts/portal/quickstart.d.ts +28 -29
  182. package/lib/prompts/portal/quickstart.js +102 -185
  183. package/lib/prompts/portal/quickstart.js.map +1 -0
  184. package/lib/prompts/portal/recipe/new-recipe.d.ts +29 -0
  185. package/lib/prompts/portal/recipe/new-recipe.js +165 -0
  186. package/lib/prompts/portal/recipe/new-recipe.js.map +1 -0
  187. package/lib/prompts/portal/serve.d.ts +9 -5
  188. package/lib/prompts/portal/serve.js +29 -19
  189. package/lib/prompts/portal/serve.js.map +1 -0
  190. package/lib/prompts/portal/toc/new-toc.d.ts +15 -0
  191. package/lib/prompts/portal/toc/new-toc.js +38 -0
  192. package/lib/prompts/portal/toc/new-toc.js.map +1 -0
  193. package/lib/prompts/prompt.d.ts +3 -0
  194. package/lib/prompts/prompt.js +37 -0
  195. package/lib/prompts/prompt.js.map +1 -0
  196. package/lib/prompts/quickstart.d.ts +6 -0
  197. package/lib/prompts/quickstart.js +25 -0
  198. package/lib/prompts/quickstart.js.map +1 -0
  199. package/lib/prompts/sdk/generate.d.ts +11 -0
  200. package/lib/prompts/sdk/generate.js +37 -0
  201. package/lib/prompts/sdk/generate.js.map +1 -0
  202. package/lib/prompts/sdk/quickstart.d.ts +32 -0
  203. package/lib/prompts/sdk/quickstart.js +140 -0
  204. package/lib/prompts/sdk/quickstart.js.map +1 -0
  205. package/lib/types/api/account.d.ts +10 -0
  206. package/lib/types/api/account.js +2 -0
  207. package/lib/types/api/account.js.map +1 -0
  208. package/lib/types/api/transform.d.ts +14 -25
  209. package/lib/types/api/transform.js +20 -23
  210. package/lib/types/api/transform.js.map +1 -0
  211. package/lib/types/build/build.d.ts +22 -0
  212. package/lib/types/build/build.js +7 -0
  213. package/lib/types/build/build.js.map +1 -0
  214. package/lib/types/build-context.d.ts +13 -0
  215. package/lib/types/build-context.js +33 -0
  216. package/lib/types/build-context.js.map +1 -0
  217. package/lib/types/common/command-metadata.d.ts +4 -0
  218. package/lib/types/common/command-metadata.js +2 -0
  219. package/lib/types/common/command-metadata.js.map +1 -0
  220. package/lib/types/events/domain-event.d.ts +8 -0
  221. package/lib/types/events/domain-event.js +11 -0
  222. package/lib/types/events/domain-event.js.map +1 -0
  223. package/lib/types/events/quickstart-completed.d.ts +7 -0
  224. package/lib/types/events/quickstart-completed.js +10 -0
  225. package/lib/types/events/quickstart-completed.js.map +1 -0
  226. package/lib/types/events/quickstart-initiated.d.ts +7 -0
  227. package/lib/types/events/quickstart-initiated.js +10 -0
  228. package/lib/types/events/quickstart-initiated.js.map +1 -0
  229. package/lib/types/events/recipe-creation-failed.d.ts +5 -0
  230. package/lib/types/events/recipe-creation-failed.js +8 -0
  231. package/lib/types/events/recipe-creation-failed.js.map +1 -0
  232. package/lib/types/events/toc-creation-failed.d.ts +5 -0
  233. package/lib/types/events/toc-creation-failed.js +8 -0
  234. package/lib/types/events/toc-creation-failed.js.map +1 -0
  235. package/lib/types/file/directory.d.ts +17 -0
  236. package/lib/types/file/directory.js +87 -0
  237. package/lib/types/file/directory.js.map +1 -0
  238. package/lib/types/file/directoryPath.d.ts +10 -0
  239. package/lib/types/file/directoryPath.js +26 -0
  240. package/lib/types/file/directoryPath.js.map +1 -0
  241. package/lib/types/file/fileName.d.ts +7 -0
  242. package/lib/types/file/fileName.js +21 -0
  243. package/lib/types/file/fileName.js.map +1 -0
  244. package/lib/types/file/filePath.d.ts +10 -0
  245. package/lib/types/file/filePath.js +32 -0
  246. package/lib/types/file/filePath.js.map +1 -0
  247. package/lib/types/file/resource-input.d.ts +5 -0
  248. package/lib/types/file/resource-input.js +42 -0
  249. package/lib/types/file/resource-input.js.map +1 -0
  250. package/lib/types/file/urlPath.d.ts +6 -0
  251. package/lib/types/file/urlPath.js +22 -0
  252. package/lib/types/file/urlPath.js.map +1 -0
  253. package/lib/types/flags-provider.d.ts +15 -0
  254. package/lib/types/flags-provider.js +34 -0
  255. package/lib/types/flags-provider.js.map +1 -0
  256. package/lib/types/portal-context.d.ts +13 -0
  257. package/lib/types/portal-context.js +38 -0
  258. package/lib/types/portal-context.js.map +1 -0
  259. package/lib/types/recipe/recipe.d.ts +22 -0
  260. package/lib/types/recipe/recipe.js +6 -0
  261. package/lib/types/recipe/recipe.js.map +1 -0
  262. package/lib/types/recipe-context.d.ts +9 -0
  263. package/lib/types/recipe-context.js +26 -0
  264. package/lib/types/recipe-context.js.map +1 -0
  265. package/lib/types/resource-context.d.ts +12 -0
  266. package/lib/types/resource-context.js +30 -0
  267. package/lib/types/resource-context.js.map +1 -0
  268. package/lib/types/sdk/generate.d.ts +9 -22
  269. package/lib/types/sdk/generate.js +25 -14
  270. package/lib/types/sdk/generate.js.map +1 -0
  271. package/lib/types/sdk-context.d.ts +14 -0
  272. package/lib/types/sdk-context.js +32 -0
  273. package/lib/types/sdk-context.js.map +1 -0
  274. package/lib/types/sdl/sdl.d.ts +10 -0
  275. package/lib/types/sdl/sdl.js +47 -3
  276. package/lib/types/sdl/sdl.js.map +1 -0
  277. package/lib/types/spec-context.d.ts +12 -0
  278. package/lib/types/spec-context.js +29 -0
  279. package/lib/types/spec-context.js.map +1 -0
  280. package/lib/types/temp-context.d.ts +11 -0
  281. package/lib/types/temp-context.js +27 -0
  282. package/lib/types/temp-context.js.map +1 -0
  283. package/lib/types/toc/toc.js +2 -10
  284. package/lib/types/toc/toc.js.map +1 -0
  285. package/lib/types/toc-context.d.ts +12 -0
  286. package/lib/types/toc-context.js +26 -0
  287. package/lib/types/toc-context.js.map +1 -0
  288. package/lib/types/transform-context.d.ts +13 -0
  289. package/lib/types/transform-context.js +30 -0
  290. package/lib/types/transform-context.js.map +1 -0
  291. package/lib/types/utils.d.ts +0 -9
  292. package/lib/types/utils.js +2 -3
  293. package/lib/types/utils.js.map +1 -0
  294. package/lib/utils/string-utils.d.ts +2 -0
  295. package/lib/utils/string-utils.js +37 -0
  296. package/lib/utils/string-utils.js.map +1 -0
  297. package/lib/utils/utils.d.ts +2 -44
  298. package/lib/utils/utils.js +14 -366
  299. package/lib/utils/utils.js.map +1 -0
  300. package/package.json +50 -31
  301. package/bin/run +0 -9
  302. package/lib/actions/portal/new/toc.d.ts +0 -17
  303. package/lib/actions/portal/new/toc.js +0 -134
  304. package/lib/application/portal/new/toc/sdl-parser.d.ts +0 -13
  305. package/lib/application/portal/new/toc/sdl-parser.js +0 -53
  306. package/lib/application/portal/new/toc/toc-content-parser.js +0 -46
  307. package/lib/application/portal/new/toc/toc-structure-generator.js +0 -88
  308. package/lib/client-utils/sdk-client.d.ts +0 -23
  309. package/lib/client-utils/sdk-client.js +0 -124
  310. package/lib/commands/portal/new/toc.d.ts +0 -15
  311. package/lib/commands/portal/new/toc.js +0 -65
  312. package/lib/commands/portal/quickstart.d.ts +0 -10
  313. package/lib/commands/portal/quickstart.js +0 -79
  314. package/lib/config/env.d.ts +0 -27
  315. package/lib/config/env.js +0 -31
  316. package/lib/controllers/api/transform.d.ts +0 -5
  317. package/lib/controllers/api/transform.js +0 -56
  318. package/lib/controllers/api/validate.d.ts +0 -3
  319. package/lib/controllers/api/validate.js +0 -33
  320. package/lib/controllers/portal/generate.d.ts +0 -3
  321. package/lib/controllers/portal/generate.js +0 -110
  322. package/lib/controllers/portal/quickstart.d.ts +0 -14
  323. package/lib/controllers/portal/quickstart.js +0 -258
  324. package/lib/controllers/portal/serve.d.ts +0 -3
  325. package/lib/controllers/portal/serve.js +0 -138
  326. package/lib/controllers/sdk/generate.d.ts +0 -4
  327. package/lib/controllers/sdk/generate.js +0 -66
  328. package/lib/prompts/portal/new/toc.d.ts +0 -10
  329. package/lib/prompts/portal/new/toc.js +0 -46
  330. package/lib/services/portal/server.d.ts +0 -14
  331. package/lib/services/portal/server.js +0 -101
  332. package/lib/types/api/validate.d.ts +0 -12
  333. package/lib/types/api/validate.js +0 -3
  334. package/lib/types/common/result.d.ts +0 -17
  335. package/lib/types/common/result.js +0 -36
  336. package/lib/types/portal/generate.d.ts +0 -26
  337. package/lib/types/portal/generate.js +0 -4
  338. package/lib/types/portal/quickstart.d.ts +0 -17
  339. package/lib/types/portal/quickstart.js +0 -3
  340. package/lib/validators/common/directoryValidator.d.ts +0 -9
  341. package/lib/validators/common/directoryValidator.js +0 -53
  342. package/lib/validators/common/portValidator.d.ts +0 -5
  343. package/lib/validators/common/portValidator.js +0 -20
  344. package/lib/validators/portal/serveValidator.d.ts +0 -6
  345. package/lib/validators/portal/serveValidator.js +0 -21
@@ -0,0 +1,97 @@
1
+ import { ok } from "neverthrow";
2
+ import { PortalNewTocPrompts } from "../../../prompts/portal/toc/new-toc.js";
3
+ import { TocStructureGenerator } from "../../../application/portal/toc/toc-structure-generator.js";
4
+ import { ActionResult } from "../../action-result.js";
5
+ import { TocContext } from "../../../types/toc-context.js";
6
+ import { FileService } from "../../../infrastructure/file-service.js";
7
+ import { BuildContext } from "../../../types/build-context.js";
8
+ import { getEndpointGroupsAndModels } from "../../../types/sdl/sdl.js";
9
+ import { withDirPath } from "../../../infrastructure/tmp-extensions.js";
10
+ import { TempContext } from "../../../types/temp-context.js";
11
+ import { PortalService } from "../../../infrastructure/services/portal-service.js";
12
+ export class ContentContext {
13
+ constructor(contentDirectory) {
14
+ this.contentDirectory = contentDirectory;
15
+ this.fileService = new FileService();
16
+ }
17
+ async exists() {
18
+ return this.fileService.directoryExists(this.contentDirectory);
19
+ }
20
+ async extractContentGroups() {
21
+ const directory = await this.fileService.getDirectory(this.contentDirectory);
22
+ return await directory.parseContentFolder(this.contentDirectory);
23
+ }
24
+ }
25
+ export class PortalNewTocAction {
26
+ constructor(configDirectory, commandMetadata) {
27
+ this.configDirectory = configDirectory;
28
+ this.commandMetadata = commandMetadata;
29
+ this.prompts = new PortalNewTocPrompts();
30
+ this.tocGenerator = new TocStructureGenerator();
31
+ this.fileService = new FileService();
32
+ this.portalService = new PortalService();
33
+ }
34
+ async execute(buildDirectory, tocDirectory, force = false, expandEndpoints = false, expandModels = false) {
35
+ var _a, _b;
36
+ // Validate build directory
37
+ const buildContext = new BuildContext(buildDirectory);
38
+ if (!(await buildContext.validate())) {
39
+ this.prompts.invalidBuildDirectory(buildDirectory);
40
+ return ActionResult.failed();
41
+ }
42
+ const buildConfig = await buildContext.getBuildFileContents();
43
+ const contentDirectory = buildDirectory.join((_b = (_a = buildConfig.generatePortal) === null || _a === void 0 ? void 0 : _a.contentFolder) !== null && _b !== void 0 ? _b : "content");
44
+ const tocDir = tocDirectory !== null && tocDirectory !== void 0 ? tocDirectory : contentDirectory;
45
+ const tocContext = new TocContext(tocDir);
46
+ if (!force && (await tocContext.exists()) && !(await this.prompts.overwriteToc(tocContext.tocPath))) {
47
+ this.prompts.tocFileAlreadyExists();
48
+ return ActionResult.cancelled();
49
+ }
50
+ let sdlComponents = { endpointGroups: new Map(), models: [] };
51
+ if (expandEndpoints || expandModels) {
52
+ const specDirectory = buildDirectory.join("spec");
53
+ if (!(await this.fileService.directoryExists(specDirectory))) {
54
+ this.prompts.fallingBackToDefault();
55
+ }
56
+ else {
57
+ const sdlResult = await withDirPath(async (tempDirectory) => {
58
+ const tempContext = new TempContext(tempDirectory);
59
+ const specZipPath = await tempContext.zip(specDirectory);
60
+ const specFileStream = await this.fileService.getStream(specZipPath);
61
+ try {
62
+ const result = await this.prompts.extractEndpointGroupsAndModels(this.portalService.generateSdl(specFileStream, this.configDirectory, this.commandMetadata));
63
+ if (result.isErr()) {
64
+ this.prompts.fallingBackToDefault();
65
+ return ok({ endpointGroups: new Map(), models: [] });
66
+ }
67
+ return ok(getEndpointGroupsAndModels(result.value));
68
+ }
69
+ finally {
70
+ specFileStream.close();
71
+ }
72
+ });
73
+ if (sdlResult.isErr()) {
74
+ this.prompts.logError(sdlResult.error);
75
+ return ActionResult.failed();
76
+ }
77
+ sdlComponents = sdlResult.value;
78
+ }
79
+ }
80
+ const contentContext = new ContentContext(contentDirectory);
81
+ const contentExists = await contentContext.exists();
82
+ let contentGroups;
83
+ if (!contentExists) {
84
+ this.prompts.contentDirectoryNotFound(contentDirectory);
85
+ contentGroups = [];
86
+ }
87
+ else {
88
+ contentGroups = await contentContext.extractContentGroups();
89
+ }
90
+ const toc = this.tocGenerator.createTocStructure(sdlComponents.endpointGroups, sdlComponents.models, expandEndpoints, expandModels, contentGroups);
91
+ const yamlString = this.tocGenerator.transformToYaml(toc);
92
+ const tocFilePath = await tocContext.save(yamlString);
93
+ this.prompts.tocCreated(tocFilePath);
94
+ return ActionResult.success();
95
+ }
96
+ }
97
+ //# sourceMappingURL=new-toc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"new-toc.js","sourceRoot":"","sources":["../../../../src/actions/portal/toc/new-toc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAChC,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,4DAA4D,CAAC;AAInG,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,oDAAoD,CAAC;AAEnF,MAAM,OAAO,cAAc;IAGzB,YAA6B,gBAA+B;QAA/B,qBAAgB,GAAhB,gBAAgB,CAAe;QAF3C,gBAAW,GAAG,IAAI,WAAW,EAAE,CAAC;IAEc,CAAC;IAEzD,KAAK,CAAC,MAAM;QACjB,OAAO,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACjE,CAAC;IAEM,KAAK,CAAC,oBAAoB;QAC/B,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC7E,OAAO,MAAM,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACnE,CA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ath } from "../types/file/directoryPath.js";
3
+ import { ActionResult } from "./action-result.js";
4
+ export declare class QuickstartAction {
5
+ private readonly configDir;
6
+ private readonly commandMetadata;
7
+ private readonly prompts;
8
+ constructor(configDir: DirectoryPath, commandMetadata: CommandMetadata);
9
+ readonly execute: () => Promise<ActionResult>;
10
+ }
@@ -0,0 +1,30 @@
1
+ import { QuickstartPrompts } from "../prompts/quickstart.js";
2
+ import { ActionResult } from "./action-result.js";
3
+ import { PortalQuickstartAction } from "./portal/quickstart.js";
4
+ import { SdkQuickstartAction } from "./sdk/quickstart.js";
5
+ export class QuickstartAction {
6
+ constructor(configDir, commandMetadata) {
7
+ this.configDir = configDir;
8
+ this.commandMetadata = commandMetadata;
9
+ this.prompts = new QuickstartPrompts();
10
+ this.execute = async () => {
11
+ this.prompts.welcomeMessage();
12
+ const selectedFlow = await this.prompts.selectQuickstartFlow();
13
+ switch (selectedFlow) {
14
+ case "portal": {
15
+ const action = new PortalQuickstartAction(this.configDir, this.commandMetadata);
16
+ return await action.execute();
17
+ }
18
+ case "sdk": {
19
+ const action = new SdkQuickstartAction(this.configDir, this.commandMetadata);
20
+ return await action.execute();
21
+ }
22
+ case undefined: {
23
+ this.prompts.noQuickstartFlowSelected();
24
+ return ActionResult.cancelled();
25
+ }
26
+ }
27
+ };
28
+ }
29
+ }
30
+ //# sourceMappingURL=quickstart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quickstart.js","sourceRoot":"","sources":["../../src/actions/quickstart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAG7D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,MAAM,OAAO,gBAAgB;IAG3B,YAAoC,SAAwB,EAAmB,eAAgC;QAA3E,cAAS,GAAT,SAAS,CAAe;QAAmB,oBAAe,GAAf,eAAe,CAAiB;QAF9F,YAAO,GAAG,IAAI,iBAAiB,EAAE,CAAC;QAInC,YAAO,GAAG,KAAK,IAA2B,EAAE;YAC1D,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;YAC9B,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,CAAC;YAC/D,QAAQ,YAAY,EAAE,CAAC;gBACrB,KAAK,QAAQ,CAAC,CAAC,CAAC;oBACd,MAAM,MAAM,GAAG,IAAI,sBAAsB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;oBAChF,OAAO,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;gBAChC,CAAC;gBACD,KAAK,KAAK,CAAC,CAAC,CAAC;oBACX,MAAM,MAAM,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;oBAC7E,OAAO,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;gBAChC,CAAC;gBACD,KAAK,SAAS,CAAC,CAAC,CAAC;oBACf,IAAI,CAAC,OAAO,CAAC,wBAAwB,EAAE,CAAC;oBACxC,OAAO,YAAY,CAAC,SAAS,EAAE,CAAC;gBAClC,CAAC;YACH,CAAC;QACH,CAAC,CAAC;IAnBgH,CAAC;CAoBpH"}
@@ -0,0 +1,13 @@
1
+ import { DirectoryPath } from "../../types/file/directoryPath.js";
2
+ import { ActionResult } from "../action-result.js";
3
+ import { CommandMetadata } from "../../types/common/command-metadata.js";
4
+ import { Language } from "../../types/sdk/generate.js";
5
+ export declare class GenerateAction {
6
+ private readonly prompts;
7
+ private readonly portalService;
8
+ private readonly configDir;
9
+ private readonly commandMetadata;
10
+ private readonly authKey;
11
+ constructor(configDir: DirectoryPath, commandMetadata: CommandMetadata, authKey?: string | null);
12
+ readonly execute: (specDirectory: DirectoryPath, sdkDirectory: DirectoryPath, language: Language, force: boolean, zipSdk: boolean) => Promise<ActionResult>;
13
+ }
@@ -0,0 +1,47 @@
1
+ import { PortalService } from "../../infrastructure/services/portal-service.js";
2
+ import { ActionResult } from "../action-result.js";
3
+ import { withDirPath } from "../../infrastructure/tmp-extensions.js";
4
+ import { SdkContext } from "../../types/sdk-context.js";
5
+ import { SpecContext } from "../../types/spec-context.js";
6
+ import { SdkGeneratePrompts } from "../../prompts/sdk/generate.js";
7
+ import { TempContext } from "../../types/temp-context.js";
8
+ export class GenerateAction {
9
+ constructor(configDir, commandMetadata, authKey = null) {
10
+ this.prompts = new SdkGeneratePrompts();
11
+ this.portalService = new PortalService();
12
+ this.execute = async (specDirectory, sdkDirectory, language, force, zipSdk) => {
13
+ if (specDirectory.isEqual(sdkDirectory)) {
14
+ this.prompts.sameSpecAndSdkDir(specDirectory);
15
+ return ActionResult.failed();
16
+ }
17
+ const specContext = new SpecContext(specDirectory);
18
+ if (!(await specContext.validate())) {
19
+ this.prompts.invalidSpecDirectory(specDirectory);
20
+ return ActionResult.failed();
21
+ }
22
+ const sdkContext = new SdkContext(sdkDirectory, language);
23
+ if (!force && (await sdkContext.exists()) && !(await this.prompts.overwriteSdk(sdkContext.sdkLanguageDirectory))) {
24
+ this.prompts.destinationDirNotEmpty();
25
+ return ActionResult.cancelled();
26
+ }
27
+ return await withDirPath(async (tempDirectory) => {
28
+ const tempContext = new TempContext(tempDirectory);
29
+ const specZipPath = await tempContext.zip(specDirectory);
30
+ const response = await this.prompts.generateSDK(this.portalService.generateSdk(specZipPath, language, this.configDir, this.commandMetadata, this.authKey));
31
+ // TODO: this should be service error
32
+ if (response.isErr()) {
33
+ this.prompts.logGenerationError(response.error);
34
+ return ActionResult.failed();
35
+ }
36
+ const tempSdkFilePath = await tempContext.save(response.value);
37
+ const sdkLanguageDirectory = await sdkContext.save(tempSdkFilePath, zipSdk);
38
+ this.prompts.sdkGenerated(sdkLanguageDirectory);
39
+ return ActionResult.success();
40
+ });
41
+ };
42
+ this.configDir = configDir;
43
+ this.commandMetadata = commandMetadata;
44
+ this.authKey = authKey;
45
+ }
46
+ }
47
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/actions/sdk/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iDAAiD,CAAC;AAEhF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAG1D,MAAM,OAAO,cAAc;IAOzB,YAAY,SAAwB,EAAE,eAAgC,EAAE,UAAyB,IAAI;QANpF,YAAO,GAAuB,IAAI,kBAAkB,EAAE,CAAC;QACvD,kBAAa,GAAkB,IAAI,aAAa,EAAE,CAAC;QAWpD,YAAO,GAAG,KAAK,EAC7B,aAA4B,EAC5B,YAA2B,EAC3B,QAAkB,EAClB,KAAc,EACd,MAAe,EACQ,EAAE;YACzB,IAAI,aAAa,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;gBACxC,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;gBAC9C,OAAO,YAAY,CAAC,MAAM,EAAE,CAAC;YAC/B,CAAC;YAED,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,aAAa,CAAC,CAAC;YACnD,IAAI,CAAC,CAAC,MAAM,WAAW,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC;gBACpC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,aAAa,CAAC,CAAC;gBACjD,OAAO,YAAY,CAAC,MAAM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AAC;gBAEhD,OAAO,YAAY,CAAC,OAAO,EAAE,CAAC;YAChC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QAlDA,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CAgDF"}
@@ -0,0 +1,14 @@
1
+ import { ActionResult } from "../action-result.js";
2
+ import { CommandMetadata } from "../../types/common/command-metadata.js";
3
+ import { DirectoryPath } from "../../types/file/directoryPath.js";
4
+ export declare class SdkQuickstartAction {
5
+ private readonly configDir;
6
+ private readonly commandMetadata;
7
+ private readonly prompts;
8
+ private readonly fileDownloadService;
9
+ private readonly fileService;
10
+ private readonly launcherService;
11
+ private readonly zipService;
12
+ constructor(configDir: DirectoryPath, commandMetadata: CommandMetadata);
13
+ readonly execute: () => Promise<ActionResult>;
14
+ }
@@ -0,0 +1,149 @@
1
+ import { SdkQuickstartPrompts } from "../../prompts/sdk/quickstart.js";
2
+ import { ActionResult } from "../action-result.js";
3
+ import { UrlPath } from "../../types/file/urlPath.js";
4
+ import { LoginAction } from "../auth/login.js";
5
+ import { getAuthInfo } from "../../client-utils/auth-manager.js";
6
+ import { withDirPath } from "../../infrastructure/tmp-extensions.js";
7
+ import { FilePath } from "../../types/file/filePath.js";
8
+ import { SpecContext } from "../../types/spec-context.js";
9
+ import { ValidateAction } from "../api/validate.js";
10
+ import { FileDownloadService } from "../../infrastructure/services/file-download-service.js";
11
+ import { FileService } from "../../infrastructure/file-service.js";
12
+ import { GenerateAction } from "./generate.js";
13
+ import { LauncherService } from "../../infrastructure/launcher-service.js";
14
+ import { ZipService } from "../../infrastructure/zip-service.js";
15
+ import { FileName } from "../../types/file/fileName.js";
16
+ const defaultSpecUrl = new UrlPath(`https://raw.githubusercontent.com/apimatic/sample-docs-as-code-portal/refs/heads/master/src/spec/openapi.json`);
17
+ const metadataFileUrl = new UrlPath(`https://raw.githubusercontent.com/apimatic/sample-docs-as-code-portal/refs/heads/master/src/spec/APIMATIC-META.json`);
18
+ export class SdkQuickstartAction {
19
+ constructor(configDir, commandMetadata) {
20
+ this.configDir = configDir;
21
+ this.commandMetadata = commandMetadata;
22
+ this.prompts = new SdkQuickstartPrompts();
23
+ this.fileDownloadService = new FileDownloadService();
24
+ this.fileService = new FileService();
25
+ this.launcherService = new LauncherService();
26
+ this.zipService = new ZipService();
27
+ this.execute = async () => {
28
+ const storedAuth = await getAuthInfo(this.configDir.toString());
29
+ if (!(storedAuth === null || storedAuth === void 0 ? void 0 : storedAuth.authKey)) {
30
+ const loginResult = await new LoginAction(this.configDir, this.commandMetadata).execute();
31
+ if (loginResult.isFailed()) {
32
+ return ActionResult.failed();
33
+ }
34
+ }
35
+ return await withDirPath(async (tempDirectory) => {
36
+ // Step 1/4
37
+ this.prompts.importSpecStep();
38
+ let specPath;
39
+ while (!specPath) {
40
+ const inputPath = await this.prompts.specPathPrompt(defaultSpecUrl);
41
+ if (!inputPath) {
42
+ this.prompts.noSpecSpecified();
43
+ return ActionResult.cancelled();
44
+ }
45
+ if (inputPath instanceof UrlPath) {
46
+ const downloadFileResult = await this.prompts.downloadSpecFile(this.fileDownloadService.downloadFile(inputPath));
47
+ if (downloadFileResult.isErr()) {
48
+ this.prompts.serviceError(downloadFileResult.error);
49
+ }
50
+ else {
51
+ const specContext = new SpecContext(tempDirectory);
52
+ specPath = await specContext.save(downloadFileResult.value.stream, downloadFileResult.value.filename);
53
+ }
54
+ }
55
+ else {
56
+ const fileExists = await this.fileService.fileExists(inputPath);
57
+ if (!fileExists) {
58
+ this.prompts.specFileDoesNotExist();
59
+ }
60
+ else {
61
+ specPath = inputPath;
62
+ }
63
+ }
64
+ }
65
+ // Step 2/4
66
+ this.prompts.validateSpecStep();
67
+ const validateAction = new ValidateAction(this.configDir, this.commandMetadata);
68
+ const validationResult = await validateAction.execute(specPath, false);
69
+ if (validationResult.isFailed()) {
70
+ this.prompts.specValidationFailed();
71
+ if (!(await this.prompts.useDefaultSpecPrompt())) {
72
+ this.prompts.fixYourSpec();
73
+ return ActionResult.cancelled();
74
+ }
75
+ const downloadFileResult = await this.prompts.downloadSpecFile(this.fileDownloadService.downloadFile(defaultSpecUrl));
76
+ if (downloadFileResult.isErr()) {
77
+ this.prompts.serviceError(downloadFileResult.error);
78
+ }
79
+ else {
80
+ const specContext = new SpecContext(tempDirectory);
81
+ specPath = await specContext.save(downloadFileResult.value.stream, downloadFileResult.value.filename);
82
+ }
83
+ }
84
+ // Step 3/4
85
+ this.prompts.selectLanguageStep();
86
+ const language = await this.prompts.selectLanguagePrompt();
87
+ if (!language) {
88
+ this.prompts.noLanguageSelected();
89
+ return ActionResult.cancelled();
90
+ }
91
+ // Step 4/4
92
+ this.prompts.selectInputDirectoryStep();
93
+ let inputDirectory;
94
+ while (true) {
95
+ inputDirectory = await this.prompts.inputDirectoryPathPrompt();
96
+ if (!inputDirectory) {
97
+ this.prompts.noInputDirectoryProvided();
98
+ return ActionResult.cancelled();
99
+ }
100
+ if (!(await this.fileService.directoryExists(inputDirectory))) {
101
+ this.prompts.inputDirectoryPathDoesNotExist(inputDirectory);
102
+ // TODO: Prompt user if he wants to create the directory
103
+ continue;
104
+ }
105
+ if (!(await this.fileService.directoryEmpty(inputDirectory))) {
106
+ this.prompts.inputDirectoryNotEmpty(inputDirectory);
107
+ continue;
108
+ }
109
+ break;
110
+ }
111
+ // Setup source directory with the spec folder
112
+ const apimaticMetaFile = await this.prompts.downloadMetadataFile(this.fileDownloadService.downloadFile(metadataFileUrl));
113
+ if (apimaticMetaFile.isErr()) {
114
+ this.prompts.serviceError(apimaticMetaFile.error);
115
+ return ActionResult.failed();
116
+ }
117
+ const tempSpecDirectory = tempDirectory.join("spec");
118
+ await this.fileService.createDirectoryIfNotExists(tempSpecDirectory);
119
+ const metadataFilePath = new FilePath(tempSpecDirectory, apimaticMetaFile.value.filename);
120
+ await this.fileService.writeFile(metadataFilePath, apimaticMetaFile.value.stream);
121
+ if (await this.fileService.isZipFile(specPath)) {
122
+ await this.zipService.unArchive(specPath, tempSpecDirectory);
123
+ }
124
+ else {
125
+ await this.fileService.copyToDir(specPath, tempSpecDirectory);
126
+ }
127
+ const sourceDirectory = inputDirectory.join("src");
128
+ const specDirectory = sourceDirectory.join("spec");
129
+ await this.fileService.copyDirectoryContents(tempSpecDirectory, specDirectory);
130
+ const srcDirectoryStructure = await this.fileService.getDirectory(sourceDirectory);
131
+ this.prompts.printDirectoryStructure(inputDirectory, srcDirectoryStructure);
132
+ const sdkDirectory = inputDirectory.join("sdk");
133
+ const sdkGenerateAction = new GenerateAction(this.configDir, this.commandMetadata);
134
+ const result = await sdkGenerateAction.execute(specDirectory, sdkDirectory, language, true, false);
135
+ if (result.isFailed()) {
136
+ return ActionResult.failed();
137
+ }
138
+ const languageDirectory = sdkDirectory.join(language);
139
+ const readmeFilePath = new FilePath(languageDirectory, new FileName("README.md"));
140
+ if (await this.launcherService.openFolderInIde(languageDirectory, readmeFilePath)) {
141
+ this.prompts.sdkOpenedInEditor();
142
+ }
143
+ this.prompts.nextSteps(language, inputDirectory);
144
+ return ActionResult.success();
145
+ });
146
+ };
147
+ }
148
+ }
149
+ //# sourceMappingURL=quickstart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quickstart.js","sourceRoot":"","sources":["../../../src/actions/sdk/quickstart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACx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c,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;gBACnF,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,OAAO,CAAC,aAAa,EAAE,YAAY,EAAE,QAAoB,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;gBAC/G,IAAI,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;oBACtB,OAAO,YAAY,CAAC,MAAM,EAAE,CAAC;gBAC/B,CAAC;gBAED,MAAM,iBAAiB,GAAG,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACtD,MAAM,cAAc,GAAG,IAAI,QAAQ,CAAC,iBAAiB,EAAE,IAAI,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC;gBAClF,IAAI,MAAM,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,iBAAiB,EAAE,cAAc,CAAC,EAAE,CAAC;oBAClF,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC;gBACnC,CAAC;gBAED,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;gBACjD,OAAO,YAAY,CAAC,OAAO,EAAE,CAAC;YAChC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;IA7IyG,CAAC;CA8I7G"}
@@ -0,0 +1,8 @@
1
+ import { SerializableRecipe } from "../../../types/recipe/recipe.js";
2
+ export declare class PortalRecipe {
3
+ private readonly recipe;
4
+ constructor(name: string);
5
+ addContentStep(key: string, content: string): void;
6
+ addEndpointStep(key: string, description: string, endpointGroupName: string, endpointName: string): void;
7
+ toSerializableRecipe(): SerializableRecipe;
8
+ }
@@ -0,0 +1,33 @@
1
+ import { StepType } from "../../../types/recipe/recipe.js";
2
+ export class PortalRecipe {
3
+ constructor(name) {
4
+ this.recipe = {
5
+ name,
6
+ steps: []
7
+ };
8
+ }
9
+ addContentStep(key, content) {
10
+ this.recipe.steps.push({
11
+ key,
12
+ name: key, //TODO: Check if key is required
13
+ type: StepType.Content,
14
+ config: { content }
15
+ });
16
+ }
17
+ addEndpointStep(key, description, endpointGroupName, endpointName) {
18
+ const endpointPermalink = `$e/${[endpointGroupName, endpointName].map(encodeURIComponent).join("/")}`;
19
+ this.recipe.steps.push({
20
+ key,
21
+ name: key, //TODO: Check if key is required
22
+ type: StepType.Endpoint,
23
+ config: {
24
+ description,
25
+ endpointPermalink
26
+ }
27
+ });
28
+ }
29
+ toSerializableRecipe() {
30
+ return this.recipe;
31
+ }
32
+ }
33
+ //# sourceMappingURL=portal-recipe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portal-recipe.js","sourceRoot":"","sources":["../../../../src/application/portal/recipe/portal-recipe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAE/E,MAAM,OAAO,YAAY;IAGvB,YAAY,IAAY;QACtB,IAAI,CAAC,MAAM,GAAG;YACZ,IAAI;YACJ,KAAK,EAAE,EAAE;SACV,CAAC;IACJ,CAAC;IAED,cAAc,CAAC,GAAW,EAAE,OAAe;QACzC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;YACrB,GAAG;YACH,IAAI,EAAE,GAAG,EAAE,gCAAgC;YAC3C,IAAI,EAAE,QAAQ,CAAC,OAAO;YACtB,MAAM,EAAE,EAAE,OAAO,EAAE;SACpB,CAAC,CAAC;IACL,CAAC;IAED,eAAe,CAAC,GAAW,EAAE,WAAmB,EAAE,iBAAyB,EAAE,YAAoB;QAC/F,MAAM,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACtG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;YACrB,GAAG;YACH,IAAI,EAAE,GAAG,EAAE,gCAAgC;YAC3C,IAAI,EAAE,QAAQ,CAAC,QAAQ;YACvB,MAAM,EAAE;gBACN,WAAW;gBACX,iBAAiB;aAClB;SACF,CAAC,CAAC;IACL,CAAC;IAED,oBAAoB;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,21 @@
1
+ import { SerializableRecipe } from "../../../types/recipe/recipe.js";
2
+ import { DirectoryPath } from "../../../types/file/directoryPath.js";
3
+ import { Toc } from "../../../types/toc/toc.js";
4
+ import { FilePath } from "../../../types/file/filePath.js";
5
+ import { FileName } from "../../../types/file/fileName.js";
6
+ import { BuildContext } from "../../../types/build-context.js";
7
+ export declare class PortalRecipeGenerator {
8
+ private readonly fileService;
9
+ createRecipe(recipe: SerializableRecipe, tocFileContent: Toc, tocFilePath: FilePath, recipeName: string, recipeScriptFileName: FileName, recipeMarkdownFileName: FileName, buildContext: BuildContext, buildDirectory: DirectoryPath): Promise<void>;
10
+ private addRecipeToToc;
11
+ private registerRecipeInBuildConfigFile;
12
+ private createMarkdownFile;
13
+ private createScriptFromRecipe;
14
+ private saveGeneratedRecipeScriptToBuildDirectory;
15
+ private generateVerifyFunction;
16
+ private addContentStepToScript;
17
+ private addEndpointStepToScript;
18
+ private getMarkdownFileContent;
19
+ private formatScript;
20
+ private toPascalCase;
21
+ }
@@ -0,0 +1,145 @@
1
+ import prettier from "prettier";
2
+ import { stringify } from "yaml";
3
+ import { FileService } from "../../../infrastructure/file-service.js";
4
+ import { FilePath } from "../../../types/file/filePath.js";
5
+ export class PortalRecipeGenerator {
6
+ constructor() {
7
+ //TODO: Replace tocFileContent any type with concrete type.
8
+ this.fileService = new FileService();
9
+ }
10
+ async createRecipe(recipe, tocFileContent, tocFilePath, recipeName, recipeScriptFileName, recipeMarkdownFileName, buildContext, buildDirectory) {
11
+ await this.addRecipeToToc(tocFileContent, tocFilePath, recipeName, recipeMarkdownFileName);
12
+ await this.registerRecipeInBuildConfigFile(buildContext, recipeName, recipeScriptFileName);
13
+ await this.createMarkdownFile(recipeMarkdownFileName, buildDirectory.join("content"));
14
+ const generatedRecipeScript = await this.createScriptFromRecipe(recipe);
15
+ const generatedRecipeScriptsDirectoryPath = buildDirectory.join("static", "scripts", "recipes");
16
+ await this.saveGeneratedRecipeScriptToBuildDirectory(generatedRecipeScript, generatedRecipeScriptsDirectoryPath, recipeScriptFileName);
17
+ }
18
+ async addRecipeToToc(tocData, tocFilePath, recipeName, recipeMarkdownFileName) {
19
+ let toc = tocData.toc;
20
+ let apiRecipesGroup = toc.find((item) => item.group === "API Recipes");
21
+ if (!apiRecipesGroup) {
22
+ // If the group doesn't exist, create and insert it after the last group
23
+ apiRecipesGroup = {
24
+ group: "API Recipes",
25
+ items: []
26
+ };
27
+ // Insert after the last group section, before generate sections
28
+ let lastGroupIdx = -1;
29
+ for (let i = 0; i < toc.length; i++) {
30
+ if (toc[i].group)
31
+ lastGroupIdx = i;
32
+ }
33
+ toc.splice(lastGroupIdx + 1, 0, apiRecipesGroup);
34
+ }
35
+ // Only add the recipe if it doesn't already exist
36
+ const existingRecipe = apiRecipesGroup.items.find((item) => item.page === recipeName || item.file === `recipes/${recipeMarkdownFileName}`);
37
+ if (!existingRecipe) {
38
+ apiRecipesGroup.items.push({
39
+ page: recipeName,
40
+ file: `recipes/${recipeMarkdownFileName}`
41
+ });
42
+ await this.fileService.writeContents(tocFilePath, stringify(tocData));
43
+ }
44
+ }
45
+ async registerRecipeInBuildConfigFile(buildContext, recipeName, recipeScriptFileName) {
46
+ const buildConfig = await buildContext.getBuildFileContents();
47
+ if (!buildConfig.recipes) {
48
+ buildConfig.recipes = {};
49
+ }
50
+ const recipesConfig = buildConfig.recipes;
51
+ if (!recipesConfig.workflows) {
52
+ recipesConfig.workflows = [];
53
+ }
54
+ const existingIndex = recipesConfig.workflows.findIndex((workflow) => workflow.permalink === `page:recipes/${this.toPascalCase(recipeName)}`);
55
+ const newWorkflow = {
56
+ name: recipeName,
57
+ permalink: `page:recipes/${this.toPascalCase(recipeName)}`,
58
+ functionName: this.toPascalCase(recipeName),
59
+ scriptPath: `./static/scripts/recipes/${recipeScriptFileName}`
60
+ };
61
+ if (existingIndex !== -1) {
62
+ // Replace the existing workflow
63
+ recipesConfig.workflows[existingIndex] = newWorkflow;
64
+ }
65
+ else {
66
+ // Add as new workflow
67
+ recipesConfig.workflows.push(newWorkflow);
68
+ }
69
+ await buildContext.updateBuildFileContents(buildConfig);
70
+ }
71
+ async createMarkdownFile(recipeMarkdownFileName, contentFolder) {
72
+ const directory = contentFolder.join("recipes");
73
+ const markdownFileContent = this.getMarkdownFileContent();
74
+ await this.fileService.createDirectoryIfNotExists(directory);
75
+ await this.fileService.writeContents(new FilePath(directory, recipeMarkdownFileName), markdownFileContent);
76
+ }
77
+ async createScriptFromRecipe(recipe) {
78
+ let script = `export default function ${this.toPascalCase(recipe.name)}(workflowCtx, portal) {`;
79
+ script += "return {";
80
+ recipe.steps.forEach((step, index) => {
81
+ script += `"${step.key}": {`;
82
+ script += `name: "${step.name}",`;
83
+ script += "stepCallback: async () => {";
84
+ if (step.type === "content") {
85
+ script += this.addContentStepToScript(step.config);
86
+ }
87
+ else if (step.type === "endpoint") {
88
+ script += this.addEndpointStepToScript(step.config);
89
+ }
90
+ script += "},";
91
+ script += "}";
92
+ if (index < recipe.steps.length - 1) {
93
+ script += ",";
94
+ }
95
+ });
96
+ script += "};";
97
+ script += "}";
98
+ return script;
99
+ }
100
+ async saveGeneratedRecipeScriptToBuildDirectory(generatedRecipeScript, generatedRecipeScriptsDirectoryPath, recipeScriptFileName, format = false) {
101
+ if (format) {
102
+ generatedRecipeScript = await this.formatScript(generatedRecipeScript);
103
+ }
104
+ await this.fileService.createDirectoryIfNotExists(generatedRecipeScriptsDirectoryPath);
105
+ await this.fileService.writeContents(new FilePath(generatedRecipeScriptsDirectoryPath, recipeScriptFileName), generatedRecipeScript);
106
+ }
107
+ generateVerifyFunction() {
108
+ return `if (response.StatusCode == 200) { return true; } else { setError("API Call wasn't able to get a valid response. Please try again."); return false; }`;
109
+ }
110
+ addContentStepToScript(contentConfig) {
111
+ return `return workflowCtx.showContent(${JSON.stringify(contentConfig.content)});`;
112
+ }
113
+ addEndpointStepToScript(endpointConfig) {
114
+ let script = "return workflowCtx.showEndpoint({";
115
+ if (endpointConfig.description !== "") {
116
+ script += `description: ${JSON.stringify(endpointConfig.description)},`;
117
+ }
118
+ script += `endpointPermalink: "${endpointConfig.endpointPermalink}",`;
119
+ script += "verify: (response, setError) => {";
120
+ script += this.generateVerifyFunction();
121
+ script += "},";
122
+ script += "});";
123
+ return script;
124
+ }
125
+ getMarkdownFileContent() {
126
+ return `# This is a Guided Walkthrough File
127
+ This is the starter content`;
128
+ }
129
+ async formatScript(code) {
130
+ return prettier.format(code, {
131
+ parser: "babel",
132
+ semi: true,
133
+ singleQuote: false,
134
+ tabWidth: 2,
135
+ trailingComma: "es5"
136
+ });
137
+ }
138
+ toPascalCase(str) {
139
+ return str
140
+ .split(" ")
141
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
142
+ .join("");
143
+ }
144
+ }
145
+ //# sourceMappingURL=recipe-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recipe-generator.js","sourceRoot":"","sources":["../../../../src/application/portal/recipe/recipe-generator.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAGjC,OAAO,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAEtE,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAI3D,MAAM,OAAO,qBAAqB;IAAlC;QACE,2DAA2D;QAC1C,gBAAW,GAAgB,IAAI,WAAW,EAAE,CAAC;IAiMhE,CAAC;IA/LQ,KAAK,CAAC,YAAY,CACvB,MAA0B,EAC1B,cAAmB,EACnB,WAAqB,EACrB,UAAkB,EAClB,oBAA8B,EAC9B,sBAAgC,EAChC,YAA0B,EAC1B,cAA6B;QAE7B,MAAM,IAAI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IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,WAAW,CAAC,GAAG,CAAC;QAC1E,CAAC;QACD,MAAM,IAAI,uBAAuB,cAAc,CAAC,iBAAiB,IAAI,CAAC;QACtE,MAAM,IAAI,mCAAmC,CAAC;QAC9C,MAAM,IAAI,IAAI,CAAC,sBAAsB,EAAE,CAAC;QACxC,MAAM,IAAI,IAAI,CAAC;QACf,MAAM,IAAI,KAAK,CAAC;QAChB,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,sBAAsB;QAC5B,OAAO;4BACiB,CAAC;IAC3B,CAAC;IAEO,KAAK,CAAC,YAAY,CAAC,IAAY;QACrC,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE;YAC3B,MAAM,EAAE,OAAO;YACf,IAAI,EAAE,IAAI;YACV,WAAW,EAAE,KAAK;YAClB,QAAQ,EAAE,CAAC;YACX,aAAa,EAAE,KAAK;SACrB,CAAC,CAAC;IACL,CAAC;IAEO,YAAY,CAAC,GAAW;QAC9B,OAAO,GAAG;aACP,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;aACzE,IAAI,CAAC,EAAE,CAAC,CAAC;IACd,CAAC;CACF"}
@@ -1,4 +1,4 @@
1
- import { TocGroup } from "../../../../types/toc/toc";
1
+ import { TocGroup } from "../../../types/toc/toc.js";
2
2
  export declare class TocContentParser {
3
3
  parseContentFolder(contentFolderPath: string, workingDirectory: string): Promise<TocGroup[]>;
4
4
  private normalizePath;