@apimatic/cli 0.0.0-alpha.4 → 1.0.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 (305) hide show
  1. package/README.md +308 -130
  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 +13 -0
  25. package/lib/actions/portal/generate.js +59 -0
  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 +145 -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 +176 -0
  32. package/lib/actions/portal/recipe/new-recipe.js.map +1 -0
  33. package/lib/actions/portal/serve.d.ts +16 -0
  34. package/lib/actions/portal/serve.js +119 -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/sdk/generate.d.ts +13 -0
  40. package/lib/actions/sdk/generate.js +47 -0
  41. package/lib/actions/sdk/generate.js.map +1 -0
  42. package/lib/application/portal/recipe/portal-recipe.d.ts +8 -0
  43. package/lib/application/portal/recipe/portal-recipe.js +33 -0
  44. package/lib/application/portal/recipe/portal-recipe.js.map +1 -0
  45. package/lib/application/portal/recipe/recipe-generator.d.ts +21 -0
  46. package/lib/application/portal/recipe/recipe-generator.js +146 -0
  47. package/lib/application/portal/recipe/recipe-generator.js.map +1 -0
  48. package/lib/application/portal/toc/toc-content-parser.d.ts +5 -0
  49. package/lib/application/portal/toc/toc-content-parser.js +44 -0
  50. package/lib/application/portal/toc/toc-content-parser.js.map +1 -0
  51. package/lib/application/portal/toc/toc-structure-generator.d.ts +6 -0
  52. package/lib/application/portal/toc/toc-structure-generator.js +84 -0
  53. package/lib/application/portal/toc/toc-structure-generator.js.map +1 -0
  54. package/lib/client-utils/auth-manager.d.ts +8 -3
  55. package/lib/client-utils/auth-manager.js +26 -14
  56. package/lib/client-utils/auth-manager.js.map +1 -0
  57. package/lib/commands/api/transform.d.ts +11 -8
  58. package/lib/commands/api/transform.js +52 -105
  59. package/lib/commands/api/transform.js.map +1 -0
  60. package/lib/commands/api/validate.d.ts +8 -5
  61. package/lib/commands/api/validate.js +31 -63
  62. package/lib/commands/api/validate.js.map +1 -0
  63. package/lib/commands/auth/login.d.ts +4 -2
  64. package/lib/commands/auth/login.js +26 -51
  65. package/lib/commands/auth/login.js.map +1 -0
  66. package/lib/commands/auth/logout.d.ts +4 -2
  67. package/lib/commands/auth/logout.js +14 -20
  68. package/lib/commands/auth/logout.js.map +1 -0
  69. package/lib/commands/auth/status.d.ts +2 -1
  70. package/lib/commands/auth/status.js +18 -20
  71. package/lib/commands/auth/status.js.map +1 -0
  72. package/lib/commands/portal/copilot.d.ts +13 -0
  73. package/lib/commands/portal/copilot.js +34 -0
  74. package/lib/commands/portal/copilot.js.map +1 -0
  75. package/lib/commands/portal/generate.d.ts +9 -8
  76. package/lib/commands/portal/generate.js +31 -97
  77. package/lib/commands/portal/generate.js.map +1 -0
  78. package/lib/commands/portal/quickstart.d.ts +9 -0
  79. package/lib/commands/portal/quickstart.js +37 -0
  80. package/lib/commands/portal/quickstart.js.map +1 -0
  81. package/lib/commands/portal/recipe/new.d.ts +12 -0
  82. package/lib/commands/portal/recipe/new.js +46 -0
  83. package/lib/commands/portal/recipe/new.js.map +1 -0
  84. package/lib/commands/portal/serve.d.ts +16 -0
  85. package/lib/commands/portal/serve.js +54 -0
  86. package/lib/commands/portal/serve.js.map +1 -0
  87. package/lib/commands/portal/toc/new.d.ts +14 -0
  88. package/lib/commands/portal/toc/new.js +61 -0
  89. package/lib/commands/portal/toc/new.js.map +1 -0
  90. package/lib/commands/sdk/generate.d.ts +11 -9
  91. package/lib/commands/sdk/generate.js +48 -122
  92. package/lib/commands/sdk/generate.js.map +1 -0
  93. package/lib/config/axios-config.d.ts +2 -0
  94. package/lib/config/axios-config.js +10 -0
  95. package/lib/config/axios-config.js.map +1 -0
  96. package/lib/hooks/not-found.d.ts +3 -0
  97. package/lib/hooks/not-found.js +52 -0
  98. package/lib/hooks/not-found.js.map +1 -0
  99. package/lib/hooks/utils.d.ts +5 -0
  100. package/lib/hooks/utils.js +51 -0
  101. package/lib/hooks/utils.js.map +1 -0
  102. package/lib/index.d.ts +1 -1
  103. package/lib/index.js +2 -4
  104. package/lib/index.js.map +1 -0
  105. package/lib/infrastructure/api-utils.d.ts +9 -0
  106. package/lib/infrastructure/api-utils.js +34 -0
  107. package/lib/infrastructure/api-utils.js.map +1 -0
  108. package/lib/infrastructure/debounce-service.d.ts +10 -0
  109. package/lib/infrastructure/debounce-service.js +52 -0
  110. package/lib/infrastructure/debounce-service.js.map +1 -0
  111. package/lib/infrastructure/env-info.d.ts +12 -0
  112. package/lib/infrastructure/env-info.js +58 -0
  113. package/lib/infrastructure/env-info.js.map +1 -0
  114. package/lib/infrastructure/file-service.d.ts +23 -0
  115. package/lib/infrastructure/file-service.js +117 -0
  116. package/lib/infrastructure/file-service.js.map +1 -0
  117. package/lib/infrastructure/launcher-service.d.ts +7 -0
  118. package/lib/infrastructure/launcher-service.js +51 -0
  119. package/lib/infrastructure/launcher-service.js.map +1 -0
  120. package/lib/infrastructure/network-service.d.ts +3 -0
  121. package/lib/infrastructure/network-service.js +7 -0
  122. package/lib/infrastructure/network-service.js.map +1 -0
  123. package/lib/infrastructure/services/api-client-factory.d.ts +6 -0
  124. package/lib/infrastructure/services/api-client-factory.js +20 -0
  125. package/lib/infrastructure/services/api-client-factory.js.map +1 -0
  126. package/lib/infrastructure/services/api-service.d.ts +10 -0
  127. package/lib/infrastructure/services/api-service.js +55 -0
  128. package/lib/infrastructure/services/api-service.js.map +1 -0
  129. package/lib/infrastructure/services/auth-service.d.ts +11 -0
  130. package/lib/infrastructure/services/auth-service.js +37 -0
  131. package/lib/infrastructure/services/auth-service.js.map +1 -0
  132. package/lib/infrastructure/services/file-download-service.d.ts +15 -0
  133. package/lib/infrastructure/services/file-download-service.js +104 -0
  134. package/lib/infrastructure/services/file-download-service.js.map +1 -0
  135. package/lib/infrastructure/services/portal-service.d.ts +21 -0
  136. package/lib/infrastructure/services/portal-service.js +157 -0
  137. package/lib/infrastructure/services/portal-service.js.map +1 -0
  138. package/lib/infrastructure/services/telemetry-service.d.ts +9 -0
  139. package/lib/infrastructure/services/telemetry-service.js +38 -0
  140. package/lib/infrastructure/services/telemetry-service.js.map +1 -0
  141. package/lib/infrastructure/services/transformation-service.d.ts +23 -0
  142. package/lib/infrastructure/services/transformation-service.js +56 -0
  143. package/lib/infrastructure/services/transformation-service.js.map +1 -0
  144. package/lib/infrastructure/services/validation-service.d.ts +17 -0
  145. package/lib/infrastructure/services/validation-service.js +49 -0
  146. package/lib/infrastructure/services/validation-service.js.map +1 -0
  147. package/lib/infrastructure/tmp-extensions.d.ts +2 -0
  148. package/lib/infrastructure/tmp-extensions.js +6 -0
  149. package/lib/infrastructure/tmp-extensions.js.map +1 -0
  150. package/lib/infrastructure/zip-service.d.ts +6 -0
  151. package/lib/infrastructure/zip-service.js +39 -0
  152. package/lib/infrastructure/zip-service.js.map +1 -0
  153. package/lib/prompts/api/transform.d.ts +11 -0
  154. package/lib/prompts/api/transform.js +30 -0
  155. package/lib/prompts/api/transform.js.map +1 -0
  156. package/lib/prompts/api/validate.d.ts +12 -0
  157. package/lib/prompts/api/validate.js +41 -0
  158. package/lib/prompts/api/validate.js.map +1 -0
  159. package/lib/prompts/auth/login.d.ts +10 -0
  160. package/lib/prompts/auth/login.js +22 -0
  161. package/lib/prompts/auth/login.js.map +1 -0
  162. package/lib/prompts/auth/logout.d.ts +3 -0
  163. package/lib/prompts/auth/logout.js +7 -0
  164. package/lib/prompts/auth/logout.js.map +1 -0
  165. package/lib/prompts/auth/status.d.ts +8 -0
  166. package/lib/prompts/auth/status.js +21 -0
  167. package/lib/prompts/auth/status.js.map +1 -0
  168. package/lib/prompts/format.d.ts +33 -0
  169. package/lib/prompts/format.js +99 -0
  170. package/lib/prompts/format.js.map +1 -0
  171. package/lib/prompts/portal/copilot.d.ts +18 -0
  172. package/lib/prompts/portal/copilot.js +82 -0
  173. package/lib/prompts/portal/copilot.js.map +1 -0
  174. package/lib/prompts/portal/generate.d.ts +13 -0
  175. package/lib/prompts/portal/generate.js +41 -0
  176. package/lib/prompts/portal/generate.js.map +1 -0
  177. package/lib/prompts/portal/quickstart.d.ts +31 -0
  178. package/lib/prompts/portal/quickstart.js +146 -0
  179. package/lib/prompts/portal/quickstart.js.map +1 -0
  180. package/lib/prompts/portal/recipe/new-recipe.d.ts +29 -0
  181. package/lib/prompts/portal/recipe/new-recipe.js +165 -0
  182. package/lib/prompts/portal/recipe/new-recipe.js.map +1 -0
  183. package/lib/prompts/portal/serve.d.ts +11 -0
  184. package/lib/prompts/portal/serve.js +33 -0
  185. package/lib/prompts/portal/serve.js.map +1 -0
  186. package/lib/prompts/portal/toc/new-toc.d.ts +15 -0
  187. package/lib/prompts/portal/toc/new-toc.js +37 -0
  188. package/lib/prompts/portal/toc/new-toc.js.map +1 -0
  189. package/lib/prompts/sdk/generate.d.ts +11 -0
  190. package/lib/prompts/sdk/generate.js +36 -0
  191. package/lib/prompts/sdk/generate.js.map +1 -0
  192. package/lib/types/api/account.d.ts +10 -0
  193. package/lib/types/api/account.js +2 -0
  194. package/lib/types/api/account.js.map +1 -0
  195. package/lib/types/api/transform.d.ts +17 -17
  196. package/lib/types/api/transform.js +21 -6
  197. package/lib/types/api/transform.js.map +1 -0
  198. package/lib/types/build/build.d.ts +22 -0
  199. package/lib/types/build/build.js +7 -0
  200. package/lib/types/build/build.js.map +1 -0
  201. package/lib/types/build-context.d.ts +17 -0
  202. package/lib/types/build-context.js +47 -0
  203. package/lib/types/build-context.js.map +1 -0
  204. package/lib/types/common/command-metadata.d.ts +4 -0
  205. package/lib/types/common/command-metadata.js +2 -0
  206. package/lib/types/common/command-metadata.js.map +1 -0
  207. package/lib/types/events/domain-event.d.ts +8 -0
  208. package/lib/types/events/domain-event.js +11 -0
  209. package/lib/types/events/domain-event.js.map +1 -0
  210. package/lib/types/events/quickstart-completed.d.ts +7 -0
  211. package/lib/types/events/quickstart-completed.js +10 -0
  212. package/lib/types/events/quickstart-completed.js.map +1 -0
  213. package/lib/types/events/quickstart-initiated.d.ts +7 -0
  214. package/lib/types/events/quickstart-initiated.js +10 -0
  215. package/lib/types/events/quickstart-initiated.js.map +1 -0
  216. package/lib/types/events/recipe-creation-failed.d.ts +5 -0
  217. package/lib/types/events/recipe-creation-failed.js +8 -0
  218. package/lib/types/events/recipe-creation-failed.js.map +1 -0
  219. package/lib/types/events/toc-creation-failed.d.ts +5 -0
  220. package/lib/types/events/toc-creation-failed.js +8 -0
  221. package/lib/types/events/toc-creation-failed.js.map +1 -0
  222. package/lib/types/file/directory.d.ts +17 -0
  223. package/lib/types/file/directory.js +86 -0
  224. package/lib/types/file/directory.js.map +1 -0
  225. package/lib/types/file/directoryPath.d.ts +9 -0
  226. package/lib/types/file/directoryPath.js +22 -0
  227. package/lib/types/file/directoryPath.js.map +1 -0
  228. package/lib/types/file/fileName.d.ts +7 -0
  229. package/lib/types/file/fileName.js +21 -0
  230. package/lib/types/file/fileName.js.map +1 -0
  231. package/lib/types/file/filePath.d.ts +10 -0
  232. package/lib/types/file/filePath.js +32 -0
  233. package/lib/types/file/filePath.js.map +1 -0
  234. package/lib/types/file/resource-input.d.ts +5 -0
  235. package/lib/types/file/resource-input.js +42 -0
  236. package/lib/types/file/resource-input.js.map +1 -0
  237. package/lib/types/file/urlPath.d.ts +6 -0
  238. package/lib/types/file/urlPath.js +22 -0
  239. package/lib/types/file/urlPath.js.map +1 -0
  240. package/lib/types/flags-provider.d.ts +15 -0
  241. package/lib/types/flags-provider.js +34 -0
  242. package/lib/types/flags-provider.js.map +1 -0
  243. package/lib/types/portal-context.d.ts +13 -0
  244. package/lib/types/portal-context.js +38 -0
  245. package/lib/types/portal-context.js.map +1 -0
  246. package/lib/types/recipe/recipe.d.ts +22 -0
  247. package/lib/types/recipe/recipe.js +6 -0
  248. package/lib/types/recipe/recipe.js.map +1 -0
  249. package/lib/types/recipe-context.d.ts +8 -0
  250. package/lib/types/recipe-context.js +21 -0
  251. package/lib/types/recipe-context.js.map +1 -0
  252. package/lib/types/resource-context.d.ts +12 -0
  253. package/lib/types/resource-context.js +30 -0
  254. package/lib/types/resource-context.js.map +1 -0
  255. package/lib/types/sdk/generate.d.ts +9 -21
  256. package/lib/types/sdk/generate.js +25 -12
  257. package/lib/types/sdk/generate.js.map +1 -0
  258. package/lib/types/sdk-context.d.ts +14 -0
  259. package/lib/types/sdk-context.js +32 -0
  260. package/lib/types/sdk-context.js.map +1 -0
  261. package/lib/types/sdl/sdl.d.ts +21 -0
  262. package/lib/types/sdl/sdl.js +47 -0
  263. package/lib/types/sdl/sdl.js.map +1 -0
  264. package/lib/types/spec-context.d.ts +10 -0
  265. package/lib/types/spec-context.js +17 -0
  266. package/lib/types/spec-context.js.map +1 -0
  267. package/lib/types/temp-context.d.ts +11 -0
  268. package/lib/types/temp-context.js +27 -0
  269. package/lib/types/temp-context.js.map +1 -0
  270. package/lib/types/toc/toc.d.ts +31 -0
  271. package/lib/types/toc/toc.js +9 -0
  272. package/lib/types/toc/toc.js.map +1 -0
  273. package/lib/types/toc-context.d.ts +12 -0
  274. package/lib/types/toc-context.js +26 -0
  275. package/lib/types/toc-context.js.map +1 -0
  276. package/lib/types/transform-context.d.ts +13 -0
  277. package/lib/types/transform-context.js +30 -0
  278. package/lib/types/transform-context.js.map +1 -0
  279. package/lib/types/utils.d.ts +1 -6
  280. package/lib/types/utils.js +2 -2
  281. package/lib/types/utils.js.map +1 -0
  282. package/lib/utils/string-utils.d.ts +1 -0
  283. package/lib/utils/string-utils.js +10 -0
  284. package/lib/utils/string-utils.js.map +1 -0
  285. package/lib/utils/utils.d.ts +2 -18
  286. package/lib/utils/utils.js +33 -116
  287. package/lib/utils/utils.js.map +1 -0
  288. package/package.json +101 -44
  289. package/bin/run +0 -5
  290. package/lib/client-utils/sdk-client.d.ts +0 -23
  291. package/lib/client-utils/sdk-client.js +0 -119
  292. package/lib/config/env.d.ts +0 -1
  293. package/lib/config/env.js +0 -4
  294. package/lib/controllers/api/transform.d.ts +0 -5
  295. package/lib/controllers/api/transform.js +0 -49
  296. package/lib/controllers/api/validate.d.ts +0 -3
  297. package/lib/controllers/api/validate.js +0 -22
  298. package/lib/controllers/portal/generate.d.ts +0 -2
  299. package/lib/controllers/portal/generate.js +0 -49
  300. package/lib/controllers/sdk/generate.d.ts +0 -4
  301. package/lib/controllers/sdk/generate.js +0 -64
  302. package/lib/types/api/validate.d.ts +0 -12
  303. package/lib/types/api/validate.js +0 -2
  304. package/lib/types/portal/generate.d.ts +0 -9
  305. package/lib/types/portal/generate.js +0 -2
@@ -0,0 +1,48 @@
1
+ import { ActionResult } from "../action-result.js";
2
+ import { ApiTransformPrompts } from "../../prompts/api/transform.js";
3
+ import { withDirPath } from "../../infrastructure/tmp-extensions.js";
4
+ import { TransformationService } from "../../infrastructure/services/transformation-service.js";
5
+ import { ApiValidatePrompts } from "../../prompts/api/validate.js";
6
+ import { TransformContext } from "../../types/transform-context.js";
7
+ import { ResourceContext } from "../../types/resource-context.js";
8
+ export class TransformAction {
9
+ constructor(configDir, commandMetadata, authKey = null) {
10
+ this.prompts = new ApiTransformPrompts();
11
+ this.validatePrompts = new ApiValidatePrompts();
12
+ this.transformationService = new TransformationService();
13
+ this.execute = async (resourcePath, format, destination, force) => {
14
+ return await withDirPath(async (tempDirectory) => {
15
+ const resourceContext = new ResourceContext(tempDirectory);
16
+ const specFileDirResult = await resourceContext.resolveTo(resourcePath);
17
+ if (specFileDirResult.isErr()) {
18
+ this.prompts.networkError(specFileDirResult.error);
19
+ return ActionResult.failed();
20
+ }
21
+ const transformContext = new TransformContext(specFileDirResult.value, format, destination);
22
+ if (!force && (await transformContext.exists()) && !(await this.prompts.overwriteApi(destination))) {
23
+ this.prompts.transformedApiAlreadyExists();
24
+ return ActionResult.cancelled();
25
+ }
26
+ const result = await this.prompts.transformApi(this.transformationService.transformViaFile({
27
+ file: specFileDirResult.value,
28
+ format: format,
29
+ configDir: this.configDir,
30
+ commandMetadata: this.commandMetadata,
31
+ authKey: this.authKey
32
+ }));
33
+ if (result.isErr()) {
34
+ this.prompts.logTransformationError(result.error);
35
+ return ActionResult.failed();
36
+ }
37
+ const transformedFilePath = await transformContext.save(result.value.stream);
38
+ this.validatePrompts.displayValidationMessages(result.value.apiValidationSummary);
39
+ this.validatePrompts.transformedApiSaved(transformedFilePath);
40
+ return ActionResult.success();
41
+ });
42
+ };
43
+ this.configDir = configDir;
44
+ this.commandMetadata = commandMetadata;
45
+ this.authKey = authKey;
46
+ }
47
+ }
48
+ //# sourceMappingURL=transform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.js","sourceRo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C;CA4CF"}
@@ -0,0 +1,12 @@
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 { ResourceInput } from "../../types/file/resource-input.js";
5
+ export declare class ValidateAction {
6
+ private readonly prompts;
7
+ private readonly validationService;
8
+ private readonly authKey;
9
+ private readonly commandMetadata;
10
+ constructor(configDir: DirectoryPath, commandMetadata: CommandMetadata, authKey?: string | null);
11
+ readonly execute: (resourcePath: ResourceInput, displayValidationSummary?: boolean) => Promise<ActionResult>;
12
+ }
@@ -0,0 +1,41 @@
1
+ import { ActionResult } from "../action-result.js";
2
+ import { ApiValidatePrompts } from "../../prompts/api/validate.js";
3
+ import { ValidationService } from "../../infrastructure/services/validation-service.js";
4
+ import { withDirPath } from "../../infrastructure/tmp-extensions.js";
5
+ import { ResourceContext } from "../../types/resource-context.js";
6
+ export class ValidateAction {
7
+ constructor(configDir, commandMetadata, authKey = null) {
8
+ this.prompts = new ApiValidatePrompts();
9
+ this.execute = async (resourcePath, displayValidationSummary = true) => {
10
+ return await withDirPath(async (tempDirectory) => {
11
+ const resourceContext = new ResourceContext(tempDirectory);
12
+ const specFileDirResult = await resourceContext.resolveTo(resourcePath);
13
+ if (specFileDirResult.isErr()) {
14
+ this.prompts.networkError(specFileDirResult.error);
15
+ return ActionResult.failed();
16
+ }
17
+ const validationSummaryResult = await this.prompts.validateApi(this.validationService.validateViaFile({
18
+ file: specFileDirResult.value,
19
+ commandMetadata: this.commandMetadata,
20
+ authKey: this.authKey
21
+ }));
22
+ if (validationSummaryResult.isErr()) {
23
+ this.prompts.logValidationError(validationSummaryResult.error);
24
+ return ActionResult.failed();
25
+ }
26
+ const validationSummary = validationSummaryResult.value;
27
+ if (displayValidationSummary) {
28
+ this.prompts.displayValidationMessages(validationSummary);
29
+ }
30
+ if (!validationSummary.success) {
31
+ return ActionResult.failed();
32
+ }
33
+ return ActionResult.success();
34
+ });
35
+ };
36
+ this.authKey = authKey;
37
+ this.validationService = new ValidationService(configDir);
38
+ this.commandMetadata = commandMetadata;
39
+ }
40
+ }
41
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../src/actions/api/validate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qDAAqD,CAAC;AAGxF,OAAO,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAElE,MAAM,OAAO,cAAc;IAMzB,YAAY,SAAwB,EAAE,eAAgC,EAAE,UAAyB,IAAI;QALpF,YAAO,GAAuB,IAAI,kBAAkB,EAAE,CAAC;QAWxD,YAAO,GAAG,KAAK,EAC7B,YAA2B,EAC3B,wBAAwB,GAAG,IAAI,EACR,EAAE;YACzB,OAAO,MAAM,WAAW,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE;gBAC/C,MAAM,eAAe,GAAG,IAAI,eAAe,CAAC,aAAa,CAAC,CAAC;gBAC3D,MAAM,iBAAiB,GAAG,MAAM,eAAe,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;gBACxE,IAAI,iBAAiB,CAAC,KAAK,EAAE,EAAE,CAAC;oBAC9B,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;oBACnD,OAAO,YAAY,CAAC,MAAM,EAAE,CAAC;gBAC/B,CAAC;gBACD,MAAM,uBAAuB,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,WAAW,CAC5D,IAAI,CAAC,iBAAiB,CAAC,eAAe,CAAC;oBACrC,IAAI,EAAE,iBAAiB,CAAC,KAAK;oBAC7B,eAAe,EAAE,IAAI,CAAC,eAAe;oBACrC,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB,CAAC,CACH,CAAC;gBAEF,IAAI,uBAAuB,CAAC,KAAK,EAAE,EAAE,CAAC;oBACpC,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC;oBAC/D,OAAO,YAAY,CAAC,MAAM,EAAE,CAAC;gBAC/B,CAAC;gBACD,MAAM,iBAAiB,GAAG,uBAAuB,CAAC,KAAK,CAAC;gBACxD,IAAI,wBAAwB,EAAE,CAAC;oBAC7B,IAAI,CAAC,OAAO,CAAC,yBAAyB,CAAC,iBAAiB,CAAC,CAAC;gBAC5D,CAAC;gBACD,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC;oBAC/B,OAAO,YAAY,CAAC,MAAM,EAAE,CAAC;gBAC/B,CAAC;gBAED,OAAO,YAAY,CAAC,OAAO,EAAE,CAAC;YAChC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QAtCA,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAC1D,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,CAAC;CAoCF"}
@@ -0,0 +1,13 @@
1
+ import { DirectoryPath } from "../../types/file/directoryPath.js";
2
+ import { CommandMetadata } from "../../types/common/command-metadata.js";
3
+ import { ActionResult } from "../action-result.js";
4
+ export declare class LoginAction {
5
+ private readonly configDir;
6
+ private readonly commandMetadata;
7
+ private readonly authService;
8
+ private readonly apiService;
9
+ private readonly prompts;
10
+ constructor(configDir: DirectoryPath, commandMetadata: CommandMetadata);
11
+ execute(apiKey?: string | undefined): Promise<ActionResult>;
12
+ private pollDeviceToken;
13
+ }
@@ -0,0 +1,55 @@
1
+ import { AuthService } from "../../infrastructure/services/auth-service.js";
2
+ import { ApiService } from "../../infrastructure/services/api-service.js";
3
+ import { v4 as uuid } from "uuid";
4
+ import open from "open";
5
+ import { setAuthInfo } from "../../client-utils/auth-manager.js";
6
+ import { LoginPrompts } from "../../prompts/auth/login.js";
7
+ import { ActionResult } from "../action-result.js";
8
+ import { err, ok } from "neverthrow";
9
+ export class LoginAction {
10
+ constructor(configDir, commandMetadata) {
11
+ this.configDir = configDir;
12
+ this.commandMetadata = commandMetadata;
13
+ this.authService = new AuthService();
14
+ this.apiService = new ApiService();
15
+ this.prompts = new LoginPrompts();
16
+ }
17
+ async execute(apiKey = undefined) {
18
+ const apiKeyResult = await this.pollDeviceToken(apiKey, this.commandMetadata.shell);
19
+ if (apiKeyResult.isErr()) {
20
+ this.prompts.loginTimeout();
21
+ return ActionResult.failed();
22
+ }
23
+ // TODO: Use status endpoint here
24
+ // Problem, we don't have email info here, just the key and required for setAuthInfo
25
+ const accountInfoResult = await this.prompts.accountInfoSpinner(this.apiService.getAccountInfo(this.configDir, this.commandMetadata.shell, apiKeyResult.value));
26
+ if (accountInfoResult.isErr()) {
27
+ this.prompts.invalidKeyProvided(accountInfoResult.error);
28
+ return ActionResult.failed();
29
+ }
30
+ await setAuthInfo(accountInfoResult.value.Email, apiKeyResult.value, false, this.configDir);
31
+ this.prompts.loginSuccessful(accountInfoResult.value.Email);
32
+ return ActionResult.success();
33
+ }
34
+ async pollDeviceToken(apiKey, shell) {
35
+ if (apiKey)
36
+ return ok(apiKey);
37
+ const state = uuid();
38
+ this.prompts.openBrowser();
39
+ await open(this.authService.getDeviceLoginUrl(state));
40
+ const timeoutDuration = 5 * 60 * 1000; // 5 minutes in milliseconds
41
+ const startTime = Date.now();
42
+ const delayMs = 3 * 1000;
43
+ while (true) {
44
+ if (Date.now() - startTime > timeoutDuration) {
45
+ return err("TIMEOUT");
46
+ }
47
+ const result = await this.authService.getDeviceLoginToken(state, shell);
48
+ if (result.isOk()) {
49
+ return ok(result.value.apiKey);
50
+ }
51
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
52
+ }
53
+ }
54
+ }
55
+ //# sour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B,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YACxE,IAAI,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;gBAClB,OAAO,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YACjC,CAAC;YACD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ import { DirectoryPath } from "../../types/file/directoryPath.js";
2
+ import { ActionResult } from "../action-result.js";
3
+ export declare class LogoutAction {
4
+ private readonly configDir;
5
+ private readonly prompts;
6
+ constructor(configDir: DirectoryPath);
7
+ execute(): Promise<ActionResult>;
8
+ }
@@ -0,0 +1,15 @@
1
+ import { ActionResult } from "../action-result.js";
2
+ import { removeAuthInfo } from "../../client-utils/auth-manager.js";
3
+ import { LogoutPrompts } from "../../prompts/auth/logout.js";
4
+ export class LogoutAction {
5
+ constructor(configDir) {
6
+ this.configDir = configDir;
7
+ this.prompts = new LogoutPrompts();
8
+ }
9
+ async execute() {
10
+ await removeAuthInfo(this.configDir);
11
+ this.prompts.removeAuthInfo();
12
+ return ActionResult.success();
13
+ }
14
+ }
15
+ //# sourceMappingURL=logout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logout.js","sourceRoot":"","sources":["../../../src/actions/auth/logout.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D,MAAM,OAAO,YAAY;IAGvB,YAA6B,SAAwB;QAAxB,cAAS,GAAT,SAAS,CAAe;QAFpC,YAAO,GAAG,IAAI,aAAa,EAAE,CAAC;IAES,CAAC;IAElD,KAAK,CAAC,OAAO;QAClB,MAAM,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACrC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;QAC9B,OAAO,YAAY,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ import { ActionResult } from "../action-result.js";
2
+ import { DirectoryPath } from "../../types/file/directoryPath.js";
3
+ import { CommandMetadata } from "../../types/common/command-metadata.js";
4
+ export declare class StatusAction {
5
+ private readonly configDir;
6
+ private readonly commandMetadata;
7
+ private readonly prompts;
8
+ private readonly apiService;
9
+ constructor(configDir: DirectoryPath, commandMetadata: CommandMetadata);
10
+ execute(authKey: string | null): Promise<ActionResult>;
11
+ }
@@ -0,0 +1,26 @@
1
+ import { ActionResult } from "../action-result.js";
2
+ import { getAuthInfo } from "../../client-utils/auth-manager.js";
3
+ import { StatusPrompts } from "../../prompts/auth/status.js";
4
+ import { ApiService } from "../../infrastructure/services/api-service.js";
5
+ export class StatusAction {
6
+ constructor(configDir, commandMetadata) {
7
+ this.configDir = configDir;
8
+ this.commandMetadata = commandMetadata;
9
+ this.prompts = new StatusPrompts();
10
+ this.apiService = new ApiService();
11
+ }
12
+ async execute(authKey) {
13
+ const accountInfo = await getAuthInfo(this.configDir.toString());
14
+ if (accountInfo === null) {
15
+ return ActionResult.failed();
16
+ }
17
+ const result = await this.prompts.accountInfoSpinner(this.apiService.getAccountInfo(this.configDir, this.commandMetadata.shell, authKey));
18
+ if (result.isErr()) {
19
+ this.prompts.invalidKeyProvided(result.error);
20
+ return ActionResult.failed();
21
+ }
22
+ this.prompts.showAccountInfo(result.value);
23
+ return ActionResult.success();
24
+ }
25
+ }
26
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.js","sourceRoot":"","sources":["../../../src/actions/auth/status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAE1E,MAAM,OAAO,YAAY;IAIvB,YAA6B,SAAwB,EAAmB,eAAgC;QAA3E,cAAS,GAAT,SAAS,CAAe;QAAmB,oBAAe,GAAf,eAAe,CAAiB;QAHvF,YAAO,GAAG,IAAI,aAAa,EAAE,CAAC;QAC9B,eAAU,GAAG,IAAI,UAAU,EAAE,CAAC;IAE4D,CAAC;IAErG,KAAK,CAAC,OAAO,CAAC,OAAsB;QACzC,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjE,IAAI,WAAW,KAAK,IAAI,EAAE,CAAC;YACzB,OAAO,YAAY,CAAC,MAAM,EAAE,CAAC;QAC/B,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAClD,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,CACpF,CAAC;QACF,IAAI,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC;YACnB,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC9C,OAAO,YAAY,CAAC,MAAM,EAAE,CAAC;QAC/B,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC3C,OAAO,YAAY,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC;CACF"}
@@ -0,0 +1,16 @@
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
+ export declare class CopilotAction {
5
+ private readonly apiService;
6
+ private readonly fileService;
7
+ private readonly launcherService;
8
+ private readonly prompts;
9
+ private readonly configDir;
10
+ private readonly commandMetadata;
11
+ private readonly authKey;
12
+ constructor(configDir: DirectoryPath, commandMetadata: CommandMetadata, authKey?: string | null);
13
+ readonly execute: (buildDirectory: DirectoryPath, force: boolean, enable: boolean) => Promise<ActionResult>;
14
+ private selectCopilotKey;
15
+ private prepareWelcomeMessage;
16
+ }
@@ -0,0 +1,89 @@
1
+ import { ApiService } from "../../infrastructure/services/api-service.js";
2
+ import { PortalCopilotPrompts } from "../../prompts/portal/copilot.js";
3
+ import { ActionResult } from "../action-result.js";
4
+ import { BuildContext } from "../../types/build-context.js";
5
+ import { withDirPath } from "../../infrastructure/tmp-extensions.js";
6
+ import { FilePath } from "../../types/file/filePath.js";
7
+ import { FileName } from "../../types/file/fileName.js";
8
+ import { FileService } from "../../infrastructure/file-service.js";
9
+ import { LauncherService } from "../../infrastructure/launcher-service.js";
10
+ import { err, ok } from "neverthrow";
11
+ export class CopilotAction {
12
+ constructor(configDir, commandMetadata, authKey = null) {
13
+ this.apiService = new ApiService();
14
+ this.fileService = new FileService();
15
+ this.launcherService = new LauncherService();
16
+ this.prompts = new PortalCopilotPrompts();
17
+ this.execute = async (buildDirectory, force, enable) => {
18
+ const buildContext = new BuildContext(buildDirectory);
19
+ if (!(await buildContext.validate())) {
20
+ this.prompts.srcDirectoryEmpty(buildDirectory);
21
+ return ActionResult.failed();
22
+ }
23
+ const buildJson = await buildContext.getBuildFileContents();
24
+ if (!force && buildJson.apiCopilotConfig != null && !(await this.prompts.confirmOverwrite())) {
25
+ this.prompts.cancelled();
26
+ return ActionResult.cancelled();
27
+ }
28
+ const response = await this.prompts.spinnerAccountInfo(this.apiService.getAccountInfo(this.configDir, this.commandMetadata.shell, this.authKey));
29
+ if (response.isErr()) {
30
+ this.prompts.serviceError(response.error);
31
+ return ActionResult.failed();
32
+ }
33
+ const apiCopilotKeyResult = await this.selectCopilotKey(response.value, force);
34
+ if (apiCopilotKeyResult.isErr()) {
35
+ if (apiCopilotKeyResult.error === "cancelled")
36
+ return ActionResult.cancelled();
37
+ return ActionResult.failed();
38
+ }
39
+ const welcomeMessage = await this.prepareWelcomeMessage();
40
+ buildJson.apiCopilotConfig = {
41
+ isEnabled: enable,
42
+ key: apiCopilotKeyResult.value,
43
+ welcomeMessage: welcomeMessage
44
+ };
45
+ await buildContext.updateBuildFileContents(buildJson);
46
+ this.prompts.copilotConfigured(enable, apiCopilotKeyResult.value);
47
+ return ActionResult.success();
48
+ };
49
+ this.configDir = configDir;
50
+ this.commandMetadata = commandMetadata;
51
+ this.authKey = authKey;
52
+ }
53
+ async selectCopilotKey(subscription, force) {
54
+ if (subscription.ApiCopilotKeys === undefined || subscription.ApiCopilotKeys.length === 0) {
55
+ this.prompts.noCopilotKeyFound();
56
+ return err("failed");
57
+ }
58
+ if (subscription.ApiCopilotKeys.length === 1) {
59
+ if (force || (await this.prompts.confirmSingleKeyUsage(subscription.ApiCopilotKeys[0])))
60
+ return ok(subscription.ApiCopilotKeys[0]);
61
+ this.prompts.noCopilotKeySelected();
62
+ return err("cancelled");
63
+ }
64
+ const key = await this.prompts.selectCopilotKey(subscription.ApiCopilotKeys);
65
+ if (key === null) {
66
+ this.prompts.noCopilotKeySelected();
67
+ return err("cancelled");
68
+ }
69
+ await this.prompts.displayApiCopilotKeyUsageWarning();
70
+ return ok(key);
71
+ }
72
+ async prepareWelcomeMessage() {
73
+ return await withDirPath(async (tempDir) => {
74
+ const tempFile = new FilePath(tempDir, new FileName("welcome-message.md"));
75
+ const defaultContent = "Hi there! I'm your API Integration Assistant, here to help you learn and integrate with this API.\n" +
76
+ "\n" +
77
+ "Ask me anything about this API or try one of these example prompts:\n" +
78
+ "\n" +
79
+ "`- What authentication methods does this API support?`\n" +
80
+ "`- [Enter another prompt here]`";
81
+ await this.fileService.writeContents(tempFile, defaultContent);
82
+ this.prompts.openWelcomeMessageEditor();
83
+ await this.launcherService.openInEditor(tempFile);
84
+ const welcomeMessage = await this.fileService.getContents(tempFile);
85
+ return welcomeMessage.replace(/\r\n|\r/g, "\n");
86
+ });
87
+ }
88
+ }
89
+ //# sourceMappingURL=copilot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilot.js","sourceRoot":"","sources":["../../../src/actions/portal/copilot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAE3E,OAAO,EAAE,GAAG,EAAE,EAAE,EAAU,MAAM,YAAY,CAAC;AAK7C,MAAM,OAAO,aAAa;IASxB,YAAY,SAAwB,EAAE,eAAgC,EAAE,UAAyB,IAAI;QARpF,eAAU,GAAG,IAAI,UAAU,EAAE,CAAC;QAC9B,gBAAW,GAAG,IAAI,WAAW,EAAE,CAAC;QAChC,oBAAe,GAAG,IAAI,eAAe,EAAE,CAAC;QACxC,YAAO,GAAG,IAAI,oBAAoB,EAAE,CAAC;QAWtC,YAAO,GAAG,KAAK,EAC7B,cAA6B,EAC7B,KAAc,EACd,MAAe,EACQ,EAAE;YACzB,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,cAAc,CAAC,CAAC;YAEtD,IAAI,CAAC,CAAC,MAAM,YAAY,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC;gBACrC,IAAI,CAAC,OAAO,CAAC,iBAAiB,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,CAAC,WAAW,CAAC,CAAC;QAC1B,CAAC;QACD,MAAM,IAAI,CAAC,OAAO,CAAC,gCAAgC,EAAE,CAAC;QACtD,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC;IAEO,KAAK,CAAC,qBAAqB;QACjC,OAAO,MAAM,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;YACzC,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,OAAO,EAAE,IAAI,QAAQ,CAAC,oBAAoB,CAAC,CAAC,CAAC;YAC3E,MAAM,cAAc,GAClB,qGAAqG;gBACrG,IAAI;gBACJ,uEAAuE;gBACvE,IAAI;gBACJ,0DAA0D;gBAC1D,iCAAiC,CAAC;YACpC,MAAM,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;YAC/D,IAAI,CAAC,OAAO,CAAC,wBAAwB,EAAE,CAAC;YACxC,MAAM,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;YAClD,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;YACpE,OAAO,cAAc,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -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
+ export declare class GenerateAction {
5
+ private readonly prompts;
6
+ private readonly launcherService;
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: (buildDirectory: DirectoryPath, portalDirectory: DirectoryPath, force: boolean, zipPortal: boolean, displayMessages?: boolean) => Promise<ActionResult>;
13
+ }
@@ -0,0 +1,59 @@
1
+ import { PortalGeneratePrompts } from "../../prompts/portal/generate.js";
2
+ import { PortalService } from "../../infrastructure/services/portal-service.js";
3
+ import { ActionResult } from "../action-result.js";
4
+ import { BuildContext } from "../../types/build-context.js";
5
+ import { PortalContext } from "../../types/portal-context.js";
6
+ import { withDirPath } from "../../infrastructure/tmp-extensions.js";
7
+ import { LauncherService } from "../../infrastructure/launcher-service.js";
8
+ import { TempContext } from "../../types/temp-context.js";
9
+ export class GenerateAction {
10
+ constructor(configDir, commandMetadata, authKey = null) {
11
+ this.prompts = new PortalGeneratePrompts();
12
+ this.launcherService = new LauncherService();
13
+ this.portalService = new PortalService();
14
+ this.execute = async (buildDirectory, portalDirectory, force, zipPortal, displayMessages = true) => {
15
+ if (buildDirectory.isEqual(portalDirectory)) {
16
+ this.prompts.directoryCannotBeSame(portalDirectory);
17
+ return ActionResult.failed();
18
+ }
19
+ const buildContext = new BuildContext(buildDirectory);
20
+ if (!(await buildContext.validate())) {
21
+ this.prompts.srcDirectoryEmpty(buildDirectory);
22
+ return ActionResult.failed();
23
+ }
24
+ const portalContext = new PortalContext(portalDirectory);
25
+ if (!force && (await portalContext.exists()) && !(await this.prompts.overwritePortal(portalDirectory))) {
26
+ this.prompts.portalDirectoryNotEmpty();
27
+ return ActionResult.cancelled();
28
+ }
29
+ return await withDirPath(async (tempDirectory) => {
30
+ const tempContext = new TempContext(tempDirectory);
31
+ const buildZipPath = await tempContext.zip(buildDirectory);
32
+ const response = await this.prompts.generatePortal(this.portalService.generatePortal(buildZipPath, this.configDir, this.commandMetadata, this.authKey));
33
+ if (response.isErr()) {
34
+ const error = response.error;
35
+ if (typeof error === "string") {
36
+ this.prompts.portalGenerationError(error);
37
+ }
38
+ else {
39
+ const errorZipPath = await tempContext.save(error);
40
+ const reportPath = await portalContext.saveError(errorZipPath);
41
+ await this.launcherService.openFile(reportPath);
42
+ this.prompts.portalGenerationErrorWithReport(reportPath);
43
+ }
44
+ return ActionResult.failed();
45
+ }
46
+ const tempPortalZipPath = await tempContext.save(response.value);
47
+ await portalContext.save(tempPortalZipPath, zipPortal);
48
+ if (displayMessages) {
49
+ this.prompts.portalGenerated(portalDirectory);
50
+ }
51
+ return ActionResult.success();
52
+ });
53
+ };
54
+ this.configDir = configDir;
55
+ this.commandMetadata = commandMetadata;
56
+ this.authKey = authKey;
57
+ }
58
+ }
59
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/actions/portal/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,iDAAiD,CAAC;AAEhF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAG1D,MAAM,OAAO,cAAc;IAQzB,YAAY,SAAwB,EAAE,eAAgC,EAAE,UAAyB,IAAI;QAPpF,YAAO,GAA0B,IAAI,qBAAqB,EAAE,CAAC;QAC7D,oBAAe,GAAoB,IAAI,eAAe,EAAE,CAAC;QACzD,kBAAa,GAAkB,IAAI,aAAa,EAAE,CAAC;QAWpD,YAAO,GAAG,KAAK,EAC7B,cAA6B,EAC7B,eAA8B,EAC9B,KAAc,EACd,SAAkB,EAClB,kBAA2B,IAAI,EACR,EAAE;YACzB,IAAI,cAAc,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC;gBAC5C,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,eAAe,CAAC,CAAC;gBACpD,OA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CAAC,CAAC;oBAC5C,CAAC;yBAAM,CAAC;wBACN,MAAM,YAAY,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;wBACnD,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;wBAC/D,MAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;wBAChD,IAAI,CAAC,OAAO,CAAC,+BAA+B,CAAC,UAAU,CAAC,CAAC;oBAC3D,CAAC;oBACD,OAAO,YAAY,CAAC,MAAM,EAAE,CAAC;gBAC/B,CAAC;gBAED,MAAM,iBAAiB,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;gBACjE,MAAM,aAAa,CAAC,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,CAAC;gBAEvD,IAAI,eAAe,EAAE,CAAC;oBACpB,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;gBAChD,CAAC;gBAED,OAAO,YAAY,CAAC,OAAO,EAAE,CAAC;YAChC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QA3DA,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CAyDF"}
@@ -0,0 +1,16 @@
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
+ export declare class PortalQuickstartAction {
5
+ private readonly prompts;
6
+ private readonly zipService;
7
+ private readonly fileService;
8
+ private readonly configDir;
9
+ private readonly commandMetadata;
10
+ private readonly fileDownloadService;
11
+ private readonly buildFileUrl;
12
+ private readonly defaultSpecUrl;
13
+ private readonly repositoryFolderName;
14
+ constructor(configDir: DirectoryPath, commandMetadata: CommandMetadata);
15
+ readonly execute: () => Promise<ActionResult>;
16
+ }
@@ -0,0 +1,145 @@
1
+ import { getAuthInfo } from "../../client-utils/auth-manager.js";
2
+ import { FileService } from "../../infrastructure/file-service.js";
3
+ import { withDirPath } from "../../infrastructure/tmp-extensions.js";
4
+ import { ZipService } from "../../infrastructure/zip-service.js";
5
+ import { PortalQuickstartPrompts } from "../../prompts/portal/quickstart.js";
6
+ import { UrlPath } from "../../types/file/urlPath.js";
7
+ import { LoginAction } from "../auth/login.js";
8
+ import { ActionResult } from "../action-result.js";
9
+ import { PortalServeAction } from "./serve.js";
10
+ import { ValidateAction } from "../api/validate.js";
11
+ import { BuildContext } from "../../types/build-context.js";
12
+ import { TempContext } from "../../types/temp-context.js";
13
+ import { FileDownloadService } from "../../infrastructure/services/file-download-service.js";
14
+ import { getLanguagesConfig } from "../../types/build/build.js";
15
+ import { SpecContext } from "../../types/spec-context.js";
16
+ const defaultPort = 3000;
17
+ export class PortalQuickstartAction {
18
+ constructor(configDir, commandMetadata) {
19
+ this.prompts = new PortalQuickstartPrompts();
20
+ this.zipService = new ZipService();
21
+ this.fileService = new FileService();
22
+ this.fileDownloadService = new FileDownloadService();
23
+ this.buildFileUrl = new UrlPath(`https://github.com/apimatic/static-portal-workflow/archive/refs/heads/master.zip`);
24
+ this.defaultSpecUrl = new UrlPath(`https://raw.githubusercontent.com/apimatic/static-portal-workflow/refs/heads/master/spec/openapi.json`);
25
+ this.repositoryFolderName = "static-portal-workflow-master";
26
+ this.execute = async () => {
27
+ this.prompts.welcomeMessage();
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(this.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(this.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.selectLanguagesStep();
86
+ const languages = await this.prompts.selectLanguagesPrompt();
87
+ if (!languages) {
88
+ this.prompts.noLanguagesSelected();
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
+ const masterBuildFile = await this.prompts.downloadBuildDirectory(this.fileDownloadService.downloadFile(this.buildFileUrl));
112
+ if (masterBuildFile.isErr()) {
113
+ this.prompts.serviceError(masterBuildFile.error);
114
+ return ActionResult.failed();
115
+ }
116
+ const tempContext = new TempContext(tempDirectory);
117
+ const masterBuildFilePath = await tempContext.save(masterBuildFile.value.stream);
118
+ await this.zipService.unArchive(masterBuildFilePath, tempDirectory);
119
+ const extractedFolder = tempDirectory.join(this.repositoryFolderName);
120
+ const tempBuildContext = new BuildContext(extractedFolder);
121
+ await tempBuildContext.replaceDefaultSpec(specPath);
122
+ await tempBuildContext.deleteWorkflowDir();
123
+ const buildFile = await tempBuildContext.getBuildFileContents();
124
+ buildFile.generatePortal.languageConfig = getLanguagesConfig(languages);
125
+ await tempBuildContext.updateBuildFileContents(buildFile);
126
+ const sourceDirectory = inputDirectory.join("src");
127
+ await this.fileService.copyDirectoryContents(extractedFolder, sourceDirectory);
128
+ const buildDirectoryStructure = await this.fileService.getDirectory(sourceDirectory);
129
+ this.prompts.printDirectoryStructure(inputDirectory, buildDirectoryStructure);
130
+ const portalDirectory = inputDirectory.join("portal");
131
+ const portalServeAction = new PortalServeAction(this.configDir, this.commandMetadata, null);
132
+ const result = await portalServeAction.execute(sourceDirectory, portalDirectory, defaultPort, true, false, () => {
133
+ this.prompts.nextSteps();
134
+ });
135
+ if (result.isFailed()) {
136
+ return ActionResult.failed();
137
+ }
138
+ return ActionResult.success();
139
+ });
140
+ };
141
+ this.configDir = configDir;
142
+ this.commandMetadata = commandMetadata;
143
+ }
144
+ }
145
+ //# sourceMappingURL=quickstart.js.map