Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

Sunbeam integration for Val Town

Installation

First, install sunbeam.

Then create a new val referencing this val.

const sunbeamValtown = @pomdtr.sunbeamValTownFn(@me.secrets.valtown)

then switch it's visibility to unlisted.

46b309779996a810253227eeb3cd3580ac8a4edd346cbf6b60ca18748a95ea36.png

You can then install your val in sunbeam

# install the extension sunbeam extension install --alias valtown val:<username>/sunbeamValtown

Usage

sunbeam valtown # list your vals sunbeam valtown --help # list available commands

Demo

62fd8643bec98164e6e6a97447fc3947d39fea827d2641d9a6dcb86e276bfe35.png

ec86d87e149e7c4d9013d6f1ff0ac2236c9f85b9323be50ccc50f4cdcbd3dc45.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { fetch } from "https://esm.town/v/std/fetch";
export function sunbeamValTownFn(valtownToken: string) {
return async (req: Request) => {
const { Hono } = await import("npm:hono");
const app = new Hono();
// extension manifest
app.get("/", async (c) => {
const resp = await fetch("https://api.val.town/v1/me", {
headers: {
Authorization: `Bearer ${valtownToken}`,
},
});
const { id: userID } = await resp.json();
return c.json({
title: "Val Town",
commands: [
{
name: "search-vals",
title: "Seach Vals",
mode: "view",
params: [
{
name: "user",
type: "string",
description: "User ID",
default: userID,
},
],
},
{
name: "view-val",
title: "view-val",
mode: "view",
params: [
{
name: "val",
type: "string",
description: "Val ID",
required: true,
},
],
},
],
});
});
// search-val command handler
app.post("/search-vals", async (c) => {
const { params, query } = await c.req.json();
const { user } = params;
const endpoint = query
? `https://api.val.town/v1/search/vals?query=${
encodeURIComponent(query)
}`
: `https://api.val.town/v1/users/${user}/vals`;
const resp = await fetch(endpoint, {
headers: {
Authorization: `Bearer ${valtownToken}`,
},
});
const { data: vals } = await resp.json();
return c.json({
type: "list",
dynamic: true,
items: vals.map((val) => {
const fullName = `${val.author.username}.${val.name}`;
return {
title: fullName,
accessories: [val.privacy],
actions: [
{
title: "View Val",
onAction: {
type: "run",
command: "view-val",
params: {
val: val.id,
},
},
},
{
title: "Open Val",
key: "o",
onAction: {
type: "open",
exit: true,
target: `https://val.town/v/${fullName}`,
},
},
],
};
}),
});
});
// view-val command handler
app.post("/view-val", async (c) => {
const { params } = await c.req.json();
const resp = await fetch(`https://api.val.town/v1/vals/${params.val}`, {
headers: {
Authorization: `Bearer ${valtownToken}`,
pomdtr-sunbeamvaltownfn.web.val.run
October 23, 2023