raqibo 0.0.0-stage → 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 The Raqibo authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,68 @@
1
- # Temporary Holding Version
1
+ # raqibo
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Website checks from a server, for terminals and CI pipelines: uptime, redirects, TLS expiry,
4
+ security headers, domain expiry, email security, broken links and robots.txt - and your
5
+ [Raqibo](https://raqibo.com) monitors as a file you keep in version control.
6
+
7
+ ```sh
8
+ npx raqibo down example.com
9
+ ```
10
+
11
+ Node 20 or newer. No dependencies.
12
+
13
+ ## Checks
14
+
15
+ No account needed. Each exits **0** when it passes, **1** when it fails, and **2** when it could
16
+ not check at all (a bad argument, the API out of reach, a rate limit), so a pipeline can tell
17
+ "the site is wrong" from "the check did not happen".
18
+
19
+ | Command | Fails when |
20
+ | --- | --- |
21
+ | `raqibo down <url>` | the site does not answer, or answers with an error |
22
+ | `raqibo trace <url> [--max-redirects n] [--expect url]` | too many redirects, the wrong end, or a drop from https to http |
23
+ | `raqibo ssl <host> [--min-days 14]` | the certificate is untrusted, for another name, or expires sooner |
24
+ | `raqibo headers <url> [--min-grade C]` | the security headers grade is below the minimum |
25
+ | `raqibo domain <domain> [--min-days 30]` | the registration expires sooner, or is at risk |
26
+ | `raqibo email <domain> [--min-grade C]` | the SPF/DKIM/DMARC/DNSSEC/CAA grade is below the minimum |
27
+ | `raqibo links <url>` | a link or image on the page is broken |
28
+ | `raqibo robots <url>` | robots.txt or a sitemap has a real problem |
29
+
30
+ `--json` prints the API's full answer. `--api <url>` (or `RAQIBO_API_URL`) points at another
31
+ API address.
32
+
33
+ ## Monitors as code
34
+
35
+ With an API key from the dashboard (Settings, API keys) in `RAQIBO_API_KEY`:
36
+
37
+ ```sh
38
+ raqibo monitors export -o monitors.yaml # every monitor, as YAML
39
+ raqibo monitors apply monitors.yaml --dry-run # what would change
40
+ raqibo monitors apply monitors.yaml # apply it, all or nothing
41
+ raqibo monitors apply monitors.yaml --prune # and delete monitors the file does not list
42
+ ```
43
+
44
+ The file holds alert destinations, so keep it private. Credentials for the sites checked are
45
+ never in it.
46
+
47
+ ## Development
48
+
49
+ ```sh
50
+ cd apps/cli && npm test # node --test, against a fake API
51
+ node bin/raqibo.js --help
52
+ ```
53
+
54
+ ### Publishing (the owner)
55
+
56
+ MIT licensed (`LICENSE`). From a clean, up-to-date `main`:
57
+
58
+ ```sh
59
+ cd apps/cli
60
+ npm test
61
+ npm login
62
+ npm publish --dry-run # the files listed must be bin/, src/, README.md, LICENSE, package.json
63
+ npm publish
64
+ ```
65
+
66
+ After the first publish, set `CLI_PUBLISHED = true` in `apps/web/lib/cli.ts`, which turns on
67
+ `raqibo.com/docs/cli`. For a later release, raise `version` in `package.json` and `VERSION` in
68
+ `src/cli.js` together (a test checks they match), then publish again.
package/bin/raqibo.js ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import { main } from "../src/cli.js";
3
+
4
+ const code = await main(process.argv.slice(2), {
5
+ fetch: globalThis.fetch,
6
+ api: process.env.RAQIBO_API_URL,
7
+ key: process.env.RAQIBO_API_KEY?.trim() || undefined,
8
+ out: (text) => process.stdout.write(`${text}\n`),
9
+ err: (text) => process.stderr.write(`${text}\n`),
10
+ });
11
+ process.exitCode = code;
package/package.json CHANGED
@@ -1,6 +1,31 @@
1
1
  {
2
2
  "name": "raqibo",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Website checks from a server, for terminals and CI: uptime, redirects, TLS, headers, domain, email security, broken links, robots.txt - and monitors as a file.",
5
+ "type": "module",
6
+ "bin": {
7
+ "raqibo": "bin/raqibo.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "src",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "engines": {
16
+ "node": ">=20"
17
+ },
18
+ "scripts": {
19
+ "test": "node --test"
20
+ },
21
+ "homepage": "https://raqibo.com/docs/cli",
22
+ "keywords": [
23
+ "monitoring",
24
+ "uptime",
25
+ "ssl",
26
+ "security-headers",
27
+ "broken-links",
28
+ "ci"
29
+ ],
30
+ "license": "MIT"
31
+ }
package/src/cli.js ADDED
@@ -0,0 +1,326 @@
1
+ // The Raqibo command line: the free checks in a terminal or a CI pipeline, and monitors as a file.
2
+ //
3
+ // Every check exits 0 when it passes, 1 when it fails, and 2 when it could not be run (a bad
4
+ // argument, a refusal, the API out of reach). A pipeline can therefore tell "the site is wrong"
5
+ // from "the check did not happen", and must never mistake the second for the first. The checks
6
+ // need no account; `monitors` needs an API key in RAQIBO_API_KEY.
7
+ //
8
+ // No dependencies: Node's own fetch, argument parsing and test runner.
9
+
10
+ import { readFile, writeFile } from "node:fs/promises";
11
+ import { parseArgs } from "node:util";
12
+
13
+ export const VERSION = "0.1.0";
14
+ export const DEFAULT_API = "https://api.raqibo.com";
15
+
16
+ export const PASS = 0;
17
+ export const FAIL = 1;
18
+ export const ERROR = 2;
19
+
20
+ const GRADES = ["A", "B", "C", "D", "F"];
21
+
22
+ export class UsageError extends Error {}
23
+
24
+ /** A refusal or failure from the API, with its own code and message. */
25
+ export class ApiError extends Error {
26
+ constructor(status, code, message, retryAfter) {
27
+ super(message);
28
+ this.status = status;
29
+ this.code = code;
30
+ this.retryAfter = retryAfter;
31
+ }
32
+ }
33
+
34
+ const HELP = `raqibo ${VERSION} - website checks from a server, for terminals and CI
35
+
36
+ Usage: raqibo <command> [target] [options]
37
+
38
+ Checks (no account needed; exit 0 pass, 1 fail, 2 could not check):
39
+ down <url> Fails when the site does not answer, or answers with an error
40
+ trace <url> Every redirect hop
41
+ --max-redirects <n> Fail on more redirects than this
42
+ --expect <url> Fail unless the chain ends at this address
43
+ headers <url> Security headers grade
44
+ --min-grade <A-F> Fail below this grade (default: C)
45
+ ssl <host> TLS certificate
46
+ --min-days <n> Fail when it expires sooner (default: 14)
47
+ domain <domain> Domain registration
48
+ --min-days <n> Fail when it expires sooner (default: 30)
49
+ email <domain> SPF, DKIM, DMARC, DNSSEC, CAA - one grade
50
+ --min-grade <A-F> Fail below this grade (default: C)
51
+ links <url> Broken links and images on one page
52
+ robots <url> robots.txt and sitemaps
53
+
54
+ Monitors as a file (needs RAQIBO_API_KEY):
55
+ monitors export [-o <file>] Every monitor as YAML (stdout unless -o)
56
+ monitors apply <file> Apply a monitors file, all or nothing
57
+ --dry-run Show what would change, change nothing
58
+ --prune Delete monitors the file does not list
59
+
60
+ Options:
61
+ --json Print the API's answer as JSON
62
+ --api <url> API address (default: ${DEFAULT_API}, or RAQIBO_API_URL)
63
+ -h, --help This help
64
+ -v, --version The version
65
+ `;
66
+
67
+ /** POST/GET to the API; resolves to the parsed body or rejects with ApiError. */
68
+ export async function call(env, path, { method = "GET", body, key, text = false } = {}) {
69
+ const headers = { "User-Agent": `raqibo-cli/${VERSION}`, Accept: text ? "application/yaml" : "application/json" };
70
+ if (body !== undefined) headers["Content-Type"] = "application/json";
71
+ if (key) headers["X-Api-Key"] = key;
72
+ let response;
73
+ try {
74
+ response = await env.fetch(`${env.api}${path}`, {
75
+ method,
76
+ headers,
77
+ body: body === undefined ? undefined : JSON.stringify(body),
78
+ });
79
+ } catch (cause) {
80
+ throw new ApiError(0, "network_error", `Could not reach ${env.api}: ${cause?.message ?? cause}`);
81
+ }
82
+ if (!response.ok) {
83
+ let payload = null;
84
+ try {
85
+ payload = await response.json();
86
+ } catch {
87
+ // not JSON
88
+ }
89
+ const error = payload?.error ?? payload?.detail?.error;
90
+ let message = error?.message ?? `The API answered HTTP ${response.status}.`;
91
+ if (response.status === 401) message = "The API key was not accepted. Set RAQIBO_API_KEY to a key from the dashboard.";
92
+ if (error?.code === "human_check") {
93
+ message = "This address has run many checks; the API wants a person to confirm on raqibo.com. Try again in an hour.";
94
+ }
95
+ const retry = response.headers.get("retry-after");
96
+ throw new ApiError(response.status, error?.code ?? "http_error", message, retry ? Number(retry) : undefined);
97
+ }
98
+ return text ? response.text() : response.json();
99
+ }
100
+
101
+ function gradeAtLeast(grade, minimum) {
102
+ return GRADES.indexOf(grade) <= GRADES.indexOf(minimum);
103
+ }
104
+
105
+ function checkGrade(value) {
106
+ const grade = String(value).toUpperCase();
107
+ if (!GRADES.includes(grade)) throw new UsageError(`--min-grade must be one of ${GRADES.join(", ")}.`);
108
+ return grade;
109
+ }
110
+
111
+ function checkNumber(value, name) {
112
+ const n = Number(value);
113
+ if (!Number.isInteger(n) || n < 0) throw new UsageError(`${name} must be a whole number of 0 or more.`);
114
+ return n;
115
+ }
116
+
117
+ function need(target, what) {
118
+ if (!target) throw new UsageError(`Give ${what}. See raqibo --help.`);
119
+ return target;
120
+ }
121
+
122
+ // ------------------------------------------------------------------------------------ checks
123
+ // Each returns { code, lines, answer }: the exit code, what to print, the API's answer.
124
+
125
+ const CHECKS = {
126
+ async down(env, target) {
127
+ const answer = await call(env, "/v1/tools/down-check", { method: "POST", body: { url: need(target, "a website") } });
128
+ const up = answer.verdict === "up";
129
+ const lines = [
130
+ `${up ? "UP" : "DOWN"} ${answer.url}`,
131
+ ` ${answer.summary}`,
132
+ answer.status !== null ? ` HTTP ${answer.status}${answer.response_ms !== null ? `, ${Math.round(answer.response_ms)} ms` : ""}` : null,
133
+ ];
134
+ return { code: up ? PASS : FAIL, lines, answer };
135
+ },
136
+
137
+ async trace(env, target, options) {
138
+ const answer = await call(env, "/v1/tools/redirect-trace", { method: "POST", body: { url: need(target, "a URL") } });
139
+ const lines = answer.hops.map((hop) => ` ${hop.status} ${hop.url}`);
140
+ const failures = [];
141
+ if (options["max-redirects"] !== undefined) {
142
+ const most = checkNumber(options["max-redirects"], "--max-redirects");
143
+ if (answer.redirect_count > most) failures.push(`${answer.redirect_count} redirects; at most ${most} allowed.`);
144
+ }
145
+ if (options.expect !== undefined && answer.final_url !== options.expect) {
146
+ failures.push(`Ends at ${answer.final_url}, not ${options.expect}.`);
147
+ }
148
+ if (answer.downgrades_to_http) failures.push("The chain drops from https to http on the way.");
149
+ lines.unshift(`${failures.length ? "FAIL" : "OK"} ${answer.redirect_count} redirect${answer.redirect_count === 1 ? "" : "s"}, ends at ${answer.final_url} (HTTP ${answer.final_status})`);
150
+ lines.push(...failures.map((f) => ` ! ${f}`));
151
+ return { code: failures.length ? FAIL : PASS, lines, answer };
152
+ },
153
+
154
+ async headers(env, target, options) {
155
+ const minimum = checkGrade(options["min-grade"] ?? "C");
156
+ const answer = await call(env, "/v1/tools/security-headers", { method: "POST", body: { url: need(target, "a URL") } });
157
+ const ok = gradeAtLeast(answer.grade, minimum);
158
+ const lines = [
159
+ `${ok ? "OK" : "FAIL"} grade ${answer.grade} (at least ${minimum} wanted) ${answer.final_url}`,
160
+ ...answer.findings.filter((f) => f.status === "fail" || f.status === "warn").map((f) => ` - ${f.title}: ${f.fix ?? f.explanation}`),
161
+ ` ${answer.scope_note}`,
162
+ ];
163
+ return { code: ok ? PASS : FAIL, lines, answer };
164
+ },
165
+
166
+ async ssl(env, target, options) {
167
+ const minimum = checkNumber(options["min-days"] ?? 14, "--min-days");
168
+ const answer = await call(env, "/v1/tools/tls-inspect", { method: "POST", body: { host: need(target, "a hostname") } });
169
+ const problems = [];
170
+ if (!answer.trusted) problems.push(`Not trusted: ${answer.trust_error ?? "unknown reason"}`);
171
+ if (!answer.hostname_matches) problems.push("The certificate is not for this name.");
172
+ if (answer.expired) problems.push("Expired.");
173
+ else if (answer.days_until_expiry < minimum) problems.push(`Expires in ${answer.days_until_expiry} days; at least ${minimum} wanted.`);
174
+ const lines = [
175
+ `${problems.length ? "FAIL" : "OK"} ${answer.host}:${answer.port} expires in ${answer.days_until_expiry} days`,
176
+ ...problems.map((p) => ` ! ${p}`),
177
+ ];
178
+ return { code: problems.length ? FAIL : PASS, lines, answer };
179
+ },
180
+
181
+ async domain(env, target, options) {
182
+ const minimum = checkNumber(options["min-days"] ?? 30, "--min-days");
183
+ const answer = await call(env, "/v1/tools/domain-expiry", { method: "POST", body: { domain: need(target, "a domain") } });
184
+ if (answer.verdict === "unsupported" || answer.verdict === "unknown") {
185
+ return { code: ERROR, lines: [`UNKNOWN ${answer.summary}`], answer };
186
+ }
187
+ const days = answer.days_until_expiry;
188
+ const failed =
189
+ ["expired", "at_risk", "not_registered"].includes(answer.verdict) || (days !== null && days < minimum);
190
+ const lines = [
191
+ `${failed ? "FAIL" : "OK"} ${answer.domain ?? target}${days !== null ? ` expires in ${days} days` : ""}`,
192
+ ` ${answer.summary}`,
193
+ ];
194
+ return { code: failed ? FAIL : PASS, lines, answer };
195
+ },
196
+
197
+ async email(env, target, options) {
198
+ const minimum = checkGrade(options["min-grade"] ?? "C");
199
+ const answer = await call(env, "/v1/tools/email-dns", { method: "POST", body: { domain: need(target, "a domain") } });
200
+ if (!answer.grade) return { code: ERROR, lines: [`UNKNOWN ${answer.domain}: no grade (${answer.grade_reason ?? "no answer"})`], answer };
201
+ const ok = gradeAtLeast(answer.grade, minimum);
202
+ const lines = [
203
+ `${ok ? "OK" : "FAIL"} ${answer.domain} grade ${answer.grade} (at least ${minimum} wanted)`,
204
+ answer.grade_reason ? ` ${answer.grade_reason}` : null,
205
+ ];
206
+ return { code: ok ? PASS : FAIL, lines, answer };
207
+ },
208
+
209
+ async links(env, target) {
210
+ const answer = await call(env, "/v1/tools/broken-links", { method: "POST", body: { url: need(target, "a page") } });
211
+ const bad = answer.links.filter((l) => l.state === "broken" || l.state === "unreachable");
212
+ const lines = [
213
+ `${bad.length ? "FAIL" : "OK"} ${bad.length} broken of ${answer.checked} checked (${answer.found} found) ${answer.page_url}`,
214
+ ...bad.map((l) => ` ${l.status ?? "---"} ${l.url}${l.reason ? ` (${l.reason})` : ""}`),
215
+ ];
216
+ if (answer.counts.not_checked) lines.push(` ${answer.counts.not_checked} not checked (limits per check).`);
217
+ return { code: bad.length ? FAIL : PASS, lines, answer };
218
+ },
219
+
220
+ async robots(env, target) {
221
+ const answer = await call(env, "/v1/tools/robots-sitemap", { method: "POST", body: { url: need(target, "a website") } });
222
+ const problems = answer.findings.filter((f) => f.level === "problem");
223
+ const lines = [
224
+ `${problems.length ? "FAIL" : "OK"} ${answer.site} robots.txt ${answer.robots.state}, ${answer.sitemaps.length} sitemap${answer.sitemaps.length === 1 ? "" : "s"} read`,
225
+ ...answer.findings.map((f) => ` ${f.level === "good" ? "+" : f.level === "warning" ? "-" : "!"} ${f.text}`),
226
+ ];
227
+ return { code: problems.length ? FAIL : PASS, lines, answer };
228
+ },
229
+ };
230
+
231
+ // ---------------------------------------------------------------------------------- monitors
232
+
233
+ async function monitors(env, args, options) {
234
+ const key = env.key;
235
+ if (!key) throw new UsageError("Set RAQIBO_API_KEY to an API key from the dashboard (Settings, API keys).");
236
+ const [action, file] = args;
237
+ if (action === "export") {
238
+ const text = await call(env, "/v1/monitors/export", { key, text: true });
239
+ if (options.output) {
240
+ await (env.writeFile ?? writeFile)(options.output, text);
241
+ return { code: PASS, lines: [`Wrote ${options.output}.`] };
242
+ }
243
+ return { code: PASS, lines: [text.replace(/\n$/, "")] };
244
+ }
245
+ if (action === "apply") {
246
+ const text = await (env.readFile ?? readFile)(need(file, "a monitors file"), "utf8");
247
+ const preview = Boolean(options["dry-run"]);
248
+ const answer = await call(env, "/v1/monitors/apply", {
249
+ method: "POST",
250
+ key,
251
+ body: { text, preview, prune: Boolean(options.prune) },
252
+ });
253
+ const rows = answer.rows.filter((row) => row.action !== "unchanged");
254
+ const lines = [
255
+ answer.refused > 0
256
+ ? `REFUSED ${answer.refused} entr${answer.refused === 1 ? "y" : "ies"} cannot be applied, so nothing was.`
257
+ : `${preview ? "WOULD" : "DONE"} ${answer.created} added, ${answer.updated} changed, ${answer.deleted} deleted`,
258
+ ...rows.map((row) => ` ${row.action.padEnd(9)} ${row.name || "-"}${row.problem ? ` (${row.problem})` : ""}`),
259
+ ];
260
+ return { code: answer.refused > 0 ? FAIL : PASS, lines, answer };
261
+ }
262
+ throw new UsageError("Use: raqibo monitors export [-o file] | raqibo monitors apply <file> [--dry-run] [--prune]");
263
+ }
264
+
265
+ // -------------------------------------------------------------------------------------- main
266
+
267
+ /**
268
+ * Run with `argv` (no node/script prefix). `env` carries fetch, the API address, the key and
269
+ * the output streams, so tests can run it without a network. Resolves to the exit code.
270
+ */
271
+ export async function main(argv, env) {
272
+ let parsed;
273
+ try {
274
+ parsed = parseArgs({
275
+ args: argv,
276
+ allowPositionals: true,
277
+ options: {
278
+ json: { type: "boolean" },
279
+ api: { type: "string" },
280
+ help: { type: "boolean", short: "h" },
281
+ version: { type: "boolean", short: "v" },
282
+ "min-grade": { type: "string" },
283
+ "min-days": { type: "string" },
284
+ "max-redirects": { type: "string" },
285
+ expect: { type: "string" },
286
+ output: { type: "string", short: "o" },
287
+ "dry-run": { type: "boolean" },
288
+ prune: { type: "boolean" },
289
+ },
290
+ });
291
+ } catch (error) {
292
+ env.err(`${error.message}\nSee raqibo --help.`);
293
+ return ERROR;
294
+ }
295
+ const { values: options, positionals } = parsed;
296
+ if (options.version) {
297
+ env.out(VERSION);
298
+ return PASS;
299
+ }
300
+ const [command, ...rest] = positionals;
301
+ if (options.help || !command) {
302
+ env.out(HELP);
303
+ return command || options.help ? PASS : ERROR;
304
+ }
305
+ const run = { ...env, api: (options.api ?? env.api ?? DEFAULT_API).replace(/\/+$/, "") };
306
+ try {
307
+ let result;
308
+ if (command === "monitors") result = await monitors(run, rest, options);
309
+ else if (Object.hasOwn(CHECKS, command)) result = await CHECKS[command](run, rest[0], options);
310
+ else throw new UsageError(`Unknown command "${command}". See raqibo --help.`);
311
+ if (options.json && result.answer !== undefined) env.out(JSON.stringify(result.answer, null, 2));
312
+ else env.out(result.lines.filter((line) => line !== null).join("\n"));
313
+ return result.code;
314
+ } catch (error) {
315
+ if (error instanceof UsageError) {
316
+ env.err(error.message);
317
+ return ERROR;
318
+ }
319
+ if (error instanceof ApiError) {
320
+ const wait = error.retryAfter ? ` Try again in ${error.retryAfter} s.` : "";
321
+ env.err(`Could not check: ${error.message}${wait}`);
322
+ return ERROR;
323
+ }
324
+ throw error;
325
+ }
326
+ }