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

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 (269) hide show
  1. package/README.md +257 -101
  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 +14 -0
  10. package/lib/actions/portal/copilot.js +79 -0
  11. package/lib/actions/portal/copilot.js.map +1 -0
  12. package/lib/actions/portal/generate.d.ts +14 -0
  13. package/lib/actions/portal/generate.js +66 -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 +4 -9
  55. package/lib/client-utils/sdk-client.js +9 -87
  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 +46 -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 +35 -36
  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 +13 -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 +114 -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 +13 -0
  106. package/lib/controllers/portal/quickstart.js +214 -0
  107. package/lib/controllers/portal/quickstart.js.map +1 -0
  108. package/lib/hooks/not-found.d.ts +3 -0
  109. package/lib/hooks/not-found.js +52 -0
  110. package/lib/hooks/not-found.js.map +1 -0
  111. package/lib/hooks/utils.d.ts +5 -0
  112. package/lib/hooks/utils.js +51 -0
  113. package/lib/hooks/utils.js.map +1 -0
  114. package/lib/index.d.ts +1 -1
  115. package/lib/index.js +2 -4
  116. package/lib/index.js.map +1 -0
  117. package/lib/infrastructure/api-client-utils.d.ts +6 -0
  118. package/lib/infrastructure/api-client-utils.js +34 -0
  119. package/lib/infrastructure/api-client-utils.js.map +1 -0
  120. package/lib/infrastructure/api-utils.d.ts +9 -0
  121. package/lib/infrastructure/api-utils.js +33 -0
  122. package/lib/infrastructure/api-utils.js.map +1 -0
  123. package/lib/infrastructure/env-info.d.ts +12 -0
  124. package/lib/infrastructure/env-info.js +58 -0
  125. package/lib/infrastructure/env-info.js.map +1 -0
  126. package/lib/infrastructure/file-service.d.ts +18 -0
  127. package/lib/infrastructure/file-service.js +76 -0
  128. package/lib/infrastructure/file-service.js.map +1 -0
  129. package/lib/infrastructure/launcher-service.d.ts +5 -0
  130. package/lib/infrastructure/launcher-service.js +47 -0
  131. package/lib/infrastructure/launcher-service.js.map +1 -0
  132. package/lib/infrastructure/services/api-service.d.ts +10 -0
  133. package/lib/infrastructure/services/api-service.js +55 -0
  134. package/lib/infrastructure/services/api-service.js.map +1 -0
  135. package/lib/infrastructure/services/auth-service.d.ts +11 -0
  136. package/lib/infrastructure/services/auth-service.js +35 -0
  137. package/lib/infrastructure/services/auth-service.js.map +1 -0
  138. package/lib/infrastructure/services/portal-service.d.ts +23 -0
  139. package/lib/infrastructure/services/portal-service.js +186 -0
  140. package/lib/infrastructure/services/portal-service.js.map +1 -0
  141. package/lib/infrastructure/services/telemetry-service.d.ts +8 -0
  142. package/lib/infrastructure/services/telemetry-service.js +40 -0
  143. package/lib/infrastructure/services/telemetry-service.js.map +1 -0
  144. package/lib/infrastructure/tmp-extensions.d.ts +2 -0
  145. package/lib/infrastructure/tmp-extensions.js +6 -0
  146. package/lib/infrastructure/tmp-extensions.js.map +1 -0
  147. package/lib/infrastructure/zip-service.d.ts +6 -0
  148. package/lib/infrastructure/zip-service.js +39 -0
  149. package/lib/infrastructure/zip-service.js.map +1 -0
  150. package/lib/prompts/auth/login.d.ts +5 -0
  151. package/lib/prompts/auth/login.js +13 -0
  152. package/lib/prompts/auth/login.js.map +1 -0
  153. package/lib/prompts/portal/common/base-prompts.d.ts +7 -0
  154. package/lib/prompts/portal/common/base-prompts.js +19 -0
  155. package/lib/prompts/portal/common/base-prompts.js.map +1 -0
  156. package/lib/prompts/portal/copilot.d.ts +14 -0
  157. package/lib/prompts/portal/copilot.js +71 -0
  158. package/lib/prompts/portal/copilot.js.map +1 -0
  159. package/lib/prompts/portal/generate.d.ts +11 -0
  160. package/lib/prompts/portal/generate.js +42 -0
  161. package/lib/prompts/portal/generate.js.map +1 -0
  162. package/lib/prompts/portal/quickstart.d.ts +30 -0
  163. package/lib/prompts/portal/quickstart.js +240 -0
  164. package/lib/prompts/portal/quickstart.js.map +1 -0
  165. package/lib/prompts/portal/recipe/new-recipe.d.ts +24 -0
  166. package/lib/prompts/portal/recipe/new-recipe.js +203 -0
  167. package/lib/prompts/portal/recipe/new-recipe.js.map +1 -0
  168. package/lib/prompts/portal/serve.d.ts +4 -0
  169. package/lib/prompts/portal/serve.js +14 -0
  170. package/lib/prompts/portal/serve.js.map +1 -0
  171. package/lib/prompts/portal/toc/new-toc.d.ts +11 -0
  172. package/lib/prompts/portal/toc/new-toc.js +39 -0
  173. package/lib/prompts/portal/toc/new-toc.js.map +1 -0
  174. package/lib/prompts/sdk/generate.d.ts +11 -0
  175. package/lib/prompts/sdk/generate.js +42 -0
  176. package/lib/prompts/sdk/generate.js.map +1 -0
  177. package/lib/types/api/account.d.ts +10 -0
  178. package/lib/types/api/account.js +2 -0
  179. package/lib/types/api/account.js.map +1 -0
  180. package/lib/types/api/transform.d.ts +19 -4
  181. package/lib/types/api/transform.js +19 -4
  182. package/lib/types/api/transform.js.map +1 -0
  183. package/lib/types/api/validate.d.ts +3 -3
  184. package/lib/types/api/validate.js +2 -2
  185. package/lib/types/api/validate.js.map +1 -0
  186. package/lib/types/build/build.d.ts +14 -0
  187. package/lib/types/build/build.js +4 -0
  188. package/lib/types/build/build.js.map +1 -0
  189. package/lib/types/build-context.d.ts +13 -0
  190. package/lib/types/build-context.js +30 -0
  191. package/lib/types/build-context.js.map +1 -0
  192. package/lib/types/common/result.d.ts +17 -0
  193. package/lib/types/common/result.js +32 -0
  194. package/lib/types/common/result.js.map +1 -0
  195. package/lib/types/events/domain-event.d.ts +8 -0
  196. package/lib/types/events/domain-event.js +11 -0
  197. package/lib/types/events/domain-event.js.map +1 -0
  198. package/lib/types/events/quickstart-completed.d.ts +7 -0
  199. package/lib/types/events/quickstart-completed.js +10 -0
  200. package/lib/types/events/quickstart-completed.js.map +1 -0
  201. package/lib/types/events/quickstart-initiated.d.ts +7 -0
  202. package/lib/types/events/quickstart-initiated.js +10 -0
  203. package/lib/types/events/quickstart-initiated.js.map +1 -0
  204. package/lib/types/events/recipe-creation-failed.d.ts +5 -0
  205. package/lib/types/events/recipe-creation-failed.js +8 -0
  206. package/lib/types/events/recipe-creation-failed.js.map +1 -0
  207. package/lib/types/events/toc-creation-failed.d.ts +5 -0
  208. package/lib/types/events/toc-creation-failed.js +8 -0
  209. package/lib/types/events/toc-creation-failed.js.map +1 -0
  210. package/lib/types/file/directoryPath.d.ts +7 -0
  211. package/lib/types/file/directoryPath.js +16 -0
  212. package/lib/types/file/directoryPath.js.map +1 -0
  213. package/lib/types/file/fileName.d.ts +5 -0
  214. package/lib/types/file/fileName.js +9 -0
  215. package/lib/types/file/fileName.js.map +1 -0
  216. package/lib/types/file/filePath.d.ts +8 -0
  217. package/lib/types/file/filePath.js +11 -0
  218. package/lib/types/file/filePath.js.map +1 -0
  219. package/lib/types/flags-provider.d.ts +15 -0
  220. package/lib/types/flags-provider.js +34 -0
  221. package/lib/types/flags-provider.js.map +1 -0
  222. package/lib/types/portal/generate.d.ts +13 -9
  223. package/lib/types/portal/generate.js +3 -2
  224. package/lib/types/portal/generate.js.map +1 -0
  225. package/lib/types/portal/quickstart.d.ts +17 -0
  226. package/lib/types/portal/quickstart.js +2 -0
  227. package/lib/types/portal/quickstart.js.map +1 -0
  228. package/lib/types/portal/serve.d.ts +12 -0
  229. package/lib/types/portal/serve.js +2 -0
  230. package/lib/types/portal/serve.js.map +1 -0
  231. package/lib/types/portal-context.d.ts +11 -0
  232. package/lib/types/portal-context.js +28 -0
  233. package/lib/types/portal-context.js.map +1 -0
  234. package/lib/types/recipe/recipe.d.ts +37 -0
  235. package/lib/types/recipe/recipe.js +6 -0
  236. package/lib/types/recipe/recipe.js.map +1 -0
  237. package/lib/types/sdk/generate.d.ts +11 -10
  238. package/lib/types/sdk/generate.js +11 -12
  239. package/lib/types/sdk/generate.js.map +1 -0
  240. package/lib/types/sdk-context.d.ts +13 -0
  241. package/lib/types/sdk-context.js +28 -0
  242. package/lib/types/sdk-context.js.map +1 -0
  243. package/lib/types/sdl/sdl.d.ts +12 -0
  244. package/lib/types/sdl/sdl.js +2 -0
  245. package/lib/types/sdl/sdl.js.map +1 -0
  246. package/lib/types/spec-context.d.ts +7 -0
  247. package/lib/types/spec-context.js +12 -0
  248. package/lib/types/spec-context.js.map +1 -0
  249. package/lib/types/toc/toc.d.ts +31 -0
  250. package/lib/types/toc/toc.js +9 -0
  251. package/lib/types/toc/toc.js.map +1 -0
  252. package/lib/types/utils.d.ts +3 -3
  253. package/lib/types/utils.js +2 -2
  254. package/lib/types/utils.js.map +1 -0
  255. package/lib/utils/utils.d.ts +16 -7
  256. package/lib/utils/utils.js +142 -86
  257. package/lib/utils/utils.js.map +1 -0
  258. package/lib/validators/common/directoryValidator.d.ts +5 -0
  259. package/lib/validators/common/directoryValidator.js +22 -0
  260. package/lib/validators/common/directoryValidator.js.map +1 -0
  261. package/lib/validators/portal/serve-validator.d.ts +6 -0
  262. package/lib/validators/portal/serve-validator.js +15 -0
  263. package/lib/validators/portal/serve-validator.js.map +1 -0
  264. package/package.json +100 -43
  265. package/bin/run +0 -5
  266. package/lib/controllers/portal/generate.d.ts +0 -2
  267. package/lib/controllers/portal/generate.js +0 -49
  268. package/lib/controllers/sdk/generate.d.ts +0 -4
  269. package/lib/controllers/sdk/generate.js +0 -64
@@ -0,0 +1,76 @@
1
+ import fs from "fs";
2
+ import fsExtra from "fs-extra";
3
+ import * as path from "path";
4
+ import { pipeline } from "stream";
5
+ import { promisify } from "util";
6
+ export class FileService {
7
+ async fileExists(file) {
8
+ try {
9
+ const stat = await fsExtra.stat(file.toString());
10
+ return stat.isFile();
11
+ }
12
+ catch (_a) {
13
+ return false;
14
+ }
15
+ }
16
+ async directoryExists(dir) {
17
+ try {
18
+ const stat = await fsExtra.stat(dir.toString());
19
+ return stat.isDirectory();
20
+ }
21
+ catch (_a) {
22
+ return false;
23
+ }
24
+ }
25
+ async directoryEmpty(dir) {
26
+ try {
27
+ const files = await fsExtra.readdir(dir.toString());
28
+ return files.length === 0;
29
+ }
30
+ catch (error) {
31
+ return error instanceof Error && "code" in error && error.code === "ENOENT";
32
+ }
33
+ }
34
+ async cleanDirectory(dir) {
35
+ await fsExtra.ensureDir(dir.toString());
36
+ await fsExtra.emptyDir(dir.toString()); // removes everything inside, keeps the dir
37
+ }
38
+ async copyDirectory(source, destination) {
39
+ await fsExtra.copy(source.toString(), destination.toString());
40
+ }
41
+ async copyDirectoryContents(source, destination) {
42
+ const entries = await fsExtra.readdir(source.toString());
43
+ await Promise.all(entries.map(async (entry) => {
44
+ const srcEntry = path.join(source.toString(), entry);
45
+ const destEntry = path.join(destination.toString(), entry);
46
+ await fsExtra.copy(srcEntry, destEntry);
47
+ }));
48
+ }
49
+ async deleteFile(filePath) {
50
+ const exists = await this.fileExists(filePath);
51
+ if (exists) {
52
+ await fsExtra.remove(filePath.toString());
53
+ }
54
+ }
55
+ async getStream(filePath) {
56
+ return fs.createReadStream(filePath.toString());
57
+ }
58
+ async getContents(filePath) {
59
+ return await fsExtra.readFile(filePath.toString(), "utf-8");
60
+ }
61
+ async writeFile(filePath, stream) {
62
+ const writeStream = fs.createWriteStream(filePath.toString());
63
+ await streamPipeline(stream, writeStream);
64
+ }
65
+ async writeContents(filePath, contents) {
66
+ await fsExtra.writeFile(filePath.toString(), contents, "utf-8");
67
+ }
68
+ async writeBuffer(filePath, buffer) {
69
+ await fsExtra.writeFile(filePath.toString(), buffer);
70
+ }
71
+ async copy(source, destination) {
72
+ await fsExtra.copyFile(source.toString(), destination.toString());
73
+ }
74
+ }
75
+ const streamPipeline = promisify(pipeline);
76
+ //# sourceMappingURL=file-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-service.js","sourceRoot":"","sources":["../../src/infrastructure/file-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAG7B,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjC,MAAM,OAAO,WAAW;IACf,KAAK,CAAC,UAAU,CAAC,IAAc;QACpC,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;YACjD,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,GAAkB;QAC7C,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;YAChD,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;QAC5B,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CA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EAAE,CAAC,CAAC;IACpE,CAAC;CAEF;AAED,MAAM,cAAc,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { FilePath } from "../types/file/filePath.js";
2
+ export declare class LauncherService {
3
+ openInEditor(filePath: FilePath): Promise<void>;
4
+ openFile(filePath: FilePath): Promise<void>;
5
+ }
@@ -0,0 +1,47 @@
1
+ import { execa } from "execa";
2
+ import os from "os";
3
+ import { spawn } from "child_process";
4
+ export class LauncherService {
5
+ async openInEditor(filePath) {
6
+ try {
7
+ await execa("code", ["--wait", filePath.toString()]);
8
+ }
9
+ catch (_a) {
10
+ // TODO: check for fallback (start)
11
+ if (process.platform === "win32") {
12
+ await execa("cmd", ["/c", "start", "/wait", "notepad", filePath.toString()], { stdio: "ignore" });
13
+ }
14
+ else if (process.platform === "darwin") {
15
+ await execa("vim", [filePath.toString()], { stdio: "inherit" });
16
+ }
17
+ }
18
+ }
19
+ async openFile(filePath) {
20
+ const targetPath = filePath.toString();
21
+ // Determine the command and args without using the shell
22
+ let command;
23
+ let args;
24
+ switch (os.platform()) {
25
+ case "win32":
26
+ command = "cmd";
27
+ args = ["/c", "start", "", targetPath];
28
+ break;
29
+ case "darwin":
30
+ command = "open";
31
+ args = [targetPath];
32
+ break;
33
+ default:
34
+ command = "xdg-open";
35
+ args = [targetPath];
36
+ break;
37
+ }
38
+ try {
39
+ const child = spawn(command, args, { stdio: "ignore", detached: true });
40
+ child.unref(); // Let it run without blocking
41
+ }
42
+ catch (_a) {
43
+ // Silently ignore errors
44
+ }
45
+ }
46
+ }
47
+ //# sourceMappingURL=launcher-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launcher-service.js","sourceRoot":"","sources":["../../src/infrastructure/launcher-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,MAAM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pB,MAAM;QACV,CAAC;QAED,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;YACxE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,8BAA8B;QAC/C,CAAC;QAAC,WAAM,CAAC;YACP,yBAAyB;QAC3B,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ import { DirectoryPath } from "../../types/file/directoryPath.js";
2
+ import { SubscriptionInfo } from "../../types/api/account.js";
3
+ import { Result } from "neverthrow";
4
+ import { ServiceError } from "../api-utils.js";
5
+ export declare class ApiService {
6
+ private readonly apiBaseUrl;
7
+ getAccountInfo(configDir: DirectoryPath, authKey: string | null): Promise<Result<SubscriptionInfo, ServiceError>>;
8
+ sendTelemetry(payload: string, authKey: string): Promise<Result<string, string>>;
9
+ private axiosInstance;
10
+ }
@@ -0,0 +1,55 @@
1
+ import axios from "axios";
2
+ import { getAuthInfo } from "../../client-utils/auth-manager.js";
3
+ import { envInfo } from "../env-info.js";
4
+ import { err, ok } from "neverthrow";
5
+ import { handleServiceError } from "../api-utils.js";
6
+ export class ApiService {
7
+ constructor() {
8
+ this.apiBaseUrl = "https://api.apimatic.io";
9
+ }
10
+ async getAccountInfo(configDir, authKey) {
11
+ const authInfo = await getAuthInfo(configDir.toString());
12
+ if (authInfo === null && !authKey) {
13
+ return err("UNAUTHORIZED" /* ServiceError.UnAuthorized */);
14
+ }
15
+ try {
16
+ const token = authKey || (authInfo === null || authInfo === void 0 ? void 0 : authInfo.authKey);
17
+ const response = await this.axiosInstance(token).get("/account/profile");
18
+ if (response.status === 200) {
19
+ return ok(response.data);
20
+ }
21
+ return err("INVALID_RESPONSE" /* ServiceError.InvalidResponse */);
22
+ }
23
+ catch (error) {
24
+ return err(handleServiceError(error));
25
+ }
26
+ }
27
+ async sendTelemetry(payload, authKey) {
28
+ try {
29
+ const response = await this.axiosInstance(authKey).post("/telemetry/track", payload, {
30
+ headers: { "Content-Type": "application/json" }
31
+ });
32
+ if (response.status === 200) {
33
+ return ok("telemetry sent");
34
+ }
35
+ return err("Failed to send telemetry data");
36
+ }
37
+ catch (error) {
38
+ return err(handleServiceError(error));
39
+ }
40
+ }
41
+ axiosInstance(apiKey) {
42
+ var _a;
43
+ const headers = {
44
+ "User-Agent": envInfo.getUserAgent()
45
+ };
46
+ if (apiKey) {
47
+ headers.Authorization = `X-Auth-Key ${apiKey}`;
48
+ }
49
+ return axios.create({
50
+ baseURL: (_a = envInfo.getBaseUrl()) !== null && _a !== void 0 ? _a : this.apiBaseUrl,
51
+ headers
52
+ });
53
+ }
54
+ }
55
+ //# sourceMappingURL=api-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-service.js","sourceRoot":"","sources":["../../../src/infrastructure/services/api-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAY,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAG3E,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,EAAE,EAAU,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAgB,MAAM,iBAAiB,CAAC;AAEnE,MAAM,OAAO,UAAU;IAAvB;QACmB,eAAU,GAAG,yBAAkC,CAAC;IAqDnE,CAAC;IAnDQ,KAAK,CAAC,cAAc,CACzB,SAAwB,EACxB,OAAsB;QAEtB,MAAM,QAAQ,GAAoB,MAAM,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC1E,IAAI,QAAQ,KAAK,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAClC,OAAO,GAAG,gDAA2B,CAAC;QACxC,CAAC;QAED,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,OAAO,KAAI,QAAQ,aAAR,QAAQ,uBAAR,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C,UAAU,EAAE,mCAAI,IAAI,CAAC,UAAU;YAChD,OAAO;SACR,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ import { Result } from "neverthrow";
2
+ import { ServiceError } from "../api-utils.js";
3
+ export interface DeviceAuthToken {
4
+ apiKey: string;
5
+ }
6
+ export declare class AuthService {
7
+ private readonly apiBaseUrl;
8
+ private axiosInstance;
9
+ getDeviceLoginUrl(state: string): string;
10
+ getDeviceLoginToken(state: string): Promise<Result<DeviceAuthToken, ServiceError>>;
11
+ }
@@ -0,0 +1,35 @@
1
+ import axios from "axios";
2
+ import { envInfo } from "../env-info.js";
3
+ import { err, ok } from "neverthrow";
4
+ import { handleServiceError } from "../api-utils.js";
5
+ export class AuthService {
6
+ constructor() {
7
+ var _a;
8
+ this.apiBaseUrl = "https://auth.apimatic.io";
9
+ this.axiosInstance = axios.create({
10
+ baseURL: (_a = envInfo.getAuthBaseUrl()) !== null && _a !== void 0 ? _a : this.apiBaseUrl,
11
+ timeout: 20000,
12
+ headers: {
13
+ "User-Agent": envInfo.getUserAgent()
14
+ }
15
+ });
16
+ }
17
+ getDeviceLoginUrl(state) {
18
+ var _a;
19
+ return `${(_a = envInfo.getAuthBaseUrl()) !== null && _a !== void 0 ? _a : this.apiBaseUrl}/device-auth/login?state=${state}`;
20
+ }
21
+ async getDeviceLoginToken(state) {
22
+ var _a;
23
+ try {
24
+ const response = await this.axiosInstance.get(`/device-auth/token?state=${state}`);
25
+ if (response.status === 200 && ((_a = response.data) === null || _a === void 0 ? void 0 : _a.apiKey)) {
26
+ return ok({ apiKey: response.data.apiKey });
27
+ }
28
+ return err("INVALID_RESPONSE" /* ServiceError.InvalidResponse */);
29
+ }
30
+ catch (error) {
31
+ return err(handleServiceError(error));
32
+ }
33
+ }
34
+ }
35
+ //# sourceMappingURL=auth-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-service.js","sourceRoot":"","sources":["../../../src/infrastructure/services/auth-service.ts"],"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} from "@apimatic/sdk";
2
+ import { Result } from "../../types/common/result.js";
3
+ import { Sdl } from "../../types/sdl/sdl.js";
4
+ import { FilePath } from "../../types/file/filePath.js";
5
+ import { DirectoryPath } from "../../types/file/directoryPath.js";
6
+ import { ReadStream } from "fs";
7
+ export declare class PortalService {
8
+ private readonly CONTENT_TYPE;
9
+ private readonly TIMEOUT;
10
+ private readonly fileService;
11
+ generatePortal(buildPath: FilePath, configDir: DirectoryPath, commandName: string, authKey: string | null): Promise<Result<NodeJS.ReadableStream, string | NodeJS.ReadableStream>>;
12
+ generateSdk(specPath: FilePath, sdkPlatform: Platforms, configDir: DirectoryPath, commandName: string, authKey: string | null): Promise<Result<NodeJS.ReadableStream, string>>;
13
+ generateSdl(specFileStream: ReadStream, configDir: string, commandName: string): Promise<Result<Sdl, string>>;
14
+ private createGenericErrorResult;
15
+ private createAuthorizationHeader;
16
+ private createApiClient;
17
+ readonly createProductionApiClient: (authorizationHeader: string) => Client;
18
+ readonly createTestingApiClient: (authorizationHeader: string) => Client;
19
+ private createOriginQueryParameter;
20
+ private handlePortalGenerationErrors;
21
+ private parseBadRequestResponse;
22
+ private handleSdkGenerationErrors;
23
+ }
@@ -0,0 +1,186 @@
1
+ import { ContentType, DocsPortalManagementController, Client, UnauthorizedResponseError, ProblemDetailsError, FileWrapper, ApiError, TransformationController, ExportFormats, InternalServerErrorResponseError, CodeGenerationExternalApisController, BadRequestResponseSdkError, Accept, Environment } from "@apimatic/sdk";
2
+ import { getAuthInfo } from "../../client-utils/auth-manager.js";
3
+ import { Result } from "../../types/common/result.js";
4
+ import { getMessageInRedColor, parseStreamBodyToJson } from "../../utils/utils.js";
5
+ import { FileService } from "../file-service.js";
6
+ import { envInfo } from "../env-info.js";
7
+ export class PortalService {
8
+ constructor() {
9
+ this.CONTENT_TYPE = ContentType.EnumMultipartformdata;
10
+ this.TIMEOUT = 0;
11
+ this.fileService = new FileService();
12
+ this.createAuthorizationHeader = (authInfo, overrideAuthKey) => {
13
+ const key = overrideAuthKey || (authInfo === null || authInfo === void 0 ? void 0 : authInfo.authKey);
14
+ return `X-Auth-Key ${key !== null && key !== void 0 ? key : ""}`;
15
+ };
16
+ this.createApiClient = (authorizationHeader) => {
17
+ if (envInfo.getBaseUrl()) {
18
+ return this.createTestingApiClient(authorizationHeader);
19
+ }
20
+ return this.createProductionApiClient(authorizationHeader);
21
+ };
22
+ this.createProductionApiClient = (authorizationHeader) => {
23
+ return new Client({
24
+ customHeaderAuthenticationCredentials: {
25
+ Authorization: authorizationHeader
26
+ },
27
+ userAgent: envInfo.getUserAgent(),
28
+ timeout: this.TIMEOUT,
29
+ environment: Environment.Production
30
+ });
31
+ };
32
+ this.createTestingApiClient = (authorizationHeader) => {
33
+ return new Client({
34
+ customHeaderAuthenticationCredentials: {
35
+ Authorization: authorizationHeader
36
+ },
37
+ userAgent: envInfo.getUserAgent(),
38
+ timeout: this.TIMEOUT,
39
+ environment: Environment.Testing,
40
+ customUrl: envInfo.getBaseUrl()
41
+ });
42
+ };
43
+ this.createOriginQueryParameter = (commandName) => {
44
+ return {
45
+ origin: `APIMATIC CLI ${commandName}`
46
+ };
47
+ };
48
+ this.handlePortalGenerationErrors = async (error) => {
49
+ var _a, _b, _c, _d, _e;
50
+ if (error instanceof UnauthorizedResponseError) {
51
+ //401
52
+ const unAuthError = error;
53
+ return getMessageInRedColor((_b = (_a = unAuthError.result) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : "Authorization has been denied for this request.");
54
+ }
55
+ else if (error instanceof ProblemDetailsError) {
56
+ //400 & 403
57
+ const probDetailsError = error;
58
+ const message = (_d = (_c = Object.values(probDetailsError.result.errors)[0]) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : null;
59
+ return getMessageInRedColor(probDetailsError.result.title + "\n- " + message);
60
+ }
61
+ else if (error instanceof ApiError && error.statusCode === 422) {
62
+ //422
63
+ return error.body;
64
+ }
65
+ else if (error instanceof InternalServerErrorResponseError) {
66
+ //500
67
+ const internalServerError = error;
68
+ const message = (_e = internalServerError.result) === null || _e === void 0 ? void 0 : _e.message;
69
+ return getMessageInRedColor(`${message !== null && message !== void 0 ? message : "An unkown error occurred."} Please try again later or reach out to our team at support@apimatic.io for help if your problem persists.`);
70
+ }
71
+ else {
72
+ return getMessageInRedColor("An unexpected error occurred while generating the portal, please try again later. If the problem persists, please reach out to our team at support@apimatic.io");
73
+ }
74
+ };
75
+ this.handleSdkGenerationErrors = async (error) => {
76
+ var _a, _b, _c, _d, _e;
77
+ if (error instanceof BadRequestResponseSdkError) {
78
+ //400
79
+ const badRequestError = error;
80
+ const errorMessage = this.parseBadRequestResponse((_a = badRequestError.result) === null || _a === void 0 ? void 0 : _a.message);
81
+ return getMessageInRedColor(errorMessage);
82
+ }
83
+ else if (error instanceof UnauthorizedResponseError) {
84
+ //401
85
+ const unAuthError = error;
86
+ return getMessageInRedColor((_c = (_b = unAuthError.result) === null || _b === void 0 ? void 0 : _b.message) !== null && _c !== void 0 ? _c : "Authorization has been denied for this request.");
87
+ }
88
+ else if (error instanceof ProblemDetailsError) {
89
+ // 403
90
+ const probDetailsError = error;
91
+ const message = (_e = (_d = probDetailsError.result.errors) === null || _d === void 0 ? void 0 : _d[""]) === null || _e === void 0 ? void 0 : _e[0];
92
+ return getMessageInRedColor(probDetailsError.result.title + "\n- " + message);
93
+ }
94
+ else {
95
+ return getMessageInRedColor("An unexpected error occurred while generating the SDK, please try again later. If the problem persists, please reach out to our team at support@apimatic.io");
96
+ }
97
+ };
98
+ }
99
+ //TODO: Pass stream as parameter instead of file path.
100
+ async generatePortal(buildPath, configDir, commandName, authKey) {
101
+ const buildFileStream = await this.fileService.getStream(buildPath);
102
+ const file = new FileWrapper(buildFileStream);
103
+ const authInfo = await getAuthInfo(configDir.toString());
104
+ const authorizationHeader = this.createAuthorizationHeader(authInfo, authKey);
105
+ const client = this.createApiClient(authorizationHeader);
106
+ const docsPortalManagementController = new DocsPortalManagementController(client);
107
+ try {
108
+ const response = await docsPortalManagementController.generateOnPremPortalViaBuildInput(this.CONTENT_TYPE, file, this.createOriginQueryParameter(commandName));
109
+ return Result.success(response.result);
110
+ }
111
+ catch (error) {
112
+ return Result.failure(await this.handlePortalGenerationErrors(error));
113
+ }
114
+ finally {
115
+ buildFileStream.close();
116
+ }
117
+ }
118
+ //TODO: Pass stream as parameter instead of file path.
119
+ async generateSdk(specPath, sdkPlatform, configDir, commandName, authKey) {
120
+ const specFileStream = await this.fileService.getStream(specPath);
121
+ const file = new FileWrapper(specFileStream);
122
+ const authInfo = await getAuthInfo(configDir.toString());
123
+ const authorizationHeader = this.createAuthorizationHeader(authInfo, authKey);
124
+ const client = this.createApiClient(authorizationHeader);
125
+ const sdkGenerationController = new CodeGenerationExternalApisController(client);
126
+ try {
127
+ const response = await sdkGenerationController.generateSdkViaFile(Accept.EnumApplicationjson, file, sdkPlatform, this.createOriginQueryParameter(commandName));
128
+ const sdkResponse = await sdkGenerationController.downloadSdk(response.result.id);
129
+ return Result.success(sdkResponse.result);
130
+ }
131
+ catch (error) {
132
+ return Result.failure(await this.handleSdkGenerationErrors(error));
133
+ }
134
+ finally {
135
+ specFileStream.close();
136
+ }
137
+ }
138
+ async generateSdl(specFileStream, configDir, commandName) {
139
+ const file = new FileWrapper(specFileStream);
140
+ const authInfo = await getAuthInfo(configDir);
141
+ const authorizationHeader = this.createAuthorizationHeader(authInfo, null);
142
+ const client = this.createApiClient(authorizationHeader);
143
+ const transformationController = new TransformationController(client);
144
+ try {
145
+ const generation = await transformationController.transformViaFile(ContentType.EnumMultipartformdata, file, ExportFormats.Apimatic, this.createOriginQueryParameter(commandName));
146
+ if (!generation.result.success) {
147
+ return this.createGenericErrorResult();
148
+ }
149
+ const transformationId = generation.result.id;
150
+ const { result } = await transformationController.downloadTransformedFile(transformationId);
151
+ if (result.readable) {
152
+ return Result.success((await parseStreamBodyToJson(result)));
153
+ }
154
+ else {
155
+ return this.createGenericErrorResult();
156
+ }
157
+ }
158
+ catch (_a) {
159
+ return this.createGenericErrorResult();
160
+ }
161
+ }
162
+ createGenericErrorResult() {
163
+ return Result.failure("An unexpected error occurred");
164
+ }
165
+ parseBadRequestResponse(errorMessage) {
166
+ // #TODO: Fix server-side error message and simplify this function
167
+ if (!errorMessage) {
168
+ return "Bad request.";
169
+ }
170
+ // Parse the JSON string
171
+ const parsedResult = JSON.parse(errorMessage);
172
+ // Check if it has the expected structure with Errors array
173
+ if (parsedResult.Errors && Array.isArray(parsedResult.Errors) && parsedResult.Errors.length > 0) {
174
+ // Get the first error and clean it up
175
+ const firstError = parsedResult.Errors[0];
176
+ // Split on <br/> and take first part, then strip remaining HTML tags
177
+ const cleanError = firstError.split("<br/>")[0].replace(/<[^<>]*?>/g, "");
178
+ return cleanError;
179
+ }
180
+ else if (parsedResult.Success === false) {
181
+ return "API definition file validation failed.";
182
+ }
183
+ return errorMessage;
184
+ }
185
+ }
186
+ //# sourceMappingURL=portal-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portal-service.js","sourceRoot":"","sources":["../../../src/infrastructure/services/portal-service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,8BAA8B,EAC9B,MAAM,EACN,yBAAyB,EACzB,mBAAmB,EACnB,WAAW,EAEX,QAAQ,EACR,wBAAwB,EAExB,aAAa,EACb,gCAAgC,EAChC,oCAAoC,EAEpC,0BAA0B,EAC1B,MAAM,EACN,WAAW,EACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAY,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAKnF,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGzC,MAAM,OAAO,aAAa;IAA1B;QACmB,iBAAY,GAAG,WAAW,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,UAAU,CAAC;QACpB,CAAC;aAAM,IAAI,YAAY,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;YAC1C,OAAO,wCAAwC,CAAC;QAClD,CAAC;QACD,OAAO,YAAY,CAAC;IACtB,CAAC;CAuBF"}
@@ -0,0 +1,8 @@
1
+ import { DomainEvent } from "../../types/events/domain-event.js";
2
+ export declare class TelemetryService {
3
+ private readonly configDirectory;
4
+ private readonly apiService;
5
+ constructor(configDirectory: string);
6
+ trackEvent<T extends DomainEvent>(event: T): Promise<void>;
7
+ private getAuthInfo;
8
+ }
@@ -0,0 +1,40 @@
1
+ import process from "process";
2
+ import os from "os";
3
+ import fs from "fs-extra";
4
+ import { envInfo } from "../env-info.js";
5
+ import path from "path";
6
+ import { ApiService } from "./api-service.js";
7
+ export class TelemetryService {
8
+ constructor(configDirectory) {
9
+ this.configDirectory = configDirectory;
10
+ this.apiService = new ApiService();
11
+ }
12
+ async trackEvent(event) {
13
+ const authInfo = await this.getAuthInfo(this.configDirectory);
14
+ const telemetryOptedOut = process.env.APIMATIC_CLI_TELEMETRY_OPTOUT === "1";
15
+ const authKey = authInfo === null || authInfo === void 0 ? void 0 : authInfo.authKey;
16
+ if (telemetryOptedOut || (authInfo === null || authInfo === void 0 ? void 0 : authInfo.APIMATIC_CLI_TELEMETRY_OPTOUT) === "1" || !authKey) {
17
+ return;
18
+ }
19
+ const payload = {
20
+ payload: event,
21
+ timestamp: new Date().toISOString(),
22
+ cliVersion: envInfo.getCLIVersion(),
23
+ platform: os.platform(),
24
+ releaseVersion: os.release(),
25
+ nodeVersion: process.version,
26
+ };
27
+ const result = await this.apiService.sendTelemetry(JSON.stringify(payload), authKey);
28
+ // eslint-disable-next-line no-undef
29
+ result.mapErr((err) => console.log(err));
30
+ }
31
+ async getAuthInfo(configDirectory) {
32
+ try {
33
+ return JSON.parse(await fs.readFile(path.join(configDirectory, "config.json"), "utf8"));
34
+ }
35
+ catch (_a) {
36
+ return null;
37
+ }
38
+ }
39
+ }
40
+ //# sourceMappingURL=telemetry-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry-service.js","sourceRoot":"","sources":["../../../src/infrastructure/services/telemetry-service.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,MAAM,UAAU,CAAC;AAG1B,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAW9C,MAAM,OAAO,gBAAgB;IAG3B,YAA6B,eAAuB;QAAvB,oBAAe,GAAf,eAAe,CAAQ;QAFnC,eAAU,GAAG,IAAI,UAAU,EAAE,CAAC;IAG/C,CAAC;IAEM,KAAK,CAAC,UAAU,CAAwB,KAAQ;QACrD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAC9D,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,6BAA6B,KAAK,GAAG,CAAC;QAC5E,MAAM,OAAO,GAAG,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,CAAC;QAElC,IAAI,iBAAiB,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,6BAA6B,MAAK,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;YACrF,OAAO;QACT,CAAC;QAED,MAAM,OAAO,GAAqB;YAChC,OAAO,EAAE,KAAK;YACd,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,UAAU,EAAE,OAAO,CAAC,aAAa,EAAE;YACnC,QAAQ,EAAE,EAAE,CAAC,QAAQ,EAAE;YACvB,cAAc,EAAE,EAAE,CAAC,OAAO,EAAE;YAC5B,WAAW,EAAE,OAAO,CAAC,OAAO;SAC7B,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;QACrF,oCAAoC;QACpC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3C,CAAC;IAEO,KAAK,CAAC,WAAW,CAAC,eAAuB;QAC/C,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,aAAa,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;QAC1F,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ import { DirectoryPath } from "../types/file/directoryPath.js";
2
+ export declare function withDirPath<T>(fn: (results: DirectoryPath) => Promise<T>): Promise<T>;
@@ -0,0 +1,6 @@
1
+ import { DirectoryPath } from "../types/file/directoryPath.js";
2
+ import { withDir } from "tmp-promise";
3
+ export function withDirPath(fn) {
4
+ return withDir(results => fn(new DirectoryPath(results.path)), { unsafeCleanup: true });
5
+ }
6
+ //# sourceMappingURL=tmp-extensions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tmp-extensions.js","sourceRoot":"","sources":["../../src/infrastructure/tmp-extensions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,MAAM,UAAU,WAAW,CACzB,EAA0C;IAE1C,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;AAC1F,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { DirectoryPath } from "../types/file/directoryPath.js";
2
+ import { FilePath } from "../types/file/filePath.js";
3
+ export declare class ZipService {
4
+ archive(sourceDir: DirectoryPath, outputZipPath: FilePath): Promise<void>;
5
+ unArchive(sourceFile: FilePath, destinationDirectory: DirectoryPath): Promise<void>;
6
+ }
@@ -0,0 +1,39 @@
1
+ import fs from "fs";
2
+ import archiver from "archiver";
3
+ import extract from "extract-zip";
4
+ export class ZipService {
5
+ async archive(sourceDir, outputZipPath) {
6
+ return new Promise((resolve, reject) => {
7
+ const output = fs.createWriteStream(outputZipPath.toString());
8
+ const archive = archiver("zip");
9
+ output.on("close", () => resolve());
10
+ archive.on("error", (err) => reject(err));
11
+ archive.pipe(output);
12
+ archive.directory(sourceDir.toString(), false); // false: don't nest under folder
13
+ archive.finalize();
14
+ });
15
+ }
16
+ async unArchive(sourceFile, destinationDirectory) {
17
+ const MAX_FILES = 100000;
18
+ const MAX_SIZE = 1000000000; // 1 GB
19
+ let fileCount = 0;
20
+ let totalSize = 0;
21
+ await extract(sourceFile.toString(), {
22
+ dir: destinationDirectory.toString(),
23
+ onEntry: function (entry) {
24
+ fileCount++;
25
+ if (fileCount > MAX_FILES) {
26
+ throw new Error("Reached max. file count");
27
+ }
28
+ // The uncompressedSize comes from the zip headers, so it might not be trustworthy.
29
+ // Alternatively, calculate the size from the readStream.
30
+ let entrySize = entry.uncompressedSize;
31
+ totalSize += entrySize;
32
+ if (totalSize > MAX_SIZE) {
33
+ throw new Error("Reached max. size");
34
+ }
35
+ }
36
+ });
37
+ }
38
+ }
39
+ //# sourceMappingURL=zip-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zip-service.js","sourceRoot":"","sources":["../../src/infrastructure/zip-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,OAAO,MAAM,a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