@pilatos/bitbucket-cli 1.9.1 → 1.10.0

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.
Files changed (2) hide show
  1. package/dist/index.js +43 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -18187,6 +18187,24 @@ var axios_default = axios;
18187
18187
 
18188
18188
  // src/services/api-client.service.ts
18189
18189
  var BASE_URL = "https://api.bitbucket.org/2.0";
18190
+ var MAX_RETRIES = 3;
18191
+ var BASE_DELAY_MS = 1000;
18192
+ var RETRYABLE_STATUS_CODES = new Set([429, 502, 503, 504]);
18193
+ function getRetryDelay(error, attempt) {
18194
+ if (error.response?.status === 429) {
18195
+ const retryAfter = error.response.headers["retry-after"];
18196
+ if (retryAfter) {
18197
+ const seconds = Number.parseInt(retryAfter, 10);
18198
+ if (!Number.isNaN(seconds)) {
18199
+ return seconds * 1000;
18200
+ }
18201
+ }
18202
+ }
18203
+ return BASE_DELAY_MS * Math.pow(2, attempt - 1);
18204
+ }
18205
+ function sleep(ms) {
18206
+ return new Promise((resolve) => setTimeout(resolve, ms));
18207
+ }
18190
18208
  function createApiClient(configService) {
18191
18209
  const instance = axios_default.create({
18192
18210
  baseURL: BASE_URL,
@@ -18210,13 +18228,28 @@ function createApiClient(configService) {
18210
18228
  console.debug(`[HTTP] Response Body:`, JSON.stringify(response.data, null, 2));
18211
18229
  }
18212
18230
  return response;
18213
- }, (error) => {
18231
+ }, async (error) => {
18214
18232
  if (process.env.DEBUG === "true") {
18215
18233
  console.debug(`[HTTP] Error:`, error.message);
18216
18234
  if (error.response) {
18217
18235
  console.debug(`[HTTP] Error Response Body:`, JSON.stringify(error.response.data, null, 2));
18218
18236
  }
18219
18237
  }
18238
+ if (error.response && RETRYABLE_STATUS_CODES.has(error.response.status)) {
18239
+ const config = error.config;
18240
+ if (config) {
18241
+ const retryCount = config.__retryCount ?? 0;
18242
+ if (retryCount < MAX_RETRIES) {
18243
+ config.__retryCount = retryCount + 1;
18244
+ const delay = getRetryDelay(error, config.__retryCount);
18245
+ const status = error.response.status;
18246
+ const label = status === 429 ? "Rate limited" : `Server error (${status})`;
18247
+ console.error(`${label}, retrying in ${(delay / 1000).toFixed(1)}s (attempt ${config.__retryCount}/${MAX_RETRIES})...`);
18248
+ await sleep(delay);
18249
+ return instance(config);
18250
+ }
18251
+ }
18252
+ }
18220
18253
  if (error.response) {
18221
18254
  const { status, data } = error.response;
18222
18255
  const message = extractErrorMessage(data) || error.message;
@@ -23975,11 +24008,17 @@ function createContext(program2) {
23975
24008
  };
23976
24009
  }
23977
24010
  async function runCommand(token, options, program2, context) {
23978
- const cmd = container.resolve(token);
23979
- const resolvedContext = context ?? createContext(program2);
23980
24011
  try {
24012
+ const cmd = container.resolve(token);
24013
+ const resolvedContext = context ?? createContext(program2);
23981
24014
  return await cmd.run(options, resolvedContext);
23982
- } catch {
24015
+ } catch (error) {
24016
+ if (error instanceof Error && error.message.startsWith("Service not registered")) {
24017
+ console.error(`Internal error: ${error.message}`);
24018
+ }
24019
+ if (!process.exitCode) {
24020
+ process.exitCode = 1;
24021
+ }
23983
24022
  return;
23984
24023
  }
23985
24024
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pilatos/bitbucket-cli",
3
- "version": "1.9.1",
3
+ "version": "1.10.0",
4
4
  "description": "A command-line interface for Bitbucket Cloud",
5
5
  "author": "",
6
6
  "license": "MIT",