@fabernovel/heart-observatory
Advanced tools
Comparing version 3.3.0 to 3.4.0
@@ -1,3 +0,4 @@ | ||
import Scan from './model/Scan.js'; | ||
export default class Client { | ||
import { ObservatoryConfig } from "../config/Config"; | ||
import { ScanInterface } from "./model/Scan"; | ||
export declare class Client { | ||
private analyzeUrl; | ||
@@ -7,7 +8,7 @@ private apiUrl; | ||
constructor(); | ||
launchAnalysis(conf: object): Promise<Scan>; | ||
launchAnalysis(conf: ObservatoryConfig): Promise<ScanInterface>; | ||
getProjectHost(): string; | ||
getAnalyzeUrl(): string; | ||
getAnalysisReport(): Promise<Scan>; | ||
getAnalysisReport(): Promise<ScanInterface>; | ||
private generateApiUrl; | ||
} |
@@ -12,2 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Client = void 0; | ||
const heart_core_1 = require("@fabernovel/heart-core"); | ||
@@ -17,2 +18,3 @@ const Error_1 = require("./model/Error"); | ||
constructor() { | ||
this.host = ""; | ||
this.analyzeUrl = process.env.OBSERVATORY_ANALYZE_URL; | ||
@@ -23,11 +25,11 @@ this.apiUrl = process.env.OBSERVATORY_API_URL; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.host = conf['host']; | ||
this.host = conf.host; | ||
if (undefined === this.host) { | ||
return Promise.reject({ | ||
error: 'mandatory-parameter', | ||
message: '"host" is a mandatory parameter' | ||
error: "mandatory-parameter", | ||
message: '"host" is a mandatory parameter', | ||
}); | ||
} | ||
const scan = yield heart_core_1.Request.post(this.generateApiUrl('analyze'), conf, { | ||
[heart_core_1.Request.HEADER_CONTENT_TYPE]: heart_core_1.Request.HEADER_CONTENT_TYPE_X_WWW_FORM_URLENCODED | ||
const scan = yield heart_core_1.Request.post(this.generateApiUrl("analyze"), conf, { | ||
[heart_core_1.Request.HEADER_CONTENT_TYPE]: heart_core_1.Request.HEADER_CONTENT_TYPE_X_WWW_FORM_URLENCODED, | ||
}); | ||
@@ -37,10 +39,10 @@ // Observatory API is unconventional, and does not take advantage of http verbs :/ | ||
return Promise.reject({ | ||
error: scan['error'], | ||
message: scan['text'] | ||
error: scan["error"], | ||
message: scan["text"], | ||
}); | ||
} | ||
if ('FAILED' === scan.state || 'ABORTED' === scan.state) { | ||
if ("FAILED" === scan.state || "ABORTED" === scan.state) { | ||
return Promise.reject({ | ||
error: 'error', | ||
message: scan.state | ||
error: "error", | ||
message: scan.state, | ||
}); | ||
@@ -59,3 +61,3 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return heart_core_1.Request.get(this.generateApiUrl('analyze')); | ||
return heart_core_1.Request.get(this.generateApiUrl("analyze")); | ||
}); | ||
@@ -67,3 +69,2 @@ } | ||
} | ||
exports.default = Client; | ||
//# sourceMappingURL=Client.js.map | ||
exports.Client = Client; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isError = void 0; | ||
const isError = (object) => object['error'] !== undefined; | ||
const isError = (object) => object.error !== undefined; | ||
exports.isError = isError; | ||
//# sourceMappingURL=Error.js.map |
/** | ||
* @see {@link https://github.com/mozilla/http-observatory/blob/master/httpobs/docs/api.md#scan} | ||
*/ | ||
export default interface Scan { | ||
export interface ScanInterface { | ||
end_time: string; | ||
@@ -13,3 +13,3 @@ grade: string; | ||
start_time: string; | ||
state: 'ABORTED' | 'FAILED' | 'FINISHED' | 'PENDING' | 'STARTING' | 'RUNNING'; | ||
state: "ABORTED" | "FAILED" | "FINISHED" | "PENDING" | "STARTING" | "RUNNING"; | ||
tests_failed: number; | ||
@@ -16,0 +16,0 @@ tests_passed: number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=Scan.js.map |
@@ -1,3 +0,3 @@ | ||
import ObservatoryModule from './ObservatoryModule.js'; | ||
import { ObservatoryModule } from "./ObservatoryModule"; | ||
declare const _default: ObservatoryModule; | ||
export default _default; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ObservatoryModule_js_1 = __importDefault(require("./ObservatoryModule.js")); | ||
exports.default = new ObservatoryModule_js_1.default({ | ||
name: 'Heart Observatory', | ||
const ObservatoryModule_1 = require("./ObservatoryModule"); | ||
exports.default = new ObservatoryModule_1.ObservatoryModule({ | ||
name: "Heart Observatory", | ||
service: { | ||
name: 'Mozilla Observatory', | ||
logo: 'https://gitlab.com/fabernovel/heart/raw/master/assets/images/logos/Observatory.png?v=20190723' | ||
name: "Mozilla Observatory", | ||
logo: "https://gitlab.com/fabernovel/heart/raw/master/assets/images/logos/Observatory.png?v=20190723", | ||
}, | ||
}); | ||
//# sourceMappingURL=index.js.map |
@@ -1,9 +0,11 @@ | ||
import { Module, ModuleAnalysisInterface, ModuleInterface, Report } from '@fabernovel/heart-core'; | ||
export default class ObservatoryModule extends Module implements ModuleAnalysisInterface { | ||
import { Module, ModuleAnalysisInterface, ModuleInterface, Report } from "@fabernovel/heart-core"; | ||
import { ObservatoryConfig } from "./config/Config"; | ||
export declare class ObservatoryModule extends Module implements ModuleAnalysisInterface<ObservatoryConfig> { | ||
private readonly TIME_BETWEEN_TRIES; | ||
private apiClient; | ||
constructor(module: Partial<ModuleInterface>); | ||
startAnalysis(conf: object): Promise<Report>; | ||
private threshold?; | ||
constructor(module: Omit<ModuleInterface, "id">); | ||
startAnalysis(conf: ObservatoryConfig, threshold?: number): Promise<Report>; | ||
private requestScan; | ||
private handleRequestScan; | ||
} |
@@ -11,8 +11,6 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ObservatoryModule = void 0; | ||
const heart_core_1 = require("@fabernovel/heart-core"); | ||
const Client_1 = __importDefault(require("./api/Client")); | ||
const Client_1 = require("./api/Client"); | ||
class ObservatoryModule extends heart_core_1.Module { | ||
@@ -22,6 +20,7 @@ constructor(module) { | ||
this.TIME_BETWEEN_TRIES = 10000; | ||
this.apiClient = new Client_1.default(); | ||
this.apiClient = new Client_1.Client(); | ||
} | ||
startAnalysis(conf) { | ||
startAnalysis(conf, threshold) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.threshold = threshold; | ||
yield this.apiClient.launchAnalysis(conf); | ||
@@ -33,12 +32,3 @@ return this.requestScan(); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let scan; | ||
try { | ||
scan = yield this.apiClient.getAnalysisReport(); | ||
} | ||
catch (error) { | ||
return Promise.reject({ | ||
error: 'error', | ||
message: error.message | ||
}); | ||
} | ||
const scan = yield this.apiClient.getAnalysisReport(); | ||
return this.handleRequestScan(scan); | ||
@@ -50,6 +40,10 @@ }); | ||
switch (scan.state) { | ||
case 'FAILED': | ||
case "FAILED": | ||
throw new Error(scan.state); | ||
break; | ||
case 'FINISHED': | ||
case "PENDING": | ||
case "STARTING": | ||
case "RUNNING": | ||
yield heart_core_1.Helper.timeout(this.TIME_BETWEEN_TRIES); | ||
return this.requestScan(); | ||
case "FINISHED": | ||
return new heart_core_1.Report({ | ||
@@ -61,9 +55,7 @@ analyzedUrl: this.apiClient.getProjectHost(), | ||
date: new Date(scan.end_time), | ||
normalizedNote: scan.score > 100 ? 100 : scan.score | ||
normalizedNote: scan.score > 100 ? 100 : scan.score, | ||
threshold: this.threshold, | ||
}); | ||
break; | ||
default: | ||
yield heart_core_1.Helper.timeout(this.TIME_BETWEEN_TRIES); | ||
return this.requestScan(); | ||
break; | ||
throw new Error(scan.state); | ||
} | ||
@@ -73,3 +65,2 @@ }); | ||
} | ||
exports.default = ObservatoryModule; | ||
//# sourceMappingURL=ObservatoryModule.js.map | ||
exports.ObservatoryModule = ObservatoryModule; |
{ | ||
"name": "@fabernovel/heart-observatory", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"description": "Analysis module of Heart, which analyses URLs with Mozilla Observatory", | ||
"homepage": "https://gitlab.com/fabernovel/heart", | ||
"homepage": "https://heart.fabernovel.com", | ||
"bugs": { | ||
@@ -17,6 +17,2 @@ "url": "https://gitlab.com/fabernovel/heart/issues" | ||
], | ||
"files": [ | ||
"lib/**/*", | ||
".env.sample" | ||
], | ||
"main": "lib/index.js", | ||
@@ -27,10 +23,8 @@ "types": "lib/index.d.ts", | ||
}, | ||
"engines": { | ||
"node": ">=14.17.0" | ||
}, | ||
"peerDependencies": { | ||
"@fabernovel/heart-cli": "^3.2.0" | ||
}, | ||
"files": [ | ||
"lib/**/*", | ||
".env.sample" | ||
], | ||
"dependencies": { | ||
"@fabernovel/heart-core": "^3.1.2" | ||
"@fabernovel/heart-core": "^3.3.0" | ||
}, | ||
@@ -40,16 +34,22 @@ "devDependencies": { | ||
"@types/node": "^10.14.10", | ||
"jest": "^27.5.1", | ||
"ts-jest": "^27.1.3", | ||
"typescript": "^4.0.0", | ||
"@typescript-eslint/eslint-plugin": "^5.32.0", | ||
"@typescript-eslint/parser": "^5.32.0", | ||
"eslint": "^8.16.0", | ||
"@typescript-eslint/parser": "^5.26.0", | ||
"@typescript-eslint/eslint-plugin": "^5.26.0" | ||
"jest": "^28.1.0", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^28.0.2", | ||
"typescript": "^4.6.4" | ||
}, | ||
"peerDependencies": { | ||
"@fabernovel/heart-cli": "^3.3.0" | ||
}, | ||
"engines": { | ||
"node": ">=14.17.0" | ||
}, | ||
"scripts": { | ||
"build": "tsc", | ||
"build-watch": "tsc -w", | ||
"build": "rimraf lib && tsc --project tsconfig.build.json", | ||
"build:watch": "npm run build --watch", | ||
"lint": "eslint .", | ||
"outdated": "npm outdated", | ||
"test": "jest --silent" | ||
} | ||
} |
@@ -5,3 +5,3 @@ # Heart Observatory | ||
Read more about [the purpose, design and general installation of _Heart_](https://www.fabernovel.com/en/clients/cases/heart-a-tool-for-automating-web-quality-metrics). | ||
Read more about [the purpose, design and general installation of _Heart_](https://gitlab.com/fabernovel/heart/-/blob/master/README.md). | ||
@@ -53,6 +53,10 @@ # Package manager | ||
Using _[Heart CLI](https://www.npmjs.com/package/@fabernovel/heart-cli)_, starting an _Observatory_ analysis of https://heart.fabernovel.com could look like that: | ||
Starting with this situation: | ||
> Using _[Heart CLI](https://www.npmjs.com/package/@fabernovel/heart-cli)_ | ||
> | ||
> You want to analyse the https://heart.fabernovel.com URL and check that the rating is at least 90 | ||
```shell | ||
npx heart observatory --inline '{"host": "heart.fabernovel.com"}' | ||
npx heart observatory --inline '{"host": "heart.fabernovel.com"}' --threshold 90 | ||
``` |
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
60
12288
9
16
1