Skip to content

Commit bcdcb7e

Browse files
committed
feat: add client and client version to request headers
1 parent 6747e5a commit bcdcb7e

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bucketco/cli",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"packageManager": "yarn@4.1.1",
55
"description": "CLI for Bucket service",
66
"main": "./dist/index.js",

packages/cli/stores/config.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class ConfigStore {
5959
protected config: Config = { ...defaultConfig };
6060
protected configPath: string | undefined;
6161
protected projectPath: string | undefined;
62+
protected clientVersion: string | undefined;
6263
protected validateConfig: ValidateFunction | undefined;
6364

6465
async initialize() {
@@ -101,6 +102,20 @@ class ConfigStore {
101102
const content = await readFile(this.configPath, "utf-8");
102103
const parsed = parseJSON(content) as unknown as Partial<Config>;
103104

105+
if (packageJSONPath) {
106+
try {
107+
const packageJSONContent = await readFile(packageJSONPath, "utf-8");
108+
const packageJSONParsed = parseJSON(
109+
packageJSONContent,
110+
) as unknown as {
111+
version: string;
112+
};
113+
this.clientVersion = packageJSONParsed.version;
114+
} catch {
115+
// Should not be the case, but no package.json found
116+
}
117+
}
118+
104119
// Normalize values
105120
if (parsed.baseUrl)
106121
parsed.baseUrl = stripTrailingSlash(parsed.baseUrl.trim());
@@ -167,6 +182,10 @@ class ConfigStore {
167182
return this.configPath;
168183
}
169184

185+
getClientVersion() {
186+
return this.clientVersion;
187+
}
188+
170189
getProjectPath() {
171190
return this.projectPath ?? process.cwd();
172191
}

packages/cli/utils/auth.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ export async function authRequest<T = Record<string, unknown>>(
153153
headers: {
154154
...options?.headers,
155155
Authorization: `Bearer ${token}`,
156+
"X-Client": "cli",
157+
"X-Client-Version": configStore.getClientVersion() ?? "unknown",
156158
},
157159
});
158160

0 commit comments

Comments
 (0)