debugbear
Advanced tools
Comparing version 2.0.8 to 2.0.9
113
DebugBear.ts
@@ -21,3 +21,3 @@ import { analyzePage } from "./analyzePage"; | ||
this.pages = new PagesApiClient(apiKey); | ||
this.projects = new ProjectsApiClient(apiKey); | ||
this.projects = new ProjectsApiClient(apiKey, this); | ||
this.collaborators = new CollaboratorsApiClient(apiKey); | ||
@@ -27,2 +27,11 @@ } | ||
class ApiClientObject { | ||
toJSON() { | ||
return { | ||
...this, | ||
_apiClient: undefined | ||
}; | ||
} | ||
} | ||
async function waitForAnalysisResult(analysisId, explicitApiKeyParam) { | ||
@@ -51,6 +60,57 @@ let hasFinished = false; | ||
class ProjectsApiClient { | ||
constructor(private apiKey: string) {} | ||
class ProjectObject extends ApiClientObject { | ||
id!: string; | ||
name!: string; | ||
pages!: PageObject[]; | ||
async get() { | ||
constructor(private _apiClient: DebugBear, data) { | ||
super(); | ||
Object.assign(this, data); | ||
} | ||
createPage(options: CreatePageOptions) { | ||
return this._apiClient.pages.create(this.id, options); | ||
} | ||
deletePage(pageId: string) { | ||
return this._apiClient.pages.delete(pageId); | ||
} | ||
delete() { | ||
return this._apiClient.projects.delete(this.id); | ||
} | ||
} | ||
interface CreatePageOptions { | ||
name: string; | ||
url: string; | ||
everyNHours?: number; | ||
formFactor?: "mobile" | "desktop"; | ||
region?: ServerRegion; | ||
} | ||
interface PageObject { | ||
id: string; | ||
name: string; | ||
formFactor: "desktop" | "mobile"; | ||
region: ServerRegion; | ||
everyNHours: number; | ||
} | ||
type ServerRegion = | ||
| "us-east" | ||
| "us-west" | ||
| "uk" | ||
| "australia" | ||
| "japan" | ||
| "germany" | ||
| "brazil" | ||
| "finland"; | ||
class ProjectsApiClient extends ApiClientObject { | ||
constructor(private apiKey: string, private _apiClient: DebugBear) { | ||
super(); | ||
} | ||
async list() { | ||
const res = await callApi({ | ||
@@ -61,7 +121,9 @@ method: "GET", | ||
}); | ||
return res; | ||
return res.map(project => { | ||
return new ProjectObject(this._apiClient, project); | ||
}); | ||
} | ||
async create({ name }) { | ||
const res = await callApi({ | ||
async create({ name }: { name: string }): Promise<ProjectObject> { | ||
const page = await callApi({ | ||
method: "POST", | ||
@@ -74,4 +136,12 @@ path: "/projects", | ||
}); | ||
return res; | ||
return new ProjectObject(this._apiClient, page); | ||
} | ||
async delete(projectId: string) { | ||
return callApi({ | ||
method: "delete", | ||
path: "/projects/" + projectId, | ||
explicitApiKeyParam: this.apiKey | ||
}); | ||
} | ||
} | ||
@@ -153,2 +223,3 @@ | ||
url: resultUrl, | ||
__id: analysis.id, | ||
waitForResult: async () => { | ||
@@ -161,17 +232,5 @@ return waitForAnalysisResult(analysis.id, this.apiKey); | ||
create( | ||
projectId: number, | ||
{ | ||
name, | ||
url, | ||
everyNHours, | ||
formFactor, | ||
region | ||
}: { | ||
name: string; | ||
url: string; | ||
everyNHours?: number; | ||
formFactor?: "mobile" | "desktop"; | ||
region?: string; | ||
} | ||
) { | ||
projectId: string, | ||
{ name, url, everyNHours, formFactor, region }: CreatePageOptions | ||
): Promise<PageObject> { | ||
return callApi({ | ||
@@ -190,2 +249,10 @@ method: "POST", | ||
} | ||
delete(pageId: string) { | ||
return callApi({ | ||
method: "DELETE", | ||
path: "/pages/" + pageId, | ||
explicitApiKeyParam: this.apiKey | ||
}); | ||
} | ||
} |
@@ -7,9 +7,41 @@ export declare class DebugBear { | ||
} | ||
declare class ProjectsApiClient { | ||
declare class ApiClientObject { | ||
toJSON(): this & { | ||
_apiClient: undefined; | ||
}; | ||
} | ||
declare class ProjectObject extends ApiClientObject { | ||
private _apiClient; | ||
id: string; | ||
name: string; | ||
pages: PageObject[]; | ||
constructor(_apiClient: DebugBear, data: any); | ||
createPage(options: CreatePageOptions): Promise<PageObject>; | ||
deletePage(pageId: string): Promise<any>; | ||
delete(): Promise<any>; | ||
} | ||
interface CreatePageOptions { | ||
name: string; | ||
url: string; | ||
everyNHours?: number; | ||
formFactor?: "mobile" | "desktop"; | ||
region?: ServerRegion; | ||
} | ||
interface PageObject { | ||
id: string; | ||
name: string; | ||
formFactor: "desktop" | "mobile"; | ||
region: ServerRegion; | ||
everyNHours: number; | ||
} | ||
declare type ServerRegion = "us-east" | "us-west" | "uk" | "australia" | "japan" | "germany" | "brazil" | "finland"; | ||
declare class ProjectsApiClient extends ApiClientObject { | ||
private apiKey; | ||
constructor(apiKey: string); | ||
get(): Promise<any>; | ||
private _apiClient; | ||
constructor(apiKey: string, _apiClient: DebugBear); | ||
list(): Promise<any>; | ||
create({ name }: { | ||
name: any; | ||
}): Promise<any>; | ||
name: string; | ||
}): Promise<ProjectObject>; | ||
delete(projectId: string): Promise<any>; | ||
} | ||
@@ -48,12 +80,8 @@ declare class CollaboratorsApiClient { | ||
url: any; | ||
__id: any; | ||
waitForResult: () => Promise<any>; | ||
}>; | ||
create(projectId: number, { name, url, everyNHours, formFactor, region }: { | ||
name: string; | ||
url: string; | ||
everyNHours?: number; | ||
formFactor?: "mobile" | "desktop"; | ||
region?: string; | ||
}): Promise<any>; | ||
create(projectId: string, { name, url, everyNHours, formFactor, region }: CreatePageOptions): Promise<PageObject>; | ||
delete(pageId: string): Promise<any>; | ||
} | ||
export {}; |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -50,3 +74,3 @@ return new (P || (P = Promise))(function (resolve, reject) { | ||
this.pages = new PagesApiClient(apiKey); | ||
this.projects = new ProjectsApiClient(apiKey); | ||
this.projects = new ProjectsApiClient(apiKey, this); | ||
this.collaborators = new CollaboratorsApiClient(apiKey); | ||
@@ -57,2 +81,10 @@ } | ||
exports.DebugBear = DebugBear; | ||
var ApiClientObject = /** @class */ (function () { | ||
function ApiClientObject() { | ||
} | ||
ApiClientObject.prototype.toJSON = function () { | ||
return __assign({}, this, { _apiClient: undefined }); | ||
}; | ||
return ApiClientObject; | ||
}()); | ||
function waitForAnalysisResult(analysisId, explicitApiKeyParam) { | ||
@@ -91,9 +123,33 @@ return __awaiter(this, void 0, void 0, function () { | ||
} | ||
var ProjectsApiClient = /** @class */ (function () { | ||
function ProjectsApiClient(apiKey) { | ||
this.apiKey = apiKey; | ||
var ProjectObject = /** @class */ (function (_super) { | ||
__extends(ProjectObject, _super); | ||
function ProjectObject(_apiClient, data) { | ||
var _this = _super.call(this) || this; | ||
_this._apiClient = _apiClient; | ||
Object.assign(_this, data); | ||
return _this; | ||
} | ||
ProjectsApiClient.prototype.get = function () { | ||
ProjectObject.prototype.createPage = function (options) { | ||
return this._apiClient.pages.create(this.id, options); | ||
}; | ||
ProjectObject.prototype.deletePage = function (pageId) { | ||
return this._apiClient.pages.delete(pageId); | ||
}; | ||
ProjectObject.prototype.delete = function () { | ||
return this._apiClient.projects.delete(this.id); | ||
}; | ||
return ProjectObject; | ||
}(ApiClientObject)); | ||
var ProjectsApiClient = /** @class */ (function (_super) { | ||
__extends(ProjectsApiClient, _super); | ||
function ProjectsApiClient(apiKey, _apiClient) { | ||
var _this = _super.call(this) || this; | ||
_this.apiKey = apiKey; | ||
_this._apiClient = _apiClient; | ||
return _this; | ||
} | ||
ProjectsApiClient.prototype.list = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var res; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
@@ -108,3 +164,5 @@ switch (_a.label) { | ||
res = _a.sent(); | ||
return [2 /*return*/, res]; | ||
return [2 /*return*/, res.map(function (project) { | ||
return new ProjectObject(_this._apiClient, project); | ||
})]; | ||
} | ||
@@ -117,3 +175,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var res; | ||
var page; | ||
return __generator(this, function (_b) { | ||
@@ -130,4 +188,4 @@ switch (_b.label) { | ||
case 1: | ||
res = _b.sent(); | ||
return [2 /*return*/, res]; | ||
page = _b.sent(); | ||
return [2 /*return*/, new ProjectObject(this._apiClient, page)]; | ||
} | ||
@@ -137,4 +195,15 @@ }); | ||
}; | ||
ProjectsApiClient.prototype.delete = function (projectId) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, callApi_1.callApi({ | ||
method: "delete", | ||
path: "/projects/" + projectId, | ||
explicitApiKeyParam: this.apiKey | ||
})]; | ||
}); | ||
}); | ||
}; | ||
return ProjectsApiClient; | ||
}()); | ||
}(ApiClientObject)); | ||
var CollaboratorsApiClient = /** @class */ (function () { | ||
@@ -208,2 +277,3 @@ function CollaboratorsApiClient(apiKey) { | ||
url: resultUrl, | ||
__id: analysis.id, | ||
waitForResult: function () { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -234,3 +304,10 @@ return __generator(this, function (_a) { | ||
}; | ||
PagesApiClient.prototype.delete = function (pageId) { | ||
return callApi_1.callApi({ | ||
method: "DELETE", | ||
path: "/pages/" + pageId, | ||
explicitApiKeyParam: this.apiKey | ||
}); | ||
}; | ||
return PagesApiClient; | ||
}()); |
@@ -44,3 +44,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var urlValue, program, baseUrl, repo, commit, loginStep, err_1; | ||
var urlValue, program, baseUrl, repo, commit, err_1; | ||
return __generator(this, function (_a) { | ||
@@ -63,4 +63,2 @@ switch (_a.label) { | ||
.option("--buildTitle <buildTitle>", "title of the build, e.g. a commit message") | ||
// .option("--loginStep.username <loginStep.username>") | ||
// .option("--loginStep.password <loginStep.password>") | ||
.option("--customHeader <customHeader>", "custom header, name and value separated by a colon", function collect(value, previous) { | ||
@@ -111,12 +109,2 @@ var _a; | ||
_a.trys.push([1, 3, , 4]); | ||
loginStep = { | ||
username: null, | ||
password: null | ||
}; | ||
if (program["loginStep.username"]) { | ||
loginStep.username = program["loginStep.username"]; | ||
} | ||
if (program["loginStep.password"]) { | ||
loginStep.password = program["loginStep.password"]; | ||
} | ||
return [4 /*yield*/, analyzePage_1.analyzePage(Object.assign({ | ||
@@ -142,3 +130,3 @@ url: urlValue, | ||
"ngrokWebPort" | ||
]), { loginStep: loginStep }))]; | ||
])))]; | ||
case 2: | ||
@@ -145,0 +133,0 @@ _a.sent(); |
{ | ||
"name": "debugbear", | ||
"version": "2.0.8", | ||
"version": "2.0.9", | ||
"description": "API/CLI for DebugBearAnalyze pages with DebugBear. Analyze pages on demand on demand or as part of your Continuous Integration process.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -29,4 +29,2 @@ import * as commander from "commander"; | ||
) | ||
// .option("--loginStep.username <loginStep.username>") | ||
// .option("--loginStep.password <loginStep.password>") | ||
.option( | ||
@@ -89,13 +87,2 @@ "--customHeader <customHeader>", | ||
try { | ||
let loginStep = { | ||
username: null, | ||
password: null | ||
}; | ||
if (program["loginStep.username"]) { | ||
loginStep.username = program["loginStep.username"]; | ||
} | ||
if (program["loginStep.password"]) { | ||
loginStep.password = program["loginStep.password"]; | ||
} | ||
await analyzePage( | ||
@@ -125,4 +112,3 @@ Object.assign( | ||
"ngrokWebPort" | ||
]), | ||
{ loginStep } | ||
]) | ||
) | ||
@@ -129,0 +115,0 @@ ); |
60326
1493