@apimatic/cli 1.1.0-alpha.13 → 1.1.0-alpha.15

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 (209) hide show
  1. package/README.md +96 -95
  2. package/lib/actions/action-result.d.ts +8 -0
  3. package/lib/actions/action-result.js +25 -0
  4. package/lib/actions/action-result.js.map +1 -0
  5. package/lib/actions/auth/login.d.ts +12 -0
  6. package/lib/actions/auth/login.js +63 -0
  7. package/lib/actions/auth/login.js.map +1 -0
  8. package/lib/actions/portal/copilot.d.ts +11 -0
  9. package/lib/actions/portal/copilot.js +46 -0
  10. package/lib/actions/portal/copilot.js.map +1 -0
  11. package/lib/actions/portal/generate.d.ts +11 -5
  12. package/lib/actions/portal/generate.js +54 -47
  13. package/lib/actions/portal/generate.js.map +1 -1
  14. package/lib/actions/portal/recipe/new-recipe.d.ts +3 -3
  15. package/lib/actions/portal/recipe/new-recipe.js +18 -31
  16. package/lib/actions/portal/recipe/new-recipe.js.map +1 -1
  17. package/lib/actions/portal/serve.d.ts +17 -0
  18. package/lib/actions/portal/serve.js +36 -0
  19. package/lib/actions/portal/serve.js.map +1 -0
  20. package/lib/actions/portal/toc/new-toc.d.ts +4 -1
  21. package/lib/actions/portal/toc/new-toc.js +37 -34
  22. package/lib/actions/portal/toc/new-toc.js.map +1 -1
  23. package/lib/actions/sdk/generate.d.ts +13 -0
  24. package/lib/actions/sdk/generate.js +49 -0
  25. package/lib/actions/sdk/generate.js.map +1 -0
  26. package/lib/application/portal/serve/portal-watcher.d.ts +11 -0
  27. package/lib/application/portal/serve/portal-watcher.js +67 -0
  28. package/lib/application/portal/serve/portal-watcher.js.map +1 -0
  29. package/lib/application/portal/serve/serve-handler.d.ts +16 -0
  30. package/lib/application/portal/serve/serve-handler.js +91 -0
  31. package/lib/application/portal/serve/serve-handler.js.map +1 -0
  32. package/lib/application/portal/serve/watcher-handler.d.ts +10 -0
  33. package/lib/application/portal/serve/watcher-handler.js +51 -0
  34. package/lib/application/portal/serve/watcher-handler.js.map +1 -0
  35. package/lib/application/portal/toc/sdl-parser.d.ts +2 -1
  36. package/lib/application/portal/toc/sdl-parser.js +4 -4
  37. package/lib/application/portal/toc/sdl-parser.js.map +1 -1
  38. package/lib/client-utils/auth-manager.d.ts +7 -2
  39. package/lib/client-utils/auth-manager.js +24 -7
  40. package/lib/client-utils/auth-manager.js.map +1 -1
  41. package/lib/client-utils/sdk-client.d.ts +0 -1
  42. package/lib/client-utils/sdk-client.js +7 -38
  43. package/lib/client-utils/sdk-client.js.map +1 -1
  44. package/lib/commands/api/transform.d.ts +2 -2
  45. package/lib/commands/api/transform.js +10 -19
  46. package/lib/commands/api/transform.js.map +1 -1
  47. package/lib/commands/api/validate.d.ts +1 -1
  48. package/lib/commands/api/validate.js +5 -13
  49. package/lib/commands/api/validate.js.map +1 -1
  50. package/lib/commands/auth/login.d.ts +2 -1
  51. package/lib/commands/auth/login.js +19 -65
  52. package/lib/commands/auth/login.js.map +1 -1
  53. package/lib/commands/auth/logout.js +2 -6
  54. package/lib/commands/auth/logout.js.map +1 -1
  55. package/lib/commands/auth/status.js +3 -6
  56. package/lib/commands/auth/status.js.map +1 -1
  57. package/lib/commands/portal/copilot.d.ts +12 -0
  58. package/lib/commands/portal/copilot.js +35 -0
  59. package/lib/commands/portal/copilot.js.map +1 -0
  60. package/lib/commands/portal/generate.d.ts +7 -10
  61. package/lib/commands/portal/generate.js +18 -83
  62. package/lib/commands/portal/generate.js.map +1 -1
  63. package/lib/commands/portal/quickstart.d.ts +2 -2
  64. package/lib/commands/portal/quickstart.js +58 -29
  65. package/lib/commands/portal/quickstart.js.map +1 -1
  66. package/lib/commands/portal/recipe/new.d.ts +1 -3
  67. package/lib/commands/portal/recipe/new.js +21 -27
  68. package/lib/commands/portal/recipe/new.js.map +1 -1
  69. package/lib/commands/portal/serve.d.ts +7 -6
  70. package/lib/commands/portal/serve.js +62 -112
  71. package/lib/commands/portal/serve.js.map +1 -1
  72. package/lib/commands/portal/toc/new.d.ts +4 -5
  73. package/lib/commands/portal/toc/new.js +26 -37
  74. package/lib/commands/portal/toc/new.js.map +1 -1
  75. package/lib/commands/sdk/generate.d.ts +8 -6
  76. package/lib/commands/sdk/generate.js +53 -124
  77. package/lib/commands/sdk/generate.js.map +1 -1
  78. package/lib/controllers/portal/quickstart.d.ts +0 -2
  79. package/lib/controllers/portal/quickstart.js +2 -60
  80. package/lib/controllers/portal/quickstart.js.map +1 -1
  81. package/lib/infrastructure/api-utils.d.ts +9 -0
  82. package/lib/infrastructure/api-utils.js +33 -0
  83. package/lib/infrastructure/api-utils.js.map +1 -0
  84. package/lib/infrastructure/env-info.d.ts +8 -0
  85. package/lib/infrastructure/env-info.js +37 -0
  86. package/lib/infrastructure/env-info.js.map +1 -0
  87. package/lib/infrastructure/file-service.d.ts +15 -0
  88. package/lib/infrastructure/file-service.js +61 -0
  89. package/lib/infrastructure/file-service.js.map +1 -0
  90. package/lib/infrastructure/services/api-service.d.ts +10 -0
  91. package/lib/infrastructure/services/api-service.js +52 -0
  92. package/lib/infrastructure/services/api-service.js.map +1 -0
  93. package/lib/infrastructure/services/auth-service.d.ts +11 -0
  94. package/lib/infrastructure/services/auth-service.js +33 -0
  95. package/lib/infrastructure/services/auth-service.js.map +1 -0
  96. package/lib/infrastructure/services/portal-service.d.ts +7 -4
  97. package/lib/infrastructure/services/portal-service.js +70 -49
  98. package/lib/infrastructure/services/portal-service.js.map +1 -1
  99. package/lib/infrastructure/services/telemetry-service.d.ts +8 -0
  100. package/lib/infrastructure/services/telemetry-service.js +40 -0
  101. package/lib/infrastructure/services/telemetry-service.js.map +1 -0
  102. package/lib/infrastructure/tmp-extensions.d.ts +2 -0
  103. package/lib/infrastructure/tmp-extensions.js +6 -0
  104. package/lib/infrastructure/tmp-extensions.js.map +1 -0
  105. package/lib/infrastructure/zip-service.d.ts +6 -0
  106. package/lib/infrastructure/zip-service.js +25 -0
  107. package/lib/infrastructure/zip-service.js.map +1 -0
  108. package/lib/prompts/auth/login.d.ts +5 -0
  109. package/lib/prompts/auth/login.js +13 -0
  110. package/lib/prompts/auth/login.js.map +1 -0
  111. package/lib/prompts/portal/common/base-prompts.d.ts +7 -0
  112. package/lib/prompts/portal/common/base-prompts.js +19 -0
  113. package/lib/prompts/portal/common/base-prompts.js.map +1 -0
  114. package/lib/prompts/portal/copilot.d.ts +6 -0
  115. package/lib/prompts/portal/copilot.js +35 -0
  116. package/lib/prompts/portal/copilot.js.map +1 -0
  117. package/lib/prompts/portal/generate.d.ts +3 -2
  118. package/lib/prompts/portal/generate.js +21 -36
  119. package/lib/prompts/portal/generate.js.map +1 -1
  120. package/lib/prompts/portal/quickstart.d.ts +8 -9
  121. package/lib/prompts/portal/quickstart.js +44 -32
  122. package/lib/prompts/portal/quickstart.js.map +1 -1
  123. package/lib/prompts/portal/recipe/new-recipe.d.ts +1 -0
  124. package/lib/prompts/portal/recipe/new-recipe.js +18 -8
  125. package/lib/prompts/portal/recipe/new-recipe.js.map +1 -1
  126. package/lib/prompts/portal/serve.d.ts +4 -6
  127. package/lib/prompts/portal/serve.js +24 -15
  128. package/lib/prompts/portal/serve.js.map +1 -1
  129. package/lib/prompts/portal/toc/new-toc.d.ts +3 -2
  130. package/lib/prompts/portal/toc/new-toc.js +11 -14
  131. package/lib/prompts/portal/toc/new-toc.js.map +1 -1
  132. package/lib/prompts/sdk/generate.d.ts +11 -0
  133. package/lib/prompts/sdk/generate.js +42 -0
  134. package/lib/prompts/sdk/generate.js.map +1 -0
  135. package/lib/types/api/account.d.ts +10 -0
  136. package/lib/types/api/account.js +2 -0
  137. package/lib/types/api/account.js.map +1 -0
  138. package/lib/types/build/build.d.ts +14 -0
  139. package/lib/types/build/build.js +4 -0
  140. package/lib/types/build/build.js.map +1 -0
  141. package/lib/types/build-context.d.ts +13 -0
  142. package/lib/types/build-context.js +30 -0
  143. package/lib/types/build-context.js.map +1 -0
  144. package/lib/types/events/domain-event.d.ts +8 -0
  145. package/lib/types/events/domain-event.js +11 -0
  146. package/lib/types/events/domain-event.js.map +1 -0
  147. package/lib/types/events/recipe-creation-failed.d.ts +5 -0
  148. package/lib/types/events/recipe-creation-failed.js +8 -0
  149. package/lib/types/events/recipe-creation-failed.js.map +1 -0
  150. package/lib/types/events/toc-creation-failed.d.ts +5 -0
  151. package/lib/types/events/toc-creation-failed.js +8 -0
  152. package/lib/types/events/toc-creation-failed.js.map +1 -0
  153. package/lib/types/file/directoryPath.d.ts +7 -0
  154. package/lib/types/file/directoryPath.js +16 -0
  155. package/lib/types/file/directoryPath.js.map +1 -0
  156. package/lib/types/file/fileName.d.ts +5 -0
  157. package/lib/types/file/fileName.js +9 -0
  158. package/lib/types/file/fileName.js.map +1 -0
  159. package/lib/types/file/filePath.d.ts +8 -0
  160. package/lib/types/file/filePath.js +11 -0
  161. package/lib/types/file/filePath.js.map +1 -0
  162. package/lib/types/flags-provider.d.ts +15 -0
  163. package/lib/types/flags-provider.js +34 -0
  164. package/lib/types/flags-provider.js.map +1 -0
  165. package/lib/types/portal/generate.d.ts +0 -13
  166. package/lib/types/portal/quickstart.d.ts +1 -1
  167. package/lib/types/portal/serve.d.ts +13 -0
  168. package/lib/types/portal/serve.js +2 -0
  169. package/lib/types/portal/serve.js.map +1 -0
  170. package/lib/types/portal-context.d.ts +11 -0
  171. package/lib/types/portal-context.js +28 -0
  172. package/lib/types/portal-context.js.map +1 -0
  173. package/lib/types/sdk/generate.d.ts +8 -8
  174. package/lib/types/sdk/generate.js +10 -10
  175. package/lib/types/sdk/generate.js.map +1 -1
  176. package/lib/types/sdk-context.d.ts +13 -0
  177. package/lib/types/sdk-context.js +28 -0
  178. package/lib/types/sdk-context.js.map +1 -0
  179. package/lib/types/spec-context.d.ts +7 -0
  180. package/lib/types/spec-context.js +12 -0
  181. package/lib/types/spec-context.js.map +1 -0
  182. package/lib/utils/utils.d.ts +1 -4
  183. package/lib/utils/utils.js +18 -32
  184. package/lib/utils/utils.js.map +1 -1
  185. package/lib/validators/common/directoryValidator.d.ts +3 -7
  186. package/lib/validators/common/directoryValidator.js +10 -37
  187. package/lib/validators/common/directoryValidator.js.map +1 -1
  188. package/lib/validators/portal/serve-validator.d.ts +6 -0
  189. package/lib/validators/portal/serve-validator.js +15 -0
  190. package/lib/validators/portal/serve-validator.js.map +1 -0
  191. package/package.json +6 -3
  192. package/lib/controllers/portal/generate.d.ts +0 -3
  193. package/lib/controllers/portal/generate.js +0 -106
  194. package/lib/controllers/portal/generate.js.map +0 -1
  195. package/lib/controllers/portal/serve.d.ts +0 -3
  196. package/lib/controllers/portal/serve.js +0 -136
  197. package/lib/controllers/portal/serve.js.map +0 -1
  198. package/lib/controllers/sdk/generate.d.ts +0 -4
  199. package/lib/controllers/sdk/generate.js +0 -61
  200. package/lib/controllers/sdk/generate.js.map +0 -1
  201. package/lib/services/portal/server.d.ts +0 -14
  202. package/lib/services/portal/server.js +0 -97
  203. package/lib/services/portal/server.js.map +0 -1
  204. package/lib/validators/common/portValidator.d.ts +0 -5
  205. package/lib/validators/common/portValidator.js +0 -16
  206. package/lib/validators/common/portValidator.js.map +0 -1
  207. package/lib/validators/portal/serveValidator.d.ts +0 -6
  208. package/lib/validators/portal/serveValidator.js +0 -17
  209. package/lib/validators/portal/serveValidator.js.map +0 -1
@@ -0,0 +1,49 @@
1
+ import { ZipService } from "../../infrastructure/zip-service.js";
2
+ import { FileService } from "../../infrastructure/file-service.js";
3
+ import { PortalService } from "../../infrastructure/services/portal-service.js";
4
+ import { FilePath } from "../../types/file/filePath.js";
5
+ import { FileName } from "../../types/file/fileName.js";
6
+ import { ActionResult } from "../action-result.js";
7
+ import { withDirPath } from "../../infrastructure/tmp-extensions.js";
8
+ import { SdkContext } from "../../types/sdk-context.js";
9
+ import { SpecContext } from "../../types/spec-context.js";
10
+ import { SdkGeneratePrompts } from "../../prompts/sdk/generate.js";
11
+ export class GenerateAction {
12
+ constructor(configDir, authKey = null) {
13
+ this.prompts = new SdkGeneratePrompts();
14
+ this.zipArchiver = new ZipService();
15
+ this.fileService = new FileService();
16
+ this.portalService = new PortalService();
17
+ this.execute = async (specDirectory, sdkDirectory, platform, force, zipSdk) => {
18
+ if (specDirectory.isEqual(sdkDirectory)) {
19
+ return ActionResult.error(`The spec directory and sdk directory cannot be the same: "${specDirectory}"`);
20
+ }
21
+ const specContext = new SpecContext(specDirectory);
22
+ if (!await specContext.validate()) {
23
+ return ActionResult.error(`The spec directory is either empty or invalid: "${specDirectory}"`);
24
+ }
25
+ const sdkContext = new SdkContext(sdkDirectory, platform);
26
+ if (!force && (await sdkContext.exists()) && !(await this.prompts.overwriteSdk(sdkDirectory))) {
27
+ return ActionResult.error("Please enter a different destination folder or remove the existing files and try again.");
28
+ }
29
+ return await withDirPath(async (tempDirectory) => {
30
+ this.prompts.displaySdkGenerationMessage();
31
+ const specZipPath = new FilePath(tempDirectory, new FileName("spec.zip"));
32
+ await this.zipArchiver.archive(specDirectory, specZipPath);
33
+ const response = await this.portalService.generateSdk(specZipPath, platform, this.configDir, this.authKey);
34
+ if (!response.isSuccess()) {
35
+ this.prompts.displaySdkGenerationErrorMessage();
36
+ return ActionResult.error(response.error);
37
+ }
38
+ const tempSdkFilePath = new FilePath(tempDirectory, new FileName("sdk.zip"));
39
+ await this.fileService.writeFile(tempSdkFilePath, response.value);
40
+ await sdkContext.save(tempSdkFilePath, zipSdk);
41
+ this.prompts.displaySdkGenerationSuccessMessage();
42
+ return ActionResult.success();
43
+ });
44
+ };
45
+ this.configDir = configDir;
46
+ this.authKey = authKey;
47
+ }
48
+ }
49
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/actions/sdk/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,iDAAiD,CAAC;AAEhF,OAAO,EAAE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AAC;IACzB,CAAC;CAgDF"}
@@ -0,0 +1,11 @@
1
+ import chokidar from "chokidar";
2
+ import { ServePaths } from "../../../types/portal/serve.js";
3
+ import { DirectoryPath } from "../../../types/file/directoryPath.js";
4
+ import { ActionResult } from "../../../actions/action-result.js";
5
+ export declare class PortalWatcher {
6
+ private watcherHandler;
7
+ constructor();
8
+ watchAndRegeneratePortalOnChange(paths: ServePaths, ignoredPaths: string[], generatePortal: (buildDirectory: DirectoryPath, portalDirectory: DirectoryPath, force: boolean, zipPortal: boolean) => Promise<ActionResult>): Promise<chokidar.FSWatcher>;
9
+ cancelPendingOperations(): void;
10
+ protected handleFileChange(paths: ServePaths, eventQueue: Map<string, string>, eventId: string, generatePortal: (buildDirectory: DirectoryPath, portalDirectory: DirectoryPath, force: boolean, zipPortal: boolean) => Promise<ActionResult>): Promise<void>;
11
+ }
@@ -0,0 +1,67 @@
1
+ import * as path from "path";
2
+ import chokidar from "chokidar";
3
+ import crypto from "crypto";
4
+ import console from "console";
5
+ import { Mutex } from "async-mutex";
6
+ import { WatcherHandler } from "./watcher-handler.js";
7
+ import { DirectoryPath } from "../../../types/file/directoryPath.js";
8
+ export class PortalWatcher {
9
+ constructor() {
10
+ this.watcherHandler = new WatcherHandler();
11
+ }
12
+ async watchAndRegeneratePortalOnChange(paths, ignoredPaths, generatePortal) {
13
+ // Convert ignoredPaths to absolute paths for consistent comparison
14
+ const absoluteIgnoredPaths = [...ignoredPaths.filter((ignoredPath) => ignoredPath.trim() !== "")].map((ignoredPath) => path.resolve(paths.sourceDirectoryPath, ignoredPath));
15
+ //Regex matches any hidden files and folders.
16
+ const watcher = chokidar.watch(paths.sourceDirectoryPath, {
17
+ ignored: [...absoluteIgnoredPaths, /(^|[/\\])\..+/],
18
+ ignoreInitial: true,
19
+ persistent: true,
20
+ awaitWriteFinish: true,
21
+ atomic: true
22
+ });
23
+ const deletedDirectories = new Set();
24
+ const eventQueue = new Map();
25
+ const mutex = new Mutex();
26
+ watcher
27
+ .on("all", async (event, path) => {
28
+ if (event == "unlinkDir") {
29
+ deletedDirectories.add(path);
30
+ }
31
+ if (event == "unlink") {
32
+ for (const dir of deletedDirectories) {
33
+ if (path.startsWith(dir)) {
34
+ return;
35
+ }
36
+ }
37
+ }
38
+ const eventId = `${Date.now()}-${crypto.randomUUID()}`;
39
+ await mutex.runExclusive(async () => {
40
+ eventQueue.clear();
41
+ eventQueue.set(eventId, path);
42
+ });
43
+ await this.watcherHandler.execute(async () => {
44
+ await this.handleFileChange(paths, eventQueue, eventId, generatePortal);
45
+ });
46
+ })
47
+ .on("error", () => {
48
+ console.error("An unexpected error occurred while watching your build folder for changes. Please try again later. If the issue persists, contact our team at support@apimatic.io");
49
+ watcher.close();
50
+ });
51
+ return watcher;
52
+ }
53
+ // TODO: Remove this method. Figure out a better way to do this.
54
+ cancelPendingOperations() {
55
+ if (this.watcherHandler) {
56
+ this.watcherHandler.cancel();
57
+ }
58
+ }
59
+ async handleFileChange(paths, eventQueue, eventId, generatePortal) {
60
+ if (!eventQueue.has(eventId)) {
61
+ return;
62
+ }
63
+ const result = await generatePortal(new DirectoryPath(paths.sourceDirectoryPath), new DirectoryPath(paths.destinationDirectoryPath), true, false);
64
+ result.map((error) => console.log(error));
65
+ }
66
+ }
67
+ //# sourceMappingURL=portal-watcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portal-watcher.js","sourceRoot":"","sources":["../../../../src/application/portal/serve/portal-watcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAGrE,MAA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AG,CAAC,KAAK,CAAC,CAAC,CAAC;IAC5C,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ import { Result } from "../../../types/common/result.js";
2
+ import { ServeFlags, ServePaths } from "../../../types/portal/serve.js";
3
+ import { DirectoryPath } from "../../../types/file/directoryPath.js";
4
+ import { ActionResult } from "../../../actions/action-result.js";
5
+ export declare class ServeHandler {
6
+ private server;
7
+ private liveReloadServer;
8
+ private readonly app;
9
+ private readonly portalWatcher;
10
+ constructor();
11
+ setupServer(generatedPortalArtifactsDirectoryPath: string): Promise<Result<string, string>>;
12
+ startServer(paths: ServePaths, flags: ServeFlags, ignoredPaths: string[], generatePortal: (buildDirectory: DirectoryPath, portalDirectory: DirectoryPath, force: boolean, zipPortal: boolean) => Promise<ActionResult>, displayShutdownMessages?: boolean): Promise<Result<boolean, string>>;
13
+ private stopServer;
14
+ private createLiveReloadServer;
15
+ private getPortForReloadServer;
16
+ }
@@ -0,0 +1,91 @@
1
+ import express from "express";
2
+ import livereload from "livereload";
3
+ import connectLivereload from "connect-livereload";
4
+ import open from "open";
5
+ import process from "process";
6
+ import getPort from "get-port";
7
+ import console from "console";
8
+ import { Result } from "../../../types/common/result.js";
9
+ import { PortalWatcher } from "./portal-watcher.js";
10
+ export class ServeHandler {
11
+ constructor() {
12
+ this.app = express();
13
+ this.portalWatcher = new PortalWatcher();
14
+ }
15
+ //TODO: Needs to be refactored after refactoring quickstart.
16
+ async setupServer(generatedPortalArtifactsDirectoryPath) {
17
+ const createLiveReloadServerResult = await this.createLiveReloadServer(generatedPortalArtifactsDirectoryPath);
18
+ if (createLiveReloadServerResult.isFailed()) {
19
+ return Result.failure(createLiveReloadServerResult.error);
20
+ }
21
+ this.app.use(express.static(generatedPortalArtifactsDirectoryPath, { extensions: ["html"] }));
22
+ return Result.success(`Server is set up and serving files from ${generatedPortalArtifactsDirectoryPath}`);
23
+ }
24
+ //TODO: Needs to be refactored after refactoring quickstart.
25
+ async startServer(paths, flags, ignoredPaths, generatePortal, displayShutdownMessages = true) {
26
+ return new Promise((resolve, reject) => {
27
+ this.server = this.app
28
+ .listen(flags.port, async () => {
29
+ if (flags.open) {
30
+ await open(`http://localhost:${flags.port}`);
31
+ }
32
+ if (!flags["no-reload"]) {
33
+ await this.portalWatcher.watchAndRegeneratePortalOnChange(paths, ignoredPaths, generatePortal);
34
+ }
35
+ if (process.platform !== "darwin") {
36
+ //For non-macOS users.
37
+ if (process.stdin.setRawMode) {
38
+ process.stdin.setRawMode(false);
39
+ }
40
+ }
41
+ resolve(Result.success(true));
42
+ })
43
+ .on("error", () => {
44
+ reject(new Error(`Something went wrong while serving your portal. Please try again later. If the issue persists, contact our team at support@apimatic.io`));
45
+ });
46
+ const shutdown = async () => {
47
+ if (displayShutdownMessages) {
48
+ console.log("Shutting down server...");
49
+ }
50
+ await this.stopServer();
51
+ if (displayShutdownMessages) {
52
+ console.log("Server shut down successfully.");
53
+ }
54
+ resolve(Result.success(true));
55
+ process.exit(0);
56
+ };
57
+ process.on("SIGINT", shutdown);
58
+ process.on("SIGTERM", shutdown);
59
+ });
60
+ }
61
+ async stopServer() {
62
+ this.portalWatcher.cancelPendingOperations();
63
+ if (this.liveReloadServer) {
64
+ this.liveReloadServer.close();
65
+ }
66
+ if (this.server) {
67
+ await new Promise((resolve) => {
68
+ this.server.close(() => resolve());
69
+ });
70
+ }
71
+ }
72
+ async createLiveReloadServer(generatedPortalPath) {
73
+ try {
74
+ const availablePort = await this.getPortForReloadServer();
75
+ this.liveReloadServer = livereload.createServer({
76
+ port: availablePort
77
+ });
78
+ this.liveReloadServer.watch(generatedPortalPath);
79
+ this.app.use(connectLivereload());
80
+ return Result.success("Live Reload Server setup successfully.");
81
+ }
82
+ catch (_a) {
83
+ return Result.failure("An unexpected error occurred while serving your portal, please try again later. If the issue persists, contact our team at support@apimatic.io for assistance.");
84
+ }
85
+ }
86
+ async getPortForReloadServer() {
87
+ const defaultPorts = [35729, 35730, 35731];
88
+ return await getPort({ port: defaultPorts });
89
+ }
90
+ }
91
+ //# sourceMappingURL=serve-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve-handler.js","sourceRoot":"","sources":["../../../../src/application/portal/serve/serve-handler.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,iBAAiB,MAAM,oBAAoB,CAAC;AACnD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIpD,MAAM,OAAO,YAAY;IAMvB;QACE,IAAI,CAAC,GAAG,GAAG,OAAO,EAAE,CAAC;QACrB,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC;IAC3C,CAAC;IAED,4DAA4D;IACrD,KAAK,CAAC,WAAW,CAAC,qCAA6C;QACpE,MAAM,4BAA4B,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,qCAAqC,CAAC,CAAC;QAC9G,IAAI,4BAA4B,CAAC,QAAQ,EAAE,EAAE,CAAC;YAC5C,OAAO,MAAM,CAAC,OAAO,CAAC,4BAA4B,CAAC,KAAM,CAAC,CAAC;QAC7D,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,qCAAqC,EAAE,EAAE,UAAU,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QAE9F,OAAO,MAAM,CAAC,OAAO,CAAC,2CAA2C,qCAAqC,EAAE,CAAC,CAAC;IAC5G,CAAC;IAED,4DAA4D;IACrD,KAAK,CAAC,WAAW,CACtB,KAAiB,EACjB,KAAiB,EACjB,YAAsB,EACtB,cAK0B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QAClC,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAC3C,OAAO,MAAM,OAAO,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;IAC/C,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ export declare class WatcherHandler {
2
+ private isProcessing;
3
+ private latestHandler;
4
+ private debounceTimer;
5
+ private readonly debounceMs;
6
+ constructor(debounceMs?: number);
7
+ execute(handler: () => Promise<void>): Promise<void>;
8
+ private scheduleExecution;
9
+ cancel(): void;
10
+ }
@@ -0,0 +1,51 @@
1
+ export class WatcherHandler {
2
+ constructor(debounceMs = 500) {
3
+ this.isProcessing = false;
4
+ this.latestHandler = null;
5
+ this.debounceTimer = null;
6
+ this.debounceMs = debounceMs;
7
+ }
8
+ async execute(handler) {
9
+ // Always store the latest handler
10
+ this.latestHandler = handler;
11
+ // If already processing, don't start a new timer. Just update the latest handler
12
+ if (this.isProcessing) {
13
+ return;
14
+ }
15
+ // Clear any existing timer
16
+ if (this.debounceTimer) {
17
+ clearTimeout(this.debounceTimer);
18
+ }
19
+ // Set up debounced execution
20
+ this.scheduleExecution();
21
+ }
22
+ scheduleExecution() {
23
+ this.debounceTimer = setTimeout(async () => {
24
+ if (this.isProcessing) {
25
+ return;
26
+ }
27
+ this.isProcessing = true;
28
+ this.debounceTimer = null;
29
+ try {
30
+ // Execute the latest handler if it exists
31
+ if (this.latestHandler) {
32
+ const currentHandler = this.latestHandler;
33
+ this.latestHandler = null;
34
+ await currentHandler();
35
+ }
36
+ }
37
+ finally {
38
+ this.isProcessing = false;
39
+ }
40
+ }, this.debounceMs);
41
+ }
42
+ // Method to clear any pending execution.
43
+ cancel() {
44
+ if (this.debounceTimer) {
45
+ clearTimeout(this.debounceTimer);
46
+ this.debounceTimer = null;
47
+ }
48
+ this.latestHandler = null;
49
+ }
50
+ }
51
+ //# sourceMappingURL=watcher-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watcher-handler.js","sourceRoot":"","sources":["../../../../src/application/portal/serve/watcher-handler.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,cAAc;IAMzB,YAAY,aAAqB,GAAG;QAL5B,iBAAY,GAAG,KAAK,CAAC;QACrB,kBAAa,GAAiC,IAAI,CAAC;QACnD,kBAAa,GAA0B,IAAI,CAAC;QAIlD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAA4B;QACxC,kCAAkC;QAClC,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC;QAE7B,iFAAiF;QACjF,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,OAAO;QACT,CAAC;QAED,2BAA2B;QAC3B,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACvB,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACnC,CAAC;QAED,6BAA6B;QAC7B,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC3B,CAAC;IAEO,iBAAiB;QACvB,IAAI,CAAC,aAAa,GAAG,UAAU,CAAC,KAAK,IAAI,EAAE;YACzC,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;gBACtB,OAAO;YACT,CAAC;YAED,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;YACzB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;YAE1B,IAAI,CAAC;gBACH,0CAA0C;gBAC1C,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;oBACvB,MAAM,cAAc,GAAG,IAAI,CAAC,aAAa,CAAC;oBAC1C,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;oBAC1B,MAAM,cAAc,EAAE,CAAC;gBACzB,CAAC;YACH,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;YAC5B,CAAC;QACH,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACtB,CAAC;IAED,yCAAyC;IAClC,MAAM;QACX,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACvB,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YACjC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC5B,CAAC;QACD,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IAC5B,CAAC;CACF"}
@@ -2,10 +2,11 @@ import { PortalService } from "../../../infrastructure/services/portal-service.j
2
2
  import { TocEndpoint, TocModel } from "../../../types/toc/toc.js";
3
3
  import { Result } from "../../../types/common/result.js";
4
4
  import { SdlEndpoint } from "../../../types/sdl/sdl.js";
5
+ import { DirectoryPath } from "../../../types/file/directoryPath.js";
5
6
  export declare class SdlParser {
6
7
  private readonly portalService;
7
8
  constructor(portalService: PortalService);
8
- getTocComponentsFromSdl(specFolderPath: string, workingDirectory: string, configDir: string): Promise<Result<{
9
+ getTocComponentsFromSdl(specFolderPath: string, buildDirectory: DirectoryPath, configDir: string): Promise<Result<{
9
10
  endpointGroups: Map<string, TocEndpoint[]>;
10
11
  models: TocModel[];
11
12
  }, string>>;
@@ -1,12 +1,12 @@
1
1
  import * as path from "path";
2
- import { validateAndZipPortalSource, deleteFile } from "../../../utils/utils.js";
2
+ import { zipPortalSource, deleteFile } from "../../../utils/utils.js";
3
3
  import { Result } from "../../../types/common/result.js";
4
4
  export class SdlParser {
5
5
  constructor(portalService) {
6
6
  this.portalService = portalService;
7
7
  }
8
- async getTocComponentsFromSdl(specFolderPath, workingDirectory, configDir) {
9
- const sourceSpecInputZipFilePath = await validateAndZipPortalSource(specFolderPath, path.join(workingDirectory, ".spec_source.zip"));
8
+ async getTocComponentsFromSdl(specFolderPath, buildDirectory, configDir) {
9
+ const sourceSpecInputZipFilePath = await zipPortalSource(specFolderPath, path.join(buildDirectory.toString(), ".spec_source.zip"));
10
10
  try {
11
11
  const result = await this.portalService.generateSdl(sourceSpecInputZipFilePath, configDir);
12
12
  if (!result.isSuccess()) {
@@ -22,7 +22,7 @@ export class SdlParser {
22
22
  }
23
23
  }
24
24
  async getEndpointGroupsFromSdl(specFolderPath, contentFolderPath, configDir) {
25
- const sourceSpecInputZipFilePath = await validateAndZipPortalSource(specFolderPath, path.join(contentFolderPath, ".spec_source.zip"));
25
+ const sourceSpecInputZipFilePath = await zipPortalSource(specFolderPath, path.join(contentFolderPath, ".spec_source.zip"));
26
26
  const sdlResult = await this.portalService.generateSdl(sourceSpecInputZipFilePath, configDir);
27
27
  if (!sdlResult.isSuccess()) {
28
28
  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.");
@@ -1 +1 @@
1
- {"version":3,"file":"sdl-parser.js","sourceRoot":"","sources":["../../../../src/application/portal/toc/sdl-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,0BAA0B,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAGzD,MAAM,OAAO,SAAS;IACpB,YAA6B,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;IAAG,CAAC;IAEtD,KAAK,CAAC,uBAAuB,CAClC,cAAsB,EACtB,gBAAwB,EACxB,SAAiB;QAEjB,MAAM,0BAA0B,GAAG,MAAM,0BAA0B,CACjE,cAAc,EACd,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAChD,CAAC;QAEF,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,0BAA0B,EAAE,SAAS,CAAC,CAAC;YAE3F,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC;gBACxB,OAAO,MAAM,CAAC,OAAO,CACnB,sIAAsI,CACvI,CAAC;YACJ,CAAC;YAED,MAAM,GAAG,GAAQ,MAAM,CAAC,KAAM,CAAC;YAC/B,MAAM,cAAc,GAAG,IAA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,EAAE,CAAC,CAAC;YAChC,QAAQ,EAAE,IAAI;YACd,IAAI,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"}
@@ -1,6 +1,8 @@
1
+ import { DirectoryPath } from "../types/file/directoryPath.js";
1
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 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,5 +1,5 @@
1
1
  import * as path from "path";
2
- import fsExtra from "fs-extra";
2
+ import fs from "fs-extra";
3
3
  /**
4
4
  *
5
5
  * @param {string} configDir <- Directory with user configuration
@@ -7,7 +7,7 @@ import fsExtra from "fs-extra";
7
7
  */
8
8
  export async function getAuthInfo(configDir) {
9
9
  try {
10
- const data = JSON.parse(await fsExtra.readFile(path.join(configDir, "config.json"), "utf8"));
10
+ const data = JSON.parse(await fs.readFile(path.join(configDir, "config.json"), "utf8"));
11
11
  return data;
12
12
  }
13
13
  catch (e) {
@@ -16,14 +16,31 @@ export async function getAuthInfo(configDir) {
16
16
  }
17
17
  /**
18
18
  *
19
- * @param {AuthInfo} credentials
19
+ * @param {string} email
20
+ * @param {string} authKey
21
+ * @param {string} isTelemetryOptedOut
20
22
  * @param {string} configDir <- Directory with user configuration
21
23
  * //Function to set credentials.
22
24
  */
23
- export 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
+ };
24
41
  const configFilePath = path.join(configDir, "config.json");
25
- if (!fsExtra.existsSync(configFilePath))
26
- fsExtra.createFileSync(configFilePath);
27
- return await fsExtra.writeFile(configFilePath, JSON.stringify(credentials));
42
+ if (!fs.existsSync(configFilePath))
43
+ fs.createFileSync(configFilePath);
44
+ return await fs.writeFile(configFilePath, JSON.stringify(credentials));
28
45
  }
29
46
  //# sourceMappingURL=auth-manager.js.map
@@ -1 +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,OAAO,MAAM,UAAU,CAAC;AAM/B;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,SAAiB;IACjD,IAAI,CAAC;QACH,MAAM,IAAI,GAAoB,IAAI,CAAC,KAAK,CAAC,MAAM,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;QAC9G,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,WAAqB,EAAE,SAAiB;IACxE,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;IAE3D,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC;QAAE,OAAO,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;IAEhF,OAAO,MAAM,OAAO,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC;AAC9E,CAAC"}
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,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AC"}
@@ -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
  }
@@ -2,17 +2,9 @@ import base64 from "base-64";
2
2
  import axios from "axios";
3
3
  import { Client } from "@apimatic/sdk";
4
4
  import { baseURL } from "../config/env.js";
5
- import { setAuthInfo, getAuthInfo } from "./auth-manager.js";
5
+ import { getAuthInfo, removeAuthInfo, setAuthInfo } from "./auth-manager.js";
6
+ import { DirectoryPath } from "../types/file/directoryPath.js";
6
7
  export class SDKClient {
7
- constructor() {
8
- this.setAuthKey = (authKey, configDir) => {
9
- setAuthInfo({
10
- email: "",
11
- authKey
12
- }, configDir);
13
- return "Authentication key successfully set";
14
- };
15
- }
16
8
  /**
17
9
  * The static method that controls the access to the SDKClient instance.
18
10
  *
@@ -30,36 +22,14 @@ export class SDKClient {
30
22
  * executed on its instance.
31
23
  */
32
24
  async login(email, password, configDir) {
33
- let storedAuthInfo = await getAuthInfo(configDir);
34
- // If no config file or no credentials exist in the config file
35
- if (!storedAuthInfo) {
36
- storedAuthInfo = { email: "", authKey: "" };
37
- }
38
25
  const credentials = { email, password };
39
26
  const authKey = await this.getAuthKey(credentials);
40
- if (storedAuthInfo.email !== email) {
41
- setAuthInfo({
42
- email,
43
- authKey
44
- }, configDir);
45
- return "Logged in";
46
- }
47
- else if (authKey === storedAuthInfo.authKey) {
48
- return "Already logged in";
49
- }
50
- else {
51
- setAuthInfo({
52
- email,
53
- authKey
54
- }, configDir);
55
- return "Logged in";
56
- }
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;
57
30
  }
58
31
  async logout(configDir) {
59
- setAuthInfo({
60
- email: "",
61
- authKey: ""
62
- }, configDir);
32
+ await removeAuthInfo(configDir);
63
33
  return "Logged out";
64
34
  }
65
35
  async status(configDir) {
@@ -112,8 +82,7 @@ export class SDKClient {
112
82
  }
113
83
  };
114
84
  const response = await axios.get(SDKClient.authAPI, config);
115
- const authKey = response.data.EncryptedValue;
116
- return authKey;
85
+ return response.data.EncryptedValue;
117
86
  }
118
87
  }
119
88
  SDKClient.authAPI = `${baseURL}/account/authkey`;
@@ -1 +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,EAAE,WAAW,EAAE,WAAW,EAAY,MAAM,mBAAmB,CAAC;AASvE,MAAM,OAAO,SAAS;IAAtB;QA8HS,eAAU,GAAG,CAAC,OAAe,EAAE,SAAiB,EAAE,EAAE;YACzD,WAAW,CACT;gBACE,KAAK,EAAE,EAAE;gBACT,OAAO;aACR,EACD,SAAS,CACV,CAAC;YACF,OAAO,qCAAqC,CAAC;QAC/C,CAAC,CAAC;IACJ,CAAC;IAnIC;;;;;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,IAAI,cAAc,GAAoB,MAAM,WAAW,CAAC,SAAS,CAAC,CAAC;QAEnE,+DAA+D;QAC/D,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,cAAc,GAAG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AAE;oBACrC,aAAa,EAAE,cAAc,cAAc,CAAC,OAAO,EAAE;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"}
@@ -3,12 +3,12 @@ export default class Transform extends Command {
3
3
  static description: string;
4
4
  static examples: string[];
5
5
  static flags: {
6
+ "auth-key": import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
6
8
  format: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
7
9
  file: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
8
10
  url: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
9
11
  destination: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
10
- force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
- "auth-key": import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
12
  };
13
13
  run(): Promise<void>;
14
14
  }