@bragduck/cli 2.0.2 → 2.0.23

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/dist/index.js CHANGED
@@ -29,7 +29,7 @@ var init_constants = __esm({
29
29
  init_esm_shims();
30
30
  __filename = fileURLToPath2(import.meta.url);
31
31
  __dirname = dirname(__filename);
32
- config({ path: join(__dirname, "..", "..", ".env") });
32
+ config({ path: join(__dirname, "..", "..", ".env"), debug: false, quiet: true });
33
33
  APP_NAME = "bragduck";
34
34
  DEFAULT_CONFIG = {
35
35
  defaultCommitDays: 30,
@@ -48,14 +48,21 @@ var init_constants = __esm({
48
48
  INITIATE: "/v1/auth/cli/initiate",
49
49
  TOKEN: "/v1/auth/cli/token"
50
50
  },
51
- COMMITS: {
52
- REFINE: "/v1/commits/refine"
53
- },
54
51
  BRAGS: {
55
52
  CREATE: "/v1/brags",
56
- LIST: "/v1/brags"
53
+ LIST: "/v1/brags",
54
+ REFINE: "/v1/brags/refine"
55
+ },
56
+ SUBSCRIPTION: {
57
+ STATUS: "/v1/subscriptions/status"
57
58
  },
58
- VERSION: "/v1/cli/version"
59
+ VERSION: "/v1/cli/version",
60
+ /**
61
+ * @deprecated Use BRAGS.REFINE instead
62
+ */
63
+ COMMITS: {
64
+ REFINE: "/v1/commits/refine"
65
+ }
59
66
  };
60
67
  ENCRYPTION_CONFIG = {
61
68
  ALGORITHM: "aes-256-gcm",
@@ -308,11 +315,13 @@ var init_errors = __esm({
308
315
  "use strict";
309
316
  init_esm_shims();
310
317
  BragduckError = class extends Error {
318
+ code;
319
+ details;
311
320
  constructor(message, code, details) {
312
321
  super(message);
322
+ this.name = "BragduckError";
313
323
  this.code = code;
314
324
  this.details = details;
315
- this.name = "BragduckError";
316
325
  Error.captureStackTrace(this, this.constructor);
317
326
  }
318
327
  };
@@ -323,10 +332,11 @@ var init_errors = __esm({
323
332
  }
324
333
  };
325
334
  ApiError = class extends BragduckError {
335
+ statusCode;
326
336
  constructor(message, statusCode, details) {
327
337
  super(message, "API_ERROR", details);
328
- this.statusCode = statusCode;
329
338
  this.name = "ApiError";
339
+ this.statusCode = statusCode;
330
340
  }
331
341
  };
332
342
  NetworkError = class extends BragduckError {
@@ -417,7 +427,7 @@ async function findAvailablePort() {
417
427
  testServer.listen(port, "127.0.0.1");
418
428
  });
419
429
  return port;
420
- } catch (error) {
430
+ } catch {
421
431
  continue;
422
432
  }
423
433
  }
@@ -428,10 +438,10 @@ async function startOAuthCallbackServer(expectedState) {
428
438
  const timeout = OAUTH_CONFIG.TIMEOUT_MS;
429
439
  return new Promise((resolve, reject) => {
430
440
  let server = null;
431
- let timeoutId;
441
+ let timeoutId = null;
432
442
  const cleanup = () => {
433
443
  if (timeoutId) {
434
- clearTimeout(timeoutId);
444
+ globalThis.clearTimeout(timeoutId);
435
445
  }
436
446
  if (server) {
437
447
  if (typeof server.closeAllConnections === "function") {
@@ -477,7 +487,7 @@ async function startOAuthCallbackServer(expectedState) {
477
487
  }
478
488
  res.writeHead(200, { "Content-Type": "text/html" });
479
489
  res.end(SUCCESS_HTML);
480
- setTimeout(() => {
490
+ globalThis.setTimeout(() => {
481
491
  cleanup();
482
492
  resolve({
483
493
  code: String(code),
@@ -497,9 +507,11 @@ async function startOAuthCallbackServer(expectedState) {
497
507
  reject(new OAuthError(`OAuth server error: ${error.message}`));
498
508
  });
499
509
  server.listen(port, "127.0.0.1", () => {
500
- logger.debug(`OAuth callback server listening on http://127.0.0.1:${port}${OAUTH_CONFIG.CALLBACK_PATH}`);
510
+ logger.debug(
511
+ `OAuth callback server listening on http://127.0.0.1:${port}${OAUTH_CONFIG.CALLBACK_PATH}`
512
+ );
501
513
  });
502
- timeoutId = setTimeout(() => {
514
+ timeoutId = globalThis.setTimeout(() => {
503
515
  logger.debug("OAuth callback timeout");
504
516
  cleanup();
505
517
  reject(new OAuthError("Authentication timeout - no callback received within 2 minutes"));
@@ -658,10 +670,8 @@ async function openBrowser(url) {
658
670
  logger.debug("Browser opened successfully");
659
671
  } catch (error) {
660
672
  logger.debug(`Failed to open browser: ${error}`);
661
- throw new Error(
662
- `Failed to open browser automatically. Please open this URL manually:
663
- ${url}`
664
- );
673
+ throw new Error(`Failed to open browser automatically. Please open this URL manually:
674
+ ${url}`);
665
675
  }
666
676
  }
667
677
  var execAsync;
@@ -677,7 +687,7 @@ var init_browser = __esm({
677
687
  // src/services/auth.service.ts
678
688
  import { randomBytes as randomBytes2 } from "crypto";
679
689
  import { readFileSync as readFileSync2 } from "fs";
680
- import { fileURLToPath as fileURLToPath3 } from "url";
690
+ import { fileURLToPath as fileURLToPath3, URLSearchParams } from "url";
681
691
  import { dirname as dirname2, join as join3 } from "path";
682
692
  import { ofetch } from "ofetch";
683
693
  function getUserAgent() {
@@ -688,7 +698,7 @@ function getUserAgent() {
688
698
  const platform = process.platform;
689
699
  const arch = process.arch;
690
700
  return `BragDuck-CLI/${version2} (${platform}-${arch})`;
691
- } catch (error) {
701
+ } catch {
692
702
  logger.debug("Failed to read package.json version");
693
703
  return "BragDuck-CLI/2.0.0";
694
704
  }
@@ -786,7 +796,7 @@ var init_auth_service = __esm({
786
796
  const serverPromise = startOAuthCallbackServer(state);
787
797
  try {
788
798
  await openBrowser(authUrl);
789
- } catch (error) {
799
+ } catch {
790
800
  logger.warning("Could not open browser automatically");
791
801
  logger.info(`Please open this URL in your browser:`);
792
802
  logger.log(authUrl);
@@ -890,13 +900,14 @@ var init_auth_service = __esm({
890
900
  import { ofetch as ofetch2 } from "ofetch";
891
901
  import { readFileSync as readFileSync3 } from "fs";
892
902
  import { fileURLToPath as fileURLToPath4 } from "url";
903
+ import { URLSearchParams as URLSearchParams2 } from "url";
893
904
  import { dirname as dirname3, join as join4 } from "path";
894
905
  function getCliVersion() {
895
906
  try {
896
907
  const packageJsonPath = join4(__dirname4, "../../package.json");
897
908
  const packageJson = JSON.parse(readFileSync3(packageJsonPath, "utf-8"));
898
909
  return packageJson.version;
899
- } catch (error) {
910
+ } catch {
900
911
  logger.debug("Failed to read package.json version");
901
912
  return "2.0.0";
902
913
  }
@@ -926,29 +937,30 @@ var init_api_service = __esm({
926
937
  baseURL: this.baseURL,
927
938
  // Request interceptor
928
939
  onRequest: async ({ options }) => {
929
- logger.debug(`API Request: ${options.method} ${options.baseURL}${options.url}`);
940
+ const extendedOptions = options;
941
+ logger.debug(
942
+ `API Request: ${options.method} ${extendedOptions.baseURL}${extendedOptions.url}`
943
+ );
930
944
  const cliVersion = getCliVersion();
931
945
  const platform = getPlatformInfo();
932
946
  const userAgent = `BragDuck-CLI/${cliVersion} (${platform})`;
933
947
  const token = await authService.getAccessToken();
948
+ const newHeaders = {
949
+ "User-Agent": userAgent
950
+ };
951
+ if (options.headers) {
952
+ const existingHeaders = new Headers(options.headers);
953
+ existingHeaders.forEach((value, key) => {
954
+ newHeaders[key] = value;
955
+ });
956
+ }
934
957
  if (token) {
935
- options.headers = {
936
- ...options.headers,
937
- "User-Agent": userAgent,
938
- Authorization: `Bearer ${token}`
939
- };
940
- } else {
941
- options.headers = {
942
- ...options.headers,
943
- "User-Agent": userAgent
944
- };
958
+ newHeaders.Authorization = `Bearer ${token}`;
945
959
  }
946
960
  if (options.method && ["POST", "PUT", "PATCH"].includes(options.method)) {
947
- options.headers = {
948
- ...options.headers,
949
- "Content-Type": "application/json"
950
- };
961
+ newHeaders["Content-Type"] = "application/json";
951
962
  }
963
+ options.headers = newHeaders;
952
964
  },
953
965
  // Response interceptor for success
954
966
  onResponse: ({ response }) => {
@@ -957,7 +969,8 @@ var init_api_service = __esm({
957
969
  // Response interceptor for errors
958
970
  onResponseError: async ({ response, options }) => {
959
971
  const status = response.status;
960
- const url = `${options.baseURL}${options.url}`;
972
+ const extendedOptions = options;
973
+ const url = `${extendedOptions.baseURL}${extendedOptions.url}`;
961
974
  logger.debug(`API Error: ${status} ${response.statusText} - ${url}`);
962
975
  if (status === HTTP_STATUS.UNAUTHORIZED) {
963
976
  logger.debug("Token expired, attempting refresh");
@@ -969,7 +982,9 @@ var init_api_service = __esm({
969
982
  if (error.message === "RETRY_WITH_NEW_TOKEN") {
970
983
  throw error;
971
984
  }
972
- throw new TokenExpiredError('Your session has expired. Please run "bragduck init" to login again.');
985
+ throw new TokenExpiredError(
986
+ 'Your session has expired. Please run "bragduck init" to login again.'
987
+ );
973
988
  }
974
989
  }
975
990
  let errorMessage = "An unexpected error occurred";
@@ -1015,23 +1030,39 @@ var init_api_service = __esm({
1015
1030
  }
1016
1031
  }
1017
1032
  /**
1018
- * Refine commits using AI
1033
+ * Refine brags using AI
1034
+ */
1035
+ async refineBrags(request) {
1036
+ logger.debug(`Refining ${request.brags.length} brags`);
1037
+ try {
1038
+ const response = await this.makeRequest(API_ENDPOINTS.BRAGS.REFINE, {
1039
+ method: "POST",
1040
+ body: request
1041
+ });
1042
+ logger.debug(`Successfully refined ${response.refined_brags.length} brags`);
1043
+ return response;
1044
+ } catch (_error) {
1045
+ logger.debug("Failed to refine brags");
1046
+ throw _error;
1047
+ }
1048
+ }
1049
+ /**
1050
+ * @deprecated Use refineBrags() instead. Will be removed in v3.0.0
1051
+ * Refine commits using AI (legacy endpoint)
1019
1052
  */
1020
1053
  async refineCommits(request) {
1054
+ logger.debug(`[DEPRECATED] Using legacy refineCommits - migrate to refineBrags`);
1021
1055
  logger.debug(`Refining ${request.commits.length} commits`);
1022
1056
  try {
1023
- const response = await this.makeRequest(
1024
- API_ENDPOINTS.COMMITS.REFINE,
1025
- {
1026
- method: "POST",
1027
- body: request
1028
- }
1029
- );
1057
+ const response = await this.makeRequest(API_ENDPOINTS.COMMITS.REFINE, {
1058
+ method: "POST",
1059
+ body: request
1060
+ });
1030
1061
  logger.debug(`Successfully refined ${response.refined_commits.length} commits`);
1031
1062
  return response;
1032
- } catch (error) {
1063
+ } catch (_error) {
1033
1064
  logger.debug("Failed to refine commits");
1034
- throw error;
1065
+ throw _error;
1035
1066
  }
1036
1067
  }
1037
1068
  /**
@@ -1040,18 +1071,15 @@ var init_api_service = __esm({
1040
1071
  async createBrags(request) {
1041
1072
  logger.debug(`Creating ${request.brags.length} brags`);
1042
1073
  try {
1043
- const response = await this.makeRequest(
1044
- API_ENDPOINTS.BRAGS.CREATE,
1045
- {
1046
- method: "POST",
1047
- body: request
1048
- }
1049
- );
1074
+ const response = await this.makeRequest(API_ENDPOINTS.BRAGS.CREATE, {
1075
+ method: "POST",
1076
+ body: request
1077
+ });
1050
1078
  logger.debug(`Successfully created ${response.created} brags`);
1051
1079
  return response;
1052
- } catch (error) {
1080
+ } catch (_error) {
1053
1081
  logger.debug("Failed to create brags");
1054
- throw error;
1082
+ throw _error;
1055
1083
  }
1056
1084
  }
1057
1085
  /**
@@ -1061,7 +1089,7 @@ var init_api_service = __esm({
1061
1089
  const { limit = 50, offset = 0, tags, search } = params;
1062
1090
  logger.debug(`Listing brags: limit=${limit}, offset=${offset}`);
1063
1091
  try {
1064
- const queryParams = new URLSearchParams({
1092
+ const queryParams = new URLSearchParams2({
1065
1093
  limit: limit.toString(),
1066
1094
  offset: offset.toString()
1067
1095
  });
@@ -1075,10 +1103,33 @@ var init_api_service = __esm({
1075
1103
  const response = await this.makeRequest(url, {
1076
1104
  method: "GET"
1077
1105
  });
1078
- logger.debug(`Successfully fetched ${response.brags.length} brags (total: ${response.total})`);
1106
+ logger.debug(
1107
+ `Successfully fetched ${response.brags.length} brags (total: ${response.total})`
1108
+ );
1079
1109
  return response;
1080
- } catch (error) {
1110
+ } catch (_error) {
1081
1111
  logger.debug("Failed to list brags");
1112
+ throw _error;
1113
+ }
1114
+ }
1115
+ /**
1116
+ * Get user's subscription status
1117
+ */
1118
+ async getSubscriptionStatus() {
1119
+ logger.debug(`Fetching subscription status from ${API_ENDPOINTS.SUBSCRIPTION.STATUS}`);
1120
+ try {
1121
+ const response = await this.makeRequest(API_ENDPOINTS.SUBSCRIPTION.STATUS, {
1122
+ method: "GET"
1123
+ });
1124
+ logger.debug(`Subscription API response: ${JSON.stringify(response)}`);
1125
+ const subscriptionData = response.data;
1126
+ logger.debug(
1127
+ `Subscription tier: ${subscriptionData.tier}, status: ${subscriptionData.status}`
1128
+ );
1129
+ return subscriptionData;
1130
+ } catch (error) {
1131
+ logger.debug(`Failed to fetch subscription status: ${error}`);
1132
+ logger.debug(`Error details: ${JSON.stringify(error, null, 2)}`);
1082
1133
  throw error;
1083
1134
  }
1084
1135
  }
@@ -1088,15 +1139,12 @@ var init_api_service = __esm({
1088
1139
  async checkVersion() {
1089
1140
  logger.debug("Checking for CLI updates");
1090
1141
  try {
1091
- const response = await this.makeRequest(
1092
- API_ENDPOINTS.VERSION,
1093
- {
1094
- method: "GET"
1095
- }
1096
- );
1142
+ const response = await this.makeRequest(API_ENDPOINTS.VERSION, {
1143
+ method: "GET"
1144
+ });
1097
1145
  logger.debug(`Latest version: ${response.latest_version}`);
1098
1146
  return response;
1099
- } catch (error) {
1147
+ } catch {
1100
1148
  logger.debug("Failed to check version");
1101
1149
  const { version: version2 } = await Promise.resolve().then(() => (init_version(), version_exports));
1102
1150
  return {
@@ -1112,7 +1160,7 @@ var init_api_service = __esm({
1112
1160
  try {
1113
1161
  await this.checkVersion();
1114
1162
  return true;
1115
- } catch (error) {
1163
+ } catch {
1116
1164
  return false;
1117
1165
  }
1118
1166
  }
@@ -1155,7 +1203,7 @@ function getCurrentVersion() {
1155
1203
  const packageJsonPath = join5(__dirname5, "../../package.json");
1156
1204
  const packageJson = JSON.parse(readFileSync4(packageJsonPath, "utf-8"));
1157
1205
  return packageJson.version;
1158
- } catch (error) {
1206
+ } catch {
1159
1207
  logger.debug("Failed to read package.json version");
1160
1208
  return "1.0.0";
1161
1209
  }