Socket
Socket
Sign inDemoInstall

debugbear

Package Overview
Dependencies
75
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.10 to 0.1.11

dist/makeApiClient.js

57

analyzePage.ts

@@ -1,32 +0,6 @@

import { callApi } from "./callApi";
const debugbear = require("./makeApiClient").makeApiClient;
async function waitForAnalysisResult({ analysisId, isCli }) {
let hasFinished = false;
let timeWaited = 0;
const interval = 5000;
if (isCli) {
console.log("Waiting for result");
}
while (!hasFinished) {
await new Promise(resolve => setTimeout(resolve, interval));
timeWaited += interval;
({ hasFinished } = await callApi({
method: "GET",
path: "/analysis/" + analysisId
}));
if (timeWaited > 10 * 60 * 1000) {
throw Error("Waiting for result timed out");
}
}
if (isCli) {
console.log("Analysis complete");
}
}
export async function analyzePage(options) {
const { pageId, waitForResult, isCli, explicitApiKeyParam } = options;
if (!pageId) {
const dbbClient = debugbear(options.explicitApiKeyParam);
if (!options) {
console.log(

@@ -37,20 +11,23 @@ "The pageId option is required. You can find the page ID in the top right corner on the results page."

const { analysis, resultUrl } = await callApi({
method: "POST",
path: "/page/" + pageId + "/analyze",
body: options,
explicitApiKeyParam
});
const analysis = await dbbClient.pages.analyze(options.pageId, options);
if (isCli) {
console.log("When the result is ready you can see it here: " + resultUrl);
if (options.isCli) {
console.log(
"When the result is ready you can see it here: " + analysis.url
);
}
if (waitForResult) {
await waitForAnalysisResult({ analysisId: analysis.id, isCli });
if (options.waitForResult) {
if (options.isCli) {
console.log("Waiting for result");
}
await analysis.waitForResult();
if (options.isCli) {
console.log("Analysis complete");
}
}
return {
resultUrl
resultUrl: analysis.url
};
}

@@ -15,2 +15,20 @@ import { analyzePage } from "./analyzePage";

async function waitForAnalysisResult(analysisId) {
let hasFinished = false;
let timeWaited = 0;
const interval = 4000;
while (!hasFinished) {
await new Promise(resolve => setTimeout(resolve, interval));
timeWaited += interval;
({ hasFinished } = await callApi({
method: "GET",
path: "/analysis/" + analysisId
}));
if (timeWaited > 10 * 60 * 1000) {
throw Error("Waiting for result timed out");
}
}
}
class ProjectsApiClient {

@@ -65,5 +83,16 @@ constructor(private apiKey: string) {}

analyze(pageId: number) {
// todo: should be the other way round, the analyzePage function should call the pages api
return analyzePage({ pageId, explicitApiKeyParam: this.apiKey });
async analyze(pageId: number, options = {}) {
const { analysis, resultUrl } = await callApi({
method: "POST",
path: "/page/" + pageId + "/analyze",
body: options,
explicitApiKeyParam: this.apiKey
});
return {
url: resultUrl,
waitForResult: async function() {
waitForAnalysisResult(analysis.id);
}
};
}

@@ -70,0 +99,0 @@

@@ -38,70 +38,32 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var callApi_1 = require("./callApi");
function waitForAnalysisResult(_a) {
var analysisId = _a.analysisId, isCli = _a.isCli;
return __awaiter(this, void 0, void 0, function () {
var hasFinished, timeWaited, interval;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
hasFinished = false;
timeWaited = 0;
interval = 5000;
if (isCli) {
console.log("Waiting for result");
}
_b.label = 1;
case 1:
if (!!hasFinished) return [3 /*break*/, 4];
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, interval); })];
case 2:
_b.sent();
timeWaited += interval;
return [4 /*yield*/, callApi_1.callApi({
method: "GET",
path: "/analysis/" + analysisId
})];
case 3:
(hasFinished = (_b.sent()).hasFinished);
if (timeWaited > 10 * 60 * 1000) {
throw Error("Waiting for result timed out");
}
return [3 /*break*/, 1];
case 4:
if (isCli) {
console.log("Analysis complete");
}
return [2 /*return*/];
}
});
});
}
var debugbear = require("./makeApiClient").makeApiClient;
function analyzePage(options) {
return __awaiter(this, void 0, void 0, function () {
var pageId, waitForResult, isCli, explicitApiKeyParam, _a, analysis, resultUrl;
return __generator(this, function (_b) {
switch (_b.label) {
var dbbClient, analysis;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
pageId = options.pageId, waitForResult = options.waitForResult, isCli = options.isCli, explicitApiKeyParam = options.explicitApiKeyParam;
if (!pageId) {
dbbClient = debugbear(options.explicitApiKeyParam);
if (!options) {
console.log("The pageId option is required. You can find the page ID in the top right corner on the results page.");
}
return [4 /*yield*/, callApi_1.callApi({
method: "POST",
path: "/page/" + pageId + "/analyze",
body: options,
explicitApiKeyParam: explicitApiKeyParam
})];
return [4 /*yield*/, dbbClient.pages.analyze(options.pageId, options)];
case 1:
_a = _b.sent(), analysis = _a.analysis, resultUrl = _a.resultUrl;
if (isCli) {
console.log("When the result is ready you can see it here: " + resultUrl);
analysis = _a.sent();
if (options.isCli) {
console.log("When the result is ready you can see it here: " + analysis.url);
}
if (!waitForResult) return [3 /*break*/, 3];
return [4 /*yield*/, waitForAnalysisResult({ analysisId: analysis.id, isCli: isCli })];
if (!options.waitForResult) return [3 /*break*/, 3];
if (options.isCli) {
console.log("Waiting for result");
}
return [4 /*yield*/, analysis.waitForResult()];
case 2:
_b.sent();
_b.label = 3;
_a.sent();
if (options.isCli) {
console.log("Analysis complete");
}
_a.label = 3;
case 3: return [2 /*return*/, {
resultUrl: resultUrl
resultUrl: analysis.url
}];

@@ -108,0 +70,0 @@ }

@@ -38,3 +38,2 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var analyzePage_1 = require("./analyzePage");
var callApi_1 = require("./callApi");

@@ -50,2 +49,33 @@ var ApiClient = /** @class */ (function () {

exports.ApiClient = ApiClient;
function waitForAnalysisResult(analysisId) {
return __awaiter(this, void 0, void 0, function () {
var hasFinished, timeWaited, interval;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
hasFinished = false;
timeWaited = 0;
interval = 4000;
_a.label = 1;
case 1:
if (!!hasFinished) return [3 /*break*/, 4];
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, interval); })];
case 2:
_a.sent();
timeWaited += interval;
return [4 /*yield*/, callApi_1.callApi({
method: "GET",
path: "/analysis/" + analysisId
})];
case 3:
(hasFinished = (_a.sent()).hasFinished);
if (timeWaited > 10 * 60 * 1000) {
throw Error("Waiting for result timed out");
}
return [3 /*break*/, 1];
case 4: return [2 /*return*/];
}
});
});
}
var ProjectsApiClient = /** @class */ (function () {

@@ -121,5 +151,30 @@ function ProjectsApiClient(apiKey) {

}
PagesApiClient.prototype.analyze = function (pageId) {
// todo: should be the other way round, the analyzePage function should call the pages api
return analyzePage_1.analyzePage({ pageId: pageId, explicitApiKeyParam: this.apiKey });
PagesApiClient.prototype.analyze = function (pageId, options) {
if (options === void 0) { options = {}; }
return __awaiter(this, void 0, void 0, function () {
var _a, analysis, resultUrl;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, callApi_1.callApi({
method: "POST",
path: "/page/" + pageId + "/analyze",
body: options,
explicitApiKeyParam: this.apiKey
})];
case 1:
_a = _b.sent(), analysis = _a.analysis, resultUrl = _a.resultUrl;
return [2 /*return*/, {
url: resultUrl,
waitForResult: function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
waitForAnalysisResult(analysis.id);
return [2 /*return*/];
});
});
}
}];
}
});
});
};

@@ -126,0 +181,0 @@ PagesApiClient.prototype.create = function (projectId, _a) {

@@ -5,8 +5,5 @@ "use strict";

var analyzePage_1 = require("./analyzePage");
var ApiClient_1 = require("./ApiClient");
function makeApiClient(apiKey) {
return new ApiClient_1.ApiClient(apiKey);
}
makeApiClient.analyzePage = analyzePage_1.analyzePage;
makeApiClient.__runCli = runCli_1.__runCli;
module.exports = makeApiClient;
var makeApiClient_1 = require("./makeApiClient");
module.exports = makeApiClient_1.makeApiClient;
module.exports.analyzePage = analyzePage_1.analyzePage;
module.exports.__runCli = runCli_1.__runCli;

@@ -52,2 +52,6 @@ "use strict";

case 0:
console.log("============================================================");
console.log("== Consider upgrading to the V2 API/CLI ==");
console.log("== https://www.debugbear.com/docs/migrating-to-the-v2-api ==");
console.log("============================================================");
program = commander

@@ -54,0 +58,0 @@ .arguments("<url>")

import { __runCli } from "./runCli";
import { analyzePage } from "./analyzePage";
import { ApiClient } from "./ApiClient";
import { makeApiClient } from "./makeApiClient";
function makeApiClient(apiKey) {
return new ApiClient(apiKey);
}
makeApiClient.analyzePage = analyzePage;
makeApiClient.__runCli = __runCli;
module.exports = makeApiClient;
module.exports.analyzePage = analyzePage;
module.exports.__runCli = __runCli;
{
"name": "debugbear",
"version": "0.1.10",
"description": "Analyze pages with DebugBear, on demand or as part of your Continuous Integration process.",
"version": "0.1.11",
"description": "API/CLI for DebugBearAnalyze pages with DebugBear. Analyze pages on demand on demand or as part of your Continuous Integration process.",
"main": "dist/index.js",

@@ -6,0 +6,0 @@ "scripts": {

@@ -12,2 +12,7 @@ import * as envCi from "env-ci";

export async function __runCli() {
console.log("============================================================");
console.log("== Consider upgrading to the V2 API/CLI ==");
console.log("== https://www.debugbear.com/docs/migrating-to-the-v2-api ==");
console.log("============================================================");
let urlValue;

@@ -14,0 +19,0 @@ const program = commander

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc