@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,34 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { format as f } from "../prompts/format.js";
|
|
3
|
+
export function getErrorMessage(error) {
|
|
4
|
+
switch (error) {
|
|
5
|
+
case "NETWORK_ERROR" /* ServiceError.NetworkError */:
|
|
6
|
+
return "Unable to connect to the server.";
|
|
7
|
+
case "UNAUTHORIZED" /* ServiceError.UnAuthorized */:
|
|
8
|
+
return "Unauthorized access.";
|
|
9
|
+
case "NOT_FOUND" /* ServiceError.NotFound */:
|
|
10
|
+
case "SERVER_ERROR" /* ServiceError.ServerError */:
|
|
11
|
+
case "INVALID_RESPONSE" /* ServiceError.InvalidResponse */:
|
|
12
|
+
default:
|
|
13
|
+
return `An unexpected error occurred, please try again later. If the problem persists, please reach out to our team at ${f.var('support@apimatic.io')}`;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function handleServiceError(error) {
|
|
17
|
+
var _a, _b, _c;
|
|
18
|
+
if (axios.isAxiosError(error)) {
|
|
19
|
+
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
|
|
20
|
+
return "UNAUTHORIZED" /* ServiceError.UnAuthorized */;
|
|
21
|
+
}
|
|
22
|
+
if (((_b = error.response) === null || _b === void 0 ? void 0 : _b.status) === 404) {
|
|
23
|
+
return "NOT_FOUND" /* ServiceError.NotFound */;
|
|
24
|
+
}
|
|
25
|
+
if (((_c = error.response) === null || _c === void 0 ? void 0 : _c.status) === 500) {
|
|
26
|
+
return "SERVER_ERROR" /* ServiceError.ServerError */;
|
|
27
|
+
}
|
|
28
|
+
if (error.code === "ECONNABORTED" || error.code === "ECONNREFUSED" || error.code === "ENOTFOUND") {
|
|
29
|
+
return "NETWORK_ERROR" /* ServiceError.NetworkError */;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return "SERVER_ERROR" /* ServiceError.ServerError */;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=api-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-utils.js","sourceRoot":"","sources":["../../src/infrastructure/api-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,sBAAsB,CAAC;AAUnD,MAAM,UAAU,eAAe,CAAC,KAAmB;IACjD,QAAQ,KAAK,EAAE,CAAC;QACd;YACE,OAAO,kCAAkC,CAAC;QAC5C;YACE,OAAO,sBAAsB,CAAC;QAChC,6CAA2B;QAC3B,mDAA8B;QAC9B,2DAAkC;QAClC;YACE,OAAO,kHAAkH,CAAC,CAAC,GAAG,CAAC,qBAAqB,CAAC,EAAE,CAAC;IAC5J,CAAC;AACH,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAc;;IAC/C,IAAI,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,IAAI,CAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,MAAM,MAAK,GAAG,EAAE,CAAC;YACnC,sDAAiC;QACnC,CAAC;QACD,IAAI,CAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,MAAM,MAAK,GAAG,EAAE,CAAC;YACnC,+CAA6B;QAC/B,CAAC;QACD,IAAI,CAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,MAAM,MAAK,GAAG,EAAE,CAAC;YACnC,qDAAgC;QAClC,CAAC;QACD,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YACjG,uDAAiC;QACnC,CAAC;IACH,CAAC;IACD,qDAAgC;AAClC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class DebounceService {
|
|
2
|
+
private isProcessing;
|
|
3
|
+
private latestHandler;
|
|
4
|
+
private debounceTimer;
|
|
5
|
+
private readonly debounceMs;
|
|
6
|
+
constructor(debounceMs?: number);
|
|
7
|
+
batchSingleRequest(handler: () => Promise<void>): Promise<void>;
|
|
8
|
+
private scheduleExecution;
|
|
9
|
+
close(): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { clearTimeout, setTimeout } from "timers";
|
|
2
|
+
export class DebounceService {
|
|
3
|
+
constructor(debounceMs = 500) {
|
|
4
|
+
this.isProcessing = false;
|
|
5
|
+
this.latestHandler = null;
|
|
6
|
+
this.debounceTimer = null;
|
|
7
|
+
this.debounceMs = debounceMs;
|
|
8
|
+
}
|
|
9
|
+
async batchSingleRequest(handler) {
|
|
10
|
+
// Always store the latest handler
|
|
11
|
+
this.latestHandler = handler;
|
|
12
|
+
// If already processing, don't start a new timer. Just update the latest handler
|
|
13
|
+
if (this.isProcessing) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
// Clear any existing timer
|
|
17
|
+
if (this.debounceTimer) {
|
|
18
|
+
clearTimeout(this.debounceTimer);
|
|
19
|
+
}
|
|
20
|
+
// Set up debounced execution
|
|
21
|
+
this.scheduleExecution();
|
|
22
|
+
}
|
|
23
|
+
scheduleExecution() {
|
|
24
|
+
this.debounceTimer = setTimeout(async () => {
|
|
25
|
+
if (this.isProcessing) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
this.isProcessing = true;
|
|
29
|
+
this.debounceTimer = null;
|
|
30
|
+
try {
|
|
31
|
+
// Execute the latest handler if it exists
|
|
32
|
+
if (this.latestHandler) {
|
|
33
|
+
const currentHandler = this.latestHandler;
|
|
34
|
+
this.latestHandler = null;
|
|
35
|
+
await currentHandler();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
this.isProcessing = false;
|
|
40
|
+
}
|
|
41
|
+
}, this.debounceMs);
|
|
42
|
+
}
|
|
43
|
+
// Method to clear any pending execution.
|
|
44
|
+
close() {
|
|
45
|
+
if (this.debounceTimer) {
|
|
46
|
+
clearTimeout(this.debounceTimer);
|
|
47
|
+
this.debounceTimer = null;
|
|
48
|
+
}
|
|
49
|
+
this.latestHandler = null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=debounce-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debounce-service.js","sourceRoot":"","sources":["../../src/infrastructure/debounce-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAElD,MAAM,OAAO,eAAe;IAM1B,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,kBAAkB,CAAC,OAA4B;QACnD,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,KAAK;QACV,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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare class EnvInfo {
|
|
2
|
+
private static cachedCliVersion;
|
|
3
|
+
private static cachedUserAgent;
|
|
4
|
+
private static cachedBaseUrl;
|
|
5
|
+
private static cachedAuthBaseUrl;
|
|
6
|
+
getUserAgent(shell: string): string;
|
|
7
|
+
getCLIVersion(): string;
|
|
8
|
+
getBaseUrl(): string | undefined;
|
|
9
|
+
getAuthBaseUrl(): string | undefined;
|
|
10
|
+
}
|
|
11
|
+
export declare const envInfo: EnvInfo;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import os from "os";
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
import { dirname, join } from "path";
|
|
4
|
+
import fs from "fs-extra";
|
|
5
|
+
class EnvInfo {
|
|
6
|
+
getUserAgent(shell) {
|
|
7
|
+
if (!EnvInfo.cachedUserAgent) {
|
|
8
|
+
const osInfo = `${os.platform()} ${os.release()}`;
|
|
9
|
+
const engine = "Node.js";
|
|
10
|
+
const engineVersion = process.version;
|
|
11
|
+
EnvInfo.cachedUserAgent = `APIMATIC CLI/${this.getCLIVersion()} - (OS: ${osInfo}, Engine: ${engine}/${engineVersion}, Shell: ${shell})`;
|
|
12
|
+
}
|
|
13
|
+
return EnvInfo.cachedUserAgent;
|
|
14
|
+
}
|
|
15
|
+
getCLIVersion() {
|
|
16
|
+
if (EnvInfo.cachedCliVersion) {
|
|
17
|
+
return EnvInfo.cachedCliVersion;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
21
|
+
const __dirname = dirname(__filename);
|
|
22
|
+
const pkgPath = join(__dirname, "../../package.json");
|
|
23
|
+
const pkgJson = fs.readFileSync(pkgPath, "utf-8");
|
|
24
|
+
const pkg = JSON.parse(pkgJson);
|
|
25
|
+
const version = pkg.version || "unknown";
|
|
26
|
+
EnvInfo.cachedCliVersion = version;
|
|
27
|
+
return version;
|
|
28
|
+
}
|
|
29
|
+
catch (_a) {
|
|
30
|
+
return "unknown";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
getBaseUrl() {
|
|
34
|
+
if (EnvInfo.cachedBaseUrl) {
|
|
35
|
+
return EnvInfo.cachedBaseUrl;
|
|
36
|
+
}
|
|
37
|
+
const envBaseUrls = process.env.APIMATIC_BASE_URL;
|
|
38
|
+
if (envBaseUrls) {
|
|
39
|
+
EnvInfo.cachedBaseUrl = envBaseUrls.split(";")[0];
|
|
40
|
+
}
|
|
41
|
+
return EnvInfo.cachedBaseUrl;
|
|
42
|
+
}
|
|
43
|
+
getAuthBaseUrl() {
|
|
44
|
+
if (EnvInfo.cachedAuthBaseUrl) {
|
|
45
|
+
return EnvInfo.cachedAuthBaseUrl;
|
|
46
|
+
}
|
|
47
|
+
const envBaseUrls = process.env.APIMATIC_BASE_URL;
|
|
48
|
+
if (envBaseUrls) {
|
|
49
|
+
const baseUrls = envBaseUrls.split(";");
|
|
50
|
+
EnvInfo.cachedAuthBaseUrl = baseUrls.length === 2 ? baseUrls[1] : undefined;
|
|
51
|
+
}
|
|
52
|
+
return EnvInfo.cachedAuthBaseUrl;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
EnvInfo.cachedCliVersion = null;
|
|
56
|
+
EnvInfo.cachedUserAgent = null;
|
|
57
|
+
export const envInfo = new EnvInfo();
|
|
58
|
+
//# sourceMappingURL=env-info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-info.js","sourceRoot":"","sources":["../../src/infrastructure/env-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,MAAM,UAAU,CAAC;AAE1B,MAAM,OAAO;IAMJ,YAAY,CAAC,KAAa;QAC/B,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC;YAC7B,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC;YAClD,MAAM,MAAM,GAAG,SAAS,CAAC;YACzB,MAAM,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC;YACtC,OAAO,CAAC,eAAe,GAAG,gBAAgB,IAAI,CAAC,aAAa,EAAE,WAAW,MAAM,aAAa,MAAM,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M,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QAClD,IAAI,WAAW,EAAE,CAAC;YAChB,MAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACxC,OAAO,CAAC,iBAAiB,GAAG,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC9E,CAAC;QACD,OAAO,OAAO,CAAC,iBAAiB,CAAC;IACnC,CAAC;;AAvDc,wBAAgB,GAAkB,IAAI,CAAC;AACvC,uBAAe,GAAkB,IAAI,CAAC;AAwDvD,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { FilePath } from "../types/file/filePath.js";
|
|
3
|
+
import { DirectoryPath } from "../types/file/directoryPath.js";
|
|
4
|
+
import { Directory } from "../types/file/directory.js";
|
|
5
|
+
export declare class FileService {
|
|
6
|
+
fileExists(file: FilePath): Promise<boolean>;
|
|
7
|
+
directoryExists(dir: DirectoryPath): Promise<boolean>;
|
|
8
|
+
directoryEmpty(dir: DirectoryPath): Promise<boolean>;
|
|
9
|
+
cleanDirectory(dir: DirectoryPath): Promise<void>;
|
|
10
|
+
createDirectoryIfNotExists(dir: DirectoryPath): Promise<void>;
|
|
11
|
+
getDirectory(directoryPath: DirectoryPath): Promise<Directory>;
|
|
12
|
+
copyDirectoryContents(source: DirectoryPath, destination: DirectoryPath): Promise<void>;
|
|
13
|
+
deleteFile(filePath: FilePath): Promise<void>;
|
|
14
|
+
deleteDirectory(dirPath: DirectoryPath): Promise<void>;
|
|
15
|
+
getRelativePath(filePath: FilePath, basePath: DirectoryPath): string;
|
|
16
|
+
getStream(filePath: FilePath): Promise<fs.ReadStream>;
|
|
17
|
+
getContents(filePath: FilePath): Promise<string>;
|
|
18
|
+
writeFile(filePath: FilePath, stream: NodeJS.ReadableStream): Promise<void>;
|
|
19
|
+
ensurePathExists(filePath: FilePath): Promise<void>;
|
|
20
|
+
writeContents(filePath: FilePath, contents: string): Promise<void>;
|
|
21
|
+
copy(source: FilePath, destination: FilePath): Promise<void>;
|
|
22
|
+
isZipFile(filePath: FilePath): Promise<boolean>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import fsExtra from "fs-extra";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import { pipeline } from "stream";
|
|
5
|
+
import { promisify } from "util";
|
|
6
|
+
import { DirectoryPath } from "../types/file/directoryPath.js";
|
|
7
|
+
import { Directory } from "../types/file/directory.js";
|
|
8
|
+
import { FileName } from "../types/file/fileName.js";
|
|
9
|
+
export class FileService {
|
|
10
|
+
async fileExists(file) {
|
|
11
|
+
try {
|
|
12
|
+
const stat = await fsExtra.stat(file.toString());
|
|
13
|
+
return stat.isFile();
|
|
14
|
+
}
|
|
15
|
+
catch (_a) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async directoryExists(dir) {
|
|
20
|
+
try {
|
|
21
|
+
const stat = await fsExtra.stat(dir.toString());
|
|
22
|
+
return stat.isDirectory();
|
|
23
|
+
}
|
|
24
|
+
catch (_a) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async directoryEmpty(dir) {
|
|
29
|
+
try {
|
|
30
|
+
const files = await fsExtra.readdir(dir.toString());
|
|
31
|
+
return files.length === 0;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async cleanDirectory(dir) {
|
|
38
|
+
await fsExtra.ensureDir(dir.toString());
|
|
39
|
+
await fsExtra.emptyDir(dir.toString()); // removes everything inside, keeps the dir
|
|
40
|
+
}
|
|
41
|
+
async createDirectoryIfNotExists(dir) {
|
|
42
|
+
await fsExtra.ensureDir(dir.toString());
|
|
43
|
+
}
|
|
44
|
+
async getDirectory(directoryPath) {
|
|
45
|
+
const entries = await fsExtra.readdir(directoryPath.toString());
|
|
46
|
+
const results = await Promise.all(entries.map(async (entry) => {
|
|
47
|
+
const fullPath = path.join(directoryPath.toString(), entry);
|
|
48
|
+
const stat = await fsExtra.stat(fullPath);
|
|
49
|
+
return stat.isDirectory() ? await this.getDirectory(new DirectoryPath(fullPath)) : new FileName(entry);
|
|
50
|
+
}));
|
|
51
|
+
return new Directory(directoryPath, results);
|
|
52
|
+
}
|
|
53
|
+
async copyDirectoryContents(source, destination) {
|
|
54
|
+
const entries = await fsExtra.readdir(source.toString());
|
|
55
|
+
await Promise.all(entries.map(async (entry) => {
|
|
56
|
+
const srcEntry = path.join(source.toString(), entry);
|
|
57
|
+
const destEntry = path.join(destination.toString(), entry);
|
|
58
|
+
await fsExtra.copy(srcEntry, destEntry);
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
async deleteFile(filePath) {
|
|
62
|
+
const exists = await this.fileExists(filePath);
|
|
63
|
+
if (exists) {
|
|
64
|
+
await fsExtra.remove(filePath.toString());
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async deleteDirectory(dirPath) {
|
|
68
|
+
const exists = await this.directoryExists(dirPath);
|
|
69
|
+
if (exists) {
|
|
70
|
+
await fsExtra.remove(dirPath.toString());
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
getRelativePath(filePath, basePath) {
|
|
74
|
+
const filePathStr = filePath.toString();
|
|
75
|
+
const basePathStr = basePath.toString();
|
|
76
|
+
if (filePathStr.startsWith(basePathStr)) {
|
|
77
|
+
const relativePath = filePathStr.substring(basePathStr.length).replace(/^[/\\]/, "");
|
|
78
|
+
return relativePath.replace(/\\/g, "/");
|
|
79
|
+
}
|
|
80
|
+
// Normalize the full path if it doesn't start with basePath
|
|
81
|
+
return filePathStr.replace(/\\/g, "/");
|
|
82
|
+
}
|
|
83
|
+
async getStream(filePath) {
|
|
84
|
+
return fs.createReadStream(filePath.toString());
|
|
85
|
+
}
|
|
86
|
+
async getContents(filePath) {
|
|
87
|
+
return await fsExtra.readFile(filePath.toString(), "utf-8");
|
|
88
|
+
}
|
|
89
|
+
async writeFile(filePath, stream) {
|
|
90
|
+
const writeStream = fs.createWriteStream(filePath.toString());
|
|
91
|
+
await streamPipeline(stream, writeStream);
|
|
92
|
+
}
|
|
93
|
+
async ensurePathExists(filePath) {
|
|
94
|
+
await fsExtra.ensureFile(filePath.toString());
|
|
95
|
+
}
|
|
96
|
+
async writeContents(filePath, contents) {
|
|
97
|
+
await fsExtra.writeFile(filePath.toString(), contents, "utf-8");
|
|
98
|
+
}
|
|
99
|
+
async copy(source, destination) {
|
|
100
|
+
await fsExtra.copyFile(source.toString(), destination.toString());
|
|
101
|
+
}
|
|
102
|
+
async isZipFile(filePath) {
|
|
103
|
+
try {
|
|
104
|
+
const buffer = await fsExtra.readFile(filePath.toString());
|
|
105
|
+
return (buffer.length >= 4 &&
|
|
106
|
+
buffer[0] === 0x50 && // P
|
|
107
|
+
buffer[1] === 0x4b && // K
|
|
108
|
+
buffer[2] === 0x03 && // \x03
|
|
109
|
+
buffer[3] === 0x04); // \x04
|
|
110
|
+
}
|
|
111
|
+
catch (_a) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const streamPipeline = promisify(pipeline);
|
|
117
|
+
//# sourceMappingURL=file-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-service.js","sourceRoot":"","sources":["../../src/infrastructure/file-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,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,IAAI;gBAC1B,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,OAAO;gBAC7B,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,CACnB,CAAC,CAAC,OAAO;QACZ,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF;AAED,MAAM,cAAc,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FilePath } from "../types/file/filePath.js";
|
|
2
|
+
import { UrlPath } from "../types/file/urlPath.js";
|
|
3
|
+
export declare class LauncherService {
|
|
4
|
+
openInEditor(filePath: FilePath): Promise<void>;
|
|
5
|
+
openFile(filePath: FilePath): Promise<void>;
|
|
6
|
+
openUrlInBrowser(url: UrlPath): Promise<import("child_process").ChildProcess>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { execa } from "execa";
|
|
2
|
+
import os from "os";
|
|
3
|
+
import { spawn } from "child_process";
|
|
4
|
+
import open from "open";
|
|
5
|
+
export class LauncherService {
|
|
6
|
+
async openInEditor(filePath) {
|
|
7
|
+
try {
|
|
8
|
+
await execa("code", ["--wait", filePath.toString()]);
|
|
9
|
+
}
|
|
10
|
+
catch (_a) {
|
|
11
|
+
// TODO: check for fallback (start)
|
|
12
|
+
if (process.platform === "win32") {
|
|
13
|
+
await execa("cmd", ["/c", "start", "/wait", "notepad", filePath.toString()], { stdio: "ignore" });
|
|
14
|
+
}
|
|
15
|
+
else if (process.platform === "darwin") {
|
|
16
|
+
await execa("vim", [filePath.toString()], { stdio: "inherit" });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async openFile(filePath) {
|
|
21
|
+
const targetPath = filePath.toString();
|
|
22
|
+
// Determine the command and args without using the shell
|
|
23
|
+
let command;
|
|
24
|
+
let args;
|
|
25
|
+
switch (os.platform()) {
|
|
26
|
+
case "win32":
|
|
27
|
+
command = "cmd";
|
|
28
|
+
args = ["/c", "start", "", targetPath];
|
|
29
|
+
break;
|
|
30
|
+
case "darwin":
|
|
31
|
+
command = "open";
|
|
32
|
+
args = [targetPath];
|
|
33
|
+
break;
|
|
34
|
+
default:
|
|
35
|
+
command = "xdg-open";
|
|
36
|
+
args = [targetPath];
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const child = spawn(command, args, { stdio: "ignore", detached: true });
|
|
41
|
+
child.unref(); // Let it run without blocking
|
|
42
|
+
}
|
|
43
|
+
catch (_a) {
|
|
44
|
+
// Silently ignore errors
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
openUrlInBrowser(url) {
|
|
48
|
+
return open(url.toString());
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=launcher-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launcher-service.js","sourceRoot":"","sources":["../../src/infrastructure/launcher-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,MAAM,OAAO,eAAe;IAEnB,KAAK,CAAC,YAAY,CAAC,QAAkB;QAC1C,IAAI,CAAC;YACH,MAAM,KAAK,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QACvD,CAAC;QAAC,WAAM,CAAC;YACP,mCAAmC;YACnC,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;gBACjC,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,KAA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3,"file":"network-service.js","sourceRoot":"","sources":["../../src/infrastructure/network-service.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,UAAU,CAAC;AAE/B,MAAM,OAAO,cAAc;IAClB,KAAK,CAAC,aAAa,CAAC,cAAwB;QACjD,OAAO,MAAM,OAAO,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC;IACjD,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Client, Environment } from "@apimatic/sdk";
|
|
2
|
+
import { envInfo } from "../env-info.js";
|
|
3
|
+
export class ApiClientFactory {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.TIMEOUT = 0;
|
|
6
|
+
this.createApiClient = (authorizationHeader, shell) => {
|
|
7
|
+
const baseConfig = {
|
|
8
|
+
customHeaderAuthenticationCredentials: {
|
|
9
|
+
Authorization: authorizationHeader
|
|
10
|
+
},
|
|
11
|
+
userAgent: envInfo.getUserAgent(shell),
|
|
12
|
+
timeout: this.TIMEOUT
|
|
13
|
+
};
|
|
14
|
+
const baseUrl = envInfo.getBaseUrl();
|
|
15
|
+
return new Client(Object.assign(Object.assign(Object.assign({}, baseConfig), { environment: baseUrl ? Environment.Testing : Environment.Production }), (baseUrl && { customUrl: baseUrl })));
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export const apiClientFactory = new ApiClientFactory();
|
|
20
|
+
//# sourceMappingURL=api-client-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client-factory.js","sourceRoot":"","sources":["../../../src/infrastructure/services/api-client-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,MAAM,OAAO,gBAAgB;IAA7B;QACmB,YAAO,GAAG,CAAC,CAAC;QAEtB,oBAAe,GAAG,CAAC,mBAA2B,EAAE,KAAa,EAAU,EAAE;YAC9E,MAAM,UAAU,GAAG;gBACjB,qCAAqC,EAAE;oBACrC,aAAa,EAAE,mBAAmB;iBACnC;gBACD,SAAS,EAAE,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC;gBACtC,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB,CAAC;YAEF,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;YACrC,OAAO,IAAI,MAAM,+CACZ,UAAU,KACb,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,UAAU,KAChE,CAAC,OAAO,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EACtC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DirectoryPath } from "../../types/file/directoryPath.js";
|
|
2
|
+
import { SubscriptionInfo } from "../../types/api/account.js";
|
|
3
|
+
import { Result } from "neverthrow";
|
|
4
|
+
import { ServiceError } from "../api-utils.js";
|
|
5
|
+
export declare class ApiService {
|
|
6
|
+
private readonly apiBaseUrl;
|
|
7
|
+
getAccountInfo(configDir: DirectoryPath, shell: string, authKey: string | null): Promise<Result<SubscriptionInfo, ServiceError>>;
|
|
8
|
+
sendTelemetry(payload: string, authKey: string, shell: string): Promise<Result<string, string>>;
|
|
9
|
+
private axiosInstance;
|
|
10
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { getAuthInfo } from "../../client-utils/auth-manager.js";
|
|
3
|
+
import { envInfo } from "../env-info.js";
|
|
4
|
+
import { err, ok } from "neverthrow";
|
|
5
|
+
import { handleServiceError } from "../api-utils.js";
|
|
6
|
+
export class ApiService {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.apiBaseUrl = "https://api.apimatic.io";
|
|
9
|
+
}
|
|
10
|
+
async getAccountInfo(configDir, shell, authKey) {
|
|
11
|
+
const authInfo = await getAuthInfo(configDir.toString());
|
|
12
|
+
if (authInfo === null && !authKey) {
|
|
13
|
+
return err("UNAUTHORIZED" /* ServiceError.UnAuthorized */);
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const token = authKey || (authInfo === null || authInfo === void 0 ? void 0 : authInfo.authKey);
|
|
17
|
+
const response = await this.axiosInstance(shell, token).get("/account/profile");
|
|
18
|
+
if (response.status === 200) {
|
|
19
|
+
return ok(response.data);
|
|
20
|
+
}
|
|
21
|
+
return err("INVALID_RESPONSE" /* ServiceError.InvalidResponse */);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
return err(handleServiceError(error));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async sendTelemetry(payload, authKey, shell) {
|
|
28
|
+
try {
|
|
29
|
+
const response = await this.axiosInstance(shell, authKey).post("/telemetry/track", payload, {
|
|
30
|
+
headers: { "Content-Type": "application/json" }
|
|
31
|
+
});
|
|
32
|
+
if (response.status === 200) {
|
|
33
|
+
return ok("telemetry sent");
|
|
34
|
+
}
|
|
35
|
+
return err("Failed to send telemetry data");
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
return err(handleServiceError(error));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
axiosInstance(shell, apiKey) {
|
|
42
|
+
var _a;
|
|
43
|
+
const headers = {
|
|
44
|
+
"User-Agent": envInfo.getUserAgent(shell)
|
|
45
|
+
};
|
|
46
|
+
if (apiKey) {
|
|
47
|
+
headers.Authorization = `X-Auth-Key ${apiKey}`;
|
|
48
|
+
}
|
|
49
|
+
return axios.create({
|
|
50
|
+
baseURL: (_a = envInfo.getBaseUrl()) !== null && _a !== void 0 ? _a : this.apiBaseUrl,
|
|
51
|
+
headers
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=api-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-service.js","sourceRoot":"","sources":["../../../src/infrastructure/services/api-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAY,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAG3E,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,EAAE,EAAU,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAgB,MAAM,iBAAiB,CAAC;AAEnE,MAAM,OAAO,UAAU;IAAvB;QACmB,eAAU,GAAG,yBAAkC,CAAC;IAsDnE,CAAC;IApDQ,KAAK,CAAC,cAAc,CACzB,SAAwB,EACxB,KAAa,EACb,OAAsB;QAEtB,MAAM,QAAQ,GAAoB,MAAM,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC1E,IAAI,QAAQ,KAAK,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAClC,OAAO,GAAG,gDAA2B,CAAC;QACxC,CAAC;QAED,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,OAAO,KAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,CAAA,CAAC;YAC3C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;YAEhF,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;gBAC5B,OAAO,EAAE,CAAC,QAAQ,CAAC,IAAwB,CAAC,CAAC;YAC/C,CAAC;YACD,OAAO,GAAG,uDAA8B,CAAC;QAC3C,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,OAAO,GAAG,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,OAAe,EAAE,OAAe,EAAE,KAAa;QACxE,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,kBAAkB,EAAE,OAAO,EAAE;gBAC1F,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;aAChD,CAAC,CAAC;YAEH,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;gBAC5B,OAAO,EAAE,CAAC,gBAAgB,CAAC,CAAC;YAC9B,CAAC;YACD,OAAO,GAAG,CAAC,+BAA+B,CAAC,CAAC;QAC9C,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,OAAO,GAAG,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAEO,aAAa,CAAC,KAAa,EAAE,MAA0B;;QAC7D,MAAM,OAAO,GAA2B;YACtC,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC;SAC1C,CAAC;QAEF,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,CAAC,aAAa,GAAG,cAAc,MAAM,EAAE,CAAC;QACjD,CAAC;QAED,OAAO,KAAK,CAAC,MAAM,CAAC;YAClB,OAAO,EAAE,MAAA,OAAO,CAAC,UAAU,EAAE,mCAAI,IAAI,CAAC,UAAU;YAChD,OAAO;SACR,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Result } from "neverthrow";
|
|
2
|
+
import { ServiceError } from "../api-utils.js";
|
|
3
|
+
export interface DeviceAuthToken {
|
|
4
|
+
apiKey: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class AuthService {
|
|
7
|
+
private readonly apiBaseUrl;
|
|
8
|
+
private axiosInstance;
|
|
9
|
+
getDeviceLoginUrl(state: string): string;
|
|
10
|
+
getDeviceLoginToken(state: string, shell: string): Promise<Result<DeviceAuthToken, ServiceError>>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { envInfo } from "../env-info.js";
|
|
3
|
+
import { err, ok } from "neverthrow";
|
|
4
|
+
import { handleServiceError } from "../api-utils.js";
|
|
5
|
+
export class AuthService {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.apiBaseUrl = "https://auth.apimatic.io";
|
|
8
|
+
}
|
|
9
|
+
axiosInstance(shell) {
|
|
10
|
+
var _a;
|
|
11
|
+
return axios.create({
|
|
12
|
+
baseURL: (_a = envInfo.getAuthBaseUrl()) !== null && _a !== void 0 ? _a : this.apiBaseUrl,
|
|
13
|
+
timeout: 20000,
|
|
14
|
+
headers: {
|
|
15
|
+
"User-Agent": envInfo.getUserAgent(shell)
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
getDeviceLoginUrl(state) {
|
|
20
|
+
var _a;
|
|
21
|
+
return `${(_a = envInfo.getAuthBaseUrl()) !== null && _a !== void 0 ? _a : this.apiBaseUrl}/device-auth/login?state=${state}`;
|
|
22
|
+
}
|
|
23
|
+
async getDeviceLoginToken(state, shell) {
|
|
24
|
+
var _a;
|
|
25
|
+
try {
|
|
26
|
+
const response = await this.axiosInstance(shell).get(`/device-auth/token?state=${state}`);
|
|
27
|
+
if (response.status === 200 && ((_a = response.data) === null || _a === void 0 ? void 0 : _a.apiKey)) {
|
|
28
|
+
return ok({ apiKey: response.data.apiKey });
|
|
29
|
+
}
|
|
30
|
+
return err("INVALID_RESPONSE" /* ServiceError.InvalidResponse */);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
return err(handleServiceError(error));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=auth-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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E,CAAC;YACf,OAAO,GAAG,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { UrlPath } from "../../types/file/urlPath.js";
|
|
2
|
+
import { Result } from "neverthrow";
|
|
3
|
+
import { ServiceError } from "../api-utils.js";
|
|
4
|
+
import { FileName } from "../../types/file/fileName.js";
|
|
5
|
+
export type FileDownloadResponse = {
|
|
6
|
+
stream: NodeJS.ReadableStream;
|
|
7
|
+
filename: FileName;
|
|
8
|
+
};
|
|
9
|
+
export declare class FileDownloadService {
|
|
10
|
+
downloadFile(url: UrlPath): Promise<Result<FileDownloadResponse, ServiceError>>;
|
|
11
|
+
private parseFilenameFromContentDisposition;
|
|
12
|
+
private getFilenameFromUrl;
|
|
13
|
+
private safeDecodeURIComponent;
|
|
14
|
+
private sanitizeFilename;
|
|
15
|
+
}
|