@fungi.computer/oyster 0.12.0 → 0.13.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/dist/build/candidate-cli.mjs +7 -1
- package/dist/build/local-build.js +4 -1
- package/dist/build/workspace-build.d.ts +1 -1
- package/dist/embed-scripts.js +1 -1
- package/dist/hello-app-script.d.ts +2 -0
- package/dist/hello-app-script.js +1 -0
- package/dist/host-page-assets.d.ts +12 -0
- package/dist/host-page-assets.js +1 -0
- package/dist/host-page.d.ts +26 -0
- package/dist/host-page.js +302 -0
- package/dist/host.js +108 -41
- package/dist/page-script.d.ts +1 -1
- package/dist/page-script.js +1 -1
- package/dist/standalone/hello-app.d.ts +1 -0
- package/dist/standalone/hello-app.js +5 -2
- package/dist/standalone/local-desktop.js +2 -2
- package/dist/standalone/sign-in-link.js +36 -15
- package/dist/standalone/try-cli.js +24 -1
- package/package.json +9 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare const helloPage = "<!doctype html>\n<title>Hello</title>\n<h1>Hello from my first Oyster App</h1>\n<script type=\"module\" src=\"./main.js\"></script>\n";
|
|
1
2
|
/** Pack the Hello App kept at `<directory>/hello-app` and install it as
|
|
2
3
|
* `hello`; answers the HTTP status (201 new, 200 when already installed).
|
|
3
4
|
* The first call writes and commits the source; later calls pack its current
|
|
@@ -6,13 +6,15 @@ import { execFileSync } from "node:child_process";
|
|
|
6
6
|
import { access, mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
7
7
|
import { tmpdir } from "node:os";
|
|
8
8
|
import { join } from "node:path";
|
|
9
|
+
import { helloAppScript } from "#hello-app-script";
|
|
9
10
|
import { installRelease, packRelease } from "../pack.js";
|
|
10
11
|
const manifest = {
|
|
11
12
|
name: "hello-app",
|
|
12
13
|
private: true,
|
|
13
14
|
fungi: { app: { displayName: "Hello", icon: "fungi", capabilities: [] } },
|
|
14
15
|
};
|
|
15
|
-
|
|
16
|
+
// The script announces the page to Oyster; without it the window never opens.
|
|
17
|
+
export const helloPage = '<!doctype html>\n<title>Hello</title>\n<h1>Hello from my first Oyster App</h1>\n<script type="module" src="./main.js"></script>\n';
|
|
16
18
|
const exists = (path) => access(path).then(() => true, () => false);
|
|
17
19
|
const git = (directory, args) => execFileSync("git", [
|
|
18
20
|
"-C",
|
|
@@ -28,7 +30,8 @@ async function writeHelloApp(directory) {
|
|
|
28
30
|
const source = join(directory, "hello-app");
|
|
29
31
|
await mkdir(join(source, "bundle"), { recursive: true });
|
|
30
32
|
await writeFile(join(source, "package.json"), JSON.stringify(manifest, null, 2) + "\n");
|
|
31
|
-
await writeFile(join(source, "bundle", "index.html"),
|
|
33
|
+
await writeFile(join(source, "bundle", "index.html"), helloPage);
|
|
34
|
+
await writeFile(join(source, "bundle", "main.js"), helloAppScript);
|
|
32
35
|
git(source, ["init", "-q"]);
|
|
33
36
|
git(source, ["add", "."]);
|
|
34
37
|
git(source, ["commit", "-qm", "Hello App"]);
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// packer and installs it as the home installation, approving its shell the
|
|
5
5
|
// same way `install-apps` does.
|
|
6
6
|
import { execFileSync } from "node:child_process";
|
|
7
|
-
import { mkdtemp, rm } from "node:fs/promises";
|
|
7
|
+
import { mkdtemp, realpath, rm } from "node:fs/promises";
|
|
8
8
|
import { tmpdir } from "node:os";
|
|
9
9
|
import { join } from "node:path";
|
|
10
10
|
import * as Schema from "effect/Schema";
|
|
@@ -31,7 +31,7 @@ export async function isInstalled(input) {
|
|
|
31
31
|
}
|
|
32
32
|
/** Build Tourtois from source on this machine and install it as `tourtois`. */
|
|
33
33
|
export async function installLocalDesktop(input) {
|
|
34
|
-
const scratch = await mkdtemp(join(tmpdir(), "oyster-tourtois-"));
|
|
34
|
+
const scratch = await realpath(await mkdtemp(join(tmpdir(), "oyster-tourtois-")));
|
|
35
35
|
try {
|
|
36
36
|
const source = join(scratch, "tourtois");
|
|
37
37
|
git(scratch, ["clone", "--quiet", "--depth=1", tourtoisRepository, source]);
|
|
@@ -1,33 +1,54 @@
|
|
|
1
1
|
// A one-time sign-in link for `oyster try`. The owner key never goes in a URL:
|
|
2
2
|
// the link opens a page served by this process that posts the key to the local
|
|
3
3
|
// Oyster's own /login form, then the server forgets the link.
|
|
4
|
-
import { randomBytes } from "node:crypto";
|
|
4
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
5
5
|
import { createServer } from "node:http";
|
|
6
6
|
import * as z from "zod";
|
|
7
|
+
import { hostPage } from "../host-page.js";
|
|
8
|
+
import { loadPageAssets } from "../page-assets.js";
|
|
7
9
|
const addressSchema = z.object({ port: z.number() });
|
|
8
10
|
const lifetimeMs = 10 * 60_000;
|
|
9
|
-
const escapeAttribute = (text) => text.replace(/[&"<>]/gu, (character) => `&#${String(character.codePointAt(0))};`);
|
|
10
11
|
/** Serve one single-use page that signs the owner in to `oysterUrl`. */
|
|
11
12
|
export async function startSignInLink(input) {
|
|
12
13
|
const nonce = Array.from(randomBytes(18), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
13
14
|
let used = false;
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const sources = await loadPageAssets();
|
|
16
|
+
const stylesheets = Object.entries({
|
|
17
|
+
"styles.css": sources.shellStyles,
|
|
18
|
+
"login-fonts.css": sources.loginFontStyles,
|
|
19
|
+
}).map(([name, source]) => `/_oyster/assets/${createHash("sha256")
|
|
20
|
+
.update(source)
|
|
21
|
+
.digest("hex")}/${name}`);
|
|
22
|
+
const pageOptions = { oysterUrl: input.oysterUrl, stylesheets };
|
|
23
|
+
let page = await (await hostPage({
|
|
24
|
+
...pageOptions,
|
|
25
|
+
state: "signing-in",
|
|
26
|
+
signIn: {
|
|
27
|
+
action: new URL("/login", input.oysterUrl).href,
|
|
28
|
+
key: input.key,
|
|
29
|
+
},
|
|
30
|
+
})).text();
|
|
31
|
+
const expired = await (await hostPage({ ...pageOptions, state: "link-expired", status: 404 })).text();
|
|
32
|
+
const notFound = await (await hostPage({ ...pageOptions, state: "not-found", status: 404 })).text();
|
|
18
33
|
const server = createServer((request, response) => {
|
|
19
|
-
|
|
20
|
-
response.writeHead(404, { "Cache-Control": "no-store" }).end("Not found");
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
used = true;
|
|
24
|
-
response
|
|
25
|
-
.writeHead(200, {
|
|
34
|
+
const headers = {
|
|
26
35
|
"Content-Type": "text/html; charset=utf-8",
|
|
27
36
|
"Cache-Control": "no-store",
|
|
28
37
|
"Referrer-Policy": "no-referrer",
|
|
29
|
-
|
|
30
|
-
|
|
38
|
+
"X-Robots-Tag": "noindex, nofollow",
|
|
39
|
+
"X-Content-Type-Options": "nosniff",
|
|
40
|
+
};
|
|
41
|
+
if (request.method !== "GET" || request.url !== `/${nonce}`) {
|
|
42
|
+
response.writeHead(404, headers).end(notFound);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (used) {
|
|
46
|
+
response.writeHead(404, headers).end(expired);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
used = true;
|
|
50
|
+
response.writeHead(200, headers).end(page);
|
|
51
|
+
page = "";
|
|
31
52
|
setTimeout(() => {
|
|
32
53
|
server.close();
|
|
33
54
|
}, 1_000).unref();
|
|
@@ -69,6 +69,27 @@ export function createTryCli(args) {
|
|
|
69
69
|
? new Cli({ brand: "fungi", interactive: false })
|
|
70
70
|
: new Cli({ brand: "fungi" });
|
|
71
71
|
}
|
|
72
|
+
/** The deepest Error in a `cause` chain, where the real failure lives. */
|
|
73
|
+
function innermostError(cause) {
|
|
74
|
+
let current = cause instanceof Error ? cause : new Error(String(cause));
|
|
75
|
+
for (let depth = 0; depth < 10; depth += 1) {
|
|
76
|
+
if (!(current.cause instanceof Error))
|
|
77
|
+
break;
|
|
78
|
+
current = current.cause;
|
|
79
|
+
}
|
|
80
|
+
return current;
|
|
81
|
+
}
|
|
82
|
+
const networkErrorCodes = new Set([
|
|
83
|
+
"ENOTFOUND",
|
|
84
|
+
"EAI_AGAIN",
|
|
85
|
+
"ECONNREFUSED",
|
|
86
|
+
"ECONNRESET",
|
|
87
|
+
"ETIMEDOUT",
|
|
88
|
+
"ENETUNREACH",
|
|
89
|
+
]);
|
|
90
|
+
function isNetworkFailure(error) {
|
|
91
|
+
return "code" in error && networkErrorCodes.has(error.code);
|
|
92
|
+
}
|
|
72
93
|
/** Show a failed `oyster try` as an error with its next step. */
|
|
73
94
|
export function reportTryFailure(cause, ui) {
|
|
74
95
|
if (cause instanceof TryError)
|
|
@@ -367,7 +388,9 @@ export async function tryOyster(args, effects = realEffects, ui = createTryCli(a
|
|
|
367
388
|
? "Building Tourtois (about 2 min the first time)"
|
|
368
389
|
: "Checking Tourtois", () => effects.installDesktop({ directory, url, key }))
|
|
369
390
|
.catch((cause) => {
|
|
370
|
-
ui.warn(`Tourtois, the desktop, could not be built (${cause
|
|
391
|
+
ui.warn(`Tourtois, the desktop, could not be built (${innermostError(cause).message}). Continuing with the Hello App.`, isNetworkFailure(innermostError(cause))
|
|
392
|
+
? `Connect to the internet and run \`${command}\` again from ${directory} to try the desktop again.`
|
|
393
|
+
: `Run \`${command} --verbose\` from ${directory} and report this.`);
|
|
371
394
|
});
|
|
372
395
|
const link = await ui.task("Opening your desktop", async () => {
|
|
373
396
|
const made = await effects.signInLink({ oysterUrl: url, key });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fungi.computer/oyster",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"author": "Levi <levi@technomancy.dev>",
|
|
5
5
|
"description": "Run your own Apps on Cloudflare Workers or celld: installable App Releases, each with its own Durable Object, SQLite database and declared bindings",
|
|
6
6
|
"type": "module",
|
|
@@ -30,6 +30,10 @@
|
|
|
30
30
|
"types": "./src/frame-binding-wire-script.d.ts",
|
|
31
31
|
"default": "./dist/frame-binding-wire-script.js"
|
|
32
32
|
},
|
|
33
|
+
"#hello-app-script": {
|
|
34
|
+
"types": "./src/hello-app-script.d.ts",
|
|
35
|
+
"default": "./dist/hello-app-script.js"
|
|
36
|
+
},
|
|
33
37
|
"#page-script": {
|
|
34
38
|
"types": "./src/page-script.d.ts",
|
|
35
39
|
"default": "./dist/page-script.js"
|
|
@@ -37,6 +41,10 @@
|
|
|
37
41
|
"#snapshot-program-scripts": {
|
|
38
42
|
"types": "./src/build/snapshot-program-scripts.d.ts",
|
|
39
43
|
"default": "./dist/build/snapshot-program-scripts.js"
|
|
44
|
+
},
|
|
45
|
+
"#host-page-assets": {
|
|
46
|
+
"types": "./src/host-page-assets.d.ts",
|
|
47
|
+
"default": "./dist/host-page-assets.js"
|
|
40
48
|
}
|
|
41
49
|
},
|
|
42
50
|
"exports": {
|