mobbdev 0.0.167 → 0.0.168

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.mjs +72 -36
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -4042,10 +4042,17 @@ function getGithubSdk(parmas = {}) {
4042
4042
 
4043
4043
  // src/features/analysis/scm/gitlab/gitlab.ts
4044
4044
  import querystring2 from "node:querystring";
4045
+ import { setTimeout as setTimeout2 } from "node:timers/promises";
4046
+ import {
4047
+ createRequesterFn
4048
+ } from "@gitbeaker/requester-utils";
4045
4049
  import {
4046
4050
  Gitlab
4047
4051
  } from "@gitbeaker/rest";
4048
- import { ProxyAgent as ProxyAgent2 } from "undici";
4052
+ import {
4053
+ fetch as undiciFetch,
4054
+ ProxyAgent as ProxyAgent2
4055
+ } from "undici";
4049
4056
 
4050
4057
  // src/features/analysis/scm/gitlab/types.ts
4051
4058
  import { z as z12 } from "zod";
@@ -4065,9 +4072,23 @@ function getGitBeaker(options) {
4065
4072
  const url = options.url;
4066
4073
  const host = url ? new URL(url).origin : "https://gitlab.com";
4067
4074
  if (token?.startsWith("glpat-") || token === "") {
4068
- return new Gitlab({ token, host });
4075
+ return new Gitlab({
4076
+ token,
4077
+ host,
4078
+ requesterFn: createRequesterFn(
4079
+ (_, reqo) => Promise.resolve(reqo),
4080
+ brokerRequestHandler
4081
+ )
4082
+ });
4069
4083
  }
4070
- return new Gitlab({ oauthToken: token, host });
4084
+ return new Gitlab({
4085
+ oauthToken: token,
4086
+ host,
4087
+ requesterFn: createRequesterFn(
4088
+ (_, reqo) => Promise.resolve(reqo),
4089
+ brokerRequestHandler
4090
+ )
4091
+ });
4071
4092
  }
4072
4093
  async function gitlabValidateParams({
4073
4094
  url,
@@ -4317,41 +4338,56 @@ async function getGitlabBlameRanges({ ref, gitlabUrl, path: path9 }, options) {
4317
4338
  };
4318
4339
  });
4319
4340
  }
4320
- function initGitlabFetchMock() {
4321
- console.log("initGitlabFetchMock starting");
4322
- const globalFetch = global.fetch;
4323
- function myFetch(input, init) {
4324
- console.log(
4325
- `myFetch called with input: ${input} ${JSON.stringify(input)} ${JSON.stringify(init)}`,
4326
- input,
4327
- input?.url
4328
- );
4329
- let urlParsed = null;
4330
- try {
4331
- urlParsed = input?.url ? new URL(input?.url) : null;
4332
- } catch (err) {
4333
- console.log(
4334
- `this block is used for unit tests only. URL ${input?.url} starts from local directory`
4335
- );
4336
- }
4337
- console.log(`urlParsed: ${urlParsed} ${urlParsed?.href}`);
4338
- if (urlParsed && isBrokerUrl(urlParsed.href)) {
4339
- console.log(`urlParsed is broker url: ${urlParsed.href}`);
4340
- const dispatcher = new ProxyAgent2({
4341
- uri: GIT_PROXY_HOST,
4342
- requestTls: {
4343
- rejectUnauthorized: false
4344
- }
4345
- });
4346
- return globalFetch(input, { dispatcher });
4347
- }
4348
- console.log("urlParsed is not broker url");
4349
- return globalFetch(input, init);
4341
+ async function processBody(response) {
4342
+ const headers = response.headers;
4343
+ const type2 = headers.get("content-type")?.split(";")[0]?.trim();
4344
+ if (type2 === "application/json") {
4345
+ return await response.json();
4346
+ }
4347
+ return await response.text();
4348
+ }
4349
+ async function brokerRequestHandler(endpoint, options) {
4350
+ const retryCodes = [429, 502];
4351
+ const maxRetries = 10;
4352
+ const { prefixUrl, searchParams } = options || {};
4353
+ let baseUrl;
4354
+ if (prefixUrl)
4355
+ baseUrl = prefixUrl.endsWith("/") ? prefixUrl : `${prefixUrl}/`;
4356
+ const url = new URL(endpoint, baseUrl);
4357
+ url.search = searchParams || "";
4358
+ const dispatcher = url && isBrokerUrl(url.href) ? new ProxyAgent2({
4359
+ uri: GIT_PROXY_HOST,
4360
+ requestTls: {
4361
+ rejectUnauthorized: false
4362
+ }
4363
+ }) : void 0;
4364
+ for (let i = 0; i < maxRetries; i += 1) {
4365
+ const response = await undiciFetch(url, {
4366
+ headers: options?.headers,
4367
+ method: options?.method,
4368
+ body: options?.body ? String(options?.body) : void 0,
4369
+ dispatcher
4370
+ }).catch((e) => {
4371
+ if (e.name === "TimeoutError" || e.name === "AbortError") {
4372
+ throw new Error("Query timeout was reached");
4373
+ }
4374
+ throw e;
4375
+ });
4376
+ if (response.ok)
4377
+ return {
4378
+ body: await processBody(response),
4379
+ headers: Object.fromEntries(response.headers.entries()),
4380
+ status: response.status
4381
+ };
4382
+ if (!retryCodes.includes(response.status))
4383
+ throw new Error(`gitbeaker: ${response.statusText}`);
4384
+ await setTimeout2(2 ** i * 0.25);
4385
+ continue;
4350
4386
  }
4351
- global.fetch = myFetch;
4352
- console.log("initGitlabFetchMock finished");
4387
+ throw new Error(
4388
+ `Could not successfully complete this request due to Error 429. Check the applicable rate limits for this endpoint.`
4389
+ );
4353
4390
  }
4354
- initGitlabFetchMock();
4355
4391
 
4356
4392
  // src/features/analysis/scm/scmSubmit/index.ts
4357
4393
  import fs from "node:fs/promises";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobbdev",
3
- "version": "0.0.167",
3
+ "version": "0.0.168",
4
4
  "description": "Automated secure code remediation tool",
5
5
  "repository": "https://github.com/mobb-dev/bugsy",
6
6
  "main": "dist/index.js",