@bragduck/cli 2.0.0 → 2.0.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 CHANGED
@@ -181,20 +181,19 @@ Manage CLI configuration.
181
181
  bragduck config list
182
182
 
183
183
  # Get specific config value
184
- bragduck config get apiBaseUrl
185
184
  bragduck config get defaultCommitDays
186
185
 
187
186
  # Set config value
188
187
  bragduck config set defaultCommitDays 60
189
188
  bragduck config set autoVersionCheck false
190
- bragduck config set apiBaseUrl https://custom-api.example.com
191
189
  ```
192
190
 
193
191
  **Available Configuration Keys:**
194
- - `apiBaseUrl` - API base URL (default: https://api.bragduck.com)
195
192
  - `defaultCommitDays` - Default days to scan (1-365, default: 30)
196
193
  - `autoVersionCheck` - Automatic version checking (true/false, default: true)
197
194
 
195
+ **Note:** The API base URL is set to `https://api.bragduck.com` by default. You can override it using the `API_BASE_URL` environment variable if needed for custom deployments.
196
+
198
197
  #### `bragduck logout`
199
198
 
200
199
  Clear stored credentials from your system.
@@ -255,10 +254,11 @@ Configuration is stored in `~/.config/bragduck/config.json` (or equivalent on yo
255
254
 
256
255
  | Key | Type | Default | Description |
257
256
  |-----|------|---------|-------------|
258
- | `apiBaseUrl` | string | `https://api.bragduck.com` | API base URL |
259
257
  | `defaultCommitDays` | number | `30` | Default days to scan (1-365) |
260
258
  | `autoVersionCheck` | boolean | `true` | Automatic version checking |
261
259
 
260
+ **API Base URL:** The CLI connects to `https://api.bragduck.com` by default. For custom deployments, set the `API_BASE_URL` environment variable.
261
+
262
262
  ### Credentials Storage
263
263
 
264
264
  Credentials are encrypted and stored at:
@@ -358,9 +358,6 @@ gh --version
358
358
  # Check your internet connection
359
359
  # Try with debug mode to see detailed logs
360
360
  bragduck --debug scan
361
-
362
- # Check if custom API URL is correct
363
- bragduck config get apiBaseUrl
364
361
  ```
365
362
 
366
363
  ### Version Check Failures
@@ -32,12 +32,10 @@ var init_constants = __esm({
32
32
  config({ path: join(__dirname, "..", "..", ".env") });
33
33
  APP_NAME = "bragduck";
34
34
  CONFIG_KEYS = {
35
- API_BASE_URL: "apiBaseUrl",
36
35
  DEFAULT_COMMIT_DAYS: "defaultCommitDays",
37
36
  AUTO_VERSION_CHECK: "autoVersionCheck"
38
37
  };
39
38
  DEFAULT_CONFIG = {
40
- apiBaseUrl: process.env.API_BASE_URL || "https://api.bragduck.com",
41
39
  defaultCommitDays: 30,
42
40
  autoVersionCheck: true
43
41
  };
@@ -700,8 +698,24 @@ var init_browser = __esm({
700
698
 
701
699
  // src/services/auth.service.ts
702
700
  import { randomBytes as randomBytes2 } from "crypto";
701
+ import { readFileSync as readFileSync2 } from "fs";
702
+ import { fileURLToPath as fileURLToPath3 } from "url";
703
+ import { dirname as dirname2, join as join3 } from "path";
703
704
  import { ofetch } from "ofetch";
704
- var AuthService, authService;
705
+ function getUserAgent() {
706
+ try {
707
+ const packageJsonPath2 = join3(__dirname3, "../../package.json");
708
+ const packageJson2 = JSON.parse(readFileSync2(packageJsonPath2, "utf-8"));
709
+ const version2 = packageJson2.version;
710
+ const platform = process.platform;
711
+ const arch = process.arch;
712
+ return `BragDuck-CLI/${version2} (${platform}-${arch})`;
713
+ } catch (error) {
714
+ logger.debug("Failed to read package.json version");
715
+ return "BragDuck-CLI/2.0.0";
716
+ }
717
+ }
718
+ var __filename3, __dirname3, AuthService, authService;
705
719
  var init_auth_service = __esm({
706
720
  "src/services/auth.service.ts"() {
707
721
  "use strict";
@@ -712,10 +726,12 @@ var init_auth_service = __esm({
712
726
  init_browser();
713
727
  init_errors();
714
728
  init_logger();
729
+ __filename3 = fileURLToPath3(import.meta.url);
730
+ __dirname3 = dirname2(__filename3);
715
731
  AuthService = class {
716
732
  apiBaseUrl;
717
733
  constructor() {
718
- this.apiBaseUrl = process.env.API_BASE_URL || storageService.getConfig("apiBaseUrl") || "https://api.bragduck.com";
734
+ this.apiBaseUrl = process.env.API_BASE_URL || "https://api.bragduck.com";
719
735
  }
720
736
  /**
721
737
  * Generate a random state string for CSRF protection
@@ -751,7 +767,8 @@ var init_auth_service = __esm({
751
767
  grant_type: "authorization_code"
752
768
  },
753
769
  headers: {
754
- "Content-Type": "application/json"
770
+ "Content-Type": "application/json",
771
+ "User-Agent": getUserAgent()
755
772
  }
756
773
  }
757
774
  );
@@ -867,7 +884,8 @@ var init_auth_service = __esm({
867
884
  grant_type: "refresh_token"
868
885
  },
869
886
  headers: {
870
- "Content-Type": "application/json"
887
+ "Content-Type": "application/json",
888
+ "User-Agent": getUserAgent()
871
889
  }
872
890
  }
873
891
  );
@@ -899,15 +917,15 @@ __export(version_exports, {
899
917
  getCurrentVersion: () => getCurrentVersion,
900
918
  version: () => version
901
919
  });
902
- import { readFileSync as readFileSync2 } from "fs";
903
- import { fileURLToPath as fileURLToPath3 } from "url";
904
- import { dirname as dirname2, join as join4 } from "path";
920
+ import { readFileSync as readFileSync3 } from "fs";
921
+ import { fileURLToPath as fileURLToPath4 } from "url";
922
+ import { dirname as dirname3, join as join5 } from "path";
905
923
  import chalk4 from "chalk";
906
924
  import boxen3 from "boxen";
907
925
  function getCurrentVersion() {
908
926
  try {
909
- const packageJsonPath2 = join4(__dirname3, "../../package.json");
910
- const packageJson2 = JSON.parse(readFileSync2(packageJsonPath2, "utf-8"));
927
+ const packageJsonPath2 = join5(__dirname4, "../../package.json");
928
+ const packageJson2 = JSON.parse(readFileSync3(packageJsonPath2, "utf-8"));
911
929
  return packageJson2.version;
912
930
  } catch (error) {
913
931
  logger.debug("Failed to read package.json version");
@@ -989,7 +1007,7 @@ function formatVersion(includePrefix = true) {
989
1007
  const prefix = includePrefix ? "v" : "";
990
1008
  return `${prefix}${version}`;
991
1009
  }
992
- var __filename3, __dirname3, version;
1010
+ var __filename4, __dirname4, version;
993
1011
  var init_version = __esm({
994
1012
  "src/utils/version.ts"() {
995
1013
  "use strict";
@@ -997,40 +1015,68 @@ var init_version = __esm({
997
1015
  init_api_service();
998
1016
  init_storage_service();
999
1017
  init_logger();
1000
- __filename3 = fileURLToPath3(import.meta.url);
1001
- __dirname3 = dirname2(__filename3);
1018
+ __filename4 = fileURLToPath4(import.meta.url);
1019
+ __dirname4 = dirname3(__filename4);
1002
1020
  version = getCurrentVersion();
1003
1021
  }
1004
1022
  });
1005
1023
 
1006
1024
  // src/services/api.service.ts
1007
1025
  import { ofetch as ofetch2 } from "ofetch";
1008
- var ApiService, apiService;
1026
+ import { readFileSync as readFileSync4 } from "fs";
1027
+ import { fileURLToPath as fileURLToPath5 } from "url";
1028
+ import { dirname as dirname4, join as join6 } from "path";
1029
+ function getCliVersion() {
1030
+ try {
1031
+ const packageJsonPath2 = join6(__dirname5, "../../package.json");
1032
+ const packageJson2 = JSON.parse(readFileSync4(packageJsonPath2, "utf-8"));
1033
+ return packageJson2.version;
1034
+ } catch (error) {
1035
+ logger.debug("Failed to read package.json version");
1036
+ return "2.0.0";
1037
+ }
1038
+ }
1039
+ function getPlatformInfo() {
1040
+ const platform = process.platform;
1041
+ const arch = process.arch;
1042
+ return `${platform}-${arch}`;
1043
+ }
1044
+ var __filename5, __dirname5, ApiService, apiService;
1009
1045
  var init_api_service = __esm({
1010
1046
  "src/services/api.service.ts"() {
1011
1047
  "use strict";
1012
1048
  init_esm_shims();
1013
- init_storage_service();
1014
1049
  init_auth_service();
1015
1050
  init_constants();
1016
1051
  init_errors();
1017
1052
  init_logger();
1053
+ __filename5 = fileURLToPath5(import.meta.url);
1054
+ __dirname5 = dirname4(__filename5);
1018
1055
  ApiService = class {
1019
1056
  baseURL;
1020
1057
  client;
1021
1058
  constructor() {
1022
- this.baseURL = process.env.API_BASE_URL || storageService.getConfig("apiBaseUrl");
1059
+ this.baseURL = process.env.API_BASE_URL || "https://api.bragduck.com";
1023
1060
  this.client = ofetch2.create({
1024
1061
  baseURL: this.baseURL,
1025
1062
  // Request interceptor
1026
1063
  onRequest: async ({ options }) => {
1027
1064
  logger.debug(`API Request: ${options.method} ${options.baseURL}${options.url}`);
1065
+ const cliVersion = getCliVersion();
1066
+ const platform = getPlatformInfo();
1067
+ const userAgent = `BragDuck-CLI/${cliVersion} (${platform})`;
1028
1068
  const token = await authService.getAccessToken();
1029
1069
  if (token) {
1030
1070
  options.headers = {
1031
1071
  ...options.headers,
1072
+ "User-Agent": userAgent,
1032
1073
  Authorization: `Bearer ${token}`
1033
1074
  };
1075
+ } else {
1076
+ options.headers = {
1077
+ ...options.headers,
1078
+ "User-Agent": userAgent
1079
+ };
1034
1080
  }
1035
1081
  if (options.method && ["POST", "PUT", "PATCH"].includes(options.method)) {
1036
1082
  options.headers = {
@@ -1210,7 +1256,6 @@ var init_api_service = __esm({
1210
1256
  */
1211
1257
  setBaseURL(url) {
1212
1258
  this.baseURL = url;
1213
- storageService.setConfig("apiBaseUrl", url);
1214
1259
  this.client = ofetch2.create({
1215
1260
  baseURL: url
1216
1261
  });
@@ -1229,9 +1274,9 @@ var init_api_service = __esm({
1229
1274
  // src/cli.ts
1230
1275
  init_esm_shims();
1231
1276
  import { Command } from "commander";
1232
- import { readFileSync as readFileSync3 } from "fs";
1233
- import { fileURLToPath as fileURLToPath4 } from "url";
1234
- import { dirname as dirname3, join as join5 } from "path";
1277
+ import { readFileSync as readFileSync5 } from "fs";
1278
+ import { fileURLToPath as fileURLToPath6 } from "url";
1279
+ import { dirname as dirname5, join as join7 } from "path";
1235
1280
 
1236
1281
  // src/commands/init.ts
1237
1282
  init_esm_shims();
@@ -1420,9 +1465,9 @@ import simpleGit from "simple-git";
1420
1465
  init_esm_shims();
1421
1466
  init_errors();
1422
1467
  import { existsSync as existsSync2 } from "fs";
1423
- import { join as join3 } from "path";
1468
+ import { join as join4 } from "path";
1424
1469
  function validateGitRepository(path2) {
1425
- const gitDir = join3(path2, ".git");
1470
+ const gitDir = join4(path2, ".git");
1426
1471
  if (!existsSync2(gitDir)) {
1427
1472
  throw new GitError(
1428
1473
  "Not a git repository. Please run this command from within a git repository.",
@@ -1910,7 +1955,7 @@ function formatSuccessMessage(count) {
1910
1955
  );
1911
1956
  const message = chalk5.white("\nYour achievements are now saved and ready to showcase.");
1912
1957
  const hint = chalk5.dim("\nRun ") + chalk5.cyan("bragduck list") + chalk5.dim(" to see all your brags");
1913
- const url = "https://app.bragduck.com/brags";
1958
+ const url = "https://bragduck.com/app/brags";
1914
1959
  const clickableUrl = terminalLink(url, url, {
1915
1960
  fallback: () => chalk5.blue.underline(url)
1916
1961
  });
@@ -2320,7 +2365,6 @@ function getErrorHint3(error) {
2320
2365
  // src/commands/config.ts
2321
2366
  init_esm_shims();
2322
2367
  init_storage_service();
2323
- init_api_service();
2324
2368
  init_logger();
2325
2369
  init_constants();
2326
2370
  import boxen6 from "boxen";
@@ -2370,7 +2414,6 @@ async function configCommand(subcommand, key, value) {
2370
2414
  }
2371
2415
  async function handleListConfig() {
2372
2416
  const config2 = {
2373
- apiBaseUrl: storageService.getConfig("apiBaseUrl"),
2374
2417
  defaultCommitDays: storageService.getConfig("defaultCommitDays"),
2375
2418
  autoVersionCheck: storageService.getConfig("autoVersionCheck")
2376
2419
  };
@@ -2383,11 +2426,6 @@ async function handleListConfig() {
2383
2426
  border: ["gray"]
2384
2427
  }
2385
2428
  });
2386
- table.push([
2387
- chalk9.white("apiBaseUrl"),
2388
- chalk9.yellow(config2.apiBaseUrl),
2389
- chalk9.dim(DEFAULT_CONFIG.apiBaseUrl)
2390
- ]);
2391
2429
  table.push([
2392
2430
  chalk9.white("defaultCommitDays"),
2393
2431
  chalk9.yellow(String(config2.defaultCommitDays)),
@@ -2427,9 +2465,6 @@ async function handleSetConfig(key, value) {
2427
2465
  validateConfigKey(key);
2428
2466
  const typedValue = validateAndConvertValue(key, value);
2429
2467
  storageService.setConfig(key, typedValue);
2430
- if (key === CONFIG_KEYS.API_BASE_URL) {
2431
- apiService.setBaseURL(typedValue);
2432
- }
2433
2468
  logger.log(
2434
2469
  boxen6(
2435
2470
  `${chalk9.green.bold("\u2713 Configuration updated")}
@@ -2456,15 +2491,6 @@ ${VALID_CONFIG_KEYS.map((k) => ` - ${k}`).join("\n")}`
2456
2491
  }
2457
2492
  function validateAndConvertValue(key, value) {
2458
2493
  switch (key) {
2459
- case CONFIG_KEYS.API_BASE_URL:
2460
- if (!isValidUrl(value)) {
2461
- throw new ValidationError(
2462
- `Invalid URL format: "${value}"
2463
-
2464
- Example: https://api.bragduck.com`
2465
- );
2466
- }
2467
- return value;
2468
2494
  case CONFIG_KEYS.DEFAULT_COMMIT_DAYS:
2469
2495
  const days = parseInt(value, 10);
2470
2496
  if (isNaN(days) || days < 1 || days > 365) {
@@ -2488,15 +2514,7 @@ Must be a number between 1 and 365`
2488
2514
  Must be one of: true, false, yes, no, 1, 0`
2489
2515
  );
2490
2516
  default:
2491
- return value;
2492
- }
2493
- }
2494
- function isValidUrl(url) {
2495
- try {
2496
- const parsed = new URL(url);
2497
- return parsed.protocol === "http:" || parsed.protocol === "https:";
2498
- } catch {
2499
- return false;
2517
+ throw new ValidationError(`Unknown config key: "${key}"`);
2500
2518
  }
2501
2519
  }
2502
2520
  function getConfigHint(error) {
@@ -2509,10 +2527,10 @@ function getConfigHint(error) {
2509
2527
  // src/cli.ts
2510
2528
  init_version();
2511
2529
  init_logger();
2512
- var __filename4 = fileURLToPath4(import.meta.url);
2513
- var __dirname4 = dirname3(__filename4);
2514
- var packageJsonPath = join5(__dirname4, "../../package.json");
2515
- var packageJson = JSON.parse(readFileSync3(packageJsonPath, "utf-8"));
2530
+ var __filename6 = fileURLToPath6(import.meta.url);
2531
+ var __dirname6 = dirname5(__filename6);
2532
+ var packageJsonPath = join7(__dirname6, "../../package.json");
2533
+ var packageJson = JSON.parse(readFileSync5(packageJsonPath, "utf-8"));
2516
2534
  var program = new Command();
2517
2535
  program.name("bragduck").description("CLI tool for managing developer achievements and brags").version(packageJson.version, "-v, --version", "Display version number").helpOption("-h, --help", "Display help information").option("--skip-version-check", "Skip automatic version check on startup").option("--debug", "Enable debug mode (shows detailed logs)");
2518
2536
  program.command("init").description("Authenticate with Bragduck").action(async () => {