webhand 0.3.0 → 0.4.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/README.ja.md +19 -4
- package/README.md +19 -4
- package/assets/recorder.js +4 -0
- package/assets/snapshot.js +218 -3
- package/dist/agent.js +136 -9
- package/dist/auth.js +62 -0
- package/dist/browser.js +701 -22
- package/dist/cli.js +641 -35
- package/dist/collect.js +70 -0
- package/dist/compare.js +173 -0
- package/dist/daemon.js +125 -0
- package/dist/knowledge.js +206 -0
- package/dist/learn.js +10 -3
- package/dist/metrics.js +19 -2
- package/dist/more.js +58 -0
- package/dist/policies/base.js +105 -9
- package/dist/policies/jev.js +243 -16
- package/dist/remote.js +165 -0
- package/dist/runbook.js +6 -1
- package/dist/session.js +256 -12
- package/dist/types.js +12 -0
- package/package.json +1 -1
package/dist/auth.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Saved logins: the cookies and localStorage of a session, kept so a later new session can start signed in
|
|
3
|
+
* (`start --auth NAME`). Unlike a saved profile, a login is not tied to Chrome: any engine can take it.
|
|
4
|
+
*
|
|
5
|
+
* A login file is the sign-in itself. It lives only in the user's state folder, readable by the owner alone, and
|
|
6
|
+
* its contents are never printed.
|
|
7
|
+
*/
|
|
8
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { quote } from "./format.js";
|
|
11
|
+
import { home, SessionError } from "./session.js";
|
|
12
|
+
const NAME = /^[\p{L}\p{N}_-]{1,40}$/u;
|
|
13
|
+
/** A login name can be a file name. */
|
|
14
|
+
export function checkName(name) {
|
|
15
|
+
if (!NAME.test(name))
|
|
16
|
+
throw new SessionError(`Expected a login name of letters, digits, - or _ (up to 40), got ${quote(name)}`);
|
|
17
|
+
return name;
|
|
18
|
+
}
|
|
19
|
+
function folder() {
|
|
20
|
+
return join(home(), "auth");
|
|
21
|
+
}
|
|
22
|
+
function path(name) {
|
|
23
|
+
return join(folder(), `${checkName(name)}.json`);
|
|
24
|
+
}
|
|
25
|
+
export function exists(name) {
|
|
26
|
+
return existsSync(path(name));
|
|
27
|
+
}
|
|
28
|
+
export function save(name, state) {
|
|
29
|
+
const target = path(name);
|
|
30
|
+
mkdirSync(folder(), { recursive: true, mode: 0o700 });
|
|
31
|
+
const temporary = `${target}.tmp`;
|
|
32
|
+
const login = { saved_at: new Date().toISOString(), state };
|
|
33
|
+
writeFileSync(temporary, JSON.stringify(login), { encoding: "utf8", mode: 0o600 });
|
|
34
|
+
renameSync(temporary, target);
|
|
35
|
+
}
|
|
36
|
+
export function load(name) {
|
|
37
|
+
return JSON.parse(readFileSync(path(name), "utf8"));
|
|
38
|
+
}
|
|
39
|
+
export function names() {
|
|
40
|
+
if (!existsSync(folder()))
|
|
41
|
+
return [];
|
|
42
|
+
return readdirSync(folder())
|
|
43
|
+
.filter((file) => file.endsWith(".json"))
|
|
44
|
+
.map((file) => file.slice(0, -".json".length))
|
|
45
|
+
.sort();
|
|
46
|
+
}
|
|
47
|
+
export function remove(name) {
|
|
48
|
+
if (!exists(name))
|
|
49
|
+
return false;
|
|
50
|
+
rmSync(path(name), { force: true });
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
/** What a login holds, without its values: how many cookies, and which sites. */
|
|
54
|
+
export function summary(login) {
|
|
55
|
+
const hosts = new Set();
|
|
56
|
+
for (const cookie of login.state.cookies)
|
|
57
|
+
hosts.add(cookie.domain.replace(/^\./, ""));
|
|
58
|
+
for (const origin of login.state.origins)
|
|
59
|
+
hosts.add(new URL(origin.origin).host);
|
|
60
|
+
const stored = login.state.origins.reduce((sum, origin) => sum + origin.localStorage.length, 0);
|
|
61
|
+
return `${login.state.cookies.length} cookies, ${stored} localStorage items; ${[...hosts].sort().join(", ") || "no sites"}`;
|
|
62
|
+
}
|