@apimatic/cli 0.0.0-alpha.4 → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +308 -130
- package/bin/run.js +5 -0
- package/lib/actions/action-result.d.ts +13 -0
- package/lib/actions/action-result.js +44 -0
- package/lib/actions/action-result.js.map +1 -0
- package/lib/actions/api/transform.d.ts +15 -0
- package/lib/actions/api/transform.js +48 -0
- package/lib/actions/api/transform.js.map +1 -0
- package/lib/actions/api/validate.d.ts +12 -0
- package/lib/actions/api/validate.js +41 -0
- package/lib/actions/api/validate.js.map +1 -0
- package/lib/actions/auth/login.d.ts +13 -0
- package/lib/actions/auth/login.js +55 -0
- package/lib/actions/auth/login.js.map +1 -0
- package/lib/actions/auth/logout.d.ts +8 -0
- package/lib/actions/auth/logout.js +15 -0
- package/lib/actions/auth/logout.js.map +1 -0
- package/lib/actions/auth/status.d.ts +11 -0
- package/lib/actions/auth/status.js +26 -0
- package/lib/actions/auth/status.js.map +1 -0
- package/lib/actions/portal/copilot.d.ts +16 -0
- package/lib/actions/portal/copilot.js +89 -0
- package/lib/actions/portal/copilot.js.map +1 -0
- package/lib/actions/portal/generate.d.ts +13 -0
- package/lib/actions/portal/generate.js +59 -0
- package/lib/actions/portal/generate.js.map +1 -0
- package/lib/actions/portal/quickstart.d.ts +16 -0
- package/lib/actions/portal/quickstart.js +145 -0
- package/lib/actions/portal/quickstart.js.map +1 -0
- package/lib/actions/portal/recipe/new-recipe.d.ts +15 -0
- package/lib/actions/portal/recipe/new-recipe.js +176 -0
- package/lib/actions/portal/recipe/new-recipe.js.map +1 -0
- package/lib/actions/portal/serve.d.ts +16 -0
- package/lib/actions/portal/serve.js +119 -0
- package/lib/actions/portal/serve.js.map +1 -0
- package/lib/actions/portal/toc/new-toc.d.ts +21 -0
- package/lib/actions/portal/toc/new-toc.js +97 -0
- package/lib/actions/portal/toc/new-toc.js.map +1 -0
- package/lib/actions/sdk/generate.d.ts +13 -0
- package/lib/actions/sdk/generate.js +47 -0
- package/lib/actions/sdk/generate.js.map +1 -0
- package/lib/application/portal/recipe/portal-recipe.d.ts +8 -0
- package/lib/application/portal/recipe/portal-recipe.js +33 -0
- package/lib/application/portal/recipe/portal-recipe.js.map +1 -0
- package/lib/application/portal/recipe/recipe-generator.d.ts +21 -0
- package/lib/application/portal/recipe/recipe-generator.js +146 -0
- package/lib/application/portal/recipe/recipe-generator.js.map +1 -0
- package/lib/application/portal/toc/toc-content-parser.d.ts +5 -0
- package/lib/application/portal/toc/toc-content-parser.js +44 -0
- package/lib/application/portal/toc/toc-content-parser.js.map +1 -0
- package/lib/application/portal/toc/toc-structure-generator.d.ts +6 -0
- package/lib/application/portal/toc/toc-structure-generator.js +84 -0
- package/lib/application/portal/toc/toc-structure-generator.js.map +1 -0
- package/lib/client-utils/auth-manager.d.ts +8 -3
- package/lib/client-utils/auth-manager.js +26 -14
- package/lib/client-utils/auth-manager.js.map +1 -0
- package/lib/commands/api/transform.d.ts +11 -8
- package/lib/commands/api/transform.js +52 -105
- package/lib/commands/api/transform.js.map +1 -0
- package/lib/commands/api/validate.d.ts +8 -5
- package/lib/commands/api/validate.js +31 -63
- package/lib/commands/api/validate.js.map +1 -0
- package/lib/commands/auth/login.d.ts +4 -2
- package/lib/commands/auth/login.js +26 -51
- package/lib/commands/auth/login.js.map +1 -0
- package/lib/commands/auth/logout.d.ts +4 -2
- package/lib/commands/auth/logout.js +14 -20
- package/lib/commands/auth/logout.js.map +1 -0
- package/lib/commands/auth/status.d.ts +2 -1
- package/lib/commands/auth/status.js +18 -20
- package/lib/commands/auth/status.js.map +1 -0
- package/lib/commands/portal/copilot.d.ts +13 -0
- package/lib/commands/portal/copilot.js +34 -0
- package/lib/commands/portal/copilot.js.map +1 -0
- package/lib/commands/portal/generate.d.ts +9 -8
- package/lib/commands/portal/generate.js +31 -97
- package/lib/commands/portal/generate.js.map +1 -0
- package/lib/commands/portal/quickstart.d.ts +9 -0
- package/lib/commands/portal/quickstart.js +37 -0
- package/lib/commands/portal/quickstart.js.map +1 -0
- package/lib/commands/portal/recipe/new.d.ts +12 -0
- package/lib/commands/portal/recipe/new.js +46 -0
- package/lib/commands/portal/recipe/new.js.map +1 -0
- package/lib/commands/portal/serve.d.ts +16 -0
- package/lib/commands/portal/serve.js +54 -0
- package/lib/commands/portal/serve.js.map +1 -0
- package/lib/commands/portal/toc/new.d.ts +14 -0
- package/lib/commands/portal/toc/new.js +61 -0
- package/lib/commands/portal/toc/new.js.map +1 -0
- package/lib/commands/sdk/generate.d.ts +11 -9
- package/lib/commands/sdk/generate.js +48 -122
- package/lib/commands/sdk/generate.js.map +1 -0
- package/lib/config/axios-config.d.ts +2 -0
- package/lib/config/axios-config.js +10 -0
- package/lib/config/axios-config.js.map +1 -0
- package/lib/hooks/not-found.d.ts +3 -0
- package/lib/hooks/not-found.js +52 -0
- package/lib/hooks/not-found.js.map +1 -0
- package/lib/hooks/utils.d.ts +5 -0
- package/lib/hooks/utils.js +51 -0
- package/lib/hooks/utils.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -4
- package/lib/index.js.map +1 -0
- package/lib/infrastructure/api-utils.d.ts +9 -0
- package/lib/infrastructure/api-utils.js +34 -0
- package/lib/infrastructure/api-utils.js.map +1 -0
- package/lib/infrastructure/debounce-service.d.ts +10 -0
- package/lib/infrastructure/debounce-service.js +52 -0
- package/lib/infrastructure/debounce-service.js.map +1 -0
- package/lib/infrastructure/env-info.d.ts +12 -0
- package/lib/infrastructure/env-info.js +58 -0
- package/lib/infrastructure/env-info.js.map +1 -0
- package/lib/infrastructure/file-service.d.ts +23 -0
- package/lib/infrastructure/file-service.js +117 -0
- package/lib/infrastructure/file-service.js.map +1 -0
- package/lib/infrastructure/launcher-service.d.ts +7 -0
- package/lib/infrastructure/launcher-service.js +51 -0
- package/lib/infrastructure/launcher-service.js.map +1 -0
- package/lib/infrastructure/network-service.d.ts +3 -0
- package/lib/infrastructure/network-service.js +7 -0
- package/lib/infrastructure/network-service.js.map +1 -0
- package/lib/infrastructure/services/api-client-factory.d.ts +6 -0
- package/lib/infrastructure/services/api-client-factory.js +20 -0
- package/lib/infrastructure/services/api-client-factory.js.map +1 -0
- package/lib/infrastructure/services/api-service.d.ts +10 -0
- package/lib/infrastructure/services/api-service.js +55 -0
- package/lib/infrastructure/services/api-service.js.map +1 -0
- package/lib/infrastructure/services/auth-service.d.ts +11 -0
- package/lib/infrastructure/services/auth-service.js +37 -0
- package/lib/infrastructure/services/auth-service.js.map +1 -0
- package/lib/infrastructure/services/file-download-service.d.ts +15 -0
- package/lib/infrastructure/services/file-download-service.js +104 -0
- package/lib/infrastructure/services/file-download-service.js.map +1 -0
- package/lib/infrastructure/services/portal-service.d.ts +21 -0
- package/lib/infrastructure/services/portal-service.js +157 -0
- package/lib/infrastructure/services/portal-service.js.map +1 -0
- package/lib/infrastructure/services/telemetry-service.d.ts +9 -0
- package/lib/infrastructure/services/telemetry-service.js +38 -0
- package/lib/infrastructure/services/telemetry-service.js.map +1 -0
- package/lib/infrastructure/services/transformation-service.d.ts +23 -0
- package/lib/infrastructure/services/transformation-service.js +56 -0
- package/lib/infrastructure/services/transformation-service.js.map +1 -0
- package/lib/infrastructure/services/validation-service.d.ts +17 -0
- package/lib/infrastructure/services/validation-service.js +49 -0
- package/lib/infrastructure/services/validation-service.js.map +1 -0
- package/lib/infrastructure/tmp-extensions.d.ts +2 -0
- package/lib/infrastructure/tmp-extensions.js +6 -0
- package/lib/infrastructure/tmp-extensions.js.map +1 -0
- package/lib/infrastructure/zip-service.d.ts +6 -0
- package/lib/infrastructure/zip-service.js +39 -0
- package/lib/infrastructure/zip-service.js.map +1 -0
- package/lib/prompts/api/transform.d.ts +11 -0
- package/lib/prompts/api/transform.js +30 -0
- package/lib/prompts/api/transform.js.map +1 -0
- package/lib/prompts/api/validate.d.ts +12 -0
- package/lib/prompts/api/validate.js +41 -0
- package/lib/prompts/api/validate.js.map +1 -0
- package/lib/prompts/auth/login.d.ts +10 -0
- package/lib/prompts/auth/login.js +22 -0
- package/lib/prompts/auth/login.js.map +1 -0
- package/lib/prompts/auth/logout.d.ts +3 -0
- package/lib/prompts/auth/logout.js +7 -0
- package/lib/prompts/auth/logout.js.map +1 -0
- package/lib/prompts/auth/status.d.ts +8 -0
- package/lib/prompts/auth/status.js +21 -0
- package/lib/prompts/auth/status.js.map +1 -0
- package/lib/prompts/format.d.ts +33 -0
- package/lib/prompts/format.js +99 -0
- package/lib/prompts/format.js.map +1 -0
- package/lib/prompts/portal/copilot.d.ts +18 -0
- package/lib/prompts/portal/copilot.js +82 -0
- package/lib/prompts/portal/copilot.js.map +1 -0
- package/lib/prompts/portal/generate.d.ts +13 -0
- package/lib/prompts/portal/generate.js +41 -0
- package/lib/prompts/portal/generate.js.map +1 -0
- package/lib/prompts/portal/quickstart.d.ts +31 -0
- package/lib/prompts/portal/quickstart.js +146 -0
- package/lib/prompts/portal/quickstart.js.map +1 -0
- package/lib/prompts/portal/recipe/new-recipe.d.ts +29 -0
- package/lib/prompts/portal/recipe/new-recipe.js +165 -0
- package/lib/prompts/portal/recipe/new-recipe.js.map +1 -0
- package/lib/prompts/portal/serve.d.ts +11 -0
- package/lib/prompts/portal/serve.js +33 -0
- package/lib/prompts/portal/serve.js.map +1 -0
- package/lib/prompts/portal/toc/new-toc.d.ts +15 -0
- package/lib/prompts/portal/toc/new-toc.js +37 -0
- package/lib/prompts/portal/toc/new-toc.js.map +1 -0
- package/lib/prompts/sdk/generate.d.ts +11 -0
- package/lib/prompts/sdk/generate.js +36 -0
- package/lib/prompts/sdk/generate.js.map +1 -0
- package/lib/types/api/account.d.ts +10 -0
- package/lib/types/api/account.js +2 -0
- package/lib/types/api/account.js.map +1 -0
- package/lib/types/api/transform.d.ts +17 -17
- package/lib/types/api/transform.js +21 -6
- package/lib/types/api/transform.js.map +1 -0
- package/lib/types/build/build.d.ts +22 -0
- package/lib/types/build/build.js +7 -0
- package/lib/types/build/build.js.map +1 -0
- package/lib/types/build-context.d.ts +17 -0
- package/lib/types/build-context.js +47 -0
- package/lib/types/build-context.js.map +1 -0
- package/lib/types/common/command-metadata.d.ts +4 -0
- package/lib/types/common/command-metadata.js +2 -0
- package/lib/types/common/command-metadata.js.map +1 -0
- package/lib/types/events/domain-event.d.ts +8 -0
- package/lib/types/events/domain-event.js +11 -0
- package/lib/types/events/domain-event.js.map +1 -0
- package/lib/types/events/quickstart-completed.d.ts +7 -0
- package/lib/types/events/quickstart-completed.js +10 -0
- package/lib/types/events/quickstart-completed.js.map +1 -0
- package/lib/types/events/quickstart-initiated.d.ts +7 -0
- package/lib/types/events/quickstart-initiated.js +10 -0
- package/lib/types/events/quickstart-initiated.js.map +1 -0
- package/lib/types/events/recipe-creation-failed.d.ts +5 -0
- package/lib/types/events/recipe-creation-failed.js +8 -0
- package/lib/types/events/recipe-creation-failed.js.map +1 -0
- package/lib/types/events/toc-creation-failed.d.ts +5 -0
- package/lib/types/events/toc-creation-failed.js +8 -0
- package/lib/types/events/toc-creation-failed.js.map +1 -0
- package/lib/types/file/directory.d.ts +17 -0
- package/lib/types/file/directory.js +86 -0
- package/lib/types/file/directory.js.map +1 -0
- package/lib/types/file/directoryPath.d.ts +9 -0
- package/lib/types/file/directoryPath.js +22 -0
- package/lib/types/file/directoryPath.js.map +1 -0
- package/lib/types/file/fileName.d.ts +7 -0
- package/lib/types/file/fileName.js +21 -0
- package/lib/types/file/fileName.js.map +1 -0
- package/lib/types/file/filePath.d.ts +10 -0
- package/lib/types/file/filePath.js +32 -0
- package/lib/types/file/filePath.js.map +1 -0
- package/lib/types/file/resource-input.d.ts +5 -0
- package/lib/types/file/resource-input.js +42 -0
- package/lib/types/file/resource-input.js.map +1 -0
- package/lib/types/file/urlPath.d.ts +6 -0
- package/lib/types/file/urlPath.js +22 -0
- package/lib/types/file/urlPath.js.map +1 -0
- package/lib/types/flags-provider.d.ts +15 -0
- package/lib/types/flags-provider.js +34 -0
- package/lib/types/flags-provider.js.map +1 -0
- package/lib/types/portal-context.d.ts +13 -0
- package/lib/types/portal-context.js +38 -0
- package/lib/types/portal-context.js.map +1 -0
- package/lib/types/recipe/recipe.d.ts +22 -0
- package/lib/types/recipe/recipe.js +6 -0
- package/lib/types/recipe/recipe.js.map +1 -0
- package/lib/types/recipe-context.d.ts +8 -0
- package/lib/types/recipe-context.js +21 -0
- package/lib/types/recipe-context.js.map +1 -0
- package/lib/types/resource-context.d.ts +12 -0
- package/lib/types/resource-context.js +30 -0
- package/lib/types/resource-context.js.map +1 -0
- package/lib/types/sdk/generate.d.ts +9 -21
- package/lib/types/sdk/generate.js +25 -12
- package/lib/types/sdk/generate.js.map +1 -0
- package/lib/types/sdk-context.d.ts +14 -0
- package/lib/types/sdk-context.js +32 -0
- package/lib/types/sdk-context.js.map +1 -0
- package/lib/types/sdl/sdl.d.ts +21 -0
- package/lib/types/sdl/sdl.js +47 -0
- package/lib/types/sdl/sdl.js.map +1 -0
- package/lib/types/spec-context.d.ts +10 -0
- package/lib/types/spec-context.js +17 -0
- package/lib/types/spec-context.js.map +1 -0
- package/lib/types/temp-context.d.ts +11 -0
- package/lib/types/temp-context.js +27 -0
- package/lib/types/temp-context.js.map +1 -0
- package/lib/types/toc/toc.d.ts +31 -0
- package/lib/types/toc/toc.js +9 -0
- package/lib/types/toc/toc.js.map +1 -0
- package/lib/types/toc-context.d.ts +12 -0
- package/lib/types/toc-context.js +26 -0
- package/lib/types/toc-context.js.map +1 -0
- package/lib/types/transform-context.d.ts +13 -0
- package/lib/types/transform-context.js +30 -0
- package/lib/types/transform-context.js.map +1 -0
- package/lib/types/utils.d.ts +1 -6
- package/lib/types/utils.js +2 -2
- package/lib/types/utils.js.map +1 -0
- package/lib/utils/string-utils.d.ts +1 -0
- package/lib/utils/string-utils.js +10 -0
- package/lib/utils/string-utils.js.map +1 -0
- package/lib/utils/utils.d.ts +2 -18
- package/lib/utils/utils.js +33 -116
- package/lib/utils/utils.js.map +1 -0
- package/package.json +101 -44
- package/bin/run +0 -5
- package/lib/client-utils/sdk-client.d.ts +0 -23
- package/lib/client-utils/sdk-client.js +0 -119
- package/lib/config/env.d.ts +0 -1
- package/lib/config/env.js +0 -4
- package/lib/controllers/api/transform.d.ts +0 -5
- package/lib/controllers/api/transform.js +0 -49
- package/lib/controllers/api/validate.d.ts +0 -3
- package/lib/controllers/api/validate.js +0 -22
- package/lib/controllers/portal/generate.d.ts +0 -2
- package/lib/controllers/portal/generate.js +0 -49
- package/lib/controllers/sdk/generate.d.ts +0 -4
- package/lib/controllers/sdk/generate.js +0 -64
- package/lib/types/api/validate.d.ts +0 -12
- package/lib/types/api/validate.js +0 -2
- package/lib/types/portal/generate.d.ts +0 -9
- package/lib/types/portal/generate.js +0 -2
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { err, ok } from "neverthrow";
|
|
3
|
+
import { handleServiceError } from "../api-utils.js";
|
|
4
|
+
import { FileName } from "../../types/file/fileName.js";
|
|
5
|
+
export class FileDownloadService {
|
|
6
|
+
async downloadFile(url) {
|
|
7
|
+
try {
|
|
8
|
+
const response = await axios.get(url.toString(), {
|
|
9
|
+
responseType: "stream"
|
|
10
|
+
});
|
|
11
|
+
const contentDisposition = response.headers["content-disposition"];
|
|
12
|
+
let filename;
|
|
13
|
+
// Try to parse filename from Content-Disposition (supports filename* as per RFC 5987 and plain filename)
|
|
14
|
+
if (contentDisposition) {
|
|
15
|
+
const parsed = this.parseFilenameFromContentDisposition(contentDisposition);
|
|
16
|
+
if (parsed) {
|
|
17
|
+
filename = new FileName(parsed);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
// ... existing code ...
|
|
21
|
+
// If no filename derived from headers, fallback to URL
|
|
22
|
+
if (!filename) {
|
|
23
|
+
const fromUrl = this.getFilenameFromUrl(url.toString());
|
|
24
|
+
if (fromUrl) {
|
|
25
|
+
filename = new FileName(fromUrl);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
filename = new FileName("file");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// Basic guard — responseType: "stream" should always yield a stream
|
|
32
|
+
const data = response.data;
|
|
33
|
+
const isReadableStream = data && typeof data.pipe === "function";
|
|
34
|
+
if (!isReadableStream) {
|
|
35
|
+
return err("INVALID_RESPONSE" /* ServiceError.InvalidResponse */);
|
|
36
|
+
}
|
|
37
|
+
return ok({
|
|
38
|
+
stream: response.data,
|
|
39
|
+
filename
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
return err(handleServiceError(error));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
parseFilenameFromContentDisposition(headerValue) {
|
|
47
|
+
// Try RFC 5987: filename*=UTF-8''encoded%20name.ext
|
|
48
|
+
const filenameStarMatch = headerValue.match(/filename\*\s*=\s*([^']*)''([^;]+)/i); // NOSONAR - safe regex for CLI use
|
|
49
|
+
if (filenameStarMatch) {
|
|
50
|
+
const encoded = filenameStarMatch[2].trim();
|
|
51
|
+
try {
|
|
52
|
+
const decoded = decodeURIComponent(encoded);
|
|
53
|
+
return this.sanitizeFilename(decoded);
|
|
54
|
+
}
|
|
55
|
+
catch (_a) {
|
|
56
|
+
// fall through to other strategies
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Try plain: filename="name.ext" or filename=name.ext
|
|
60
|
+
const filenameMatch = headerValue.match(/filename\s*=\s*"?([^";]+)"?/i);
|
|
61
|
+
if (filenameMatch) {
|
|
62
|
+
return this.sanitizeFilename(filenameMatch[1]);
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
getFilenameFromUrl(rawUrl) {
|
|
67
|
+
try {
|
|
68
|
+
const u = new URL(rawUrl);
|
|
69
|
+
const last = u.pathname.split("/").filter(Boolean).pop();
|
|
70
|
+
if (!last)
|
|
71
|
+
return null;
|
|
72
|
+
// Remove any spurious trailing spaces and decode
|
|
73
|
+
const decoded = this.safeDecodeURIComponent(last.trim());
|
|
74
|
+
return this.sanitizeFilename(decoded);
|
|
75
|
+
}
|
|
76
|
+
catch (_a) {
|
|
77
|
+
// Fallback for non-URL-safe strings
|
|
78
|
+
const parts = rawUrl.split("/").filter(Boolean);
|
|
79
|
+
const last = parts.pop();
|
|
80
|
+
if (!last)
|
|
81
|
+
return null;
|
|
82
|
+
return this.sanitizeFilename(this.safeDecodeURIComponent(last));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
safeDecodeURIComponent(value) {
|
|
86
|
+
try {
|
|
87
|
+
return decodeURIComponent(value);
|
|
88
|
+
}
|
|
89
|
+
catch (_a) {
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
sanitizeFilename(name) {
|
|
94
|
+
// Replace characters not allowed in common filesystems and trim dots/spaces
|
|
95
|
+
const sanitized = name
|
|
96
|
+
.replace('/[<>:"/\\|?*\x00-\x1F]/g', "_")
|
|
97
|
+
.replace(/\s+/g, " ")
|
|
98
|
+
.trim();
|
|
99
|
+
// Avoid names that are empty or only dots/spaces
|
|
100
|
+
const safe = sanitized.replace(/^[. ]+|[. ]+$/g, ""); // NOSONAR - safe regex for CLI use
|
|
101
|
+
return safe.length > 0 ? safe : "file";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=file-download-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-download-service.js","sourceRoot":"","sources":["../../../src/infrastructure/services/file-download-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,GAAG,EAAE,EAAE,EAAU,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAgB,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAOxD,MAAM,OAAO,mBAAmB;IACvB,KAAK,CAAC,YAAY,CAAC,GAAY;QACpC,IAAI,C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CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAChD,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;YACzB,IAAI,CAAC,IAAI;gBAAE,OAAO,IAAI,CAAC;YACvB,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;IAEO,sBAAsB,CAAC,KAAa;QAC1C,IAAI,CAAC;YACH,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAEO,gBAAgB,CAAC,IAAY;QACnC,4EAA4E;QAC5E,MAAM,SAAS,GAAG,IAAI;aACnB,OAAO,CAAC,0BAA0B,EAAE,GAAG,CAAC;aACxC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;aACpB,IAAI,EAAE,CAAC;QACV,iDAAiD;QACjD,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC,CAAC,mCAAmC;QACzF,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;IACzC,CAAC;CACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ReadStream } from "fs";
|
|
2
|
+
import { Sdl } from "../../types/sdl/sdl.js";
|
|
3
|
+
import { FilePath } from "../../types/file/filePath.js";
|
|
4
|
+
import { DirectoryPath } from "../../types/file/directoryPath.js";
|
|
5
|
+
import { CommandMetadata } from "../../types/common/command-metadata.js";
|
|
6
|
+
import { Result } from "neverthrow";
|
|
7
|
+
import { Language } from "../../types/sdk/generate.js";
|
|
8
|
+
import { ServiceError } from "../api-utils.js";
|
|
9
|
+
export declare class PortalService {
|
|
10
|
+
private readonly CONTENT_TYPE;
|
|
11
|
+
private readonly fileService;
|
|
12
|
+
generatePortal(buildPath: FilePath, configDir: DirectoryPath, eventMetadata: CommandMetadata, authKey: string | null): Promise<Result<NodeJS.ReadableStream, string | NodeJS.ReadableStream>>;
|
|
13
|
+
generateSdk(specPath: FilePath, language: Language, configDir: DirectoryPath, commandMetadata: CommandMetadata, authKey: string | null): Promise<Result<NodeJS.ReadableStream, string>>;
|
|
14
|
+
generateSdl(specFileStream: ReadStream, configDir: DirectoryPath, commandMetadata: CommandMetadata): Promise<Result<Sdl, ServiceError>>;
|
|
15
|
+
private createAuthorizationHeader;
|
|
16
|
+
private createOriginQueryParameter;
|
|
17
|
+
private static handlePortalGenerationErrors;
|
|
18
|
+
private handleSdkGenerationErrors;
|
|
19
|
+
private parseBadRequestResponse;
|
|
20
|
+
private readonly languagePlatform;
|
|
21
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import { Accept, ApiError, BadRequestResponseSdkError, CodeGenerationExternalApisController, ContentType, DocsPortalManagementController, UnauthorizedResponseError, ProblemDetailsError, FileWrapper, TransformationController, ExportFormats, InternalServerErrorResponseError, Platforms } from "@apimatic/sdk";
|
|
3
|
+
import { getAuthInfo } from "../../client-utils/auth-manager.js";
|
|
4
|
+
import { parseStreamBodyToJson } from "../../utils/utils.js";
|
|
5
|
+
import { FileService } from "../file-service.js";
|
|
6
|
+
import { apiClientFactory } from "./api-client-factory.js";
|
|
7
|
+
import { err, ok } from "neverthrow";
|
|
8
|
+
import { Language } from "../../types/sdk/generate.js";
|
|
9
|
+
import { handleServiceError } from "../api-utils.js";
|
|
10
|
+
export class PortalService {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.CONTENT_TYPE = ContentType.EnumMultipartformdata;
|
|
13
|
+
this.fileService = new FileService();
|
|
14
|
+
this.createAuthorizationHeader = (authInfo, overrideAuthKey) => {
|
|
15
|
+
const key = overrideAuthKey || (authInfo === null || authInfo === void 0 ? void 0 : authInfo.authKey);
|
|
16
|
+
return `X-Auth-Key ${key !== null && key !== void 0 ? key : ""}`;
|
|
17
|
+
};
|
|
18
|
+
this.createOriginQueryParameter = (commandName) => {
|
|
19
|
+
return {
|
|
20
|
+
origin: `APIMATIC CLI ${commandName}`
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
this.handleSdkGenerationErrors = async (error) => {
|
|
24
|
+
var _b, _c, _d, _e, _f;
|
|
25
|
+
if (error instanceof BadRequestResponseSdkError) {
|
|
26
|
+
//400
|
|
27
|
+
return this.parseBadRequestResponse((_b = error.result) === null || _b === void 0 ? void 0 : _b.message);
|
|
28
|
+
}
|
|
29
|
+
if (error instanceof UnauthorizedResponseError) {
|
|
30
|
+
//401
|
|
31
|
+
return (_d = (_c = error.result) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : "Authorization has been denied for this request.";
|
|
32
|
+
}
|
|
33
|
+
if (error instanceof ProblemDetailsError) {
|
|
34
|
+
// 403
|
|
35
|
+
const message = (_f = (_e = error.result.errors) === null || _e === void 0 ? void 0 : _e[""]) === null || _f === void 0 ? void 0 : _f[0];
|
|
36
|
+
return error.result.title + "\n- " + message;
|
|
37
|
+
}
|
|
38
|
+
return "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";
|
|
39
|
+
};
|
|
40
|
+
this.languagePlatform = {
|
|
41
|
+
[Language.CSHARP]: Platforms.CsNetStandardLib,
|
|
42
|
+
[Language.JAVA]: Platforms.JavaEclipseJreLib,
|
|
43
|
+
[Language.PHP]: Platforms.PhpGenericLibV2,
|
|
44
|
+
[Language.PYTHON]: Platforms.PythonGenericLib,
|
|
45
|
+
[Language.RUBY]: Platforms.RubyGenericLib,
|
|
46
|
+
[Language.TYPESCRIPT]: Platforms.TsGenericLib,
|
|
47
|
+
[Language.GO]: Platforms.GoGenericLib
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// TODO: Pass stream as parameter instead of file path.
|
|
51
|
+
async generatePortal(buildPath, configDir, eventMetadata, authKey) {
|
|
52
|
+
const buildFileStream = await this.fileService.getStream(buildPath);
|
|
53
|
+
const file = new FileWrapper(buildFileStream);
|
|
54
|
+
const authInfo = await getAuthInfo(configDir.toString());
|
|
55
|
+
const authorizationHeader = this.createAuthorizationHeader(authInfo, authKey);
|
|
56
|
+
const client = apiClientFactory.createApiClient(authorizationHeader, eventMetadata.shell);
|
|
57
|
+
const docsPortalManagementController = new DocsPortalManagementController(client);
|
|
58
|
+
try {
|
|
59
|
+
const response = await docsPortalManagementController.generateOnPremPortalViaBuildInput(this.CONTENT_TYPE, file, this.createOriginQueryParameter(eventMetadata.commandName));
|
|
60
|
+
return ok(response.result);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
return err(await _a.handlePortalGenerationErrors(error));
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
buildFileStream.close();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// TODO: Pass stream as parameter instead of file path.
|
|
70
|
+
async generateSdk(specPath, language, configDir, commandMetadata, authKey) {
|
|
71
|
+
const specFileStream = await this.fileService.getStream(specPath);
|
|
72
|
+
const file = new FileWrapper(specFileStream);
|
|
73
|
+
const authInfo = await getAuthInfo(configDir.toString());
|
|
74
|
+
const authorizationHeader = this.createAuthorizationHeader(authInfo, authKey);
|
|
75
|
+
const client = apiClientFactory.createApiClient(authorizationHeader, commandMetadata.shell);
|
|
76
|
+
const sdkGenerationController = new CodeGenerationExternalApisController(client);
|
|
77
|
+
try {
|
|
78
|
+
const response = await sdkGenerationController.generateSdkViaFile(Accept.EnumApplicationjson, file, this.languagePlatform[language], this.createOriginQueryParameter(commandMetadata.commandName));
|
|
79
|
+
const sdkResponse = await sdkGenerationController.downloadSdk(response.result.id);
|
|
80
|
+
return ok(sdkResponse.result);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
return err(await this.handleSdkGenerationErrors(error));
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
specFileStream.close();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async generateSdl(specFileStream, configDir, commandMetadata) {
|
|
90
|
+
const file = new FileWrapper(specFileStream);
|
|
91
|
+
const authInfo = await getAuthInfo(configDir.toString());
|
|
92
|
+
const authorizationHeader = this.createAuthorizationHeader(authInfo, null);
|
|
93
|
+
const client = apiClientFactory.createApiClient(authorizationHeader, commandMetadata.shell);
|
|
94
|
+
const transformationController = new TransformationController(client);
|
|
95
|
+
try {
|
|
96
|
+
const generation = await transformationController.transformViaFile(ContentType.EnumMultipartformdata, file, ExportFormats.Apimatic, this.createOriginQueryParameter(commandMetadata.commandName));
|
|
97
|
+
if (!generation.result.success) {
|
|
98
|
+
return err("INVALID_RESPONSE" /* ServiceError.InvalidResponse */);
|
|
99
|
+
}
|
|
100
|
+
const transformationId = generation.result.id;
|
|
101
|
+
const { result } = await transformationController.downloadTransformedFile(transformationId);
|
|
102
|
+
if (result.readable) {
|
|
103
|
+
return ok((await parseStreamBodyToJson(result)));
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
return err("INVALID_RESPONSE" /* ServiceError.InvalidResponse */);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
return err(handleServiceError(error));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
parseBadRequestResponse(errorMessage) {
|
|
114
|
+
// #TODO: Fix server-side error message and simplify this function
|
|
115
|
+
if (!errorMessage) {
|
|
116
|
+
return "Bad request.";
|
|
117
|
+
}
|
|
118
|
+
// Parse the JSON string
|
|
119
|
+
const parsedResult = JSON.parse(errorMessage);
|
|
120
|
+
// Check if it has the expected structure with Errors
|
|
121
|
+
if (parsedResult.Errors && Array.isArray(parsedResult.Errors) && parsedResult.Errors.length > 0) {
|
|
122
|
+
// Get the first error and clean it up
|
|
123
|
+
return parsedResult.Errors[0].split(".")[0] + ".";
|
|
124
|
+
// Split on <br/> and take the first part, then strip remaining HTML tags
|
|
125
|
+
// return firstError.split("<br/>")[0].replace(/<[^<>]*?>/g, "");
|
|
126
|
+
}
|
|
127
|
+
else if (parsedResult.Success === false) {
|
|
128
|
+
return "API definition file validation failed.";
|
|
129
|
+
}
|
|
130
|
+
return errorMessage;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
_a = PortalService;
|
|
134
|
+
PortalService.handlePortalGenerationErrors = async (error) => {
|
|
135
|
+
var _b, _c, _d, _e, _f;
|
|
136
|
+
if (error instanceof UnauthorizedResponseError) {
|
|
137
|
+
// 401
|
|
138
|
+
return (_c = (_b = error.result) === null || _b === void 0 ? void 0 : _b.message) !== null && _c !== void 0 ? _c : "Authorization has been denied for this request.";
|
|
139
|
+
}
|
|
140
|
+
if (error instanceof ProblemDetailsError) {
|
|
141
|
+
// 400 & 403
|
|
142
|
+
const probDetailsError = error;
|
|
143
|
+
const message = (_e = (_d = Object.values(probDetailsError.result.errors)[0]) === null || _d === void 0 ? void 0 : _d[0]) !== null && _e !== void 0 ? _e : null;
|
|
144
|
+
return error.result.title + "\n- " + message;
|
|
145
|
+
}
|
|
146
|
+
if (error instanceof ApiError && error.statusCode === 422) {
|
|
147
|
+
// 422
|
|
148
|
+
return error.body;
|
|
149
|
+
}
|
|
150
|
+
if (error instanceof InternalServerErrorResponseError) {
|
|
151
|
+
// 422
|
|
152
|
+
const message = (_f = error.result) === null || _f === void 0 ? void 0 : _f.message;
|
|
153
|
+
return `${message !== null && message !== void 0 ? message : "An unknown error occurred."} Please try again later or reach out to our team at support@apimatic.io for help if your problem persists.`;
|
|
154
|
+
}
|
|
155
|
+
return "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";
|
|
156
|
+
};
|
|
157
|
+
//# 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":";AACA,O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EAAiE;QACnE,CAAC;aAAM,IAAI,YAAY,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;YAC1C,OAAO,wCAAwC,CAAC;QAClD,CAAC;QACD,OAAO,YAAY,CAAC;IACtB,CAAC;;;AA5Dc,0CAA4B,GAAG,KAAK,EAAE,KAAc,EAA2C,EAAE;;IAC9G,IAAI,KAAK,YAAY,yBAAyB,EAAE,CAAC;QAC/C,MAAM;QACN,OAAO,MAAA,MAAA,KAAK,CAAC,MAAM,0CAAE,OAAO,mCAAI,iDAAiD,CAAC;IACpF,CAAC;IACD,IAAI,KAAK,YAAY,mBAAmB,EAAE,CAAC;QACzC,YAAY;QACZ,MAAM,gBAAgB,GAAG,KAA4B,CAAC;QACtD,MAAM,OAAO,GAAG,MAAA,MAAA,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,MAAO,CAAC,MAAkC,CAAC,CAAC,CAAC,CAAC,0CAAG,CAAC,CAAC,mCAAI,IAAI,CAAC;QAC3G,OAAO,KAAK,CAAC,MAAO,CAAC,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC;IAChD,CAAC;IACD,IAAI,KAAK,YAAY,QAAQ,IAAI,KAAK,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;QAC1D,MAAM;QACN,OAAO,KAAK,CAAC,IAA6B,CAAC;IAC7C,CAAC;IACD,IAAI,KAAK,YAAY,gCAAgC,EAAE,CAAC;QACtD,MAAM;QACN,MAAM,OAAO,GAAG,MAAA,KAAK,CAAC,MAAM,0CAAE,OAAO,CAAC;QACtC,OAAO,GACL,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,4BACb,4GAA4G,CAAC;IAC/G,CAAC;IACD,OAAO,gKAAgK,CAAC;AAC1K,CAAC,AAvB0C,CAuBzC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DomainEvent } from "../../types/events/domain-event.js";
|
|
2
|
+
import { DirectoryPath } from "../../types/file/directoryPath.js";
|
|
3
|
+
export declare class TelemetryService {
|
|
4
|
+
private readonly configDirectory;
|
|
5
|
+
private readonly apiService;
|
|
6
|
+
constructor(configDirectory: DirectoryPath);
|
|
7
|
+
trackEvent<T extends DomainEvent>(event: T, shell: string): Promise<void>;
|
|
8
|
+
private getAuthInfo;
|
|
9
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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, shell) {
|
|
13
|
+
const authInfo = await this.getAuthInfo(this.configDirectory.toString());
|
|
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
|
+
await this.apiService.sendTelemetry(JSON.stringify(payload), authKey, shell);
|
|
28
|
+
}
|
|
29
|
+
async getAuthInfo(configDirectory) {
|
|
30
|
+
try {
|
|
31
|
+
return JSON.parse(await fs.readFile(path.join(configDirectory, "config.json"), "utf8"));
|
|
32
|
+
}
|
|
33
|
+
catch (_a) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# 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;AAY9C,MAAM,OAAO,gBAAgB;IAG3B,YAA6B,eAA8B;QAA9B,oBAAe,GAAf,eAAe,CAAe;QAF1C,eAAU,GAAG,IAAI,UAAU,EAAE,CAAC;IAEe,CAAC;IAExD,KAAK,CAAC,UAAU,CAAwB,KAAQ,EAAE,KAAa;QACpE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC,CAAC;QACzE,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,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IAC/E,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,23 @@
|
|
|
1
|
+
import { ExportFormats, ApiValidationSummary } from "@apimatic/sdk";
|
|
2
|
+
import { DirectoryPath } from "../../types/file/directoryPath.js";
|
|
3
|
+
import { FilePath } from "../../types/file/filePath.js";
|
|
4
|
+
import { CommandMetadata } from "../../types/common/command-metadata.js";
|
|
5
|
+
import { Result } from "neverthrow";
|
|
6
|
+
export interface TransformViaFileParams {
|
|
7
|
+
file: FilePath;
|
|
8
|
+
format: ExportFormats;
|
|
9
|
+
configDir: DirectoryPath;
|
|
10
|
+
commandMetadata: CommandMetadata;
|
|
11
|
+
authKey?: string | null;
|
|
12
|
+
}
|
|
13
|
+
export interface TransformationResultData {
|
|
14
|
+
stream: NodeJS.ReadableStream;
|
|
15
|
+
apiValidationSummary: ApiValidationSummary;
|
|
16
|
+
}
|
|
17
|
+
export declare class TransformationService {
|
|
18
|
+
private readonly CONTENT_TYPE;
|
|
19
|
+
transformViaFile({ file, format, configDir, commandMetadata, authKey }: TransformViaFileParams): Promise<Result<TransformationResultData, string>>;
|
|
20
|
+
private createAuthorizationHeader;
|
|
21
|
+
private readonly createOriginQueryParameter;
|
|
22
|
+
private readonly handleTransformationErrors;
|
|
23
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import fsExtra from "fs-extra";
|
|
2
|
+
import { ContentType, FileWrapper, TransformationController, ApiError } from "@apimatic/sdk";
|
|
3
|
+
import { getAuthInfo } from "../../client-utils/auth-manager.js";
|
|
4
|
+
import { apiClientFactory } from "./api-client-factory.js";
|
|
5
|
+
import { err, ok } from "neverthrow";
|
|
6
|
+
export class TransformationService {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.CONTENT_TYPE = ContentType.EnumMultipartformdata;
|
|
9
|
+
this.createOriginQueryParameter = (commandName) => {
|
|
10
|
+
return {
|
|
11
|
+
origin: `APIMATIC CLI ${commandName}`
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
this.handleTransformationErrors = async (error) => {
|
|
15
|
+
if (error instanceof ApiError) {
|
|
16
|
+
const apiError = error;
|
|
17
|
+
if (apiError.statusCode === 400) {
|
|
18
|
+
return "Your API Definition is invalid. Please use the APIMatic VS Code Extension to fix the errors and try again.";
|
|
19
|
+
}
|
|
20
|
+
else if (apiError.statusCode === 401) {
|
|
21
|
+
const message = JSON.parse(apiError.body).message;
|
|
22
|
+
return `${message} You are not authorized to perform this action. Please run 'auth:login' or provide a valid auth key.`;
|
|
23
|
+
}
|
|
24
|
+
return `Error ${apiError.statusCode}: An error occurred during the transformation. Please try again or contact support@apimatic.io for assistance.`;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return "An unexpected error occurred while validating your API Definition. Please try again later. If the problem persists, please reach out to our team at support@apimatic.io";
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
async transformViaFile({ file, format, configDir, commandMetadata, authKey }) {
|
|
32
|
+
const authInfo = await getAuthInfo(configDir.toString());
|
|
33
|
+
const authorizationHeader = this.createAuthorizationHeader(authInfo, authKey !== null && authKey !== void 0 ? authKey : null);
|
|
34
|
+
const client = apiClientFactory.createApiClient(authorizationHeader, commandMetadata.shell);
|
|
35
|
+
const transformationController = new TransformationController(client);
|
|
36
|
+
try {
|
|
37
|
+
const fileStream = fsExtra.createReadStream(file.toString());
|
|
38
|
+
const fileWrapper = new FileWrapper(fileStream);
|
|
39
|
+
const generation = await transformationController.transformViaFile(this.CONTENT_TYPE, fileWrapper, format, this.createOriginQueryParameter(commandMetadata.commandName));
|
|
40
|
+
const { id, apiValidationSummary } = generation.result;
|
|
41
|
+
const { result } = await transformationController.downloadTransformedFile(id);
|
|
42
|
+
return ok({
|
|
43
|
+
stream: result,
|
|
44
|
+
apiValidationSummary
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
return err(await this.handleTransformationErrors(error));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
createAuthorizationHeader(authInfo, overrideAuthKey) {
|
|
52
|
+
const key = overrideAuthKey || (authInfo === null || authInfo === void 0 ? void 0 : authInfo.authKey);
|
|
53
|
+
return `X-Auth-Key ${key !== null && key !== void 0 ? key : ""}`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=transformation-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformation-service.js","sourceRoot":"","sources":["../../../src/infrastructure/services/transformation-service.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,EAEL,WAAW,EAEX,WAAW,EACX,wBAAwB,EAExB,QAAQ,EAET,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAY,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAG3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAG3D,OAAO,EAAE,GAAG,EAAE,EAAE,EAAS,MAAM,YAAY,CAAC;AAe5C,MAAM,OAAO,qBAAqB;IAAlC;QACmB,iBAAY,GAAG,WAAW,CAAC,qBAAqB,CAAC;QAyCjD,+BAA0B,GAAG,CAAC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AAQ,EAAE,CAAC,CAAC;YAC7D,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,UAAU,CAAC,CAAC;YAChD,MAAM,UAAU,GAAgC,MAAM,wBAAwB,CAAC,gBAAgB,CAC7F,IAAI,CAAC,YAAY,EACjB,WAAW,EACX,MAAuB,EACvB,IAAI,CAAC,0BAA0B,CAAC,eAAe,CAAC,WAAW,CAAC,CAC7D,CAAC;YAEF,MAAM,EAAE,EAAE,EAAE,oBAAoB,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC;YACvD,MAAM,EAAE,MAAM,EAAE,GAAuB,MAAM,wBAAwB,CAAC,uBAAuB,CAAC,EAAE,CAAC,CAAC;YAElG,OAAO,EAAE,CAAC;gBACR,MAAM,EAAE,MAA+B;gBACvC,oBAAoB;aACrB,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,GAAG,CAAC,MAAM,IAAI,CAAC,0BAA0B,CAAC,KAAK,CAAC,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;IAEO,yBAAyB,CAAC,QAAyB,EAAE,eAA8B;QACzF,MAAM,GAAG,GAAG,eAAe,KAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,CAAA,CAAC;QACjD,OAAO,cAAc,GAAG,aAAH,GAAG,cAAH,GAAG,GAAI,EAAE,EAAE,CAAC;IACnC,CAAC;CAsBF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ApiValidationSummary } from "@apimatic/sdk";
|
|
2
|
+
import { DirectoryPath } from "../../types/file/directoryPath.js";
|
|
3
|
+
import { Result } from "neverthrow";
|
|
4
|
+
import { FilePath } from "../../types/file/filePath.js";
|
|
5
|
+
import { CommandMetadata } from "../../types/common/command-metadata.js";
|
|
6
|
+
export interface ValidateViaFileParams {
|
|
7
|
+
file: FilePath;
|
|
8
|
+
commandMetadata: CommandMetadata;
|
|
9
|
+
authKey?: string | null;
|
|
10
|
+
}
|
|
11
|
+
export declare class ValidationService {
|
|
12
|
+
private readonly configDir;
|
|
13
|
+
constructor(configDir: DirectoryPath);
|
|
14
|
+
validateViaFile({ file, commandMetadata, authKey }: ValidateViaFileParams): Promise<Result<ApiValidationSummary, string>>;
|
|
15
|
+
private createAuthorizationHeader;
|
|
16
|
+
private handleValidationErrors;
|
|
17
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import fsExtra from "fs-extra";
|
|
2
|
+
import { ApiValidationExternalApisController, ContentType, FileWrapper, ApiError } from "@apimatic/sdk";
|
|
3
|
+
import { getAuthInfo } from "../../client-utils/auth-manager.js";
|
|
4
|
+
import { apiClientFactory } from "./api-client-factory.js";
|
|
5
|
+
import { err, ok } from "neverthrow";
|
|
6
|
+
export class ValidationService {
|
|
7
|
+
constructor(configDir) {
|
|
8
|
+
this.configDir = configDir;
|
|
9
|
+
}
|
|
10
|
+
async validateViaFile({ file, commandMetadata, authKey }) {
|
|
11
|
+
const authInfo = await getAuthInfo(this.configDir.toString());
|
|
12
|
+
const authorizationHeader = this.createAuthorizationHeader(authInfo, authKey !== null && authKey !== void 0 ? authKey : null);
|
|
13
|
+
const client = apiClientFactory.createApiClient(authorizationHeader, commandMetadata.shell);
|
|
14
|
+
const controller = new ApiValidationExternalApisController(client);
|
|
15
|
+
try {
|
|
16
|
+
const fileDescriptor = new FileWrapper(fsExtra.createReadStream(file.toString()));
|
|
17
|
+
//TODO: Update spec to include origin query parameter.
|
|
18
|
+
const validation = await controller.validateApiViaFile(ContentType.EnumMultipartformdata, fileDescriptor);
|
|
19
|
+
return ok(validation.result);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
return err(await this.handleValidationErrors(error));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
createAuthorizationHeader(authInfo, overrideAuthKey) {
|
|
26
|
+
const key = overrideAuthKey || (authInfo === null || authInfo === void 0 ? void 0 : authInfo.authKey);
|
|
27
|
+
return `X-Auth-Key ${key !== null && key !== void 0 ? key : ""}`;
|
|
28
|
+
}
|
|
29
|
+
async handleValidationErrors(error) {
|
|
30
|
+
if (error instanceof ApiError) {
|
|
31
|
+
const apiError = error;
|
|
32
|
+
if (apiError.statusCode === 400) {
|
|
33
|
+
return "Your API Definition is invalid. Please fix the issues and try again.";
|
|
34
|
+
}
|
|
35
|
+
else if (apiError.statusCode === 401) {
|
|
36
|
+
return "You are not authorized to perform this action. Please run 'auth:login' or provide a valid auth key.";
|
|
37
|
+
}
|
|
38
|
+
else if (apiError.statusCode === 403) {
|
|
39
|
+
return "You do not have permission to perform this action.";
|
|
40
|
+
}
|
|
41
|
+
else if (apiError.statusCode === 500) {
|
|
42
|
+
return "An unexpected error occurred validating the API specification, please try again later. If the problem persists, please reach out to our team at support@apimatic.io";
|
|
43
|
+
}
|
|
44
|
+
return `Error ${apiError.statusCode}: An error occurred during validation.`;
|
|
45
|
+
}
|
|
46
|
+
return "Unexpected error occurred while validating API specification.";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=validation-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-service.js","sourceRoot":"","sources":["../../../src/infrastructure/services/validation-service.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,EAEL,mCAAmC,EAEnC,WAAW,EACX,WAAW,EACX,QAAQ,EACT,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAY,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,EAAE,EAAU,MAAM,YAAY,CAAC;AAU7C,MAAM,OAAO,iBAAiB;IAC5B,YAA6B,SAAwB;QAAxB,cAAS,GAAT,SAAS,CAAe;IAAG,CAAC;IAEzD,KAAK,CAAC,eAAe,CAAC,EACpB,IAAI,EACJ,eAAe,EACf,OAAO,EACe;QACt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sE,CAAC;YAChF,CAAC;iBAAM,IAAI,QAAQ,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;gBACvC,OAAO,qGAAqG,CAAC;YAC/G,CAAC;iBAAM,IAAI,QAAQ,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;gBACvC,OAAO,oDAAoD,CAAC;YAC9D,CAAC;iBAAM,IAAI,QAAQ,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;gBACvC,OAAO,qKAAqK,CAAC;YAC/K,CAAC;YAED,OAAO,SAAS,QAAQ,CAAC,UAAU,wCAAwC,CAAC;QAC9E,CAAC;QAED,OAAO,+DAA+D,CAAC;IACzE,CAAC;CACF"}
|
|
@@ -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 @@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K;gBACtB,SAAS,EAAE,CAAC;gBACZ,IAAI,SAAS,GAAG,SAAS,EAAE,CAAC;oBAC1B,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;gBAC7C,CAAC;gBACD,mFAAmF;gBACnF,yDAAyD;gBACzD,IAAI,SAAS,GAAG,KAAK,CAAC,gBAAgB,CAAC;gBACvC,SAAS,IAAI,SAAS,CAAC;gBACvB,IAAI,SAAS,GAAG,QAAQ,EAAE,CAAC;oBACzB,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;gBACvC,CAAC;YACH,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DirectoryPath } from "../../types/file/directoryPath.js";
|
|
2
|
+
import { Result } from "neverthrow";
|
|
3
|
+
import { TransformationResultData } from "../../infrastructure/services/transformation-service.js";
|
|
4
|
+
import { ServiceError } from "../../infrastructure/api-utils.js";
|
|
5
|
+
export declare class ApiTransformPrompts {
|
|
6
|
+
overwriteApi(directory: DirectoryPath): Promise<boolean>;
|
|
7
|
+
transformedApiAlreadyExists(): void;
|
|
8
|
+
transformApi(fn: Promise<Result<TransformationResultData, string>>): Promise<Result<TransformationResultData, string>>;
|
|
9
|
+
logTransformationError(error: string): void;
|
|
10
|
+
networkError(serviceError: ServiceError): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { log, isCancel, confirm } from "@clack/prompts";
|
|
2
|
+
import { format as f, withSpinner } from "../format.js";
|
|
3
|
+
import { getErrorMessage } from "../../infrastructure/api-utils.js";
|
|
4
|
+
export class ApiTransformPrompts {
|
|
5
|
+
async overwriteApi(directory) {
|
|
6
|
+
const overwrite = await confirm({
|
|
7
|
+
message: `A specification file already exists at ${f.path(directory)}. Do you want to overwrite the existing file?`,
|
|
8
|
+
initialValue: false
|
|
9
|
+
});
|
|
10
|
+
if (isCancel(overwrite)) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return overwrite;
|
|
14
|
+
}
|
|
15
|
+
transformedApiAlreadyExists() {
|
|
16
|
+
const message = `Specification already exists.`;
|
|
17
|
+
log.error(message);
|
|
18
|
+
}
|
|
19
|
+
async transformApi(fn) {
|
|
20
|
+
return withSpinner("Transforming API", "API transformed successfully.", "API transformation failed.", fn);
|
|
21
|
+
}
|
|
22
|
+
logTransformationError(error) {
|
|
23
|
+
log.error(error);
|
|
24
|
+
}
|
|
25
|
+
networkError(serviceError) {
|
|
26
|
+
const message = getErrorMessage(serviceError);
|
|
27
|
+
log.error(message);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=transform.js.map
|