clearcote 0.38.1 → 0.40.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.
@@ -0,0 +1,153 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import type { Browser } from "playwright-core";
3
+ export declare const DEFAULT_REPOSITORY = "teamflatearth/clearcote";
4
+ export declare const TEST_ONLY_ASSUME_MACOS = "CLEARCOTE_TEST_ONLY_ASSUME_MACOS";
5
+ export declare const SERVE_PROTOCOL = 2;
6
+ /** launch() needs Docker on this host (macOS has no native Clearcote build) and it is missing or not running. */
7
+ export declare class DockerUnavailableError extends Error {
8
+ constructor(message: string);
9
+ }
10
+ /** The Docker options of launch(). */
11
+ export interface DockerOption {
12
+ /** Run Clearcote in its Docker image. Unset: on macOS only (there is no native macOS build), unless
13
+ * executablePath / CLEARCOTE_BINARY names a binary. false (or CLEARCOTE_DOCKER=0) turns it off;
14
+ * true uses the image on any OS. */
15
+ docker?: boolean;
16
+ /** The image to run. Default CLEARCOTE_DOCKER_IMAGE, else teamflatearth/clearcote:sdk-<SDK version>. */
17
+ dockerImage?: string;
18
+ }
19
+ export declare const DOCKER_ACCEPTED: readonly string[];
20
+ export declare function hostIsMacos(): boolean;
21
+ /** Whether this launch runs in the Clearcote Docker image (see the header). */
22
+ export declare function dockerRequested(docker: unknown, options?: Record<string, unknown>): boolean;
23
+ export declare function defaultImage(): string;
24
+ /** The CC_* (and licence) variables the image is started with. Throws naming the first option the
25
+ * image cannot take. */
26
+ export declare function containerEnv(options: Record<string, unknown>): Record<string, string>;
27
+ export interface CliResult {
28
+ code: number;
29
+ stdout: string;
30
+ stderr: string;
31
+ }
32
+ /** A starting container's log, kept in memory (it is created with --rm: once stopped, its log is gone). The
33
+ * lines saying what the entrypoint applied (serve-state, engine, proxy) are kept apart in `marks`, whatever
34
+ * Chrome logs after them. */
35
+ export interface LogTail {
36
+ text(waitMs?: number): Promise<string>;
37
+ waitMarks(pattern: RegExp, waitMs?: number): Promise<string[]>;
38
+ stop(): void;
39
+ }
40
+ declare function followLogs(exe: string, id: string): LogTail;
41
+ /** The docker CLI. Seams: tests replace `which`, `run` and `followLogs`. */
42
+ export declare const dockerCli: {
43
+ which: () => string | null;
44
+ run: (argv: string[], env?: Record<string, string>, timeoutMs?: number, input?: Buffer) => Promise<CliResult>;
45
+ followLogs: typeof followLogs;
46
+ };
47
+ /** The docker executable, or DockerUnavailableError saying what to do. */
48
+ export declare function checkDocker(): Promise<string>;
49
+ /** How long a launched container waits with no CDP client before it stops itself: CLEARCOTE_DOCKER_IDLE_EXIT
50
+ * (seconds, 0 = never), default 30. */
51
+ export declare function idleExitSeconds(): number;
52
+ /** The named volume a licensed container keeps its engine in (shared, so it downloads once):
53
+ * CLEARCOTE_DOCKER_CACHE_VOLUME, default clearcote-cache. */
54
+ export declare function cacheVolume(): string;
55
+ export declare function pidAlive(pid: number): boolean;
56
+ /** What this host says about processes: /proc where there is one, `ps` elsewhere. Seams: tests replace members. */
57
+ export declare const hostProbe: {
58
+ platform: () => string;
59
+ readText: (path: string) => string | null;
60
+ bootId: () => string | null;
61
+ pidNamespace: () => string | null;
62
+ spawnSync: typeof spawnSync;
63
+ };
64
+ /** `ps -o lstart=` prints local time, in the locale's words. Pinned, so an owner and a sweeper that run with
65
+ * different TZ / LANG settings (or one script that changes TZ between launches) read the same string for the
66
+ * same process. Without it a sweeper in another time zone took a live owner for a reused pid. */
67
+ export declare const PS_ENV: {
68
+ readonly TZ: "UTC0";
69
+ readonly LC_ALL: "C";
70
+ };
71
+ /** A marker that differs once `pid` belongs to another process (it was reused), or null when it cannot be
72
+ * read here. Linux: the start time from /proc; macOS: `ps -o lstart=` in UTC and the C locale; Windows: not
73
+ * readable from Node (null: the pid alone is then trusted, which only ever keeps a container). The same
74
+ * strings in all three SDKs. */
75
+ export declare function processStart(pid: number): string | null;
76
+ /** This process's owner token, recording it (once) under ~/.clearcote/docker-owners/. */
77
+ export declare function ownerToken(): string;
78
+ /** Forget this process's token (tests: a new HOME gets a new record). */
79
+ export declare function resetOwnerToken(): void;
80
+ type OwnerRecord = {
81
+ pid?: unknown;
82
+ start?: string | null;
83
+ pidns?: string | null;
84
+ boot?: string | null;
85
+ host?: unknown;
86
+ };
87
+ /** The fields an owner record from this process would carry besides its pid and start marker. */
88
+ export declare const ownerHere: () => {
89
+ host: string;
90
+ boot: string | null;
91
+ pidns: string | null;
92
+ };
93
+ /** true or false for the owner a record describes, or null when that cannot be told for certain here: a record
94
+ * whose host, boot id or PID namespace is not exactly what this process would record (missing ones included),
95
+ * or whose pid is not a positive integer. A pid that is alive with a start marker of the same kind but another
96
+ * value was reused (false); one whose marker cannot be compared counts as alive. */
97
+ export declare function ownerAlive(rec: OwnerRecord): boolean | null;
98
+ /**
99
+ * Stop and remove containers an earlier launch left behind whose owner process is certainly gone (killed,
100
+ * crashed): their token's record is in this home, from this boot and PID namespace, and its process no longer
101
+ * exists. They would stop on their own after the idle period; this frees their licence seat now. Anything else
102
+ * -- live owners, owners in another namespace or on another machine, containers without a token -- is left
103
+ * alone. Resolves to the ids removed.
104
+ */
105
+ export declare function sweepStale(exe: string): Promise<string[]>;
106
+ /** The serve protocol `image` speaks (its PROTOCOL_LABEL; 0 for an image without it), pulling the image first
107
+ * when it is not here. Known before a container exists, so the settings a container gets are always ones its
108
+ * entrypoint understands. */
109
+ export declare function imageProtocol(exe: string, image: string, quiet?: boolean): Promise<number>;
110
+ /** Why an image older than FIRST_PROTOCOL_TAG cannot take this proxy, or null. Its entrypoint drops the password
111
+ * of an http(s) proxy (Chrome is then challenged and nothing answers: every request fails), and hands a SOCKS5
112
+ * password to an engine switch only the licensed engine has -- as written in the URL, without decoding it, so a
113
+ * username or password with characters that have to be escaped there arrives wrong. */
114
+ export declare function legacyProxyRefusal(image: string, proxyUrlValue: string | null | undefined, licensed: boolean): string | null;
115
+ /** What the container did not apply that was asked for (empty when all is well), from the lines its
116
+ * entrypoint logged: serve-state (protocol 2) or, for an older image, its engine and proxy lines. */
117
+ export declare function verifyApplied(marks: string[], protocol: number, expect: {
118
+ licensed: boolean;
119
+ proxy?: string | null;
120
+ }): string[];
121
+ /** A ustar archive of one file, as `docker cp -` reads it. */
122
+ export declare function tarOneFile(name: string, data: Buffer, opts: {
123
+ uid: number;
124
+ gid: number;
125
+ mode: number;
126
+ }): Buffer;
127
+ export interface DockerContainer {
128
+ id: string;
129
+ image: string;
130
+ endpoint: string;
131
+ serveProtocol: number;
132
+ }
133
+ /**
134
+ * Start the image and wait for its CDP endpoint. Nothing is left running when this rejects.
135
+ *
136
+ * What the image does with its settings is known first (imageProtocol). An image of this SDK's protocol gets
137
+ * --rm, an idle exit (it stops once no CDP client has been connected for idleExitSeconds(), counted from when
138
+ * its CDP answers) and the licence key and proxy URL as a file copied in, not as -e variables `docker inspect`
139
+ * would show. An older image gets plain variables -- they still work -- and a warning that they are visible
140
+ * and that it will not stop on its own -- and is refused, before it starts, a proxy password it cannot answer
141
+ * (legacyProxyRefusal). Either way, once the browser answers, the container's own log must show the licensed
142
+ * engine when a key was given and the proxy when one was given, logged in to when it needs a password
143
+ * (verifyApplied); otherwise it is stopped and removed and launch() rejects: a browser on the open engine, one
144
+ * sending traffic direct, or one whose every request the proxy turns away is never handed back in their place. The container carries this process's owner token for sweepStale().
145
+ */
146
+ export declare function startContainer(options: Record<string, unknown>): Promise<DockerContainer & {
147
+ exe: string;
148
+ }>;
149
+ /** `launch()` on macOS (see the header): the Playwright Browser of a Clearcote container, which also
150
+ * carries `dockerContainer` ({ id, image, endpoint }). close() disconnects and stops the container. */
151
+ export declare function launchDocker(options: Record<string, unknown>): Promise<Browser>;
152
+ export {};
153
+ //# sourceMappingURL=docker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docker.d.ts","sourceRoot":"","sources":["../src/docker.ts"],"names":[],"mappings":"AAiCA,OAAO,EAAmB,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAOhE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB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