screw-bugs 0.1.6 → 0.1.8
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.md +86 -16
- package/dist/browser-playwright/launch.d.ts +4 -2
- package/dist/browser-playwright/launch.js +8 -1
- package/dist/browser-playwright/page.d.ts +2 -2
- package/dist/browser-playwright/page.js +15 -2
- package/dist/browser-playwright/still.d.ts +12 -0
- package/dist/browser-playwright/still.js +51 -0
- package/dist/build-info.json +3 -3
- package/dist/cli/app.d.ts +1 -1
- package/dist/cli/commands.js +57 -12
- package/dist/cli/mcp.d.ts +11 -4
- package/dist/cli/mcp.js +86 -23
- package/dist/cli/operations.d.ts +30 -2
- package/dist/cli/operations.js +126 -20
- package/dist/cli/report-links.js +2 -2
- package/dist/cli/report-server.d.ts +41 -9
- package/dist/cli/report-server.js +139 -23
- package/dist/cli/share.d.ts +71 -4
- package/dist/cli/share.js +549 -118
- package/dist/cli/sign-in.d.ts +22 -10
- package/dist/cli/sign-in.js +23 -23
- package/dist/core/engine.js +67 -17
- package/dist/core/liveness.js +3 -1
- package/dist/core/services.d.ts +30 -5
- package/dist/core/share.d.ts +31 -0
- package/dist/core/share.js +139 -0
- package/dist/core/steps.d.ts +5 -0
- package/dist/core/steps.js +15 -1
- package/dist/core/video.d.ts +31 -0
- package/dist/core/video.js +132 -0
- package/dist/report/html.d.ts +4 -2
- package/dist/report/html.js +45 -13
- package/dist/report/icons.d.ts +3 -0
- package/dist/report/icons.js +5 -1
- package/dist/report/index.d.ts +3 -1
- package/dist/report/index.js +3 -1
- package/dist/report/live.d.ts +7 -0
- package/dist/report/live.js +135 -0
- package/dist/report/menu-bar.d.ts +3 -3
- package/dist/report/menu-bar.js +4 -4
- package/dist/report/player.d.ts +3 -3
- package/dist/report/player.js +3 -3
- package/dist/report/share-page.d.ts +48 -0
- package/dist/report/share-page.js +291 -0
- package/dist/report/styles.d.ts +2 -0
- package/dist/report/styles.js +2 -2
- package/dist/report/view.d.ts +16 -5
- package/dist/report/view.js +60 -24
- package/dist/report/walkthrough.d.ts +7 -3
- package/dist/report/walkthrough.js +21 -8
- package/dist/schema/accounts.js +10 -1
- package/dist/schema/evidence.d.ts +30 -8
- package/dist/schema/evidence.js +17 -4
- package/dist/schema/findings.js +1 -1
- package/dist/schema/job.d.ts +205 -65
- package/dist/schema/job.js +63 -11
- package/dist/schema/ledger.d.ts +88 -16
- package/dist/schema/ledger.js +36 -0
- package/dist/schema/share.d.ts +17 -0
- package/dist/schema/share.js +22 -0
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { NodeHttpClient, NodeHttpServer } from '@effect/platform-node';
|
|
2
2
|
// Boundary: NodeHttpServer serves a Node `http.Server`, made here (see `holdingServer`).
|
|
3
3
|
import { createServer } from 'node:http';
|
|
4
|
-
import { Config, Context, Duration, Effect, Exit, FileSystem, Layer, Option, Path, Schema, Scope, Semaphore, } from 'effect';
|
|
5
|
-
import { HttpClient, HttpIncomingMessage, HttpClientResponse, HttpServerRequest, HttpServerRespondable, HttpServerResponse, HttpStaticServer, } from 'effect/http';
|
|
4
|
+
import { ByteSize, Config, Context, Duration, Effect, Exit, FileSystem, Layer, Option, Path, Schema, Scope, Semaphore, } from 'effect';
|
|
5
|
+
import { HttpClient, HttpIncomingMessage, HttpClientResponse, HttpServerRequest, HttpServerRespondable, HttpServerResponse, HttpServer, HttpStaticServer, } from 'effect/http';
|
|
6
6
|
import { SecureRandom } from 'effect/crypto';
|
|
7
7
|
import { hex, hmacSha256, sha256 } from '../report/index.js';
|
|
8
8
|
import { runsDir } from '../store-local/index.js';
|
|
@@ -11,7 +11,8 @@ import { makeShareRoutes, ShareSource } from './share.js';
|
|
|
11
11
|
import { Failure } from './failure.js';
|
|
12
12
|
/**
|
|
13
13
|
* A local HTTP server for reports, for browsers that cannot open `file://` (the ones built into
|
|
14
|
-
* coding tools). It binds 127.0.0.1
|
|
14
|
+
* coding tools). It binds one address, 127.0.0.1 unless `SCREW_BUGS_REPORT_HOST` says another
|
|
15
|
+
* (see `reportHost`), and serves the runs folder read-only: only files with
|
|
15
16
|
* the extensions a report uses, never a directory listing, a dotfile, or anything outside the
|
|
16
17
|
* folder (also through symlinks). Range requests (206, 416) come from `HttpStaticServer`, so
|
|
17
18
|
* videos seek and play. In a process that can share (see `ShareSource`), it also answers the
|
|
@@ -19,6 +20,86 @@ import { Failure } from './failure.js';
|
|
|
19
20
|
* confirms it there.
|
|
20
21
|
*/
|
|
21
22
|
export const REPORT_HOST = '127.0.0.1';
|
|
23
|
+
const LOOPBACK = new Set(['127.0.0.1', 'localhost', '::1']);
|
|
24
|
+
/** Whether `host` (as `reportHost` gives it) is this machine's loopback. */
|
|
25
|
+
export const isLoopback = (host) => LOOPBACK.has(host);
|
|
26
|
+
/** A host without the brackets of an IPv6 address in a URL. */
|
|
27
|
+
const unbracketed = (host) => host.replace(/^\[(.*)\]$/, '$1');
|
|
28
|
+
/** A host as it goes in a URL: an IPv6 address in brackets. */
|
|
29
|
+
export const urlHost = (host) => (host.includes(':') ? `[${host}]` : host);
|
|
30
|
+
/**
|
|
31
|
+
* `SCREW_BUGS_REPORT_HOST`: where the report server listens, and the host in its links. 127.0.0.1
|
|
32
|
+
* unless set; set it to this machine's MagicDNS name or tailnet IP to open reports from another
|
|
33
|
+
* device (a name binds the one address it resolves to). Never every interface: `0.0.0.0` or `::`
|
|
34
|
+
* is a `Failure` (an empty value is unset).
|
|
35
|
+
*/
|
|
36
|
+
export const reportHost = Effect.suspend(() => hostSetting('SCREW_BUGS_REPORT_HOST', 'report_host'));
|
|
37
|
+
/**
|
|
38
|
+
* A server's host setting (`SCREW_BUGS_REPORT_HOST`, `SCREW_BUGS_SIGN_IN_HOST`): one address or
|
|
39
|
+
* name of this machine, canonical (`canonicalHost`); 127.0.0.1 when unset or empty. Every
|
|
40
|
+
* spelling of every interface (`0.0.0.0`, `0`, `::`, …) is a `Failure` with `reason`.
|
|
41
|
+
*/
|
|
42
|
+
export const hostSetting = (variable, reason) => Config.String(variable).pipe(Config.withDefault(REPORT_HOST), Effect.orDie, Effect.flatMap((value) => {
|
|
43
|
+
const trimmed = value.trim();
|
|
44
|
+
const host = trimmed === '' ? REPORT_HOST : canonicalHost(unbracketed(trimmed));
|
|
45
|
+
return host === undefined || isUnspecified(host)
|
|
46
|
+
? Effect.fail(new Failure({
|
|
47
|
+
code: ExitCode.Usage,
|
|
48
|
+
reason,
|
|
49
|
+
message: `${variable} is "${value}"; give one address or name of this machine, ` +
|
|
50
|
+
'such as its MagicDNS name or tailnet IP, or leave it unset for 127.0.0.1.',
|
|
51
|
+
}))
|
|
52
|
+
: Effect.succeed(host);
|
|
53
|
+
}));
|
|
54
|
+
/**
|
|
55
|
+
* The address a server set to `host` (from `variable`) listens on, as a URL writes it without
|
|
56
|
+
* brackets; a `Failure` with `reason` when that is every interface (a name that resolved to an
|
|
57
|
+
* unspecified address), or loopback for a name other than localhost (many Linux systems map the
|
|
58
|
+
* machine's own name to 127.0.1.1): its links would not open on another device.
|
|
59
|
+
*/
|
|
60
|
+
export const boundAddress = (address, host, variable, reason) => {
|
|
61
|
+
// A URL's hostname is already canonical.
|
|
62
|
+
const bound = Option.liftThrowable(() => new URL(HttpServer.formatAddress(address)).hostname)().pipe(Option.map(unbracketed));
|
|
63
|
+
if (Option.isNone(bound) || isUnspecified(bound.value))
|
|
64
|
+
return Effect.fail(new Failure({
|
|
65
|
+
code: ExitCode.Usage,
|
|
66
|
+
reason,
|
|
67
|
+
message: `${variable} "${host}" is not one address of this machine; give one.`,
|
|
68
|
+
}));
|
|
69
|
+
if (!isIpLiteral(host) && host !== 'localhost' && isLoopbackAddress(bound.value))
|
|
70
|
+
return Effect.fail(new Failure({
|
|
71
|
+
code: ExitCode.Usage,
|
|
72
|
+
reason,
|
|
73
|
+
message: `${variable} "${host}" resolves to ${bound.value}, a loopback address ` +
|
|
74
|
+
'other devices cannot reach; give the tailnet IP or the full MagicDNS name instead.',
|
|
75
|
+
}));
|
|
76
|
+
return Effect.succeed(bound.value);
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* `host` as a browser writes it in a URL (lowercase, IPv4 shorthand such as `0` expanded, IPv6
|
|
80
|
+
* compressed), without IPv6 brackets; undefined for what is not a host. Links, the Host check and
|
|
81
|
+
* the address bound all use this one spelling, so a browser's Host header matches it.
|
|
82
|
+
*/
|
|
83
|
+
export const canonicalHost = (host) => {
|
|
84
|
+
// Only a host: nothing a URL would read as a path, query, fragment, user or port.
|
|
85
|
+
if (host === '' || /[/?#@\\\s]/.test(host))
|
|
86
|
+
return undefined;
|
|
87
|
+
try {
|
|
88
|
+
const url = new URL(`http://${urlHost(host)}/`);
|
|
89
|
+
if (url.port !== '' || url.username !== '' || url.password !== '')
|
|
90
|
+
return undefined;
|
|
91
|
+
return unbracketed(url.hostname);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
/** Whether a canonical host is an unspecified address, which listens on every interface. */
|
|
98
|
+
/** Whether `host` (canonical, unbracketed) is an IP address rather than a name. */
|
|
99
|
+
const isIpLiteral = (host) => host.includes(':') || /^\d+\.\d+\.\d+\.\d+$/.test(host);
|
|
100
|
+
/** Whether `address` (canonical, unbracketed) is on the loopback interface. */
|
|
101
|
+
const isLoopbackAddress = (address) => address === '::1' || address.startsWith('127.') || /^::ffff:7f[0-9a-f]{2}:/.test(address);
|
|
102
|
+
const isUnspecified = (host) => ['0.0.0.0', '::', '::ffff:0:0'].includes(host);
|
|
22
103
|
/**
|
|
23
104
|
* Without `--port`, a project's report server takes a port from this range, the same one every
|
|
24
105
|
* time: a hash of the runs folder's real path picks it, so report links keep working across
|
|
@@ -153,12 +234,21 @@ const requestSegments = (url) => {
|
|
|
153
234
|
return servable(segments) ? segments : undefined;
|
|
154
235
|
};
|
|
155
236
|
/**
|
|
156
|
-
* The request handler for `root`, answering only requests addressed to `port` on
|
|
157
|
-
* name
|
|
158
|
-
* function, read per request, so the handler can be made
|
|
237
|
+
* The request handler for `root`, answering only requests addressed to `port` on `host` (and, for
|
|
238
|
+
* a loopback host, on 127.0.0.1 or localhost) by name: a Host check, so a web page cannot reach it
|
|
239
|
+
* through DNS rebinding. `port` may be a function, read per request, so the handler can be made
|
|
240
|
+
* before the server knows its port.
|
|
159
241
|
*/
|
|
160
|
-
export const makeReportApp = Effect.fnUntraced(function* (root, port, secret, share) {
|
|
242
|
+
export const makeReportApp = Effect.fnUntraced(function* (root, port, secret, share, host = REPORT_HOST, boundAt = () => undefined) {
|
|
161
243
|
const portNow = typeof port === 'number' ? () => port : port;
|
|
244
|
+
const names = isLoopback(host) ? [urlHost(host), REPORT_HOST, 'localhost'] : [urlHost(host)];
|
|
245
|
+
// Also the address the server listens on, as it is written in a URL: when `host` is a name,
|
|
246
|
+
// the IP it resolved to. A browser sends an IP as the Host only for that very address, so DNS
|
|
247
|
+
// rebinding cannot reach it.
|
|
248
|
+
const addressed = (header) => {
|
|
249
|
+
const bound = boundAt();
|
|
250
|
+
return [...names, ...(bound === undefined ? [] : [urlHost(bound)])].some((name) => header === `${name}:${portNow()}`);
|
|
251
|
+
};
|
|
162
252
|
const fs = yield* FileSystem.FileSystem;
|
|
163
253
|
const path = yield* Path.Path;
|
|
164
254
|
const realRoot = yield* fs.realPath(root);
|
|
@@ -201,23 +291,39 @@ export const makeReportApp = Effect.fnUntraced(function* (root, port, secret, sh
|
|
|
201
291
|
return Effect.gen(function* () {
|
|
202
292
|
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
203
293
|
const host = request.headers['host'];
|
|
204
|
-
if (
|
|
294
|
+
if (!addressed(host)) {
|
|
205
295
|
return HttpServerResponse.text('Forbidden', { status: 403 });
|
|
206
296
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
297
|
+
const notAllowed = HttpServerResponse.text('Method not allowed', {
|
|
298
|
+
status: 405,
|
|
299
|
+
headers: { allow: 'GET, HEAD' },
|
|
300
|
+
});
|
|
301
|
+
// POST only for the Share routes that take one: the Share button's start, which its page
|
|
302
|
+
// posts, and the screenshots the upload's page hands back (see `ShareRoutes`).
|
|
303
|
+
if (request.method === 'POST') {
|
|
304
|
+
const shared = share
|
|
305
|
+
? yield* share({
|
|
306
|
+
method: 'POST',
|
|
307
|
+
url: request.url,
|
|
308
|
+
headers: request.headers,
|
|
309
|
+
base: `http://${host}`,
|
|
310
|
+
body: (max) => request.arrayBuffer.pipe(Effect.map((buffer) => new Uint8Array(buffer)), Effect.provideService(HttpIncomingMessage.MaxBodySize, ByteSize.bytes(max))),
|
|
311
|
+
})
|
|
312
|
+
: undefined;
|
|
313
|
+
return shared ?? notAllowed;
|
|
212
314
|
}
|
|
315
|
+
if (request.method !== 'GET' && request.method !== 'HEAD')
|
|
316
|
+
return notAllowed;
|
|
213
317
|
const proof = identity(request.url);
|
|
214
318
|
if (proof)
|
|
215
319
|
return proof;
|
|
216
320
|
if (share && request.method === 'GET') {
|
|
217
321
|
const shared = yield* share({
|
|
322
|
+
method: 'GET',
|
|
218
323
|
url: request.url,
|
|
219
324
|
headers: request.headers,
|
|
220
325
|
base: `http://${host}`,
|
|
326
|
+
body: () => Effect.succeed(new Uint8Array()),
|
|
221
327
|
});
|
|
222
328
|
if (shared)
|
|
223
329
|
return shared;
|
|
@@ -279,12 +385,15 @@ const holdingServer = () => {
|
|
|
279
385
|
*/
|
|
280
386
|
export const listen = (root, port, secret, options = {}) => Effect.gen(function* () {
|
|
281
387
|
let bound = port;
|
|
282
|
-
|
|
388
|
+
let boundAt;
|
|
389
|
+
const host = yield* reportHost;
|
|
390
|
+
// The Share button's routes, when this process can share (see `ShareSource`): on loopback
|
|
391
|
+
// with Cloud's callback, elsewhere (a tailnet address) with its pairing code.
|
|
283
392
|
const share = yield* makeShareRoutes(root);
|
|
284
|
-
const app = yield* makeReportApp(root, () => bound, secret, share);
|
|
393
|
+
const app = yield* makeReportApp(root, () => bound, secret, share, host, () => boundAt);
|
|
285
394
|
// Requests that arrive before the handler is attached are held.
|
|
286
395
|
const holding = holdingServer();
|
|
287
|
-
const server = yield* NodeHttpServer.make(() => holding.server, { port, host
|
|
396
|
+
const server = yield* NodeHttpServer.make(() => holding.server, { port, host });
|
|
288
397
|
// Runs before the server's own close (finalizers run in reverse): when the handler never got
|
|
289
398
|
// attached, held requests would keep that close waiting for good.
|
|
290
399
|
let released = false;
|
|
@@ -294,6 +403,7 @@ export const listen = (root, port, secret, options = {}) => Effect.gen(function*
|
|
|
294
403
|
}));
|
|
295
404
|
if ('port' in server.address)
|
|
296
405
|
bound = server.address.port;
|
|
406
|
+
boundAt = yield* boundAddress(server.address, host, 'SCREW_BUGS_REPORT_HOST', 'report_host');
|
|
297
407
|
if (options.beforeServe)
|
|
298
408
|
yield* options.beforeServe({ port: bound, held: holding.held });
|
|
299
409
|
yield* server.serve(options.onRequest ? Effect.andThen(options.onRequest, app) : app);
|
|
@@ -301,7 +411,7 @@ export const listen = (root, port, secret, options = {}) => Effect.gen(function*
|
|
|
301
411
|
released = true;
|
|
302
412
|
holding.release();
|
|
303
413
|
});
|
|
304
|
-
return `http://${
|
|
414
|
+
return `http://${urlHost(host)}:${bound}`;
|
|
305
415
|
}).pipe(Effect.provide(NodeHttpServer.layerHttpServices));
|
|
306
416
|
/** How long to wait for whatever holds a port to answer the identity challenge. */
|
|
307
417
|
export const IDENTITY_TIMEOUT = Duration.seconds(2);
|
|
@@ -313,7 +423,8 @@ export const IDENTITY_TIMEOUT = Duration.seconds(2);
|
|
|
313
423
|
*/
|
|
314
424
|
export const servesSameRoot = (port, rootId, secret) => Effect.gen(function* () {
|
|
315
425
|
const nonce = yield* randomHex(32);
|
|
316
|
-
const
|
|
426
|
+
const host = yield* reportHost;
|
|
427
|
+
const answer = yield* HttpClient.get(`http://${urlHost(host)}:${port}${IDENTITY_PATH}?nonce=${nonce}`).pipe(Effect.flatMap(HttpClientResponse.filterStatusOk), Effect.flatMap(HttpIncomingMessage.schemaBodyJson(Identity)), Effect.scoped);
|
|
317
428
|
return answer.root === rootId && answer.proof === proofOf(secret, nonce, rootId, port);
|
|
318
429
|
}).pipe(Effect.timeout(IDENTITY_TIMEOUT), Effect.provide(NodeHttpClient.layerNodeHttp), Effect.catch(() => Effect.succeed(false)));
|
|
319
430
|
/** How often to try the preferred port again after its holder failed the challenge. */
|
|
@@ -340,7 +451,8 @@ export const serveOnPreferredPort = (root, preferred, folder, options = {}) => E
|
|
|
340
451
|
? Effect.succeed(false)
|
|
341
452
|
: servesSameRoot(preferred, folder.rootId, secret));
|
|
342
453
|
if (yield* probe) {
|
|
343
|
-
|
|
454
|
+
const host = yield* reportHost;
|
|
455
|
+
return { base: `http://${urlHost(host)}:${preferred}`, on: 'reused' };
|
|
344
456
|
}
|
|
345
457
|
for (let retry = 0; retry < BIND_RETRIES; retry++) {
|
|
346
458
|
const again = yield* bind;
|
|
@@ -362,13 +474,17 @@ export const startReportServer = (root, options = {}) => Effect.gen(function* ()
|
|
|
362
474
|
return { base: yield* listen(root, options.port, secret), on: 'preferred' };
|
|
363
475
|
}
|
|
364
476
|
return yield* serveOnPreferredPort(root, options.preferred ?? stablePortOf(folder.rootId), folder);
|
|
365
|
-
}).pipe(Effect.catchTag('ServeError', (error) => Effect.fail(new Failure({
|
|
477
|
+
}).pipe(Effect.catchTag('ServeError', (error) => reportHost.pipe(Effect.flatMap((host) => Effect.fail(new Failure({
|
|
366
478
|
code: ExitCode.Usage,
|
|
367
479
|
reason: 'serve_failed',
|
|
368
|
-
message: `Could not serve reports on ${
|
|
369
|
-
(options.port
|
|
480
|
+
message: `Could not serve reports on ${urlHost(host)}:${options.port ?? 0}` +
|
|
481
|
+
(options.port
|
|
482
|
+
? ' (is the port in use? Try another --port, or leave it out)'
|
|
483
|
+
: host === REPORT_HOST
|
|
484
|
+
? ''
|
|
485
|
+
: ' (check SCREW_BUGS_REPORT_HOST)') +
|
|
370
486
|
`: ${String(error.cause)}`,
|
|
371
|
-
}))), Effect.catchTag('PlatformError', (error) => Effect.fail(new Failure({
|
|
487
|
+
}))))), Effect.catchTag('PlatformError', (error) => Effect.fail(new Failure({
|
|
372
488
|
code: ExitCode.Usage,
|
|
373
489
|
reason: 'serve_failed',
|
|
374
490
|
message: `Could not serve reports from ${root}: ${error.message}`,
|
package/dist/cli/share.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { Config, Context, Duration, Effect, FileSystem, Layer, Path } from 'effect';
|
|
2
2
|
import { HttpClient, HttpServerResponse } from 'effect/http';
|
|
3
3
|
import { Engine } from '../core/index.js';
|
|
4
|
+
import { type SharePage } from '../report/index.js';
|
|
4
5
|
import { JobId, type ReportBundle } from '../schema/index.js';
|
|
5
6
|
export declare const SHARE_PATHS: {
|
|
6
7
|
readonly start: "/.screw-bugs/share/start";
|
|
7
8
|
readonly callback: '/.screw-bugs/share/callback';
|
|
8
9
|
readonly progress: '/.screw-bugs/share/progress';
|
|
10
|
+
readonly status: '/.screw-bugs/share/status';
|
|
11
|
+
readonly source: '/.screw-bugs/share/source';
|
|
12
|
+
readonly encoded: '/.screw-bugs/share/encoded';
|
|
9
13
|
};
|
|
10
14
|
/**
|
|
11
15
|
* Where screw-bugs Cloud is: `SCREW_BUGS_CLOUD_URL`, by default `https://screwbugs.dev`. An
|
|
@@ -24,8 +28,24 @@ export declare const CLOUD_ANSWER_TIMEOUT: Duration.Duration;
|
|
|
24
28
|
export declare const FILE_UPLOAD_TIMEOUT: Duration.Duration;
|
|
25
29
|
/** How long a whole upload may take: Cloud refuses files once an upload is an hour old. */
|
|
26
30
|
export declare const UPLOAD_DEADLINE: Duration.Duration;
|
|
31
|
+
/** How often the page with the pairing code reloads itself, to move on once it was typed. */
|
|
32
|
+
export declare const PAIRING_REFRESH_S = 2;
|
|
33
|
+
/** Whether the browser reached this server on this machine, the only callback Cloud takes. */
|
|
34
|
+
export declare const onThisMachine: (base: string) => boolean;
|
|
35
|
+
/** base64url without padding, as Cloud's tokens and the request's challenge are written. */
|
|
36
|
+
export declare const base64url: (bytes: Uint8Array) => string;
|
|
37
|
+
/** The challenge of a share request's `secret`, as PKCE's S256: base64url(SHA-256(ASCII)). */
|
|
38
|
+
export declare const challengeOf: (secret: string) => string;
|
|
27
39
|
/** How often the progress page reloads itself while files upload, in seconds. */
|
|
28
40
|
export declare const PROGRESS_REFRESH_S = 1;
|
|
41
|
+
/** How many files upload at a time. */
|
|
42
|
+
export declare const UPLOAD_CONCURRENCY = 4;
|
|
43
|
+
/** How long the upload waits for the progress page to ask for the screenshots to encode. */
|
|
44
|
+
export declare const ENCODE_FIRST_WAIT: Duration.Duration;
|
|
45
|
+
/** How long the upload waits for the page's next screenshot once it has started encoding. */
|
|
46
|
+
export declare const ENCODE_IDLE: Duration.Duration;
|
|
47
|
+
/** The longest the upload waits for the page's screenshots in all. */
|
|
48
|
+
export declare const ENCODE_WINDOW: Duration.Duration;
|
|
29
49
|
declare const ShareSource_base: Context.ServiceClass<ShareSource, "screw-bugs/ShareSource", {
|
|
30
50
|
readonly bundle: (jobId: JobId) => Effect.Effect<ReportBundle, unknown>;
|
|
31
51
|
}>;
|
|
@@ -37,6 +57,27 @@ export declare class ShareSource extends ShareSource_base {
|
|
|
37
57
|
/** From the engine. */
|
|
38
58
|
static readonly layer: Layer.Layer<ShareSource, never, Engine>;
|
|
39
59
|
}
|
|
60
|
+
/** A screenshot the progress page may make smaller: its path, and its size in bytes and pixels. */
|
|
61
|
+
export interface Encodable {
|
|
62
|
+
readonly path: string;
|
|
63
|
+
readonly size: number;
|
|
64
|
+
readonly width: number;
|
|
65
|
+
readonly height: number;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Waits for smaller copies of `files` (each read with `read`, which gives its checked bytes, or
|
|
69
|
+
* undefined when it changed), and gives the WebP of each one it got, by path.
|
|
70
|
+
*/
|
|
71
|
+
export type Encoder = (input: {
|
|
72
|
+
readonly files: ReadonlyArray<Encodable>;
|
|
73
|
+
readonly read: (path: string) => Effect.Effect<Uint8Array | undefined>;
|
|
74
|
+
}) => Effect.Effect<ReadonlyMap<string, Uint8Array>>;
|
|
75
|
+
/** How far an upload is: files up, files in all, and the local paths of those going up now. */
|
|
76
|
+
export interface UploadProgress {
|
|
77
|
+
readonly done: number;
|
|
78
|
+
readonly total: number;
|
|
79
|
+
readonly current: ReadonlyArray<string>;
|
|
80
|
+
}
|
|
40
81
|
declare const ShareFailed_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
41
82
|
readonly _tag: "ShareFailed";
|
|
42
83
|
} & Readonly<A>;
|
|
@@ -45,22 +86,45 @@ declare class ShareFailed extends ShareFailed_base<{
|
|
|
45
86
|
readonly message: string;
|
|
46
87
|
}> {
|
|
47
88
|
}
|
|
48
|
-
/**
|
|
89
|
+
/**
|
|
90
|
+
* A page of these routes (`renderSharePage`: the reports' look, one card), `text` plain text. A
|
|
91
|
+
* status of 400 or more shows as a failure. With `code`, `refresh` is how often it checks whether
|
|
92
|
+
* the code was used. A page with a form sends its origin as its referrer, so its post carries this
|
|
93
|
+
* server's `Origin` (`no-referrer` would make it `null`), and may follow the post's redirect to
|
|
94
|
+
* `form.cloud`. No page is ever shown in a frame.
|
|
95
|
+
*/
|
|
49
96
|
export declare const sharePage: (title: string, text: string, options?: {
|
|
50
97
|
readonly status?: number;
|
|
51
98
|
readonly refresh?: number;
|
|
52
99
|
readonly back?: string | undefined;
|
|
100
|
+
/** A pairing code to show large, with a Copy button. */
|
|
101
|
+
readonly code?: string;
|
|
102
|
+
/** A link to open in a new tab, as the main button. */
|
|
103
|
+
readonly link?: {
|
|
104
|
+
readonly href: string;
|
|
105
|
+
readonly text: string;
|
|
106
|
+
};
|
|
107
|
+
/** A button that posts to `action` on this server, which may then redirect to `cloud`. */
|
|
108
|
+
readonly form?: {
|
|
109
|
+
readonly action: string;
|
|
110
|
+
readonly label: string;
|
|
111
|
+
readonly cloud: string;
|
|
112
|
+
};
|
|
113
|
+
/** The upload's page: it follows the share `state` of the run `run` live, at `routes`. */
|
|
114
|
+
readonly follow?: SharePage['follow'];
|
|
53
115
|
}) => HttpServerResponse.HttpServerResponse;
|
|
54
116
|
/**
|
|
55
|
-
* Uploads the run `jobId` of the runs folder `root` with `ticket`: the scrubbed bundle, then
|
|
56
|
-
*
|
|
117
|
+
* Uploads the run `jobId` of the runs folder `root` with `ticket`: the scrubbed bundle, then its
|
|
118
|
+
* files, then completes it; the share's page on Cloud. With `encode`, its PNG screenshots may go
|
|
119
|
+
* up as the WebP copies that gives back first. `progress` hears how far it is.
|
|
57
120
|
*/
|
|
58
121
|
export declare const uploadShare: (input: {
|
|
59
122
|
readonly root: string;
|
|
60
123
|
readonly jobId: JobId;
|
|
61
124
|
readonly ticket: string;
|
|
62
125
|
readonly cloud: string;
|
|
63
|
-
readonly progress: (
|
|
126
|
+
readonly progress: (progress: UploadProgress) => Effect.Effect<void>;
|
|
127
|
+
readonly encode?: Encoder | undefined;
|
|
64
128
|
}) => Effect.Effect<{
|
|
65
129
|
readonly slug: string;
|
|
66
130
|
readonly url: string;
|
|
@@ -69,10 +133,13 @@ export declare const uploadShare: (input: {
|
|
|
69
133
|
}, ShareFailed, FileSystem.FileSystem | HttpClient.HttpClient | Path.Path | ShareSource>;
|
|
70
134
|
/** A route's answer, or none for a request that is not one of them. */
|
|
71
135
|
export type ShareRoutes = (request: {
|
|
136
|
+
readonly method: 'GET' | 'POST';
|
|
72
137
|
readonly url: string;
|
|
73
138
|
readonly headers: Readonly<Record<string, string | undefined>>;
|
|
74
139
|
/** This server's origin as the browser reached it, such as `http://127.0.0.1:41234`. */
|
|
75
140
|
readonly base: string;
|
|
141
|
+
/** The request's body, read only when asked for, failing when it is longer than `max` bytes. */
|
|
142
|
+
readonly body: (max: number) => Effect.Effect<Uint8Array, unknown>;
|
|
76
143
|
}) => Effect.Effect<HttpServerResponse.HttpServerResponse | undefined>;
|
|
77
144
|
/**
|
|
78
145
|
* The share routes of a report server for the runs folder `root`, while `scope` is open (uploads
|