@apimatic/cli 1.2.1 → 1.3.0-beta.2
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 +65 -1
- package/lib/actions/action-result.d.ts +1 -0
- package/lib/actions/action-result.js +3 -0
- package/lib/actions/action-result.js.map +1 -1
- package/lib/actions/plugin/generate.d.ts +12 -0
- package/lib/actions/plugin/generate.js +71 -0
- package/lib/actions/plugin/generate.js.map +1 -0
- package/lib/actions/plugin/publish.d.ts +6 -0
- package/lib/actions/plugin/publish.js +43 -0
- package/lib/actions/plugin/publish.js.map +1 -0
- package/lib/actions/plugin/record-metadata.d.ts +18 -0
- package/lib/actions/plugin/record-metadata.js +57 -0
- package/lib/actions/plugin/record-metadata.js.map +1 -0
- package/lib/actions/plugin/record-sdk.d.ts +14 -0
- package/lib/actions/plugin/record-sdk.js +60 -0
- package/lib/actions/plugin/record-sdk.js.map +1 -0
- package/lib/actions/sdk/generate.d.ts +2 -2
- package/lib/actions/sdk/generate.js +4 -4
- package/lib/actions/sdk/generate.js.map +1 -1
- package/lib/actions/sdk/publish/interactive.js +23 -4
- package/lib/actions/sdk/publish/interactive.js.map +1 -1
- package/lib/actions/sdk/publish/non-interactive.d.ts +2 -2
- package/lib/actions/sdk/publish/non-interactive.js +19 -12
- package/lib/actions/sdk/publish/non-interactive.js.map +1 -1
- package/lib/actions/sdk/publish.d.ts +2 -3
- package/lib/actions/sdk/publish.js +26 -5
- package/lib/actions/sdk/publish.js.map +1 -1
- package/lib/actions/sdk/quickstart.js +2 -2
- package/lib/actions/sdk/quickstart.js.map +1 -1
- package/lib/commands/plugin/generate.d.ts +14 -0
- package/lib/commands/plugin/generate.js +37 -0
- package/lib/commands/plugin/generate.js.map +1 -0
- package/lib/commands/plugin/publish.d.ts +11 -0
- package/lib/commands/plugin/publish.js +29 -0
- package/lib/commands/plugin/publish.js.map +1 -0
- package/lib/commands/sdk/generate.js +4 -3
- package/lib/commands/sdk/generate.js.map +1 -1
- package/lib/commands/sdk/publish.d.ts +3 -0
- package/lib/commands/sdk/publish.js +18 -5
- package/lib/commands/sdk/publish.js.map +1 -1
- package/lib/config/axios-config.d.ts +6 -0
- package/lib/config/axios-config.js +8 -2
- package/lib/config/axios-config.js.map +1 -1
- package/lib/infrastructure/generation-status-poller.d.ts +31 -0
- package/lib/infrastructure/generation-status-poller.js +56 -0
- package/lib/infrastructure/generation-status-poller.js.map +1 -0
- package/lib/infrastructure/service-error.d.ts +10 -1
- package/lib/infrastructure/service-error.js +47 -0
- package/lib/infrastructure/service-error.js.map +1 -1
- package/lib/infrastructure/services/api-service.d.ts +0 -7
- package/lib/infrastructure/services/api-service.js +0 -42
- package/lib/infrastructure/services/api-service.js.map +1 -1
- package/lib/infrastructure/services/plugin-service.d.ts +24 -0
- package/lib/infrastructure/services/plugin-service.js +141 -0
- package/lib/infrastructure/services/plugin-service.js.map +1 -0
- package/lib/infrastructure/services/portal-service.d.ts +16 -8
- package/lib/infrastructure/services/portal-service.js +147 -39
- package/lib/infrastructure/services/portal-service.js.map +1 -1
- package/lib/prompts/format.d.ts +4 -3
- package/lib/prompts/format.js +14 -13
- package/lib/prompts/format.js.map +1 -1
- package/lib/prompts/plugin/generate.d.ts +19 -0
- package/lib/prompts/plugin/generate.js +64 -0
- package/lib/prompts/plugin/generate.js.map +1 -0
- package/lib/prompts/plugin/publish.d.ts +25 -0
- package/lib/prompts/plugin/publish.js +77 -0
- package/lib/prompts/plugin/publish.js.map +1 -0
- package/lib/prompts/plugin/record-metadata.d.ts +25 -0
- package/lib/prompts/plugin/record-metadata.js +70 -0
- package/lib/prompts/plugin/record-metadata.js.map +1 -0
- package/lib/prompts/plugin/record-sdk.d.ts +9 -0
- package/lib/prompts/plugin/record-sdk.js +40 -0
- package/lib/prompts/plugin/record-sdk.js.map +1 -0
- package/lib/prompts/publishing/links.d.ts +1 -0
- package/lib/prompts/publishing/links.js +2 -0
- package/lib/prompts/publishing/links.js.map +1 -0
- package/lib/prompts/publishing/profile/list.js +5 -3
- package/lib/prompts/publishing/profile/list.js.map +1 -1
- package/lib/prompts/sdk/generate.d.ts +2 -0
- package/lib/prompts/sdk/generate.js +7 -0
- package/lib/prompts/sdk/generate.js.map +1 -1
- package/lib/prompts/sdk/publish/interactive.d.ts +7 -5
- package/lib/prompts/sdk/publish/interactive.js +29 -14
- package/lib/prompts/sdk/publish/interactive.js.map +1 -1
- package/lib/prompts/sdk/publish/non-interactive.d.ts +1 -6
- package/lib/prompts/sdk/publish/non-interactive.js +11 -52
- package/lib/prompts/sdk/publish/non-interactive.js.map +1 -1
- package/lib/prompts/sdk/publish.d.ts +15 -2
- package/lib/prompts/sdk/publish.js +71 -5
- package/lib/prompts/sdk/publish.js.map +1 -1
- package/lib/types/file/directory.d.ts +3 -0
- package/lib/types/file/directory.js +13 -0
- package/lib/types/file/directory.js.map +1 -1
- package/lib/types/plugin/generation-status.d.ts +23 -0
- package/lib/types/plugin/generation-status.js +18 -0
- package/lib/types/plugin/generation-status.js.map +1 -0
- package/lib/types/plugin/language-entry.d.ts +9 -0
- package/lib/types/plugin/language-entry.js +64 -0
- package/lib/types/plugin/language-entry.js.map +1 -0
- package/lib/types/plugin/plugin-config.d.ts +72 -0
- package/lib/types/plugin/plugin-config.js +4 -0
- package/lib/types/plugin/plugin-config.js.map +1 -0
- package/lib/types/plugin/plugin-contents.d.ts +5 -0
- package/lib/types/plugin/plugin-contents.js +2 -0
- package/lib/types/plugin/plugin-contents.js.map +1 -0
- package/lib/types/plugin-config-context.d.ts +63 -0
- package/lib/types/plugin-config-context.js +179 -0
- package/lib/types/plugin-config-context.js.map +1 -0
- package/lib/types/plugin-context.d.ts +13 -0
- package/lib/types/plugin-context.js +28 -0
- package/lib/types/plugin-context.js.map +1 -0
- package/lib/types/publish/package-settings-configuration.d.ts +11 -1
- package/lib/types/publish/package-settings-configuration.js +1 -1
- package/lib/types/publish/package-settings-configuration.js.map +1 -1
- package/lib/types/publish/publishing-profile.d.ts +3 -2
- package/lib/types/publish/publishing-profile.js +24 -18
- package/lib/types/publish/publishing-profile.js.map +1 -1
- package/lib/types/publish/publishing-profiles.d.ts +1 -1
- package/lib/types/publish/publishing-profiles.js +1 -1
- package/lib/types/publish/publishing-profiles.js.map +1 -1
- package/lib/types/publish/version.d.ts +6 -1
- package/lib/types/publish/version.js +2 -1
- package/lib/types/publish/version.js.map +1 -1
- package/lib/types/sdk/generate.d.ts +19 -0
- package/lib/types/sdk/generate.js +44 -0
- package/lib/types/sdk/generate.js.map +1 -1
- package/lib/types/utils.d.ts +1 -0
- package/oclif.manifest.json +1040 -0
- package/package.json +7 -4
- package/lib/types/api/generation-status-endpoint.d.ts +0 -8
- package/lib/types/api/generation-status-endpoint.js +0 -12
- package/lib/types/api/generation-status-endpoint.js.map +0 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Result } from 'neverthrow';
|
|
2
|
+
import { ServiceError } from './service-error.js';
|
|
3
|
+
export declare const STATUS_POLL_INTERVAL_MS = 3000;
|
|
4
|
+
/**
|
|
5
|
+
* Set well clear of any plausible run: it exists to end a generation that is stuck, not to
|
|
6
|
+
* cap a slow one. No duration data exists for real runs, so this is the number to revisit
|
|
7
|
+
* if a legitimate generation ever reports a timeout.
|
|
8
|
+
*/
|
|
9
|
+
export declare const GENERATION_TIMEOUT_MS: number;
|
|
10
|
+
export interface GenerationStatus {
|
|
11
|
+
status: string;
|
|
12
|
+
errors?: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
export type ValidationErrorFormatter = (errors: Record<string, string[]>) => string;
|
|
15
|
+
export interface GenerationPoll<T extends GenerationStatus> {
|
|
16
|
+
pollIntervalMs: number;
|
|
17
|
+
fetchStatus: () => Promise<Result<T, ServiceError>>;
|
|
18
|
+
/**
|
|
19
|
+
* Bounds a run whose status never reaches a terminal value. `label` opens the message.
|
|
20
|
+
* The budget is only read between polls, so `fetchStatus` must bound its own request —
|
|
21
|
+
* one that connects and never answers outlives any budget set here.
|
|
22
|
+
*/
|
|
23
|
+
timeout: {
|
|
24
|
+
budgetMs: number;
|
|
25
|
+
label: string;
|
|
26
|
+
};
|
|
27
|
+
/** Only when the endpoint needs custom validation wording. */
|
|
28
|
+
formatValidationError?: ValidationErrorFormatter;
|
|
29
|
+
}
|
|
30
|
+
export declare function pollUntilCompleted<T extends GenerationStatus>({ pollIntervalMs, fetchStatus, timeout, formatValidationError }: GenerationPoll<T>): Promise<Result<T, ServiceError>>;
|
|
31
|
+
export declare const formatValidationErrors: ValidationErrorFormatter;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Status } from '@apimatic/sdk';
|
|
2
|
+
import { err, ok } from 'neverthrow';
|
|
3
|
+
import { ServiceError } from './service-error.js';
|
|
4
|
+
export const STATUS_POLL_INTERVAL_MS = 3000;
|
|
5
|
+
/**
|
|
6
|
+
* Set well clear of any plausible run: it exists to end a generation that is stuck, not to
|
|
7
|
+
* cap a slow one. No duration data exists for real runs, so this is the number to revisit
|
|
8
|
+
* if a legitimate generation ever reports a timeout.
|
|
9
|
+
*/
|
|
10
|
+
export const GENERATION_TIMEOUT_MS = 30 * 60 * 1000;
|
|
11
|
+
export async function pollUntilCompleted({ pollIntervalMs, fetchStatus, timeout, formatValidationError = formatValidationErrors }) {
|
|
12
|
+
const deadline = Date.now() + timeout.budgetMs;
|
|
13
|
+
for (;;) {
|
|
14
|
+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
15
|
+
const statusResult = await fetchStatus();
|
|
16
|
+
if (statusResult.isErr()) {
|
|
17
|
+
return err(statusResult.error);
|
|
18
|
+
}
|
|
19
|
+
const { status, errors } = statusResult.value;
|
|
20
|
+
if (status === Status.Completed) {
|
|
21
|
+
return ok(statusResult.value);
|
|
22
|
+
}
|
|
23
|
+
if (status === Status.Failed) {
|
|
24
|
+
return err(ServiceError.ServerError);
|
|
25
|
+
}
|
|
26
|
+
if (status === Status.ValidationError) {
|
|
27
|
+
const validationErrors = asMessages(errors);
|
|
28
|
+
return err(ServiceError.badRequest(formatValidationError(validationErrors), validationErrors));
|
|
29
|
+
}
|
|
30
|
+
if (status === Status.SubscriptionError) {
|
|
31
|
+
const message = Object.values(asMessages(errors)).flat()[0];
|
|
32
|
+
return err(ServiceError.forbidden('Access denied to resource.' + (message ? '\n- ' + message : '')));
|
|
33
|
+
}
|
|
34
|
+
// Every other status keeps the run alive rather than ending it: an endpoint reporting
|
|
35
|
+
// its own in-flight vocabulary is healthy, and the plugin orchestrator reports
|
|
36
|
+
// `Unknown` until it writes a custom status. The deadline is what stops a genuinely
|
|
37
|
+
// stuck run, and it is read after the status so a run that finished during the last
|
|
38
|
+
// wait still counts.
|
|
39
|
+
if (Date.now() >= deadline) {
|
|
40
|
+
return err(ServiceError.timeout(timedOutMessage(timeout.label, timeout.budgetMs)));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export const formatValidationErrors = (errors) => {
|
|
45
|
+
const messages = Object.values(errors).flat();
|
|
46
|
+
return 'One or more validation errors occurred.' + (messages.length ? '\n- ' + messages.join('\n- ') : '');
|
|
47
|
+
};
|
|
48
|
+
const timedOutMessage = (label, budgetMs) => {
|
|
49
|
+
const minutes = Math.floor(budgetMs / 60000);
|
|
50
|
+
if (minutes < 1) {
|
|
51
|
+
return `${label} timed out.`;
|
|
52
|
+
}
|
|
53
|
+
return `${label} timed out after ${minutes} ${minutes === 1 ? 'minute' : 'minutes'}.`;
|
|
54
|
+
};
|
|
55
|
+
const asMessages = (errors) => (errors !== null && errors !== void 0 ? errors : {});
|
|
56
|
+
//# sourceMappingURL=generation-status-poller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generation-status-poller.js","sourceRoot":"","sources":["../../src/infrastructure/generation-status-poller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,EAAE,EAAU,MAAM,YAAY,CAAC;AAC7C,OA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,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC;AACxF,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,MAA2C,EAA4B,EAAE,CAC3F,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAA6B,CAAC"}
|
|
@@ -5,7 +5,8 @@ export declare enum ServiceErrorCode {
|
|
|
5
5
|
InvalidResponse = "INVALID_RESPONSE",
|
|
6
6
|
UnAuthorized = "UNAUTHORIZED",
|
|
7
7
|
BadRequest = "BAD_REQUEST",
|
|
8
|
-
Forbidden = "FORBIDDEN"
|
|
8
|
+
Forbidden = "FORBIDDEN",
|
|
9
|
+
Timeout = "TIMEOUT"
|
|
9
10
|
}
|
|
10
11
|
export declare class ServiceError {
|
|
11
12
|
readonly code: ServiceErrorCode;
|
|
@@ -20,10 +21,18 @@ export declare class ServiceError {
|
|
|
20
21
|
static badRequest(customMessage: string, errors: Record<string, string[]>): ServiceError;
|
|
21
22
|
static forbidden(customMessage: string): ServiceError;
|
|
22
23
|
static notFound(customMessage: string): ServiceError;
|
|
24
|
+
static timeout(customMessage: string): ServiceError;
|
|
23
25
|
static unauthorizedWithHint(apiMessage: string | null): ServiceError;
|
|
24
26
|
static readonly values: ServiceError[];
|
|
25
27
|
private constructor();
|
|
26
28
|
get errorMessage(): string;
|
|
27
29
|
getError(key: string): string[] | undefined;
|
|
28
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* `handleServiceError` maps an axios 401 onto the bare `Unauthorized access.`, which leaves the
|
|
33
|
+
* user with nothing to act on — the SDK path names the remedy but the axios path does not.
|
|
34
|
+
*/
|
|
35
|
+
export declare function mapTransportError(error: unknown): ServiceError;
|
|
36
|
+
/** For responses whose body is readable JSON; a streamed body can only be mapped by status. */
|
|
37
|
+
export declare function mapRequestError(error: unknown): ServiceError;
|
|
29
38
|
export declare function handleServiceError(error: unknown): ServiceError;
|
|
@@ -12,6 +12,7 @@ export var ServiceErrorCode;
|
|
|
12
12
|
ServiceErrorCode["UnAuthorized"] = "UNAUTHORIZED";
|
|
13
13
|
ServiceErrorCode["BadRequest"] = "BAD_REQUEST";
|
|
14
14
|
ServiceErrorCode["Forbidden"] = "FORBIDDEN";
|
|
15
|
+
ServiceErrorCode["Timeout"] = "TIMEOUT";
|
|
15
16
|
})(ServiceErrorCode || (ServiceErrorCode = {}));
|
|
16
17
|
export class ServiceError {
|
|
17
18
|
static badRequest(customMessage, errors) {
|
|
@@ -23,6 +24,9 @@ export class ServiceError {
|
|
|
23
24
|
static notFound(customMessage) {
|
|
24
25
|
return new _a(ServiceErrorCode.NotFound, customMessage, {});
|
|
25
26
|
}
|
|
27
|
+
static timeout(customMessage) {
|
|
28
|
+
return new _a(ServiceErrorCode.Timeout, customMessage, {});
|
|
29
|
+
}
|
|
26
30
|
static unauthorizedWithHint(apiMessage) {
|
|
27
31
|
// Both remedies name the full `auth login` command: the key is supplied to
|
|
28
32
|
// that command, not to whichever one hit the 401 — most of them don't accept
|
|
@@ -93,6 +97,49 @@ function mapApiError(error) {
|
|
|
93
97
|
return ServiceError.NotFound;
|
|
94
98
|
return ServiceError.ServerError;
|
|
95
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* `handleServiceError` reads a ProblemDetails body only off the SDK's typed errors, so on a raw
|
|
102
|
+
* axios call a 400 or 403 would collapse into a generic server error and lose its message.
|
|
103
|
+
* Unlike the SDK path this also falls back to `detail`, which io uses when it sends no `errors`
|
|
104
|
+
* map. Every other status is left to `mapTransportError`.
|
|
105
|
+
*/
|
|
106
|
+
function mapAxiosProblemDetails(error) {
|
|
107
|
+
var _b, _c, _d, _e, _f, _g;
|
|
108
|
+
if (!axios.isAxiosError(error)) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
const body = (_b = error.response) === null || _b === void 0 ? void 0 : _b.data;
|
|
112
|
+
if (typeof body !== "object" || body === null) {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
const errors = (_c = body.errors) !== null && _c !== void 0 ? _c : {};
|
|
116
|
+
const firstMessage = (_d = Object.values(errors).flat()[0]) !== null && _d !== void 0 ? _d : body.detail;
|
|
117
|
+
const title = (_e = body.title) !== null && _e !== void 0 ? _e : "Request failed.";
|
|
118
|
+
const message = firstMessage ? `${title}\n- ${firstMessage}` : title;
|
|
119
|
+
if (((_f = error.response) === null || _f === void 0 ? void 0 : _f.status) === 400) {
|
|
120
|
+
return ServiceError.badRequest(message, errors);
|
|
121
|
+
}
|
|
122
|
+
if (((_g = error.response) === null || _g === void 0 ? void 0 : _g.status) === 403) {
|
|
123
|
+
return ServiceError.forbidden(message);
|
|
124
|
+
}
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* `handleServiceError` maps an axios 401 onto the bare `Unauthorized access.`, which leaves the
|
|
129
|
+
* user with nothing to act on — the SDK path names the remedy but the axios path does not.
|
|
130
|
+
*/
|
|
131
|
+
export function mapTransportError(error) {
|
|
132
|
+
var _b;
|
|
133
|
+
if (axios.isAxiosError(error) && ((_b = error.response) === null || _b === void 0 ? void 0 : _b.status) === 401) {
|
|
134
|
+
return ServiceError.unauthorizedWithHint(null);
|
|
135
|
+
}
|
|
136
|
+
return handleServiceError(error);
|
|
137
|
+
}
|
|
138
|
+
/** For responses whose body is readable JSON; a streamed body can only be mapped by status. */
|
|
139
|
+
export function mapRequestError(error) {
|
|
140
|
+
var _b;
|
|
141
|
+
return (_b = mapAxiosProblemDetails(error)) !== null && _b !== void 0 ? _b : mapTransportError(error);
|
|
142
|
+
}
|
|
96
143
|
export function handleServiceError(error) {
|
|
97
144
|
var _b;
|
|
98
145
|
if (error instanceof ApiError) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-error.js","sourceRoot":"","sources":["../../src/infrastructure/service-error.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAA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AAM,KAAK,GAAG;YAAE,OAAO,YAAY,CAAC,YAAY,CAAC;QACrD,IAAI,MAAM,KAAK,GAAG;YAAE,OAAO,YAAY,CAAC,QAAQ,CAAC;QACjD,IAAI,MAAM,KAAK,GAAG;YAAE,OAAO,YAAY,CAAC,WAAW,CAAC;QAEpD,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YACjG,OAAO,YAAY,CAAC,YAAY,CAAC;QACnC,CAAC;IACH,CAAC;IAED,OAAO,YAAY,CAAC,WAAW,CAAC;AAClC,CAAC"}
|
|
@@ -2,16 +2,9 @@ import { DirectoryPath } from "../../types/file/directoryPath.js";
|
|
|
2
2
|
import { SubscriptionInfo } from "../../types/api/account.js";
|
|
3
3
|
import { Result } from "neverthrow";
|
|
4
4
|
import { ServiceError } from "../service-error.js";
|
|
5
|
-
import { GenerationStatusEndpoint } from "../../types/api/generation-status-endpoint.js";
|
|
6
|
-
import { GenerationStatusResponse } from "../../types/api/generation-status.js";
|
|
7
5
|
export declare class ApiService {
|
|
8
6
|
private readonly apiBaseUrl;
|
|
9
7
|
getAccountInfo(configDir: DirectoryPath, shell: string, authKey: string | null): Promise<Result<SubscriptionInfo, ServiceError>>;
|
|
10
|
-
/**
|
|
11
|
-
* Reads the status of one in-flight generation request. Shared by every
|
|
12
|
-
* async generation endpoint — see `GenerationStatusEndpoint`.
|
|
13
|
-
*/
|
|
14
|
-
getGenerationStatus(endpoint: GenerationStatusEndpoint, requestId: string, configDir: DirectoryPath, shell: string, authKey: string | null): Promise<Result<GenerationStatusResponse, ServiceError>>;
|
|
15
8
|
sendTelemetry(payload: string, authKey: string, shell: string): Promise<Result<string, string | ServiceError>>;
|
|
16
9
|
private axiosInstance;
|
|
17
10
|
}
|
|
@@ -3,7 +3,6 @@ import { getAuthInfo } from "../../client-utils/auth-manager.js";
|
|
|
3
3
|
import { envInfo } from "../env-info.js";
|
|
4
4
|
import { err, ok } from "neverthrow";
|
|
5
5
|
import { handleServiceError, ServiceError } from "../service-error.js";
|
|
6
|
-
import { Status } from "@apimatic/sdk";
|
|
7
6
|
export class ApiService {
|
|
8
7
|
constructor() {
|
|
9
8
|
this.apiBaseUrl = "https://api.apimatic.io";
|
|
@@ -25,47 +24,6 @@ export class ApiService {
|
|
|
25
24
|
return err(handleServiceError(error));
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Reads the status of one in-flight generation request. Shared by every
|
|
30
|
-
* async generation endpoint — see `GenerationStatusEndpoint`.
|
|
31
|
-
*/
|
|
32
|
-
async getGenerationStatus(endpoint, requestId, configDir, shell, authKey) {
|
|
33
|
-
const authInfo = await getAuthInfo(configDir.toString());
|
|
34
|
-
if (authInfo === null && !authKey) {
|
|
35
|
-
return err(ServiceError.UnAuthorized);
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
const token = authKey || (authInfo === null || authInfo === void 0 ? void 0 : authInfo.authKey);
|
|
39
|
-
const response = await this.axiosInstance(shell, token).get(`${endpoint}/${requestId}/status`, {
|
|
40
|
-
headers: { Accept: "application/json" },
|
|
41
|
-
maxRedirects: 0,
|
|
42
|
-
validateStatus: () => true
|
|
43
|
-
});
|
|
44
|
-
if (response.status === 200) {
|
|
45
|
-
return ok(response.data);
|
|
46
|
-
}
|
|
47
|
-
// Once generation finishes, the API redirects to the download location.
|
|
48
|
-
if (response.status === 302) {
|
|
49
|
-
return ok({ status: Status.Completed });
|
|
50
|
-
}
|
|
51
|
-
// `validateStatus` above stops axios throwing, so nothing reaches the
|
|
52
|
-
// catch block — classify the status here, or a mistyped endpoint path and
|
|
53
|
-
// an expired auth key both surface as a generic "unexpected error".
|
|
54
|
-
if (response.status === 401) {
|
|
55
|
-
return err(ServiceError.UnAuthorized);
|
|
56
|
-
}
|
|
57
|
-
if (response.status === 404) {
|
|
58
|
-
return err(ServiceError.NotFound);
|
|
59
|
-
}
|
|
60
|
-
if (response.status === 500) {
|
|
61
|
-
return err(ServiceError.ServerError);
|
|
62
|
-
}
|
|
63
|
-
return err(ServiceError.InvalidResponse);
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
return err(handleServiceError(error));
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
27
|
async sendTelemetry(payload, authKey, shell) {
|
|
70
28
|
try {
|
|
71
29
|
const response = await this.axiosInstance(shell, authKey).post("/telemetry/track", payload, {
|
|
@@ -1 +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,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;
|
|
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,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEvE,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,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AAC;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,24 @@
|
|
|
1
|
+
import { Result } from 'neverthrow';
|
|
2
|
+
import { CommandMetadata } from '../../types/common/command-metadata.js';
|
|
3
|
+
import { DirectoryPath } from '../../types/file/directoryPath.js';
|
|
4
|
+
import { FilePath } from '../../types/file/filePath.js';
|
|
5
|
+
import { ServiceError } from '../service-error.js';
|
|
6
|
+
declare const TIMING_DEFAULTS: {
|
|
7
|
+
pollIntervalMs: number;
|
|
8
|
+
generationTimeoutMs: number;
|
|
9
|
+
requestTimeoutMs: number;
|
|
10
|
+
};
|
|
11
|
+
/** Overridable so tests are not paced by the production defaults; nothing else overrides them. */
|
|
12
|
+
export type GenerationTimings = Partial<typeof TIMING_DEFAULTS>;
|
|
13
|
+
export declare class PluginService {
|
|
14
|
+
private readonly apiBaseUrl;
|
|
15
|
+
private readonly fileService;
|
|
16
|
+
private readonly timings;
|
|
17
|
+
constructor(timings?: GenerationTimings);
|
|
18
|
+
generatePlugin(buildPath: FilePath, configDir: DirectoryPath, commandMetadata: CommandMetadata, authKey: string | null): Promise<Result<NodeJS.ReadableStream, ServiceError>>;
|
|
19
|
+
private initiateGeneration;
|
|
20
|
+
private getGenerationStatus;
|
|
21
|
+
private downloadPlugin;
|
|
22
|
+
private axiosInstance;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import FormData from 'form-data';
|
|
3
|
+
import { err, ok } from 'neverthrow';
|
|
4
|
+
import { getAuthInfo } from '../../client-utils/auth-manager.js';
|
|
5
|
+
import { REQUEST_TIMEOUT_MS } from '../../config/axios-config.js';
|
|
6
|
+
import { PluginGenerationStatus } from '../../types/plugin/generation-status.js';
|
|
7
|
+
import { discardStreamBody } from '../../utils/utils.js';
|
|
8
|
+
import { envInfo } from '../env-info.js';
|
|
9
|
+
import { GENERATION_TIMEOUT_MS, pollUntilCompleted, STATUS_POLL_INTERVAL_MS } from '../generation-status-poller.js';
|
|
10
|
+
import { FileService } from '../file-service.js';
|
|
11
|
+
import { mapRequestError, mapTransportError, ServiceError } from '../service-error.js';
|
|
12
|
+
const TIMING_DEFAULTS = {
|
|
13
|
+
pollIntervalMs: STATUS_POLL_INTERVAL_MS,
|
|
14
|
+
generationTimeoutMs: GENERATION_TIMEOUT_MS,
|
|
15
|
+
requestTimeoutMs: REQUEST_TIMEOUT_MS
|
|
16
|
+
};
|
|
17
|
+
export class PluginService {
|
|
18
|
+
constructor(timings = {}) {
|
|
19
|
+
this.apiBaseUrl = 'https://api.apimatic.io';
|
|
20
|
+
this.fileService = new FileService();
|
|
21
|
+
this.timings = Object.assign(Object.assign({}, TIMING_DEFAULTS), timings);
|
|
22
|
+
}
|
|
23
|
+
async generatePlugin(buildPath, configDir, commandMetadata, authKey) {
|
|
24
|
+
const authInfo = await getAuthInfo(configDir.toString());
|
|
25
|
+
// `auth logout` blanks config.json rather than deleting it, so a logged-out user
|
|
26
|
+
// still has a non-null AuthInfo with an empty key — check the key, not the object.
|
|
27
|
+
const token = authKey || (authInfo === null || authInfo === void 0 ? void 0 : authInfo.authKey);
|
|
28
|
+
if (!token) {
|
|
29
|
+
return err(ServiceError.unauthorizedWithHint(null));
|
|
30
|
+
}
|
|
31
|
+
const initiated = await this.initiateGeneration(buildPath, commandMetadata, token);
|
|
32
|
+
if (initiated.isErr()) {
|
|
33
|
+
return err(initiated.error);
|
|
34
|
+
}
|
|
35
|
+
const generationId = initiated.value.id;
|
|
36
|
+
const completed = await pollUntilCompleted({
|
|
37
|
+
pollIntervalMs: this.timings.pollIntervalMs,
|
|
38
|
+
fetchStatus: () => this.getGenerationStatus(generationId, commandMetadata.shell, token),
|
|
39
|
+
timeout: { budgetMs: this.timings.generationTimeoutMs, label: 'Plugin generation' },
|
|
40
|
+
formatValidationError: formatPluginValidationError
|
|
41
|
+
});
|
|
42
|
+
if (completed.isErr()) {
|
|
43
|
+
return err(completed.error);
|
|
44
|
+
}
|
|
45
|
+
return await this.downloadPlugin(generationId, commandMetadata.shell, token);
|
|
46
|
+
}
|
|
47
|
+
async initiateGeneration(buildPath, commandMetadata, token) {
|
|
48
|
+
var _a;
|
|
49
|
+
const buildFileStream = await this.fileService.getStream(buildPath);
|
|
50
|
+
try {
|
|
51
|
+
const formData = new FormData();
|
|
52
|
+
formData.append('file', buildFileStream);
|
|
53
|
+
const response = await this.axiosInstance(commandMetadata.shell, token).post('/plugin', formData, {
|
|
54
|
+
headers: formData.getHeaders(),
|
|
55
|
+
params: { origin: `APIMATIC CLI ${commandMetadata.commandName}` },
|
|
56
|
+
responseType: 'json'
|
|
57
|
+
});
|
|
58
|
+
const id = (_a = response.data) === null || _a === void 0 ? void 0 : _a.id;
|
|
59
|
+
return id ? ok({ id }) : err(ServiceError.InvalidResponse);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
return err(mapRequestError(error));
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
buildFileStream.close();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async getGenerationStatus(generationId, shell, token) {
|
|
69
|
+
try {
|
|
70
|
+
const response = await this.axiosInstance(shell, token).get(`/plugin/${generationId}/status`, {
|
|
71
|
+
headers: { Accept: 'application/json' },
|
|
72
|
+
maxRedirects: 0,
|
|
73
|
+
validateStatus: () => true
|
|
74
|
+
});
|
|
75
|
+
if (response.status === 200) {
|
|
76
|
+
return ok(response.data);
|
|
77
|
+
}
|
|
78
|
+
// Once generation finishes, the API redirects to the download location.
|
|
79
|
+
if (response.status === 302) {
|
|
80
|
+
return ok({ status: PluginGenerationStatus.Completed });
|
|
81
|
+
}
|
|
82
|
+
// `validateStatus` above stops axios throwing, so nothing reaches the catch block.
|
|
83
|
+
if (response.status === 401) {
|
|
84
|
+
return err(ServiceError.unauthorizedWithHint(null));
|
|
85
|
+
}
|
|
86
|
+
if (response.status === 404) {
|
|
87
|
+
return err(ServiceError.NotFound);
|
|
88
|
+
}
|
|
89
|
+
if (response.status === 500) {
|
|
90
|
+
return err(ServiceError.ServerError);
|
|
91
|
+
}
|
|
92
|
+
return err(ServiceError.InvalidResponse);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
return err(mapRequestError(error));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async downloadPlugin(generationId, shell, token) {
|
|
99
|
+
var _a;
|
|
100
|
+
try {
|
|
101
|
+
const response = await this.axiosInstance(shell, token).get(`/plugin/${generationId}/download`, {
|
|
102
|
+
responseType: 'stream'
|
|
103
|
+
});
|
|
104
|
+
return ok(response.data);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
// The body of a failed streamed response is itself a stream; leaving it open hangs the CLI.
|
|
108
|
+
// Discarding it also rules out reading ProblemDetails here, so only the status code maps.
|
|
109
|
+
if (axios.isAxiosError(error)) {
|
|
110
|
+
discardStreamBody((_a = error.response) === null || _a === void 0 ? void 0 : _a.data);
|
|
111
|
+
}
|
|
112
|
+
return err(mapTransportError(error));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
axiosInstance(shell, apiKey) {
|
|
116
|
+
var _a;
|
|
117
|
+
return axios.create({
|
|
118
|
+
baseURL: (_a = envInfo.getBaseUrl()) !== null && _a !== void 0 ? _a : this.apiBaseUrl,
|
|
119
|
+
timeout: this.timings.requestTimeoutMs,
|
|
120
|
+
headers: {
|
|
121
|
+
'User-Agent': envInfo.getUserAgent(shell),
|
|
122
|
+
Authorization: `X-Auth-Key ${apiKey}`
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const formatPluginValidationError = (errors) => {
|
|
128
|
+
const messages = Object.entries(errors).flatMap(([path, pathMessages]) => pathMessages.map((message) => qualify(path, message)));
|
|
129
|
+
return 'One or more validation errors occurred.' + (messages.length ? '\n- ' + messages.join('\n- ') : '');
|
|
130
|
+
};
|
|
131
|
+
const qualify = (path, message) => {
|
|
132
|
+
if (!path)
|
|
133
|
+
return message;
|
|
134
|
+
const quotedProperty = /^'([^']+)'/.exec(message);
|
|
135
|
+
const property = quotedProperty === null || quotedProperty === void 0 ? void 0 : quotedProperty[1];
|
|
136
|
+
if (property && (path === property || path.endsWith(`.${property}`))) {
|
|
137
|
+
return `'${path}'${message.slice(quotedProperty[0].length)}`;
|
|
138
|
+
}
|
|
139
|
+
return `${path}: ${message}`;
|
|
140
|
+
};
|
|
141
|
+
//# sourceMappingURL=plugin-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-service.js","sourceRoot":"","sources":["../../../src/infrastructure/services/plugin-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,EAAE,EAAU,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAY,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAIlE,OAAO,EAEL,sBAAsB,EAEvB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAC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imeoutMs: number;
|
|
18
|
+
requestTimeoutMs: number;
|
|
19
|
+
};
|
|
20
|
+
/** Overridable so tests are not paced by the production defaults; nothing else overrides them. */
|
|
21
|
+
export type GenerationTimings = Partial<typeof TIMING_DEFAULTS>;
|
|
15
22
|
export declare class PortalService {
|
|
16
23
|
private readonly CONTENT_TYPE;
|
|
24
|
+
private readonly apiBaseUrl;
|
|
17
25
|
private readonly fileService;
|
|
18
|
-
private readonly
|
|
19
|
-
|
|
20
|
-
constructor(statusPollIntervalMs?: number);
|
|
26
|
+
private readonly timings;
|
|
27
|
+
constructor(timings?: GenerationTimings);
|
|
21
28
|
generatePortal(buildPath: FilePath, configDir: DirectoryPath, commandMetadata: CommandMetadata, authKey: string | null): Promise<Result<NodeJS.ReadableStream, ServiceError | NodeJS.ReadableStream>>;
|
|
22
29
|
generateSdk(buildPath: FilePath, language: Language, configDir: DirectoryPath, commandMetadata: CommandMetadata, authKey: string | null, version?: SemVersion): Promise<Result<GeneratedSdkResult, ServiceError>>;
|
|
23
30
|
generateV4Sdk(buildPath: FilePath, language: Language, stability: Stability, configDir: DirectoryPath, commandMetadata: CommandMetadata, authKey: string | null): Promise<Result<NodeJS.ReadableStream, ServiceError>>;
|
|
24
31
|
generateSdl(specFileStream: ReadStream, configDir: DirectoryPath, commandMetadata: CommandMetadata): Promise<Result<Sdl, ServiceError>>;
|
|
25
32
|
generateTocData(specFileStream: ReadStream, configDir: DirectoryPath, commandMetadata: CommandMetadata): Promise<Result<TocData, ServiceError>>;
|
|
26
|
-
/**
|
|
27
|
-
* SDK generation reports per-language merge conflicts under a dedicated
|
|
28
|
-
* `sdkMergeFailed` key, which needs its own wording. Everything else falls
|
|
29
|
-
* back to the shared format.
|
|
30
|
-
*/
|
|
31
33
|
private createAuthorizationHeader;
|
|
34
|
+
private resolveToken;
|
|
35
|
+
private getPortalGenerationStatus;
|
|
36
|
+
private getSdkGenerationStatus;
|
|
37
|
+
private getV4SdkGenerationStatus;
|
|
38
|
+
private axiosInstance;
|
|
32
39
|
private createOriginQueryParameter;
|
|
33
40
|
private readonly languageSdk;
|
|
34
41
|
private readonly stabilityTag;
|
|
35
42
|
}
|
|
43
|
+
export {};
|