Skip to content

Commit b16e374

Browse files
fix: update user-agent format in api calls (#135)
1 parent 8dabd05 commit b16e374

4 files changed

Lines changed: 11 additions & 21 deletions

File tree

src/commands/portal/copilot.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ export default class PortalCopilotEnable extends Command {
3232

3333
async run(): Promise<void> {
3434
const {
35-
flags: { folder, "auth-key": authKey, disable, 'welcome-message': welcomeMessage}
35+
flags: { input, "auth-key": authKey, disable, 'welcome-message': welcomeMessage}
3636
} = await this.parse(PortalCopilotEnable);
3737

38-
const workingDirectory = new DirectoryPath(folder ?? DEFAULT_WORKING_DIRECTORY);
39-
const buildDirectory = folder ? new DirectoryPath(folder, "src") : workingDirectory.join("src");
38+
const workingDirectory = new DirectoryPath(input ?? DEFAULT_WORKING_DIRECTORY);
39+
const buildDirectory = input ? new DirectoryPath(input, "src") : workingDirectory.join("src");
4040
const copilotConfigAction = new CopilotAction(new DirectoryPath(this.config.configDir), authKey);
4141
const result = await copilotConfigAction.execute(buildDirectory, welcomeMessage, !disable);
4242
result.map((message) => this.prompts.logError(message));

src/commands/portal/generate.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ export class PortalGenerate extends Command {
3232

3333
async run(): Promise<void> {
3434
const {
35-
flags: { folder, destination, force, zip: zipPortal, "auth-key": authKey }
35+
flags: { input, destination, force, zip: zipPortal, "auth-key": authKey }
3636
} = await this.parse(PortalGenerate);
3737

38-
const workingDirectory = new DirectoryPath(folder ?? DEFAULT_WORKING_DIRECTORY);
39-
const buildDirectory = folder ? new DirectoryPath(folder, "src") : workingDirectory.join("src");
38+
const workingDirectory = new DirectoryPath(input ?? DEFAULT_WORKING_DIRECTORY);
39+
const buildDirectory = input ? new DirectoryPath(input, "src") : workingDirectory.join("src");
4040
const portalDirectory = destination ? new DirectoryPath(destination) : workingDirectory.join("portal");
4141

4242
const action = new GenerateAction(this.getConfigDir(), authKey);

src/infrastructure/env-info.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { dirname, join } from "path";
44
import fs from "fs-extra";
55

66
class EnvInfo {
7-
87
private static cachedCliVersion: string | null = null;
98
private static cachedUserAgent: string | null = null;
109

@@ -13,12 +12,12 @@ class EnvInfo {
1312
const osInfo = `${os.platform()} ${os.release()}`;
1413
const engine = "Node.js";
1514
const engineVersion = process.version;
16-
EnvInfo.cachedUserAgent = `APIMATIC CLI - [OS: ${osInfo}, Engine: ${engine}/${engineVersion}]`;
15+
EnvInfo.cachedUserAgent = `APIMATIC CLI/${this.getCLIVersion()} - (OS: ${osInfo}, Engine: ${engine}/${engineVersion})`;
1716
}
1817
return EnvInfo.cachedUserAgent;
1918
}
2019

21-
public getCLIVersion(): string {
20+
public getCLIVersion(): string {
2221
if (EnvInfo.cachedCliVersion) {
2322
return EnvInfo.cachedCliVersion;
2423
}

src/infrastructure/services/portal-service.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import * as os from "os";
21
import fs from "fs-extra";
3-
import process from "process";
42
import {
53
ContentType,
64
DocsPortalManagementController,
@@ -26,6 +24,7 @@ import { Sdl } from "../../types/sdl/sdl.js";
2624
import { FilePath } from "../../types/file/filePath.js";
2725
import { DirectoryPath } from "../../types/file/directoryPath.js";
2826
import { FileService } from "../file-service.js";
27+
import { envInfo } from "../env-info.js";
2928

3029
export class PortalService {
3130
private readonly CONTENT_TYPE = ContentType.EnumMultipartformdata;
@@ -121,20 +120,12 @@ export class PortalService {
121120
return `X-Auth-Key ${key ?? ""}`;
122121
};
123122

124-
private getUserAgent(): string {
125-
const osInfo = `${os.platform()} ${os.release()}`;
126-
const engine = "Node.js";
127-
const engineVersion = process.version;
128-
129-
return `APIMATIC CLI - [OS: ${osInfo}, Engine: ${engine}/${engineVersion}]`;
130-
}
131-
132123
private createApiClient = (authorizationHeader: string): Client => {
133124
return new Client({
134125
customHeaderAuthenticationCredentials: {
135126
Authorization: authorizationHeader
136127
},
137-
userAgent: this.getUserAgent(),
128+
userAgent: envInfo.getUserAgent(),
138129
timeout: this.TIMEOUT
139130
});
140131
};
@@ -196,4 +187,4 @@ export class PortalService {
196187
);
197188
}
198189
};
199-
}
190+
}

0 commit comments

Comments
 (0)