Public
Script
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
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
interface ValResponse {
id: string;
author: {
id: string;
username: string;
};
name: string;
code: string;
public: boolean;
privacy: "public" | "unlisted" | "private"; // Added privacy type
version: number;
runEndAt: string;
runStartAt: string;
logs: any[];
output: object;
error: object | null;
readme: string | null;
likeCount: number;
referenceCount: number;
}
interface CreateValArgs {
token: string;
code: string;
name?: string;
readme?: string;
privacy?: "public" | "unlisted" | "private"; // Added privacy option
}
export function createVal({ token, code, name, readme, privacy }: CreateValArgs): Promise<ValResponse> {
const body: Record<string, unknown> = {
code,
token,
name,
readme,
privacy,
};
return fetchJSON("https://api.val.town/v1/vals", {
headers: {
Authorization: `Bearer ${token}`,
},
method: "POST",
body: JSON.stringify(body),
});
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
v6 was merged from the PR "Modified to include name, readme, privacy in re…" by nbbaier
January 13, 2024
Nice one @nbbaier - much better with the full return value!