@apimatic/cli 1.1.0-alpha.2 → 1.1.0-alpha.20

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 (251) hide show
  1. package/README.md +249 -99
  2. package/bin/run.js +5 -0
  3. package/lib/actions/action-result.d.ts +8 -0
  4. package/lib/actions/action-result.js +25 -0
  5. package/lib/actions/action-result.js.map +1 -0
  6. package/lib/actions/auth/login.d.ts +12 -0
  7. package/lib/actions/auth/login.js +63 -0
  8. package/lib/actions/auth/login.js.map +1 -0
  9. package/lib/actions/portal/copilot.d.ts +11 -0
  10. package/lib/actions/portal/copilot.js +49 -0
  11. package/lib/actions/portal/copilot.js.map +1 -0
  12. package/lib/actions/portal/generate.d.ts +13 -0
  13. package/lib/actions/portal/generate.js +61 -0
  14. package/lib/actions/portal/generate.js.map +1 -0
  15. package/lib/actions/portal/recipe/new-recipe.d.ts +24 -0
  16. package/lib/actions/portal/recipe/new-recipe.js +250 -0
  17. package/lib/actions/portal/recipe/new-recipe.js.map +1 -0
  18. package/lib/actions/portal/serve.d.ts +14 -0
  19. package/lib/actions/portal/serve.js +24 -0
  20. package/lib/actions/portal/serve.js.map +1 -0
  21. package/lib/actions/portal/toc/new-toc.d.ts +20 -0
  22. package/lib/actions/portal/toc/new-toc.js +133 -0
  23. package/lib/actions/portal/toc/new-toc.js.map +1 -0
  24. package/lib/actions/sdk/generate.d.ts +14 -0
  25. package/lib/actions/sdk/generate.js +72 -0
  26. package/lib/actions/sdk/generate.js.map +1 -0
  27. package/lib/application/portal/recipe/portal-recipe.d.ts +8 -0
  28. package/lib/application/portal/recipe/portal-recipe.js +33 -0
  29. package/lib/application/portal/recipe/portal-recipe.js.map +1 -0
  30. package/lib/application/portal/recipe/recipe-generator.d.ts +16 -0
  31. package/lib/application/portal/recipe/recipe-generator.js +147 -0
  32. package/lib/application/portal/recipe/recipe-generator.js.map +1 -0
  33. package/lib/application/portal/serve/portal-watcher.d.ts +11 -0
  34. package/lib/application/portal/serve/portal-watcher.js +64 -0
  35. package/lib/application/portal/serve/portal-watcher.js.map +1 -0
  36. package/lib/application/portal/serve/serve-handler.d.ts +16 -0
  37. package/lib/application/portal/serve/serve-handler.js +91 -0
  38. package/lib/application/portal/serve/serve-handler.js.map +1 -0
  39. package/lib/application/portal/serve/watcher-handler.d.ts +10 -0
  40. package/lib/application/portal/serve/watcher-handler.js +51 -0
  41. package/lib/application/portal/serve/watcher-handler.js.map +1 -0
  42. package/lib/application/portal/toc/sdl-parser.d.ts +19 -0
  43. package/lib/application/portal/toc/sdl-parser.js +90 -0
  44. package/lib/application/portal/toc/sdl-parser.js.map +1 -0
  45. package/lib/application/portal/toc/toc-content-parser.d.ts +5 -0
  46. package/lib/application/portal/toc/toc-content-parser.js +44 -0
  47. package/lib/application/portal/toc/toc-content-parser.js.map +1 -0
  48. package/lib/application/portal/toc/toc-structure-generator.d.ts +6 -0
  49. package/lib/application/portal/toc/toc-structure-generator.js +84 -0
  50. package/lib/application/portal/toc/toc-structure-generator.js.map +1 -0
  51. package/lib/client-utils/auth-manager.d.ts +8 -3
  52. package/lib/client-utils/auth-manager.js +23 -10
  53. package/lib/client-utils/auth-manager.js.map +1 -0
  54. package/lib/client-utils/sdk-client.d.ts +0 -1
  55. package/lib/client-utils/sdk-client.js +25 -55
  56. package/lib/client-utils/sdk-client.js.map +1 -0
  57. package/lib/commands/api/transform.d.ts +7 -7
  58. package/lib/commands/api/transform.js +43 -51
  59. package/lib/commands/api/transform.js.map +1 -0
  60. package/lib/commands/api/validate.d.ts +4 -4
  61. package/lib/commands/api/validate.js +26 -33
  62. package/lib/commands/api/validate.js.map +1 -0
  63. package/lib/commands/auth/login.d.ts +3 -2
  64. package/lib/commands/auth/login.js +22 -53
  65. package/lib/commands/auth/login.js.map +1 -0
  66. package/lib/commands/auth/logout.d.ts +1 -1
  67. package/lib/commands/auth/logout.js +8 -13
  68. package/lib/commands/auth/logout.js.map +1 -0
  69. package/lib/commands/auth/status.d.ts +1 -1
  70. package/lib/commands/auth/status.js +9 -13
  71. package/lib/commands/auth/status.js.map +1 -0
  72. package/lib/commands/portal/copilot.d.ts +12 -0
  73. package/lib/commands/portal/copilot.js +32 -0
  74. package/lib/commands/portal/copilot.js.map +1 -0
  75. package/lib/commands/portal/generate.d.ts +10 -8
  76. package/lib/commands/portal/generate.js +28 -107
  77. package/lib/commands/portal/generate.js.map +1 -0
  78. package/lib/commands/portal/quickstart.d.ts +10 -0
  79. package/lib/commands/portal/quickstart.js +105 -0
  80. package/lib/commands/portal/quickstart.js.map +1 -0
  81. package/lib/commands/portal/recipe/new.d.ts +10 -0
  82. package/lib/commands/portal/recipe/new.js +38 -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 +80 -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 +52 -0
  89. package/lib/commands/portal/toc/new.js.map +1 -0
  90. package/lib/commands/sdk/generate.d.ts +9 -8
  91. package/lib/commands/sdk/generate.js +39 -128
  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/config/env.d.ts +26 -1
  97. package/lib/config/env.js +27 -4
  98. package/lib/config/env.js.map +1 -0
  99. package/lib/controllers/api/transform.d.ts +1 -1
  100. package/lib/controllers/api/transform.js +23 -22
  101. package/lib/controllers/api/transform.js.map +1 -0
  102. package/lib/controllers/api/validate.d.ts +3 -3
  103. package/lib/controllers/api/validate.js +19 -12
  104. package/lib/controllers/api/validate.js.map +1 -0
  105. package/lib/controllers/portal/quickstart.d.ts +15 -0
  106. package/lib/controllers/portal/quickstart.js +217 -0
  107. package/lib/controllers/portal/quickstart.js.map +1 -0
  108. package/lib/index.d.ts +1 -1
  109. package/lib/index.js +2 -4
  110. package/lib/index.js.map +1 -0
  111. package/lib/infrastructure/api-utils.d.ts +9 -0
  112. package/lib/infrastructure/api-utils.js +33 -0
  113. package/lib/infrastructure/api-utils.js.map +1 -0
  114. package/lib/infrastructure/env-info.d.ts +8 -0
  115. package/lib/infrastructure/env-info.js +37 -0
  116. package/lib/infrastructure/env-info.js.map +1 -0
  117. package/lib/infrastructure/file-service.d.ts +18 -0
  118. package/lib/infrastructure/file-service.js +76 -0
  119. package/lib/infrastructure/file-service.js.map +1 -0
  120. package/lib/infrastructure/services/api-service.d.ts +10 -0
  121. package/lib/infrastructure/services/api-service.js +54 -0
  122. package/lib/infrastructure/services/api-service.js.map +1 -0
  123. package/lib/infrastructure/services/auth-service.d.ts +11 -0
  124. package/lib/infrastructure/services/auth-service.js +33 -0
  125. package/lib/infrastructure/services/auth-service.js.map +1 -0
  126. package/lib/infrastructure/services/portal-service.d.ts +20 -0
  127. package/lib/infrastructure/services/portal-service.js +163 -0
  128. package/lib/infrastructure/services/portal-service.js.map +1 -0
  129. package/lib/infrastructure/services/telemetry-service.d.ts +8 -0
  130. package/lib/infrastructure/services/telemetry-service.js +40 -0
  131. package/lib/infrastructure/services/telemetry-service.js.map +1 -0
  132. package/lib/infrastructure/tmp-extensions.d.ts +2 -0
  133. package/lib/infrastructure/tmp-extensions.js +6 -0
  134. package/lib/infrastructure/tmp-extensions.js.map +1 -0
  135. package/lib/infrastructure/zip-service.d.ts +6 -0
  136. package/lib/infrastructure/zip-service.js +39 -0
  137. package/lib/infrastructure/zip-service.js.map +1 -0
  138. package/lib/prompts/auth/login.d.ts +5 -0
  139. package/lib/prompts/auth/login.js +13 -0
  140. package/lib/prompts/auth/login.js.map +1 -0
  141. package/lib/prompts/portal/common/base-prompts.d.ts +7 -0
  142. package/lib/prompts/portal/common/base-prompts.js +19 -0
  143. package/lib/prompts/portal/common/base-prompts.js.map +1 -0
  144. package/lib/prompts/portal/copilot.d.ts +8 -0
  145. package/lib/prompts/portal/copilot.js +54 -0
  146. package/lib/prompts/portal/copilot.js.map +1 -0
  147. package/lib/prompts/portal/generate.d.ts +11 -0
  148. package/lib/prompts/portal/generate.js +42 -0
  149. package/lib/prompts/portal/generate.js.map +1 -0
  150. package/lib/prompts/portal/quickstart.d.ts +30 -0
  151. package/lib/prompts/portal/quickstart.js +240 -0
  152. package/lib/prompts/portal/quickstart.js.map +1 -0
  153. package/lib/prompts/portal/recipe/new-recipe.d.ts +24 -0
  154. package/lib/prompts/portal/recipe/new-recipe.js +203 -0
  155. package/lib/prompts/portal/recipe/new-recipe.js.map +1 -0
  156. package/lib/prompts/portal/serve.d.ts +4 -0
  157. package/lib/prompts/portal/serve.js +14 -0
  158. package/lib/prompts/portal/serve.js.map +1 -0
  159. package/lib/prompts/portal/toc/new-toc.d.ts +11 -0
  160. package/lib/prompts/portal/toc/new-toc.js +39 -0
  161. package/lib/prompts/portal/toc/new-toc.js.map +1 -0
  162. package/lib/prompts/sdk/generate.d.ts +11 -0
  163. package/lib/prompts/sdk/generate.js +42 -0
  164. package/lib/prompts/sdk/generate.js.map +1 -0
  165. package/lib/types/api/account.d.ts +10 -0
  166. package/lib/types/api/account.js +2 -0
  167. package/lib/types/api/account.js.map +1 -0
  168. package/lib/types/api/transform.d.ts +19 -4
  169. package/lib/types/api/transform.js +19 -4
  170. package/lib/types/api/transform.js.map +1 -0
  171. package/lib/types/api/validate.d.ts +3 -3
  172. package/lib/types/api/validate.js +2 -2
  173. package/lib/types/api/validate.js.map +1 -0
  174. package/lib/types/build/build.d.ts +14 -0
  175. package/lib/types/build/build.js +4 -0
  176. package/lib/types/build/build.js.map +1 -0
  177. package/lib/types/build-context.d.ts +13 -0
  178. package/lib/types/build-context.js +30 -0
  179. package/lib/types/build-context.js.map +1 -0
  180. package/lib/types/common/result.d.ts +17 -0
  181. package/lib/types/common/result.js +32 -0
  182. package/lib/types/common/result.js.map +1 -0
  183. package/lib/types/events/domain-event.d.ts +8 -0
  184. package/lib/types/events/domain-event.js +11 -0
  185. package/lib/types/events/domain-event.js.map +1 -0
  186. package/lib/types/events/recipe-creation-failed.d.ts +5 -0
  187. package/lib/types/events/recipe-creation-failed.js +8 -0
  188. package/lib/types/events/recipe-creation-failed.js.map +1 -0
  189. package/lib/types/events/toc-creation-failed.d.ts +5 -0
  190. package/lib/types/events/toc-creation-failed.js +8 -0
  191. package/lib/types/events/toc-creation-failed.js.map +1 -0
  192. package/lib/types/file/directoryPath.d.ts +7 -0
  193. package/lib/types/file/directoryPath.js +16 -0
  194. package/lib/types/file/directoryPath.js.map +1 -0
  195. package/lib/types/file/fileName.d.ts +5 -0
  196. package/lib/types/file/fileName.js +9 -0
  197. package/lib/types/file/fileName.js.map +1 -0
  198. package/lib/types/file/filePath.d.ts +8 -0
  199. package/lib/types/file/filePath.js +11 -0
  200. package/lib/types/file/filePath.js.map +1 -0
  201. package/lib/types/flags-provider.d.ts +15 -0
  202. package/lib/types/flags-provider.js +34 -0
  203. package/lib/types/flags-provider.js.map +1 -0
  204. package/lib/types/portal/generate.d.ts +13 -9
  205. package/lib/types/portal/generate.js +3 -2
  206. package/lib/types/portal/generate.js.map +1 -0
  207. package/lib/types/portal/quickstart.d.ts +17 -0
  208. package/lib/types/portal/quickstart.js +2 -0
  209. package/lib/types/portal/quickstart.js.map +1 -0
  210. package/lib/types/portal/serve.d.ts +12 -0
  211. package/lib/types/portal/serve.js +2 -0
  212. package/lib/types/portal/serve.js.map +1 -0
  213. package/lib/types/portal-context.d.ts +11 -0
  214. package/lib/types/portal-context.js +28 -0
  215. package/lib/types/portal-context.js.map +1 -0
  216. package/lib/types/recipe/recipe.d.ts +37 -0
  217. package/lib/types/recipe/recipe.js +6 -0
  218. package/lib/types/recipe/recipe.js.map +1 -0
  219. package/lib/types/sdk/generate.d.ts +11 -10
  220. package/lib/types/sdk/generate.js +11 -12
  221. package/lib/types/sdk/generate.js.map +1 -0
  222. package/lib/types/sdk-context.d.ts +13 -0
  223. package/lib/types/sdk-context.js +28 -0
  224. package/lib/types/sdk-context.js.map +1 -0
  225. package/lib/types/sdl/sdl.d.ts +12 -0
  226. package/lib/types/sdl/sdl.js +2 -0
  227. package/lib/types/sdl/sdl.js.map +1 -0
  228. package/lib/types/spec-context.d.ts +7 -0
  229. package/lib/types/spec-context.js +12 -0
  230. package/lib/types/spec-context.js.map +1 -0
  231. package/lib/types/toc/toc.d.ts +31 -0
  232. package/lib/types/toc/toc.js +9 -0
  233. package/lib/types/toc/toc.js.map +1 -0
  234. package/lib/types/utils.d.ts +3 -3
  235. package/lib/types/utils.js +2 -2
  236. package/lib/types/utils.js.map +1 -0
  237. package/lib/utils/utils.d.ts +16 -7
  238. package/lib/utils/utils.js +142 -86
  239. package/lib/utils/utils.js.map +1 -0
  240. package/lib/validators/common/directoryValidator.d.ts +5 -0
  241. package/lib/validators/common/directoryValidator.js +22 -0
  242. package/lib/validators/common/directoryValidator.js.map +1 -0
  243. package/lib/validators/portal/serve-validator.d.ts +6 -0
  244. package/lib/validators/portal/serve-validator.js +15 -0
  245. package/lib/validators/portal/serve-validator.js.map +1 -0
  246. package/package.json +96 -40
  247. package/bin/run +0 -5
  248. package/lib/controllers/portal/generate.d.ts +0 -2
  249. package/lib/controllers/portal/generate.js +0 -49
  250. package/lib/controllers/sdk/generate.d.ts +0 -4
  251. package/lib/controllers/sdk/generate.js +0 -64
@@ -0,0 +1,90 @@
1
+ import { Result } from "../../../types/common/result.js";
2
+ import { DirectoryPath } from "../../../types/file/directoryPath.js";
3
+ import { withDirPath } from "../../../infrastructure/tmp-extensions.js";
4
+ import { FileName } from "../../../types/file/fileName.js";
5
+ import { ZipService } from "../../../infrastructure/zip-service.js";
6
+ import { FilePath } from "../../../types/file/filePath.js";
7
+ import { FileService } from "../../../infrastructure/file-service.js";
8
+ export class SdlParser {
9
+ constructor(portalService) {
10
+ this.portalService = portalService;
11
+ this.zipArchiver = new ZipService();
12
+ this.fileService = new FileService();
13
+ }
14
+ async getTocComponentsFromSdl(specFolderPath, configDir) {
15
+ const sdlResult = await this.generateSdlFromSpec(specFolderPath, configDir);
16
+ if (!sdlResult.isSuccess()) {
17
+ return Result.failure("Failed to extract endpoints/models from the specification. Please validate your spec using APIMatic's interactive VS Code Extension and then try again.");
18
+ }
19
+ const sdl = sdlResult.value;
20
+ const endpointGroups = this.extractEndpointGroupsForToc(sdl);
21
+ const models = this.extractModelsForToc(sdl);
22
+ return Result.success({ endpointGroups, models });
23
+ }
24
+ async getEndpointGroupsFromSdl(specFolderPath, configDir) {
25
+ const sdlResult = await this.generateSdlFromSpec(specFolderPath, configDir);
26
+ if (!sdlResult.isSuccess()) {
27
+ return Result.failure("Failed to extract endpoints from the API specification. Please validate your spec using APIMatic's interactive VS Code Extension and then try again.");
28
+ }
29
+ const sdl = sdlResult.value;
30
+ const endpointGroups = this.extractEndpointGroupsForRecipe(sdl);
31
+ return Result.success(endpointGroups);
32
+ }
33
+ async generateSdlFromSpec(specFolderPath, configDir) {
34
+ return await withDirPath(async (tempDirectory) => {
35
+ const specZipPath = new FilePath(tempDirectory, new FileName("spec.zip"));
36
+ await this.zipArchiver.archive(new DirectoryPath(specFolderPath), specZipPath);
37
+ const specFileStream = await this.fileService.getStream(specZipPath);
38
+ let result;
39
+ try {
40
+ result = await this.portalService.generateSdl(specFileStream, configDir);
41
+ }
42
+ finally {
43
+ specFileStream.close();
44
+ }
45
+ if (!result.isSuccess()) {
46
+ return Result.failure("Failed to generate SDL from the API specification. Please validate your spec using APIMatic's interactive VS Code Extension.");
47
+ }
48
+ return Result.success(result.value);
49
+ });
50
+ }
51
+ extractEndpointGroupsForRecipe(sdl) {
52
+ const endpointGroups = new Map();
53
+ for (const endpoint of sdl.Endpoints) {
54
+ if (!endpointGroups.has(endpoint.Group)) {
55
+ endpointGroups.set(endpoint.Group, []);
56
+ }
57
+ endpointGroups.get(endpoint.Group).push({
58
+ Name: endpoint.Name,
59
+ Description: endpoint.Description,
60
+ Group: endpoint.Group
61
+ });
62
+ }
63
+ return endpointGroups;
64
+ }
65
+ extractEndpointGroupsForToc(sdl) {
66
+ const endpointGroups = new Map();
67
+ const endpoints = sdl.Endpoints.map((e) => ({
68
+ generate: null,
69
+ from: "endpoint",
70
+ endpointName: e.Name,
71
+ endpointGroup: e.Group
72
+ }));
73
+ endpoints.forEach((endpoint) => {
74
+ const group = endpoint.endpointGroup;
75
+ if (!endpointGroups.has(group)) {
76
+ endpointGroups.set(group, []);
77
+ }
78
+ endpointGroups.get(group).push(endpoint);
79
+ });
80
+ return endpointGroups;
81
+ }
82
+ extractModelsForToc(sdl) {
83
+ return sdl.CustomTypes.map((e) => ({
84
+ generate: null,
85
+ from: "model",
86
+ modelName: e.Name
87
+ }));
88
+ }
89
+ }
90
+ //# sourceMappingURL=sdl-parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdl-parser.js","sourceRoot":"","sources":["../../../../src/application/portal/toc/sdl-parser.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAEtE,MAAM,OAAO,SAAS;IAIpB,YAA6B,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;QAHxC,gBAAW,GAAe,IAAI,UAAU,EAAE,CAAC;QAC3C,gBAAW,GAAG,IAAI,WAAW,EAAE,CAAC;IAEW,CAAC;IAEtD,KAAK,CAAC,uBAAuB,CAClC,cAAsB,EACtB,SAAiB;QAEjB,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,cAAc,EAAE,SAAS,CAA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AAI,EAAE,UAAU;YAChB,YAAY,EAAE,CAAC,CAAC,IAAI;YACpB,aAAa,EAAE,CAAC,CAAC,KAAK;SACvB,CAAC,CACH,CAAC;QAEF,SAAS,CAAC,OAAO,CAAC,CAAC,QAAqB,EAAE,EAAE;YAC1C,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC;YACrC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC/B,cAAc,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YAChC,CAAC;YACD,cAAc,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;QAEH,OAAO,cAAc,CAAC;IACxB,CAAC;IAEO,mBAAmB,CAAC,GAAQ;QAClC,OAAO,GAAG,CAAC,WAAW,CAAC,GAAG,CACxB,CAAC,CAAW,EAAY,EAAE,CAAC,CAAC;YAC1B,QAAQ,EAAE,IAAI;YACd,IAAI,EAAE,OAAO;YACb,SAAS,EAAE,CAAC,CAAC,IAAI;SAClB,CAAC,CACH,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ import { TocGroup } from "../../../types/toc/toc.js";
2
+ export declare class TocContentParser {
3
+ parseContentFolder(contentFolderPath: string, workingDirectory: string): Promise<TocGroup[]>;
4
+ private normalizePath;
5
+ }
@@ -0,0 +1,44 @@
1
+ import * as path from "path";
2
+ import * as fs from "fs/promises";
3
+ export class TocContentParser {
4
+ async parseContentFolder(contentFolderPath, workingDirectory) {
5
+ const items = await fs.readdir(contentFolderPath);
6
+ const contentItems = [];
7
+ for (const item of items) {
8
+ const itemPath = path.join(contentFolderPath, item);
9
+ const stats = await fs.stat(itemPath);
10
+ if (stats.isDirectory()) {
11
+ const subItems = await this.parseContentFolder(itemPath, workingDirectory);
12
+ if (subItems.length > 0) {
13
+ contentItems.push({
14
+ group: item,
15
+ items: subItems[0].items // Take items from the Custom Content group
16
+ });
17
+ }
18
+ }
19
+ else if (stats.isFile() && item.endsWith(".md")) {
20
+ const relativePath = path.relative(workingDirectory, itemPath);
21
+ const pageName = path.basename(item, ".md");
22
+ contentItems.push({
23
+ page: pageName,
24
+ file: this.normalizePath(relativePath)
25
+ });
26
+ }
27
+ }
28
+ // Return empty array if no markdown files were found
29
+ if (contentItems.length === 0) {
30
+ return [];
31
+ }
32
+ // Wrap everything under a "Custom Content" group
33
+ return [
34
+ {
35
+ group: "Custom Content",
36
+ items: contentItems
37
+ }
38
+ ];
39
+ }
40
+ normalizePath(path) {
41
+ return path.replace(/\\/g, "/");
42
+ }
43
+ }
44
+ //# sourceMappingURL=toc-content-parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toc-content-parser.js","sourceRoot":"","sources":["../../../../src/application/portal/toc/toc-content-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAGlC,MAAM,OAAO,gBAAgB;IAC3B,KAAK,CAAC,kBAAkB,CAAC,iBAAyB,EAAE,gBAAwB;QAC1E,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAClD,MAAM,YAAY,GAAiC,EAAE,CAAC;QAEtD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;YACpD,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAEtC,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;gBACxB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;gBAC3E,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACxB,YAAY,CAAC,IAAI,CAAC;wBAChB,KAAK,EAAE,IAAI;wBACX,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,2CAA2C;qBACrE,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;iBAAM,IAAI,KAAK,CAAC,MAAM,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBAClD,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;gBAC/D,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;gBAE5C,YAAY,CAAC,IAAI,CAAC;oBAChB,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC;iBACvC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,qDAAqD;QACrD,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC9B,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,iDAAiD;QACjD,OAAO;YACL;gBACE,KAAK,EAAE,gBAAgB;gBACvB,KAAK,EAAE,YAAY;aACpB;SACF,CAAC;IACJ,CAAC;IAEO,aAAa,CAAC,IAAY;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAClC,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ import { Toc, TocGroup, TocEndpoint, TocModel } from "../../../types/toc/toc.js";
2
+ export declare class TocStructureGenerator {
3
+ createTocStructure(endpointGroups: Map<string, TocEndpoint[]>, models: TocModel[], expandEndpoints?: boolean, expandModels?: boolean, contentGroups?: TocGroup[]): Toc;
4
+ transformToYaml(toc: Toc): string;
5
+ private transformKeys;
6
+ }
@@ -0,0 +1,84 @@
1
+ import { stringify } from "yaml";
2
+ export class TocStructureGenerator {
3
+ createTocStructure(endpointGroups, models, expandEndpoints = false, expandModels = false, contentGroups = []) {
4
+ const tocStructure = {
5
+ toc: []
6
+ };
7
+ // Add Getting Started section
8
+ tocStructure.toc.push({
9
+ group: "Getting Started",
10
+ items: [
11
+ {
12
+ generate: "How to Get Started",
13
+ from: "getting-started"
14
+ }
15
+ ]
16
+ });
17
+ // Add content groups
18
+ if (contentGroups.length > 0) {
19
+ tocStructure.toc.push(...contentGroups);
20
+ }
21
+ // Add API Endpoints section
22
+ if (!expandEndpoints || endpointGroups.size === 0) {
23
+ tocStructure.toc.push({
24
+ generate: "API Endpoints",
25
+ from: "endpoints"
26
+ });
27
+ }
28
+ else {
29
+ tocStructure.toc.push({
30
+ group: "API Endpoints",
31
+ items: Array.from(endpointGroups).map(([groupName, endpoints]) => ({
32
+ group: groupName,
33
+ items: [
34
+ {
35
+ generate: null,
36
+ from: "endpoint-group-overview",
37
+ endpointGroup: groupName
38
+ },
39
+ ...endpoints
40
+ ]
41
+ }))
42
+ });
43
+ }
44
+ // Add Models section
45
+ if (!expandModels || models.length === 0) {
46
+ tocStructure.toc.push({
47
+ generate: "Models",
48
+ from: "models"
49
+ });
50
+ }
51
+ else {
52
+ tocStructure.toc.push({
53
+ group: "Models",
54
+ items: models
55
+ });
56
+ }
57
+ //Add Sdk Infra section
58
+ tocStructure.toc.push({
59
+ generate: "SDK Infrastructure",
60
+ from: "sdk-infra"
61
+ });
62
+ return tocStructure;
63
+ }
64
+ transformToYaml(toc) {
65
+ const transformedToc = this.transformKeys(toc);
66
+ return stringify(transformedToc, {
67
+ indent: 2,
68
+ nullStr: ""
69
+ });
70
+ }
71
+ transformKeys(obj) {
72
+ if (Array.isArray(obj)) {
73
+ return obj.map((item) => this.transformKeys(item));
74
+ }
75
+ if (obj !== null && typeof obj === "object") {
76
+ return Object.fromEntries(Object.entries(obj).map(([key, value]) => [
77
+ key.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(),
78
+ this.transformKeys(value)
79
+ ]));
80
+ }
81
+ return obj;
82
+ }
83
+ }
84
+ //# sourceMappingURL=toc-structure-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toc-structure-generator.js","sourceRoot":"","sources":["../../../../src/application/portal/toc/toc-structure-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAGjC,MAAM,OAAO,qBAAqB;IAChC,kBAAkB,CAChB,cAA0C,EAC1C,MAAkB,EAClB,kBAA2B,KAAK,EAChC,eAAwB,KAAK,EAC7B,gBAA4B,EAAE;QAE9B,MAAM,YAAY,GAAQ;YACxB,GAAG,EAAE,EAAE;SACR,CAAC;QAEF,8BAA8B;QAC9B,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC;YACpB,KAAK,EAAE,iBAAiB;YACxB,KAAK,EAAE;gBACL;oBACE,QAAQ,EAAE,oBAAoB;oBAC9B,IAAI,EAAE,iBAAiB;iBACxB;aACF;SACF,CAAC,CAAC;QAEH,qBAAqB;QACrB,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7B,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,CAAC;QAC1C,CAAC;QAED,4BAA4B;QAC5B,IAAI,CAAC,eAAe,IAAI,cAAc,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YAClD,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC;gBACpB,QAAQ,EAAE,eAAe;gBACzB,IAAI,EAAE,WAAW;aAClB,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC;gBACpB,KAAK,EAAE,eAAe;gBACtB,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC;oBACjE,KAAK,EAAE,SAAS;oBAChB,KAAK,EAAE;wBACL;4BACE,Q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C,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;gBACxC,GAAG,CAAC,OAAO,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC,WAAW,EAAE;gBACxD,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC;aAC1B,CAAC,CACH,CAAC;QACJ,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
@@ -1,6 +1,8 @@
1
- export declare type AuthInfo = {
1
+ import { DirectoryPath } from "../types/file/directoryPath.js";
2
+ export type AuthInfo = {
2
3
  email: string;
3
4
  authKey: string;
5
+ APIMATIC_CLI_TELEMETRY_OPTOUT?: string;
4
6
  };
5
7
  /**
6
8
  *
@@ -10,8 +12,11 @@ export declare type AuthInfo = {
10
12
  export declare function getAuthInfo(configDir: string): Promise<AuthInfo | null>;
11
13
  /**
12
14
  *
13
- * @param {AuthInfo} credentials
15
+ * @param {string} email
16
+ * @param {string} authKey
17
+ * @param {string} isTelemetryOptedOut
14
18
  * @param {string} configDir <- Directory with user configuration
15
19
  * //Function to set credentials.
16
20
  */
17
- export declare function setAuthInfo(credentials: AuthInfo, configDir: string): Promise<void>;
21
+ export declare function setAuthInfo(email: string, authKey: string, isTelemetryOptedOut: boolean, configDir: DirectoryPath): Promise<void>;
22
+ export declare function removeAuthInfo(configDir: string): Promise<void>;
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setAuthInfo = exports.getAuthInfo = void 0;
4
- const path = require("path");
5
- const fs = require("fs-extra");
1
+ import * as path from "path";
2
+ import fs from "fs-extra";
6
3
  /**
7
4
  *
8
5
  * @param {string} configDir <- Directory with user configuration
9
6
  * //Function to get credentials
10
7
  */
11
- async function getAuthInfo(configDir) {
8
+ export async function getAuthInfo(configDir) {
12
9
  try {
13
10
  const data = JSON.parse(await fs.readFile(path.join(configDir, "config.json"), "utf8"));
14
11
  return data;
@@ -17,17 +14,33 @@ async function getAuthInfo(configDir) {
17
14
  return null;
18
15
  }
19
16
  }
20
- exports.getAuthInfo = getAuthInfo;
21
17
  /**
22
18
  *
23
- * @param {AuthInfo} credentials
19
+ * @param {string} email
20
+ * @param {string} authKey
21
+ * @param {string} isTelemetryOptedOut
24
22
  * @param {string} configDir <- Directory with user configuration
25
23
  * //Function to set credentials.
26
24
  */
27
- async function setAuthInfo(credentials, configDir) {
25
+ export async function setAuthInfo(email, authKey, isTelemetryOptedOut, configDir) {
26
+ const credentials = {
27
+ email,
28
+ authKey,
29
+ APIMATIC_CLI_TELEMETRY_OPTOUT: isTelemetryOptedOut ? "1" : "0"
30
+ };
31
+ const configFilePath = path.join(configDir.toString(), "config.json");
32
+ if (!fs.existsSync(configFilePath))
33
+ fs.createFileSync(configFilePath);
34
+ return await fs.writeFile(configFilePath, JSON.stringify(credentials));
35
+ }
36
+ export async function removeAuthInfo(configDir) {
37
+ const credentials = {
38
+ email: "",
39
+ authKey: ""
40
+ };
28
41
  const configFilePath = path.join(configDir, "config.json");
29
42
  if (!fs.existsSync(configFilePath))
30
43
  fs.createFileSync(configFilePath);
31
44
  return await fs.writeFile(configFilePath, JSON.stringify(credentials));
32
45
  }
33
- exports.setAuthInfo = setAuthInfo;
46
+ //# sourceMappingURL=auth-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-manager.js","sourceRoot":"","sources":["../../src/client-utils/auth-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,MAAM,UAAU,CAAC;AAQ1B;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,SAAiB;IACjD,IAAI,CAAC;QACH,MAAM,IAAI,GAAoB,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;QACzG,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,KAAa,EACb,OAAe,EACf,mBAA4B,EAC5B,SAAwB;IAExB,MAAM,WAAW,GAAa;QAC5B,KAAK;QACL,OAAO;QACP,6BAA6B,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG;KAC/D,CAAC;IACF,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE,aAAa,CAAC,CAAC;IAEtE,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC;QAAE,EAAE,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;IAEtE,OAAO,MAAM,EAAE,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,SAAiB;IACpD,MAAM,WAAW,GAAa;QAC5B,KAAK,EAAE,EAAE;QACT,OAAO,EAAE,EAAE;KACZ,CAAC;IACF,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;IAE3D,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC;QAAE,EAAE,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;IAEtE,OAAO,MAAM,EAAE,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC;AACzE,CAAC"}
@@ -19,5 +19,4 @@ export declare class SDKClient {
19
19
  status(configDir: string): Promise<string>;
20
20
  getClient(overrideAuthKey: string | null, configDir: string): Promise<Client>;
21
21
  private getAuthKey;
22
- setAuthKey: (authKey: string, configDir: string) => string;
23
22
  }
@@ -1,21 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SDKClient = void 0;
4
- const base64 = require("base-64");
5
- const axios_1 = require("axios");
6
- const sdk_1 = require("@apimatic/sdk");
7
- const env_1 = require("../config/env");
8
- const auth_manager_1 = require("./auth-manager");
9
- class SDKClient {
10
- constructor() {
11
- this.setAuthKey = (authKey, configDir) => {
12
- auth_manager_1.setAuthInfo({
13
- email: "",
14
- authKey
15
- }, configDir);
16
- return "Authentication key successfully set";
17
- };
18
- }
1
+ import base64 from "base-64";
2
+ import axios from "axios";
3
+ import { Client } from "@apimatic/sdk";
4
+ import { baseURL } from "../config/env.js";
5
+ import { getAuthInfo, removeAuthInfo, setAuthInfo } from "./auth-manager.js";
6
+ import { DirectoryPath } from "../types/file/directoryPath.js";
7
+ export class SDKClient {
19
8
  /**
20
9
  * The static method that controls the access to the SDKClient instance.
21
10
  *
@@ -33,41 +22,19 @@ class SDKClient {
33
22
  * executed on its instance.
34
23
  */
35
24
  async login(email, password, configDir) {
36
- let storedAuthInfo = await auth_manager_1.getAuthInfo(configDir);
37
- // If no config file or no credentials exist in the config file
38
- if (!storedAuthInfo) {
39
- storedAuthInfo = { email: "", authKey: "" };
40
- }
41
25
  const credentials = { email, password };
42
26
  const authKey = await this.getAuthKey(credentials);
43
- if (storedAuthInfo.email !== email) {
44
- auth_manager_1.setAuthInfo({
45
- email,
46
- authKey
47
- }, configDir);
48
- return "Logged in";
49
- }
50
- else if (authKey === storedAuthInfo.authKey) {
51
- return "Already logged in";
52
- }
53
- else {
54
- auth_manager_1.setAuthInfo({
55
- email,
56
- authKey
57
- }, configDir);
58
- return "Logged in";
59
- }
27
+ const isTelemetryOptedOut = process.env.APIMATIC_CLI_TELEMETRY_OPTOUT === "1";
28
+ await setAuthInfo(email, authKey, isTelemetryOptedOut, new DirectoryPath(configDir));
29
+ return "Logged in successfully as " + email;
60
30
  }
61
31
  async logout(configDir) {
62
- auth_manager_1.setAuthInfo({
63
- email: "",
64
- authKey: ""
65
- }, configDir);
32
+ await removeAuthInfo(configDir);
66
33
  return "Logged out";
67
34
  }
68
35
  async status(configDir) {
69
36
  try {
70
- let storedAuthInfo = await auth_manager_1.getAuthInfo(configDir);
37
+ let storedAuthInfo = await getAuthInfo(configDir);
71
38
  if (!storedAuthInfo) {
72
39
  // If no config file or no credentials exist in the config file
73
40
  storedAuthInfo = { email: "", authKey: "" };
@@ -84,20 +51,24 @@ class SDKClient {
84
51
  }
85
52
  async getClient(overrideAuthKey, configDir) {
86
53
  if (overrideAuthKey) {
87
- return new sdk_1.Client({
54
+ return new Client({
88
55
  timeout: 0,
89
- authorization: `X-Auth-Key ${overrideAuthKey}`
56
+ customHeaderAuthenticationCredentials: {
57
+ Authorization: `X-Auth-Key ${overrideAuthKey}`
58
+ }
90
59
  });
91
60
  }
92
- let storedAuthInfo = await auth_manager_1.getAuthInfo(configDir);
61
+ let storedAuthInfo = await getAuthInfo(configDir);
93
62
  if (!storedAuthInfo) {
94
63
  // If no config file or no credentials exist in the config file
95
64
  storedAuthInfo = { email: "", authKey: "" };
96
65
  }
97
66
  if (storedAuthInfo.authKey !== "") {
98
- return new sdk_1.Client({
67
+ return new Client({
99
68
  timeout: 0,
100
- authorization: `X-Auth-Key ${storedAuthInfo.authKey}`
69
+ customHeaderAuthenticationCredentials: {
70
+ Authorization: `X-Auth-Key ${storedAuthInfo.authKey}`
71
+ }
101
72
  });
102
73
  }
103
74
  else {
@@ -110,10 +81,9 @@ class SDKClient {
110
81
  Authorization: `Basic ${base64.encode(`${credentials.email}:${credentials.password}`)}`
111
82
  }
112
83
  };
113
- const response = await axios_1.default.get(SDKClient.authAPI, config);
114
- const authKey = response.data.EncryptedValue;
115
- return authKey;
84
+ const response = await axios.get(SDKClient.authAPI, config);
85
+ return response.data.EncryptedValue;
116
86
  }
117
87
  }
118
- exports.SDKClient = SDKClient;
119
- SDKClient.authAPI = `${env_1.baseURL}/account/authkey`;
88
+ SDKClient.authAPI = `${baseURL}/account/authkey`;
89
+ //# sourceMappingURL=sdk-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk-client.js","sourceRoot":"","sources":["../../src/client-utils/sdk-client.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,SAAS,CAAC;AAC7B,OAAO,KAAwB,MAAM,OAAO,CAAC;AAE7C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAY,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAU/D,MAAM,OAAO,SAAS;IAKpB;;;;;OAKG;IACI,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;YACxB,SAAS,CAAC,QAAQ,GAAG,IAAI,SAAS,EAAE,CAAC;QACvC,CAAC;QAED,OAAO,SAAS,CAAC,QAAQ,CAAC;IAC5B,CAAC;IAED;;;OAGG;IAEI,KAAK,CAAC,KAAK,CAAC,KAAa,EAAE,QAAgB,EAAE,SAAiB;QACnE,MAAM,WAAW,GAAgB,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;QACrD,MAAM,OAAO,GAAW,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QAC3D,MAAM,mBAAmB,GAAG,OAAO,CAAC,GAAG,CAAC,6BAA6B,KAAK,GAAG,CAAC;QAE9E,MAAM,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,IAAI,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC;QAErF,OAAO,4BAA4B,GAAG,KAAK,CAAC;IAC9C,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,SAAiB;QACnC,MAAM,cAAc,CAAC,SAAS,CAAC,CAAC;QAChC,OAAO,YAAY,CAAC;IACtB,CAAC;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AAE;iBACtD;aACF,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,UAAU,CAAC,WAAwB;QAC/C,MAAM,MAAM,GAAG;YACb,OAAO,EAAE;gBACP,aAAa,EAAE,SAAS,MAAM,CAAC,MAAM,CAAC,GAAG,WAAW,CAAC,KAAK,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC,EAAE;aACxF;SACF,CAAC;QACF,MAAM,QAAQ,GAAkB,MAAM,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC3E,OAAO,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC;IACtC,CAAC;;AA1Fc,iBAAO,GAAG,GAAG,OAAO,kBAAkB,CAAC"}
@@ -1,14 +1,14 @@
1
- import { flags, Command } from "@oclif/command";
1
+ import { Command } from "@oclif/core";
2
2
  export default class Transform extends Command {
3
3
  static description: string;
4
4
  static examples: string[];
5
5
  static flags: {
6
- format: flags.IOptionFlag<string>;
7
- file: flags.IOptionFlag<string>;
8
- url: flags.IOptionFlag<string>;
9
- destination: flags.IOptionFlag<string>;
10
- force: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
11
- "auth-key": flags.IOptionFlag<string | undefined>;
6
+ "auth-key": import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
8
+ format: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
9
+ file: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
10
+ url: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
+ destination: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
12
12
  };
13
13
  run(): Promise<void>;
14
14
  }
@@ -1,44 +1,44 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const path = require("path");
4
- const fs = require("fs-extra");
5
- const command_1 = require("@oclif/command");
6
- const sdk_1 = require("@apimatic/sdk");
7
- const sdk_client_1 = require("../../client-utils/sdk-client");
8
- const utils_1 = require("../../utils/utils");
9
- const utils_2 = require("../../utils/utils");
10
- const transform_1 = require("../../types/api/transform");
11
- const transform_2 = require("../../controllers/api/transform");
12
- const formats = Object.keys(sdk_1.ExportFormats).join("|");
13
- class Transform extends command_1.Command {
1
+ var _a;
2
+ import * as path from "path";
3
+ import fsExtra from "fs-extra";
4
+ import { Flags, Command } from "@oclif/core";
5
+ import { TransformationController } from "@apimatic/sdk";
6
+ import { SDKClient } from "../../client-utils/sdk-client.js";
7
+ import { printValidationMessages } from "../../utils/utils.js";
8
+ import { getFileNameFromPath, replaceHTML } from "../../utils/utils.js";
9
+ import { DestinationFormats, TransformationFormats } from "../../types/api/transform.js";
10
+ import { getValidFormat, getTransformationId, downloadTransformationFile } from "../../controllers/api/transform.js";
11
+ import { FlagsProvider } from "../../types/flags-provider.js";
12
+ const formats = Object.keys(TransformationFormats).join("|");
13
+ class Transform extends Command {
14
14
  async run() {
15
- const { flags } = this.parse(Transform);
16
- const fileName = flags.file ? utils_2.getFileNameFromPath(flags.file) : utils_2.getFileNameFromPath(flags.url);
17
- const destinationFormat = transform_1.DestinationFormats[flags.format];
15
+ const { flags } = await this.parse(_a);
16
+ const fileName = flags.file ? getFileNameFromPath(flags.file) : getFileNameFromPath(flags.url);
17
+ const destinationFormat = DestinationFormats[flags.format];
18
18
  const destinationFilePath = path.join(flags.destination, `${fileName}_${flags.format}.${destinationFormat}`.toLowerCase());
19
19
  // Check if destination file already exist and throw error if force flag is not set
20
- if (fs.existsSync(destinationFilePath) && !flags.force) {
20
+ if (fsExtra.existsSync(destinationFilePath) && !flags.force) {
21
21
  throw new Error(`Can't download transformed file to path ${destinationFilePath}, because it already exists`);
22
22
  }
23
23
  try {
24
24
  // Check if paths provided are valid
25
- if (flags.file && !(await fs.pathExists(flags.file))) {
25
+ if (flags.file && !(await fsExtra.pathExists(flags.file))) {
26
26
  throw new Error(`Transformation file: ${flags.file} does not exist`);
27
27
  }
28
- else if (!(await fs.pathExists(flags.destination))) {
28
+ else if (!(await fsExtra.pathExists(flags.destination))) {
29
29
  throw new Error(`Destination path: ${flags.destination} does not exist`);
30
30
  }
31
31
  const overrideAuthKey = flags["auth-key"] ? flags["auth-key"] : null;
32
- const client = await sdk_client_1.SDKClient.getInstance().getClient(overrideAuthKey, this.config.configDir);
33
- const transformationController = new sdk_1.TransformationController(client);
34
- const { id, apiValidationSummary } = await transform_2.getTransformationId(flags, transformationController);
32
+ const client = await SDKClient.getInstance().getClient(overrideAuthKey, this.config.configDir);
33
+ const transformationController = new TransformationController(client);
34
+ const { id, apiValidationSummary } = await getTransformationId(flags, transformationController);
35
35
  const logFunctions = {
36
- log: this.log,
37
- warn: this.warn,
38
- error: this.error
36
+ log: (message) => this.log(message),
37
+ warn: (message) => this.warn(message),
38
+ error: (message) => this.error(message)
39
39
  };
40
- utils_1.printValidationMessages(apiValidationSummary, logFunctions);
41
- const savedTransformationFile = await transform_2.downloadTransformationFile({
40
+ printValidationMessages(apiValidationSummary, logFunctions);
41
+ const savedTransformationFile = await downloadTransformationFile({
42
42
  id,
43
43
  destinationFilePath,
44
44
  transformationController
@@ -52,7 +52,7 @@ class Transform extends command_1.Command {
52
52
  // updated to throw the right exception type for this status code.
53
53
  const result = apiError.result;
54
54
  if (apiError.statusCode === 422 && result && "errors" in result && Array.isArray(result.errors)) {
55
- this.error(utils_2.replaceHTML(`${result.errors}`));
55
+ this.error(replaceHTML(`${result.errors}`));
56
56
  }
57
57
  else if (apiError.statusCode === 422 && apiError.body && typeof apiError.body === "string") {
58
58
  this.error(JSON.parse(apiError.body)["dto.FileUrl"][0]);
@@ -78,37 +78,29 @@ class Transform extends command_1.Command {
78
78
  }
79
79
  }
80
80
  }
81
- exports.default = Transform;
81
+ _a = Transform;
82
82
  Transform.description = `Transform API specifications from one format to another. Supports [10+ different formats](https://www.apimatic.io/transformer/#supported-formats) including OpenApi/Swagger, RAML, WSDL and Postman Collections.`;
83
83
  Transform.examples = [
84
- `$ apimatic api:transform --format="OpenApi3Json" --file="./specs/sample.json" --destination="D:/"
85
- Success! Your transformed file is located at D:/Transformed_OpenApi3Json.json
86
- `,
87
- `$ apimatic api:transform --format=RAML --url="https://petstore.swagger.io/v2/swagger.json" --destination="D:/"
88
- Success! Your transformed file is located at D:/swagger_raml.yaml
89
- `
84
+ `apimatic api:transform --format="OpenApi3Json" --file="./specs/sample.json" --destination="D:/"`,
85
+ `apimatic api:transform --format=RAML --url="https://petstore.swagger.io/v2/swagger.json" --destination="D:/"`
90
86
  ];
91
- Transform.flags = {
92
- format: command_1.flags.string({
93
- parse: (format) => transform_2.getValidFormat(format.toUpperCase()),
87
+ Transform.flags = Object.assign(Object.assign({ format: Flags.string({
88
+ parse: async (format) => getValidFormat(format),
94
89
  required: true,
95
90
  description: `specification format to transform API specification into
96
91
  ${formats}`
97
- }),
98
- file: command_1.flags.string({
99
- parse: (input) => path.resolve(input),
92
+ }), file: Flags.string({
93
+ parse: async (input) => path.resolve(input),
100
94
  default: "",
101
95
  description: "path to the API specification file to transform"
102
- }),
103
- url: command_1.flags.string({
96
+ }), url: Flags.string({
104
97
  default: "",
105
98
  description: "URL to the API specification file to transform. Can be used in place of the --file option if the API specification is publicly available."
106
- }),
107
- destination: command_1.flags.string({
108
- parse: (input) => path.resolve(input),
99
+ }), destination: Flags.string({
100
+ parse: async (input) => path.resolve(input),
109
101
  default: path.resolve("./"),
110
- description: "directory to download transformed file to"
111
- }),
112
- force: command_1.flags.boolean({ char: "f", default: false, description: "overwrite if same file exist in the destination" }),
113
- "auth-key": command_1.flags.string({ description: "override current authentication state with an authentication key" })
114
- };
102
+ description: "directory to download transformed file to",
103
+ char: "d"
104
+ }) }, FlagsProvider.force), FlagsProvider.authKey);
105
+ export default Transform;
106
+ //# sourceMappingURL=transform.js.map