@fungi.computer/oyster 0.12.1 → 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/workspace-build.d.ts +1 -1
- package/dist/embed-scripts.js +1 -1
- 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/sign-in-link.js +36 -15
- package/package.json +5 -1
|
@@ -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();
|
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",
|
|
@@ -41,6 +41,10 @@
|
|
|
41
41
|
"#snapshot-program-scripts": {
|
|
42
42
|
"types": "./src/build/snapshot-program-scripts.d.ts",
|
|
43
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"
|
|
44
48
|
}
|
|
45
49
|
},
|
|
46
50
|
"exports": {
|