@yaks/browser 0.0.0-stage → 0.2.36
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 +202 -0
- package/README.md +50 -2
- package/_dist/cloudflare.d.ts +12 -0
- package/_dist/cloudflare.d.ts.map +1 -0
- package/_dist/driver.d.ts +23 -0
- package/_dist/driver.d.ts.map +1 -0
- package/_dist/machine-relay.d.ts +17 -0
- package/_dist/machine-relay.d.ts.map +1 -0
- package/_dist/machine-wire.d.ts +19 -0
- package/_dist/machine-wire.d.ts.map +1 -0
- package/_dist/machine.d.ts +7 -0
- package/_dist/machine.d.ts.map +1 -0
- package/_dist/mod.d.ts +125 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/script.d.ts +9 -0
- package/_dist/script.d.ts.map +1 -0
- package/_dist/session.d.ts +22 -0
- package/_dist/session.d.ts.map +1 -0
- package/_dist/site.d.ts +54 -0
- package/_dist/site.d.ts.map +1 -0
- package/_dist/time.d.ts +6 -0
- package/_dist/time.d.ts.map +1 -0
- package/cloudflare.js +39 -0
- package/cloudflare.js.map +1 -0
- package/cloudflare.ts +55 -0
- package/deno.json +1 -0
- package/driver.js +545 -0
- package/driver.js.map +1 -0
- package/driver.ts +706 -0
- package/machine-connector.ts +181 -0
- package/machine-pool.ts +86 -0
- package/machine-relay.js +116 -0
- package/machine-relay.js.map +1 -0
- package/machine-relay.ts +119 -0
- package/machine-service/nftables.conf +23 -0
- package/machine-service/yak-browser@.service +23 -0
- package/machine-wire.js +35 -0
- package/machine-wire.js.map +1 -0
- package/machine-wire.ts +35 -0
- package/machine.js +78 -0
- package/machine.js.map +1 -0
- package/machine.ts +88 -0
- package/mod.js +225 -0
- package/mod.js.map +1 -0
- package/mod.ts +375 -0
- package/package.json +53 -4
- package/script.js +43 -0
- package/script.js.map +1 -0
- package/script.ts +57 -0
- package/session.js +105 -0
- package/session.js.map +1 -0
- package/session.ts +183 -0
- package/sign-in.js +206 -0
- package/sign-in.js.map +1 -0
- package/sign-in.ts +291 -0
- package/site.js +45 -0
- package/site.js.map +1 -0
- package/site.ts +120 -0
- package/time.js +26 -0
- package/time.js.map +1 -0
- package/time.ts +35 -0
package/site.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** An enrolled site. Only its top-level pages are interactive. The driver
|
|
2
|
+
* does not expose credentialed pages as observations or accept agent actions
|
|
3
|
+
* on them. */ export let allowedHosts = (site)=>[
|
|
4
|
+
new URL(site.origin).hostname,
|
|
5
|
+
...new Set((site.dependencies ?? []).map((origin)=>new URL(origin).hostname))
|
|
6
|
+
];
|
|
7
|
+
/** The exact HTTPS origin and path matter even with a hostname guardrail. */ export let destination = (site, url)=>{
|
|
8
|
+
try {
|
|
9
|
+
let to = new URL(url);
|
|
10
|
+
if (to.protocol == 'https:' && to.origin == site.origin && !to.username && !to.password && !to.search && !to.hash) return to.pathname;
|
|
11
|
+
} catch {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
export let requestAllowed = (site, url, method, top, navigation, submitting = false)=>{
|
|
16
|
+
let path = destination(site, url);
|
|
17
|
+
if (top) {
|
|
18
|
+
if (method == 'POST') {
|
|
19
|
+
return path != null && (!site.login.endpoint && path == site.login.submit || path == site.challenge?.submit);
|
|
20
|
+
}
|
|
21
|
+
return method == 'GET' && path != null && (site.pages.includes(path) || path == site.login.path || path == site.challenge?.path || path == site.signedIn.path);
|
|
22
|
+
}
|
|
23
|
+
if (navigation) return false;
|
|
24
|
+
if (submitting) {
|
|
25
|
+
let { endpoint, follow } = site.login;
|
|
26
|
+
if (url == endpoint && (method == 'POST' || method == 'OPTIONS')) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
if (url == follow?.url && (method == follow.method || method == 'OPTIONS')) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (method != 'GET' && method != 'HEAD') return false;
|
|
34
|
+
try {
|
|
35
|
+
let target = new URL(url);
|
|
36
|
+
return target.protocol == 'https:' && !target.username && !target.password && (target.origin == site.origin || (site.dependencies ?? []).includes(target.origin));
|
|
37
|
+
} catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
export let readable = (site, url)=>{
|
|
42
|
+
let path = destination(site, url);
|
|
43
|
+
return path != null && (site.pages.includes(path) || path == site.signedIn.path) && path != site.login.path && path != site.challenge?.path;
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=site.js.map
|
package/site.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site.js","sources":["./site.ts"],"names":[],"mappings":"AAAA;;YAEY,GAiDZ,OAAO,IAAI,eAAe,CAAC,OAAyB;IAClD,IAAI,IAAI,KAAK,MAAM,EAAE,QAAQ;OAC1B,IAAI,IACL,CAAC,KAAK,YAAY,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC,SAAW,IAAI,IAAI,QAAQ,QAAQ;GAErE,CAAA;AAED,2EAA2E,GAC3E,OAAO,IAAI,cAAc,CAAC,MAAY;EACpC,IAAI;IACF,IAAI,KAAK,IAAI,IAAI;IACjB,IACE,GAAG,QAAQ,IAAI,YAAY,GAAG,MAAM,IAAI,KAAK,MAAM,IACnD,CAAC,GAAG,QAAQ,IAAI,CAAC,GAAG,QAAQ,IAAI,CAAC,GAAG,MAAM,IAAI,CAAC,GAAG,IAAI,EACtD,OAAO,GAAG,QAAQ;EACtB,EAAE,OAAM;IACN;EACF;AACF,EAAC;AAED,OAAO,IAAI,iBAAiB,CAC1B,MACA,KACA,QACA,KACA,YACA,aAAa,KAAK;EAElB,IAAI,OAAO,YAAY,MAAM;EAC7B,IAAI,KAAK;IACP,IAAI,UAAU,QAAQ;MACpB,OAAO,QAAQ,QACb,CAAC,AAAC,CAAC,KAAK,KAAK,CAAC,QAAQ,IAAI,QAAQ,KAAK,KAAK,CAAC,MAAM,IACjD,QAAQ,KAAK,SAAS,EAAE,MAAM;IACpC;IACA,OAAO,UAAU,SAAS,QAAQ,QAChC,CAAC,KAAK,KAAK,CAAC,QAAQ,CAAC,SAAS,QAAQ,KAAK,KAAK,CAAC,IAAI,IACnD,QAAQ,KAAK,SAAS,EAAE,QAAQ,QAAQ,KAAK,QAAQ,CAAC,IAAI;EAChE;EACA,IAAI,YAAY,OAAO;EACvB,IAAI,YAAY;IACd,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,KAAK,KAAK;IACrC,IAAI,OAAO,YAAY,CAAC,UAAU,UAAU,UAAU,SAAS,GAAG;MAChE,OAAO;IACT;IACA,IACE,OAAO,QAAQ,OAAO,CAAC,UAAU,OAAO,MAAM,IAAI,UAAU,SAAS,GACrE;MACA,OAAO;IACT;EACF;EACA,IAAI,UAAU,SAAS,UAAU,QAAQ,OAAO;EAChD,IAAI;IACF,IAAI,SAAS,IAAI,IAAI;IACrB,OAAO,OAAO,QAAQ,IAAI,YAAY,CAAC,OAAO,QAAQ,IACpD,CAAC,OAAO,QAAQ,IAChB,CAAC,OAAO,MAAM,IAAI,KAAK,MAAM,IAC3B,CAAC,KAAK,YAAY,IAAI,EAAE,EAAE,QAAQ,CAAC,OAAO,MAAM,CAAC;EACvD,EAAE,OAAM;IACN,OAAO;EACT;AACF,EAAC;AAED,OAAO,IAAI,WAAW,CAAC,MAAY;EACjC,IAAI,OAAO,YAAY,MAAM;EAC7B,OAAO,QAAQ,QACb,CAAC,KAAK,KAAK,CAAC,QAAQ,CAAC,SAAS,QAAQ,KAAK,QAAQ,CAAC,IAAI,KACxD,QAAQ,KAAK,KAAK,CAAC,IAAI,IAAI,QAAQ,KAAK,SAAS,EAAE;AACvD,EAAC"}
|
package/site.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/** An enrolled site. Only its top-level pages are interactive. The driver
|
|
2
|
+
* does not expose credentialed pages as observations or accept agent actions
|
|
3
|
+
* on them. */
|
|
4
|
+
export type Site = {
|
|
5
|
+
origin: string
|
|
6
|
+
dependencies?: readonly string[]
|
|
7
|
+
pages: readonly string[]
|
|
8
|
+
login: {
|
|
9
|
+
path: string
|
|
10
|
+
form: string
|
|
11
|
+
submit: string
|
|
12
|
+
username: string
|
|
13
|
+
password: string
|
|
14
|
+
button: string
|
|
15
|
+
/** Exact HTTPS endpoint a scripted form posts to. Native forms stay on
|
|
16
|
+
* the page's origin and POST to submit. */
|
|
17
|
+
endpoint?: string
|
|
18
|
+
/** An enrolled follow-up request made only during a scripted sign-in. */
|
|
19
|
+
follow?: { method: 'POST' | 'PATCH'; url: string }
|
|
20
|
+
}
|
|
21
|
+
challenge?: {
|
|
22
|
+
path: string
|
|
23
|
+
submit: string
|
|
24
|
+
/** A visible prompt when verification shares another step’s address. */
|
|
25
|
+
marker?: string
|
|
26
|
+
}
|
|
27
|
+
signedIn: {
|
|
28
|
+
path: string
|
|
29
|
+
marker: string
|
|
30
|
+
cookies: readonly string[]
|
|
31
|
+
storage?: readonly string[]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type Credential = { username: string; password: string }
|
|
36
|
+
|
|
37
|
+
export type Cookie = {
|
|
38
|
+
name: string
|
|
39
|
+
value: string
|
|
40
|
+
path: string
|
|
41
|
+
expires: number
|
|
42
|
+
secure: true
|
|
43
|
+
httpOnly: true
|
|
44
|
+
sameSite?: 'Strict' | 'Lax' | 'None'
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type SignInState = {
|
|
48
|
+
cookies: Cookie[]
|
|
49
|
+
storage?: Record<string, string>
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export let allowedHosts = (site: Site): string[] => [
|
|
53
|
+
new URL(site.origin).hostname,
|
|
54
|
+
...new Set(
|
|
55
|
+
(site.dependencies ?? []).map((origin) => new URL(origin).hostname),
|
|
56
|
+
),
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
/** The exact HTTPS origin and path matter even with a hostname guardrail. */
|
|
60
|
+
export let destination = (site: Site, url: string): string | undefined => {
|
|
61
|
+
try {
|
|
62
|
+
let to = new URL(url)
|
|
63
|
+
if (
|
|
64
|
+
to.protocol == 'https:' && to.origin == site.origin &&
|
|
65
|
+
!to.username && !to.password && !to.search && !to.hash
|
|
66
|
+
) return to.pathname
|
|
67
|
+
} catch {
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export let requestAllowed = (
|
|
73
|
+
site: Site,
|
|
74
|
+
url: string,
|
|
75
|
+
method: string,
|
|
76
|
+
top: boolean,
|
|
77
|
+
navigation: boolean,
|
|
78
|
+
submitting = false,
|
|
79
|
+
): boolean => {
|
|
80
|
+
let path = destination(site, url)
|
|
81
|
+
if (top) {
|
|
82
|
+
if (method == 'POST') {
|
|
83
|
+
return path != null &&
|
|
84
|
+
((!site.login.endpoint && path == site.login.submit) ||
|
|
85
|
+
path == site.challenge?.submit)
|
|
86
|
+
}
|
|
87
|
+
return method == 'GET' && path != null &&
|
|
88
|
+
(site.pages.includes(path) || path == site.login.path ||
|
|
89
|
+
path == site.challenge?.path || path == site.signedIn.path)
|
|
90
|
+
}
|
|
91
|
+
if (navigation) return false
|
|
92
|
+
if (submitting) {
|
|
93
|
+
let { endpoint, follow } = site.login
|
|
94
|
+
if (url == endpoint && (method == 'POST' || method == 'OPTIONS')) {
|
|
95
|
+
return true
|
|
96
|
+
}
|
|
97
|
+
if (
|
|
98
|
+
url == follow?.url && (method == follow.method || method == 'OPTIONS')
|
|
99
|
+
) {
|
|
100
|
+
return true
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (method != 'GET' && method != 'HEAD') return false
|
|
104
|
+
try {
|
|
105
|
+
let target = new URL(url)
|
|
106
|
+
return target.protocol == 'https:' && !target.username &&
|
|
107
|
+
!target.password &&
|
|
108
|
+
(target.origin == site.origin ||
|
|
109
|
+
(site.dependencies ?? []).includes(target.origin))
|
|
110
|
+
} catch {
|
|
111
|
+
return false
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export let readable = (site: Site, url: string): boolean => {
|
|
116
|
+
let path = destination(site, url)
|
|
117
|
+
return path != null &&
|
|
118
|
+
(site.pages.includes(path) || path == site.signedIn.path) &&
|
|
119
|
+
path != site.login.path && path != site.challenge?.path
|
|
120
|
+
}
|
package/time.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export class BrowserTimeout extends Error {
|
|
2
|
+
constructor(stage, ms){
|
|
3
|
+
super(ms > 0 ? `${stage} timed out after ${ms / 1000} seconds` : `${stage} could not start before the browser visit deadline`);
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
/** Give the current operation the deadline and stop starting work when it expires. */ export let bounded = async (time, ms, stage, run)=>{
|
|
7
|
+
if (ms <= 0) throw new BrowserTimeout(stage(), 0);
|
|
8
|
+
let stop = new AbortController();
|
|
9
|
+
let cancel = ()=>{};
|
|
10
|
+
let timeout = new Promise((_, reject)=>{
|
|
11
|
+
cancel = time.after(ms, ()=>{
|
|
12
|
+
let error = new BrowserTimeout(stage(), ms);
|
|
13
|
+
reject(error);
|
|
14
|
+
stop.abort(error);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
try {
|
|
18
|
+
return await Promise.race([
|
|
19
|
+
timeout,
|
|
20
|
+
run(stop.signal)
|
|
21
|
+
]);
|
|
22
|
+
} finally{
|
|
23
|
+
cancel();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=time.js.map
|
package/time.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.js","sources":["./time.ts"],"names":[],"mappings":"AAEA,OAAO,MAAM,uBAAuB;EAClC,YAAY,KAAa,EAAE,EAAU,CAAE;IACrC,KAAK,CACH,KAAK,IACD,GAAG,MAAM,iBAAiB,EAAE,KAAK,KAAK,QAAQ,CAAC,GAC/C,GAAG,MAAM,kDAAkD,CAAC;EAEpE;AACF;AAEA,oFAAoF,GACpF,OAAO,IAAI,UAAU,OACnB,MACA,IACA,OACA;EAEA,IAAI,MAAM,GAAG,MAAM,IAAI,eAAe,SAAS;EAC/C,IAAI,OAAO,IAAI;EACf,IAAI,SAAS,KAAO;EACpB,IAAI,UAAU,IAAI,QAAe,CAAC,GAAG;IACnC,SAAS,KAAK,KAAK,CAAC,IAAI;MACtB,IAAI,QAAQ,IAAI,eAAe,SAAS;MACxC,OAAO;MACP,KAAK,KAAK,CAAC;IACb;EACF;EACA,IAAI;IACF,OAAO,MAAM,QAAQ,IAAI,CAAC;MAAC;MAAS,IAAI,KAAK,MAAM;KAAE;EACvD,SAAU;IACR;EACF;AACF,EAAC"}
|
package/time.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Clock } from 'jsr:@yaks/fp@0.2.36'
|
|
2
|
+
|
|
3
|
+
export class BrowserTimeout extends Error {
|
|
4
|
+
constructor(stage: string, ms: number) {
|
|
5
|
+
super(
|
|
6
|
+
ms > 0
|
|
7
|
+
? `${stage} timed out after ${ms / 1000} seconds`
|
|
8
|
+
: `${stage} could not start before the browser visit deadline`,
|
|
9
|
+
)
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Give the current operation the deadline and stop starting work when it expires. */
|
|
14
|
+
export let bounded = async <T>(
|
|
15
|
+
time: Clock,
|
|
16
|
+
ms: number,
|
|
17
|
+
stage: () => string,
|
|
18
|
+
run: (signal: AbortSignal) => Promise<T>,
|
|
19
|
+
): Promise<T> => {
|
|
20
|
+
if (ms <= 0) throw new BrowserTimeout(stage(), 0)
|
|
21
|
+
let stop = new AbortController()
|
|
22
|
+
let cancel = () => {}
|
|
23
|
+
let timeout = new Promise<never>((_, reject) => {
|
|
24
|
+
cancel = time.after(ms, () => {
|
|
25
|
+
let error = new BrowserTimeout(stage(), ms)
|
|
26
|
+
reject(error)
|
|
27
|
+
stop.abort(error)
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
try {
|
|
31
|
+
return await Promise.race([timeout, run(stop.signal)])
|
|
32
|
+
} finally {
|
|
33
|
+
cancel()
|
|
34
|
+
}
|
|
35
|
+
}
|