@tafrahq/wt-tunnel-server 0.0.0-stage → 0.7.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 +21 -0
- package/README.md +108 -2
- package/dist/auth.js +121 -0
- package/dist/auth.js.map +1 -0
- package/dist/bin.js +32 -0
- package/dist/bin.js.map +1 -0
- package/dist/binaries.js +51 -0
- package/dist/binaries.js.map +1 -0
- package/dist/brand.js +10 -0
- package/dist/brand.js.map +1 -0
- package/dist/ca-page.js +112 -0
- package/dist/ca-page.js.map +1 -0
- package/dist/children.js +72 -0
- package/dist/children.js.map +1 -0
- package/dist/cli.js +110 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.js +55 -0
- package/dist/config.js.map +1 -0
- package/dist/context.js +5 -0
- package/dist/context.js.map +1 -0
- package/dist/daemon.js +176 -0
- package/dist/daemon.js.map +1 -0
- package/dist/dev-host.js +71 -0
- package/dist/dev-host.js.map +1 -0
- package/dist/errors.js +8 -0
- package/dist/errors.js.map +1 -0
- package/dist/hosts.js +32 -0
- package/dist/hosts.js.map +1 -0
- package/dist/internal.js +62 -0
- package/dist/internal.js.map +1 -0
- package/dist/listen.js +31 -0
- package/dist/listen.js.map +1 -0
- package/dist/packages/binaries/src/caddy.js +24 -0
- package/dist/packages/binaries/src/caddy.js.map +1 -0
- package/dist/packages/binaries/src/frp.js +45 -0
- package/dist/packages/binaries/src/frp.js.map +1 -0
- package/dist/packages/binaries/src/install.js +110 -0
- package/dist/packages/binaries/src/install.js.map +1 -0
- package/dist/packages/contract/src/index.js +12 -0
- package/dist/packages/contract/src/index.js.map +1 -0
- package/dist/packages/contract/src/root-ca.js +61 -0
- package/dist/packages/contract/src/root-ca.js.map +1 -0
- package/dist/packages/contract/src/server-config.js +99 -0
- package/dist/packages/contract/src/server-config.js.map +1 -0
- package/dist/ready.js +36 -0
- package/dist/ready.js.map +1 -0
- package/dist/render.js +101 -0
- package/dist/render.js.map +1 -0
- package/dist/reply.js +46 -0
- package/dist/reply.js.map +1 -0
- package/dist/root-ca.js +85 -0
- package/dist/root-ca.js.map +1 -0
- package/dist/runtime.js +53 -0
- package/dist/runtime.js.map +1 -0
- package/dist/service.js +59 -0
- package/dist/service.js.map +1 -0
- package/dist/session.js +65 -0
- package/dist/session.js.map +1 -0
- package/dist/sign-in.js +103 -0
- package/dist/sign-in.js.map +1 -0
- package/dist/supervise.js +33 -0
- package/dist/supervise.js.map +1 -0
- package/package.json +65 -3
- package/src/auth.ts +153 -0
- package/src/bin.ts +41 -0
- package/src/binaries.ts +82 -0
- package/src/brand.ts +10 -0
- package/src/ca-page.ts +166 -0
- package/src/children.ts +98 -0
- package/src/cli.ts +195 -0
- package/src/config.ts +92 -0
- package/src/context.ts +23 -0
- package/src/daemon.ts +254 -0
- package/src/dev-host.ts +101 -0
- package/src/errors.ts +14 -0
- package/src/hosts.ts +49 -0
- package/src/internal.ts +89 -0
- package/src/listen.ts +43 -0
- package/src/ready.ts +50 -0
- package/src/render.ts +121 -0
- package/src/reply.ts +60 -0
- package/src/root-ca.ts +116 -0
- package/src/runtime.ts +49 -0
- package/src/service.ts +90 -0
- package/src/session.ts +129 -0
- package/src/sign-in.ts +147 -0
- package/src/supervise.ts +51 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { firstExit, startChildren } from "./children.js";
|
|
2
|
+
import { serveAuth } from "./listen.js";
|
|
3
|
+
import { announceWhenReady } from "./ready.js";
|
|
4
|
+
import { childSpecs, writeRuntimeFiles } from "./runtime.js";
|
|
5
|
+
import { Console, Effect } from "effect";
|
|
6
|
+
// src/supervise.ts
|
|
7
|
+
const firstUnprivilegedPort = 1024;
|
|
8
|
+
/** Caddy reports `listen tcp :443: bind: permission denied` when it may not bind a low port. */
|
|
9
|
+
const bindDeniedHint = (exited, binaries, ports) => exited.name === "caddy" && exited.output.some((line) => line.includes("bind: permission denied")) ? [
|
|
10
|
+
`caddy may not bind ports below ${firstUnprivilegedPort} (https ${ports.https}, http ${ports.http}) as this user. Do one of:`,
|
|
11
|
+
` - let this caddy bind them: sudo setcap cap_net_bind_service=+ep ${binaries.caddy}`,
|
|
12
|
+
" - run wt-tunnel-server as root",
|
|
13
|
+
` - pick ports of ${firstUnprivilegedPort} or above with --https-port and --http-port`
|
|
14
|
+
].join("\n") : void 0;
|
|
15
|
+
/**
|
|
16
|
+
* Runs the auth service, Caddy and frps until a child dies or the runtime turns SIGTERM or SIGINT
|
|
17
|
+
* into an interruption; either way the children get SIGTERM. A dead child fails the process so the
|
|
18
|
+
* platform restarts the whole Machine.
|
|
19
|
+
*/
|
|
20
|
+
const supervise = (config, { binaries, ports }) => Effect.gen(function* superviseChildren() {
|
|
21
|
+
const dir = yield* writeRuntimeFiles(config, ports);
|
|
22
|
+
yield* serveAuth(config);
|
|
23
|
+
const children = yield* startChildren(childSpecs(dir, binaries));
|
|
24
|
+
yield* Effect.forkScoped(announceWhenReady(ports));
|
|
25
|
+
const exited = yield* firstExit(children);
|
|
26
|
+
yield* Console.error(`${exited.name} exited (${exited.reason}); stopping`);
|
|
27
|
+
const hint = bindDeniedHint(exited, binaries, ports);
|
|
28
|
+
if (hint !== void 0) yield* Console.error(hint);
|
|
29
|
+
process.exitCode = 1;
|
|
30
|
+
}).pipe(Effect.scoped);
|
|
31
|
+
export { supervise };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=supervise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supervise.js","names":[],"sources":["../src/supervise.ts"],"sourcesContent":["import type { ServerConfig } from '@tafrahq/wt-tunnel-contract/server-config';\nimport { Console, Effect } from 'effect';\n\nimport type { Binaries } from './binaries.ts';\nimport { firstExit, startChildren } from './children.ts';\nimport type { Exited } from './children.ts';\nimport { serveAuth } from './listen.ts';\nimport { announceWhenReady } from './ready.ts';\nimport type { Ports } from './render.ts';\nimport { childSpecs, writeRuntimeFiles } from './runtime.ts';\n\nconst firstUnprivilegedPort = 1024;\n\n/** Caddy reports `listen tcp :443: bind: permission denied` when it may not bind a low port. */\nconst bindDeniedHint = (exited: Exited, binaries: Binaries, ports: Ports) =>\n exited.name === 'caddy' && exited.output.some((line) => line.includes('bind: permission denied'))\n ? [\n `caddy may not bind ports below ${firstUnprivilegedPort} (https ${ports.https}, http ${ports.http}) as this user. Do one of:`,\n ` - let this caddy bind them: sudo setcap cap_net_bind_service=+ep ${binaries.caddy}`,\n ' - run wt-tunnel-server as root',\n ` - pick ports of ${firstUnprivilegedPort} or above with --https-port and --http-port`,\n ].join('\\n')\n : undefined;\n\ninterface SuperviseOptions {\n readonly binaries: Binaries;\n readonly ports: Ports;\n}\n\n/**\n * Runs the auth service, Caddy and frps until a child dies or the runtime turns SIGTERM or SIGINT\n * into an interruption; either way the children get SIGTERM. A dead child fails the process so the\n * platform restarts the whole Machine.\n */\nconst supervise = (config: ServerConfig, { binaries, ports }: SuperviseOptions) =>\n Effect.gen(function* superviseChildren() {\n const dir = yield* writeRuntimeFiles(config, ports);\n yield* serveAuth(config);\n const children = yield* startChildren(childSpecs(dir, binaries));\n yield* Effect.forkScoped(announceWhenReady(ports));\n const exited = yield* firstExit(children);\n yield* Console.error(`${exited.name} exited (${exited.reason}); stopping`);\n const hint = bindDeniedHint(exited, binaries, ports);\n if (hint !== undefined) {\n yield* Console.error(hint);\n }\n process.exitCode = 1;\n }).pipe(Effect.scoped);\n\nexport { supervise };\nexport type { SuperviseOptions };\n"],"mappings":";;;;;;AAWA,MAAM,wBAAwB;;AAG9B,MAAM,kBAAkB,QAAgB,UAAoB,UAC1D,OAAO,SAAS,WAAW,OAAO,OAAO,MAAM,SAAS,KAAK,SAAS,yBAAyB,CAAC,IAC5F;CACE,kCAAkC,sBAAsB,UAAU,MAAM,MAAM,SAAS,MAAM,KAAK;CAClG,sEAAsE,SAAS;CAC/E;CACA,qBAAqB,sBAAsB;AAC7C,CAAC,CAAC,KAAK,IAAI,IACX,KAAA;;;;;;AAYN,MAAM,aAAa,QAAsB,EAAE,UAAU,YACnD,OAAO,IAAI,UAAU,oBAAoB;CACvC,MAAM,MAAM,OAAO,kBAAkB,QAAQ,KAAK;CAClD,OAAO,UAAU,MAAM;CACvB,MAAM,WAAW,OAAO,cAAc,WAAW,KAAK,QAAQ,CAAC;CAC/D,OAAO,OAAO,WAAW,kBAAkB,KAAK,CAAC;CACjD,MAAM,SAAS,OAAO,UAAU,QAAQ;CACxC,OAAO,QAAQ,MAAM,GAAG,OAAO,KAAK,WAAW,OAAO,OAAO,YAAY;CACzE,MAAM,OAAO,eAAe,QAAQ,UAAU,KAAK;CACnD,IAAI,SAAS,KAAA,GACX,OAAO,QAAQ,MAAM,IAAI;CAE3B,QAAQ,WAAW;AACrB,CAAC,CAAC,CAAC,KAAK,OAAO,MAAM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tafrahq/wt-tunnel-server",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "Runs the wt-tunnel server: Caddy, frps and a sign-in service (Google, GitHub, Microsoft, Cloudflare Access) under one supervisor, in the foreground or detached. Downloads pinned, checksum-verified Caddy and frps when you have none.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"caddy",
|
|
7
|
+
"certificate-authority",
|
|
8
|
+
"cli",
|
|
9
|
+
"frp",
|
|
10
|
+
"frps",
|
|
11
|
+
"git-worktree",
|
|
12
|
+
"github-oauth",
|
|
13
|
+
"google-sign-in",
|
|
14
|
+
"microsoft-entra-id",
|
|
15
|
+
"name-constraints",
|
|
16
|
+
"oauth",
|
|
17
|
+
"reverse-tunnel",
|
|
18
|
+
"self-hosted",
|
|
19
|
+
"tunnel",
|
|
20
|
+
"wt-tunnel"
|
|
21
|
+
],
|
|
22
|
+
"homepage": "https://github.com/tafrahq/wt-tunnel/tree/main/apps/server#readme",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/tafrahq/wt-tunnel/issues"
|
|
25
|
+
},
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"author": "Tafra (https://github.com/tafrahq)",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/tafrahq/wt-tunnel.git",
|
|
31
|
+
"directory": "apps/server"
|
|
32
|
+
},
|
|
33
|
+
"bin": {
|
|
34
|
+
"wt-tunnel-server": "dist/bin.js"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"src",
|
|
39
|
+
"!src/**/*.test.ts"
|
|
40
|
+
],
|
|
41
|
+
"type": "module",
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@effect/platform-node": "4.0.6",
|
|
47
|
+
"better-auth": "1.7.14",
|
|
48
|
+
"effect": "4.0.6"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@effect/vitest": "^4.0.6",
|
|
52
|
+
"@tafrahq/wt-tunnel-binaries": "0.0.0",
|
|
53
|
+
"@tafrahq/wt-tunnel-contract": "0.0.0",
|
|
54
|
+
"@types/node": "^22.20.5",
|
|
55
|
+
"@types/plist": "^3.0.5",
|
|
56
|
+
"plist": "^5.0.0",
|
|
57
|
+
"tsdown": "0.23.2",
|
|
58
|
+
"vitest": "^5.0.5"
|
|
59
|
+
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": ">=22"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"build": "tsdown && node dist/bin.js --version",
|
|
65
|
+
"typecheck": "tsc --noEmit",
|
|
66
|
+
"test": "vitest run"
|
|
67
|
+
}
|
|
6
68
|
}
|
package/src/auth.ts
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
|
|
3
|
+
import type { ProviderId, ServerConfig } from '@tafrahq/wt-tunnel-contract/server-config';
|
|
4
|
+
import { betterAuth } from 'better-auth/minimal';
|
|
5
|
+
import { fromNodeHeaders, toNodeHandler } from 'better-auth/node';
|
|
6
|
+
import { genericOAuth } from 'better-auth/plugins/generic-oauth';
|
|
7
|
+
import { Option, Redacted, Schema } from 'effect';
|
|
8
|
+
|
|
9
|
+
import { sessionSeconds } from './session.ts';
|
|
10
|
+
|
|
11
|
+
interface SignedInUser {
|
|
12
|
+
readonly email: string;
|
|
13
|
+
readonly emailVerified: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Cookies Better Auth wants set, whatever the answer. */
|
|
17
|
+
interface WithCookies<Value> {
|
|
18
|
+
readonly setCookie: readonly string[];
|
|
19
|
+
readonly value: Value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The slice of Better Auth the sign-in host uses. */
|
|
23
|
+
interface SignIn {
|
|
24
|
+
/** Serves `/api/auth/*`, including each provider's redirect back to the sign-in host. */
|
|
25
|
+
readonly handler: (request: IncomingMessage, response: ServerResponse) => Promise<void>;
|
|
26
|
+
readonly session: (request: IncomingMessage) => Promise<WithCookies<SignedInUser | undefined>>;
|
|
27
|
+
readonly signOut: (request: IncomingMessage) => Promise<readonly string[]>;
|
|
28
|
+
/** The provider's authorization URL; Better Auth returns to `callbackURL` once signed in. */
|
|
29
|
+
readonly start: (
|
|
30
|
+
request: IncomingMessage,
|
|
31
|
+
sign: { readonly callbackURL: string; readonly provider: ProviderId },
|
|
32
|
+
) => Promise<WithCookies<string | undefined>>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const SignInStarted = Schema.Struct({ url: Schema.String });
|
|
36
|
+
|
|
37
|
+
const headersOf = (request: IncomingMessage) => fromNodeHeaders(request.headers);
|
|
38
|
+
|
|
39
|
+
const client = (provider: {
|
|
40
|
+
readonly clientId: string;
|
|
41
|
+
readonly clientSecret: Redacted.Redacted;
|
|
42
|
+
}) => ({
|
|
43
|
+
clientId: provider.clientId,
|
|
44
|
+
clientSecret: Redacted.value(provider.clientSecret),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Better Auth's built-in providers. Each reports whether the provider verified the email: Google
|
|
49
|
+
* from its ID token, GitHub from the account's email list, and Microsoft from the
|
|
50
|
+
* `verified_primary_email` or `email_verified` claim, which the app registration must add.
|
|
51
|
+
*/
|
|
52
|
+
const socialProviders = ({ github, google, microsoft }: ServerConfig['providers']) => ({
|
|
53
|
+
...(github === undefined ? {} : { github: client(github) }),
|
|
54
|
+
...(google === undefined
|
|
55
|
+
? {}
|
|
56
|
+
: { google: { ...client(google), prompt: 'select_account' as const } }),
|
|
57
|
+
...(microsoft === undefined
|
|
58
|
+
? {}
|
|
59
|
+
: {
|
|
60
|
+
microsoft: {
|
|
61
|
+
...client(microsoft),
|
|
62
|
+
prompt: 'select_account' as const,
|
|
63
|
+
tenantId: microsoft.tenantId ?? 'common',
|
|
64
|
+
},
|
|
65
|
+
}),
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A Cloudflare Access OIDC app, as a generic OIDC provider that Better Auth lists with the social
|
|
70
|
+
* ones. Its endpoints follow from the team domain and client ID, so the server fetches no discovery
|
|
71
|
+
* document. The email comes from the userinfo endpoint, over TLS with the access token. Access
|
|
72
|
+
* signs people in through the identity providers the team set up and sends no `email_verified`
|
|
73
|
+
* claim, so the email counts as verified.
|
|
74
|
+
*/
|
|
75
|
+
const cloudflareAccess = (cloudflare: ServerConfig['providers']['cloudflare']) => {
|
|
76
|
+
if (cloudflare === undefined) {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
const base = `https://${cloudflare.teamDomain}/cdn-cgi/access/sso/oidc/${cloudflare.clientId}`;
|
|
80
|
+
return [
|
|
81
|
+
genericOAuth({
|
|
82
|
+
config: [
|
|
83
|
+
{
|
|
84
|
+
...client(cloudflare),
|
|
85
|
+
authorizationUrl: `${base}/authorization`,
|
|
86
|
+
mapProfileToUser: () => ({ emailVerified: true }),
|
|
87
|
+
pkce: true,
|
|
88
|
+
providerId: 'cloudflare',
|
|
89
|
+
scopes: ['openid', 'email', 'profile'],
|
|
90
|
+
tokenUrl: `${base}/token`,
|
|
91
|
+
userInfoUrl: `${base}/userinfo`,
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
}),
|
|
95
|
+
];
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Better Auth with no database. These are the defaults Better Auth picks when `database` is absent,
|
|
100
|
+
* spelled out because the server's statelessness depends on them: the session lives in a JWE cookie
|
|
101
|
+
* that Better Auth re-issues before it expires, and OAuth state and the provider account live in
|
|
102
|
+
* cookies. Users land in Better Auth's in-memory adapter, which nothing reads back after sign-in,
|
|
103
|
+
* so a restart loses nothing that matters.
|
|
104
|
+
*/
|
|
105
|
+
const createBetterAuth = (config: ServerConfig) =>
|
|
106
|
+
betterAuth({
|
|
107
|
+
account: { storeAccountCookie: true, storeStateStrategy: 'cookie' },
|
|
108
|
+
baseURL: `https://${config.authHost}`,
|
|
109
|
+
plugins: cloudflareAccess(config.providers.cloudflare),
|
|
110
|
+
secret: Redacted.value(config.authSecret),
|
|
111
|
+
session: {
|
|
112
|
+
cookieCache: { enabled: true, maxAge: sessionSeconds, refreshCache: true, strategy: 'jwe' },
|
|
113
|
+
expiresIn: sessionSeconds,
|
|
114
|
+
},
|
|
115
|
+
socialProviders: socialProviders(config.providers),
|
|
116
|
+
telemetry: { enabled: false },
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const createSignIn = (config: ServerConfig): SignIn => {
|
|
120
|
+
const auth = createBetterAuth(config);
|
|
121
|
+
return {
|
|
122
|
+
handler: toNodeHandler(auth),
|
|
123
|
+
session: async (request) => {
|
|
124
|
+
const { headers, response } = await auth.api.getSession({
|
|
125
|
+
headers: headersOf(request),
|
|
126
|
+
returnHeaders: true,
|
|
127
|
+
});
|
|
128
|
+
return { setCookie: headers.getSetCookie(), value: response?.user ?? undefined };
|
|
129
|
+
},
|
|
130
|
+
signOut: async (request) => {
|
|
131
|
+
const response = await auth.api.signOut({ asResponse: true, headers: headersOf(request) });
|
|
132
|
+
return response.headers.getSetCookie();
|
|
133
|
+
},
|
|
134
|
+
start: async (request, { callbackURL, provider }) => {
|
|
135
|
+
const response = await auth.api.signInSocial({
|
|
136
|
+
asResponse: true,
|
|
137
|
+
body: { callbackURL, provider },
|
|
138
|
+
headers: headersOf(request),
|
|
139
|
+
});
|
|
140
|
+
const started = Schema.decodeUnknownOption(SignInStarted)(await response.json());
|
|
141
|
+
return {
|
|
142
|
+
setCookie: response.headers.getSetCookie(),
|
|
143
|
+
value: started.pipe(
|
|
144
|
+
Option.map(({ url }) => url),
|
|
145
|
+
Option.getOrUndefined,
|
|
146
|
+
),
|
|
147
|
+
};
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export { createSignIn };
|
|
153
|
+
export type { SignIn };
|
package/src/bin.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
|
|
4
|
+
import { NodeRuntime, NodeServices } from '@effect/platform-node';
|
|
5
|
+
import { Cause, Console, Effect, Exit, Runtime, Schema } from 'effect';
|
|
6
|
+
|
|
7
|
+
import { run } from './cli.ts';
|
|
8
|
+
|
|
9
|
+
const PackageJson = Schema.Struct({ version: Schema.String });
|
|
10
|
+
const packageJson: unknown = createRequire(import.meta.url)('../package.json');
|
|
11
|
+
|
|
12
|
+
/** Expected failures carry a message written for the user; skip the stack trace. */
|
|
13
|
+
const report = (message: string) =>
|
|
14
|
+
Effect.gen(function* reportFailure() {
|
|
15
|
+
yield* Console.error(`wt-tunnel-server: ${message}`);
|
|
16
|
+
process.exitCode = 1;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const program = Effect.gen(function* main() {
|
|
20
|
+
const { version } = yield* Schema.decodeUnknownEffect(PackageJson)(packageJson).pipe(
|
|
21
|
+
Effect.orDie,
|
|
22
|
+
);
|
|
23
|
+
yield* run(version);
|
|
24
|
+
}).pipe(
|
|
25
|
+
Effect.catchTag('ServerError', ({ message }: { readonly message: string }) => report(message)),
|
|
26
|
+
Effect.provide(NodeServices.layer),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* SIGTERM and SIGINT interrupt the program, which stops Caddy and frps. That is a clean stop, so it
|
|
31
|
+
* exits 0 rather than 130, unless a child had already died.
|
|
32
|
+
*/
|
|
33
|
+
const teardown: Runtime.Teardown = (exit, onExit) => {
|
|
34
|
+
if (Exit.isFailure(exit) && Cause.hasInterruptsOnly(exit.cause)) {
|
|
35
|
+
onExit(Number(process.exitCode ?? 0));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
Runtime.defaultTeardown(exit, onExit);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
NodeRuntime.runMain(program, { teardown });
|
package/src/binaries.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
|
+
import { access, stat } from 'node:fs/promises';
|
|
3
|
+
import { delimiter, join, resolve } from 'node:path';
|
|
4
|
+
|
|
5
|
+
import { cacheHome, pinnedBinary } from '@tafrahq/wt-tunnel-binaries';
|
|
6
|
+
import { caddyPin } from '@tafrahq/wt-tunnel-binaries/caddy';
|
|
7
|
+
import { frpPin } from '@tafrahq/wt-tunnel-binaries/frp';
|
|
8
|
+
import { Effect } from 'effect';
|
|
9
|
+
|
|
10
|
+
import { ServerError } from './errors.ts';
|
|
11
|
+
|
|
12
|
+
const pins = { caddy: caddyPin, frps: frpPin('frps') } as const;
|
|
13
|
+
|
|
14
|
+
type BinaryName = keyof typeof pins;
|
|
15
|
+
|
|
16
|
+
/** The Caddy and frps executables the server runs. */
|
|
17
|
+
type Binaries = Readonly<Record<BinaryName, string>>;
|
|
18
|
+
|
|
19
|
+
/** Where to look for a binary that no flag names. */
|
|
20
|
+
interface Search {
|
|
21
|
+
/** The cache directory pinned downloads go under. */
|
|
22
|
+
readonly cacheDir: string;
|
|
23
|
+
/** A PATH-style list of directories. */
|
|
24
|
+
readonly path: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const isExecutableFile = (file: string) =>
|
|
28
|
+
Effect.promise(async () => {
|
|
29
|
+
try {
|
|
30
|
+
await access(file, constants.X_OK);
|
|
31
|
+
const stats = await stat(file);
|
|
32
|
+
return stats.isFile();
|
|
33
|
+
} catch {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const firstOnPath = (name: string, path: string) =>
|
|
39
|
+
Effect.gen(function* searchPath() {
|
|
40
|
+
const candidates = path
|
|
41
|
+
.split(delimiter)
|
|
42
|
+
.filter(Boolean)
|
|
43
|
+
.map((dir) => join(dir, name));
|
|
44
|
+
const executable = yield* Effect.all(candidates.map((file) => isExecutableFile(file)));
|
|
45
|
+
return candidates.find((_file, index) => executable[index] === true);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
/** The flag's path, else the first on PATH, else the pinned release in the cache. */
|
|
49
|
+
const resolveBinary = (name: BinaryName, flag: string | undefined, search: Search) =>
|
|
50
|
+
Effect.gen(function* flagPathOrDownload() {
|
|
51
|
+
if (flag !== undefined) {
|
|
52
|
+
const file = resolve(flag);
|
|
53
|
+
if (!(yield* isExecutableFile(file))) {
|
|
54
|
+
return yield* new ServerError({ message: `--${name} ${flag} is not an executable file` });
|
|
55
|
+
}
|
|
56
|
+
return file;
|
|
57
|
+
}
|
|
58
|
+
const found = yield* firstOnPath(name, search.path);
|
|
59
|
+
if (found !== undefined) {
|
|
60
|
+
return found;
|
|
61
|
+
}
|
|
62
|
+
const pin = pins[name];
|
|
63
|
+
return yield* pinnedBinary(pin, join(search.cacheDir, name, pin.version, name)).pipe(
|
|
64
|
+
Effect.mapError(
|
|
65
|
+
({ message }: { readonly message: string }) =>
|
|
66
|
+
new ServerError({
|
|
67
|
+
message: `${message} Pass --${name} <path> to use one you installed.`,
|
|
68
|
+
}),
|
|
69
|
+
),
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const resolveBinaries = (flags: Readonly<Record<BinaryName, string | undefined>>) => {
|
|
74
|
+
const search = { cacheDir: join(cacheHome(), 'wt-tunnel-server'), path: process.env.PATH ?? '' };
|
|
75
|
+
return Effect.all({
|
|
76
|
+
caddy: resolveBinary('caddy', flags.caddy, search),
|
|
77
|
+
frps: resolveBinary('frps', flags.frps, search),
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export { resolveBinaries, resolveBinary };
|
|
82
|
+
export type { Binaries };
|
package/src/brand.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The small wt-tunnel mark, assets/brand/wt-tunnel-small.svg, as the pages' favicon. It is inlined
|
|
3
|
+
* as a data URI, so the pages load nothing from elsewhere; a test keeps it equal to the file.
|
|
4
|
+
*/
|
|
5
|
+
const markSvg =
|
|
6
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><title>wt-tunnel</title><defs><linearGradient id="wt-tunnel-bg" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#1d4ed8"/><stop offset="1" stop-color="#172554"/></linearGradient></defs><rect width="64" height="64" rx="14" fill="url(#wt-tunnel-bg)"/><path d="M12 56V32a20 20 0 0 1 40 0v24" fill="none" stroke="#5eead4" stroke-width="8" stroke-linecap="round"/><path d="M32 56V36" fill="none" stroke="#fff" stroke-width="6" stroke-linecap="round"/><circle cx="32" cy="31" r="7" fill="#fff"/></svg>';
|
|
7
|
+
|
|
8
|
+
const faviconLink = `<link rel="icon" href="data:image/svg+xml,${encodeURIComponent(markSvg)}">`;
|
|
9
|
+
|
|
10
|
+
export { faviconLink, markSvg };
|
package/src/ca-page.ts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import type { IncomingMessage } from 'node:http';
|
|
2
|
+
|
|
3
|
+
import { faviconLink } from './brand.ts';
|
|
4
|
+
import { escapeHtml, header, status } from './reply.ts';
|
|
5
|
+
import type { Reply } from './reply.ts';
|
|
6
|
+
import { mobileconfig } from './root-ca.ts';
|
|
7
|
+
import type { RootCa } from './root-ca.ts';
|
|
8
|
+
|
|
9
|
+
const caPath = '/ca';
|
|
10
|
+
/** Five minutes: long enough to spare the service, short enough to pick up a new root soon. */
|
|
11
|
+
const cacheControl = 'public, max-age=300';
|
|
12
|
+
|
|
13
|
+
type Platform = 'android' | 'firefox' | 'ios' | 'linux' | 'macos' | 'windows';
|
|
14
|
+
|
|
15
|
+
interface Guide {
|
|
16
|
+
readonly html: (file: string) => string;
|
|
17
|
+
readonly platform: Platform;
|
|
18
|
+
readonly title: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const code = (text: string) => `<pre><code>${escapeHtml(text)}</code></pre>`;
|
|
22
|
+
const steps = (items: readonly string[]) =>
|
|
23
|
+
`<ol>${items.map((item) => `<li>${item}</li>`).join('')}</ol>`;
|
|
24
|
+
|
|
25
|
+
/** One section per platform, in the order shown after the visitor's own. */
|
|
26
|
+
const guides: readonly Guide[] = [
|
|
27
|
+
{
|
|
28
|
+
html: (file) =>
|
|
29
|
+
`<p>In Terminal, from the folder you downloaded it to:</p>${code(`sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ${file}`)}<p>Or with Keychain Access:</p>${steps(['Double-click the downloaded file. Keychain Access adds it to a keychain.', 'Find the certificate in Keychain Access and open it.', 'Expand <b>Trust</b> and set <b>When using this certificate</b> to <b>Always Trust</b>.', 'Close the window and enter your password.'])}`,
|
|
30
|
+
platform: 'macos',
|
|
31
|
+
title: 'macOS',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
html: () =>
|
|
35
|
+
steps([
|
|
36
|
+
'In Safari, open <a href="/ca.mobileconfig">the configuration profile</a> and allow the download.',
|
|
37
|
+
'Open <b>Settings</b> and tap <b>Profile Downloaded</b>, then <b>Install</b>.',
|
|
38
|
+
'Go to <b>Settings</b> > <b>General</b> > <b>About</b> > <b>Certificate Trust Settings</b> and turn on full trust for the wt-tunnel root.',
|
|
39
|
+
]),
|
|
40
|
+
platform: 'ios',
|
|
41
|
+
title: 'iPhone and iPad',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
html: () =>
|
|
45
|
+
steps([
|
|
46
|
+
'Download <a href="/ca.crt">the certificate</a>.',
|
|
47
|
+
'Open <b>Settings</b> > <b>Security</b> (on some phones <b>Security and privacy</b> > <b>More security settings</b>) > <b>Encryption & credentials</b> > <b>Install a certificate</b> > <b>CA certificate</b>.',
|
|
48
|
+
'Accept the warning and pick the downloaded file.',
|
|
49
|
+
]),
|
|
50
|
+
platform: 'android',
|
|
51
|
+
title: 'Android',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
html: (file) =>
|
|
55
|
+
`<p>In an administrator Command Prompt, from the download folder:</p>${code(`certutil -addstore -f Root ${file}`)}<p>Without administrator rights, <code>certutil -user -addstore Root ${escapeHtml(file)}</code> trusts it for your account only. Or open the file, select <b>Install Certificate</b>, and place it in <b>Trusted Root Certification Authorities</b>.</p>`,
|
|
56
|
+
platform: 'windows',
|
|
57
|
+
title: 'Windows',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
html: (file) =>
|
|
61
|
+
`<p>Debian and Ubuntu:</p>${code(`sudo cp ${file} /usr/local/share/ca-certificates/\nsudo update-ca-certificates`)}<p>Fedora and RHEL:</p>${code(`sudo cp ${file} /etc/pki/ca-trust/source/anchors/\nsudo update-ca-trust`)}<p>Chrome and Chromium on Linux read their own store. With <code>certutil</code> from libnss3-tools or nss-tools:</p>${code(`certutil -d sql:$HOME/.pki/nssdb -A -t C,, -n wt-tunnel -i ${file}`)}`,
|
|
62
|
+
platform: 'linux',
|
|
63
|
+
title: 'Linux',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
html: () =>
|
|
67
|
+
`<p>Firefox keeps its own store. On Windows and macOS it also trusts the system's roots by default; on Linux, import the file:</p>${steps(['Open <b>Settings</b> > <b>Privacy & Security</b> > <b>Certificates</b> > <b>View Certificates</b>.', 'On <b>Authorities</b>, select <b>Import</b> and pick the downloaded file.', 'Tick <b>Trust this CA to identify websites</b>.'])}`,
|
|
68
|
+
platform: 'firefox',
|
|
69
|
+
title: 'Firefox',
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
/** IPads asking for desktop sites say Macintosh; they find their section second. */
|
|
74
|
+
const platformOf = (userAgent: string): Platform | undefined => {
|
|
75
|
+
if (/iPhone|iPad|iPod/u.test(userAgent)) {
|
|
76
|
+
return 'ios';
|
|
77
|
+
}
|
|
78
|
+
if (/Android/u.test(userAgent)) {
|
|
79
|
+
return 'android';
|
|
80
|
+
}
|
|
81
|
+
if (/Windows/u.test(userAgent)) {
|
|
82
|
+
return 'windows';
|
|
83
|
+
}
|
|
84
|
+
if (/Macintosh|Mac OS X/u.test(userAgent)) {
|
|
85
|
+
return 'macos';
|
|
86
|
+
}
|
|
87
|
+
return /Linux|X11|CrOS/u.test(userAgent) ? 'linux' : undefined;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/** The visitor's platform first, then Firefox if they use it on a desktop, then the rest. */
|
|
91
|
+
const guideOrder = (userAgent: string): readonly Guide[] => {
|
|
92
|
+
const platform = platformOf(userAgent);
|
|
93
|
+
const desktopFirefox =
|
|
94
|
+
/Firefox\//u.test(userAgent) && platform !== 'ios' && platform !== 'android';
|
|
95
|
+
const rank = (guide: Guide) => {
|
|
96
|
+
if (guide.platform === platform) {
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
return guide.platform === 'firefox' && desktopFirefox
|
|
100
|
+
? 1
|
|
101
|
+
: guides.indexOf(guide) + guides.length;
|
|
102
|
+
};
|
|
103
|
+
return guides.toSorted((left, right) => rank(left) - rank(right));
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const style =
|
|
107
|
+
'body{font:16px/1.5 system-ui,sans-serif;max-width:46rem;margin:2rem auto;padding:0 1rem}pre{background:#f3f3f3;padding:.6rem;overflow-x:auto;white-space:pre-wrap;word-break:break-all}dt{font-weight:600}dd{margin:0 0 .6rem}.button{display:inline-block;padding:.6rem 1rem;background:#1f6feb;color:#fff;border-radius:6px;text-decoration:none;margin:0 .5rem .5rem 0}';
|
|
108
|
+
|
|
109
|
+
const constraintsHtml = (root: RootCa) =>
|
|
110
|
+
root.permitted.length === 0
|
|
111
|
+
? '<dd>None. This root could vouch for any name; do not trust it.</dd>'
|
|
112
|
+
: `<dd>${root.permitted.map((name) => `<code>${escapeHtml(name)}</code>`).join(', ')}</dd><dd>This root can only vouch for names under these domains. Trusting it does not let anyone impersonate any other site.</dd>`;
|
|
113
|
+
|
|
114
|
+
const caPage = (root: RootCa, userAgent: string) => {
|
|
115
|
+
const file = `${root.fileName}.crt`;
|
|
116
|
+
const sections = guideOrder(userAgent)
|
|
117
|
+
.map(
|
|
118
|
+
(guide) =>
|
|
119
|
+
`<section id="${guide.platform}"><h3>${guide.title}</h3>${guide.html(file)}</section>`,
|
|
120
|
+
)
|
|
121
|
+
.join('');
|
|
122
|
+
return `<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width">${faviconLink}<title>Trust this deployment's certificate</title><style>${style}</style><h1>Trust this deployment's certificate</h1><p>Dev URLs under ${root.domains.map((domain) => `<code>${escapeHtml(domain)}</code>`).join(', ')} use certificates from this deployment's own root, so that no worktree name shows up in public Certificate Transparency logs. Install the root once on each device that opens them.</p><p><a class="button" href="/ca.crt" download="${escapeHtml(file)}">Download ${escapeHtml(file)}</a><a class="button" href="/ca.mobileconfig">iPhone and iPad profile</a></p><h2>The root</h2><dl><dt>Subject</dt><dd>${escapeHtml(root.subject)}</dd><dt>Valid</dt><dd>${root.validFrom} to ${root.validTo}</dd><dt>SHA-256 fingerprint</dt><dd><code>${root.fingerprint}</code></dd><dt>Permitted names</dt>${constraintsHtml(root)}</dl><p>Check that the fingerprint your device shows matches the one above before you trust it.</p><h2>Install it</h2>${sections}<h2>Then restart the browser</h2><p>Quit and reopen the browser so it reads the new root.</p>\n`;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const download = (body: string, contentType: string, fileName: string): Reply => ({
|
|
126
|
+
body,
|
|
127
|
+
headers: {
|
|
128
|
+
'cache-control': cacheControl,
|
|
129
|
+
'content-disposition': `attachment; filename="${fileName}"`,
|
|
130
|
+
'content-type': contentType,
|
|
131
|
+
'x-content-type-options': 'nosniff',
|
|
132
|
+
},
|
|
133
|
+
status: status.ok,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
/** The public trust routes on the sign-in host, or undefined for any other path. */
|
|
137
|
+
const caRoute = (request: IncomingMessage, path: string, root: RootCa): Reply | undefined => {
|
|
138
|
+
switch (path) {
|
|
139
|
+
case caPath: {
|
|
140
|
+
return {
|
|
141
|
+
body: caPage(root, header(request, 'user-agent') ?? ''),
|
|
142
|
+
headers: {
|
|
143
|
+
'cache-control': cacheControl,
|
|
144
|
+
'content-type': 'text/html; charset=utf-8',
|
|
145
|
+
vary: 'User-Agent',
|
|
146
|
+
},
|
|
147
|
+
status: status.ok,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
case '/ca.crt': {
|
|
151
|
+
return download(root.pem, 'application/x-x509-ca-cert', `${root.fileName}.crt`);
|
|
152
|
+
}
|
|
153
|
+
case '/ca.mobileconfig': {
|
|
154
|
+
return download(
|
|
155
|
+
mobileconfig(root),
|
|
156
|
+
'application/x-apple-aspen-config',
|
|
157
|
+
`${root.fileName}.mobileconfig`,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
default: {
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export { caPath, caRoute };
|
package/src/children.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import type { ChildProcess } from 'node:child_process';
|
|
3
|
+
import { once } from 'node:events';
|
|
4
|
+
import { createInterface } from 'node:readline';
|
|
5
|
+
import type { Readable } from 'node:stream';
|
|
6
|
+
|
|
7
|
+
import { Effect } from 'effect';
|
|
8
|
+
|
|
9
|
+
const stopGraceMillis = 10_000;
|
|
10
|
+
/** How many of a child's last output lines to keep for explaining why it exited. */
|
|
11
|
+
const keptLines = 20;
|
|
12
|
+
|
|
13
|
+
interface ChildSpec {
|
|
14
|
+
readonly args: readonly string[];
|
|
15
|
+
readonly command: string;
|
|
16
|
+
readonly env: Readonly<Record<string, string>>;
|
|
17
|
+
readonly name: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface Child {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
/** The child's last output lines, oldest first. */
|
|
23
|
+
readonly output: readonly string[];
|
|
24
|
+
readonly process: ChildProcess;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface Exited {
|
|
28
|
+
readonly name: string;
|
|
29
|
+
readonly output: readonly string[];
|
|
30
|
+
readonly reason: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const eachLine = (stream: Readable | null, onLine: (line: string) => void) => {
|
|
34
|
+
if (stream !== null) {
|
|
35
|
+
createInterface({ input: stream }).on('line', onLine);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const startChild = (spec: ChildSpec): Child => {
|
|
40
|
+
const output: string[] = [];
|
|
41
|
+
const child = spawn(spec.command, [...spec.args], {
|
|
42
|
+
env: { ...process.env, ...spec.env },
|
|
43
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
44
|
+
});
|
|
45
|
+
const onLine = (line: string) => {
|
|
46
|
+
console.log(`[${spec.name}] ${line}`);
|
|
47
|
+
output.push(line);
|
|
48
|
+
output.splice(0, output.length - keptLines);
|
|
49
|
+
};
|
|
50
|
+
eachLine(child.stdout, onLine);
|
|
51
|
+
eachLine(child.stderr, onLine);
|
|
52
|
+
return { name: spec.name, output, process: child };
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const running = (child: Child) =>
|
|
56
|
+
child.process.exitCode === null && child.process.signalCode === null;
|
|
57
|
+
|
|
58
|
+
/** SIGTERM to every child still running, then SIGKILL to any left after the grace period. */
|
|
59
|
+
const stopChildren = (children: readonly Child[]) =>
|
|
60
|
+
Effect.promise(async () => {
|
|
61
|
+
const alive = children.filter((child) => running(child));
|
|
62
|
+
const exits = alive.map((child) => once(child.process, 'exit'));
|
|
63
|
+
for (const child of alive) {
|
|
64
|
+
child.process.kill('SIGTERM');
|
|
65
|
+
}
|
|
66
|
+
const timer = setTimeout(() => {
|
|
67
|
+
for (const child of alive.filter((candidate) => running(candidate))) {
|
|
68
|
+
child.process.kill('SIGKILL');
|
|
69
|
+
}
|
|
70
|
+
}, stopGraceMillis);
|
|
71
|
+
await Promise.all(exits);
|
|
72
|
+
clearTimeout(timer);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
/** Starts the children for the scope; closing the scope stops them. */
|
|
76
|
+
const startChildren = (specs: readonly ChildSpec[]) =>
|
|
77
|
+
Effect.acquireRelease(
|
|
78
|
+
Effect.sync(() => specs.map((spec) => startChild(spec))),
|
|
79
|
+
(children: readonly Child[]) => stopChildren(children),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const childExit = ({ name, output, process: child }: Child) =>
|
|
83
|
+
Effect.callback<Exited>((resume) => {
|
|
84
|
+
child.once('error', (error: Readonly<Error>) => {
|
|
85
|
+
resume(Effect.succeed({ name, output, reason: error.message }));
|
|
86
|
+
});
|
|
87
|
+
// 'close' waits for the output streams to end, so `output` holds the last lines.
|
|
88
|
+
child.once('close', (code, signal) => {
|
|
89
|
+
resume(Effect.succeed({ name, output, reason: `code ${code} signal ${signal}` }));
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
/** Completes with the first child to exit or fail to spawn. */
|
|
94
|
+
const firstExit = (children: readonly Child[]) =>
|
|
95
|
+
Effect.raceAll(children.map((child) => childExit(child)));
|
|
96
|
+
|
|
97
|
+
export { firstExit, startChildren };
|
|
98
|
+
export type { Exited };
|