5};
6
7export function basicAuth(next: (Request) => Response | Promise<Response>, options: BasicAuthOptions) {
8 return async (req: Request) => {
9 if (req.headers.get("referer") == "https://www.val.town/") {
33}
34
35function extractCredentials(authorization): { username: string; password: string } {
36 const parts = authorization.split(" ");
37 if (parts[0] != "Basic") {
47}
48
49async function isRequestAuthenticated(req, userTable: string) {
50 if (!req.headers.has("authorization")) {
51 return false;
4import {Scrypt, generateId} from "npm:lucia"
5
6export async function createTables(userTable: string, sessionTable: string) {
7 return sqlite.batch([
8 `CREATE TABLE ${userTable} (
20}
21
22export async function createUser(table: string, username: string, password: string) {
23 if (
24 username.length < 3
43}
44
45export async function getUser(
46 table: string,
47 username: string,
56}
57
58export async function verifyPassword(hashed_password: string, password: string): Promise<boolean> {
59 return new Scrypt().verify(hashed_password, password);
60}
127}
128
129function transformIntoDatabaseSession(raw: SessionSchema): DatabaseSession {
130 const { id, user_id: userId, expires_at: expiresAtUnix, ...attributes } = raw;
131 return {
137}
138
139function transformIntoDatabaseUser(raw: UserSchema): DatabaseUser {
140 const { id, ...attributes } = raw;
141 return {
145}
146
147function escapeName(val: string): string {
148 return "`" + val + "`";
149}
1import { sqlite } from "https://esm.town/v/std/sqlite?v=4";
2
3export async function listSqliteTables() {
4 return (await sqlite.execute(
5 `select name from sqlite_schema where type='table' and name != 'libsql_wasm_func_table' and name != 'sqlite_sequence'`,
57};
58
59function TestItem({ test, run }: { test: Test; run: () => void }) {
60 return (
61 <div>
75}
76
77function groupBySlug(tests: Test[]): Record<string, Test[]> {
78 const groups = {};
79 for (const test of Object.values(tests)) {
89}
90
91function useTests(initialTests: Test[]) {
92 const id = (test: Test) => `${test.val.name}/${test.name}`;
93 const [tests, setTests] = useState(Object.fromEntries(initialTests.map((test) => {
118}
119
120function TestExplorerView({ tests }: Props) {
121 const { groups, runTest } = useTests(tests);
122 return (
187}
188
189export default function(props: { tests: Test[] }) {
190 return (
191 <>
24export default router.fetch;
25
26export async function createScreenshot(code: string, theme: string = "dark-plus"): Promise<URL> {
27 const apiUrl = "https://sourcecodeshots.com/api/image/permalink";
28 const { url } = await ky.post(apiUrl, {
35}
36
37async function fetchValCode(alias: string): Promise<string> {
38 const prefixUrl = "https://api.val.town/v1/alias";
39 const { code } = await ky.get(alias, { prefixUrl }).json();
3import { pathMatches } from "https://esm.town/v/postpostscript/pathAsScope";
4
5export async function authDescribeScopes(scopes: string[]) {
6 return Promise.all(scopes.map(async (scope) => {
7 const [author, name, ..._scopeName] = scope.slice(1).split("/");
1# filterVals
2
3This val exports a utility function that returns a list of all a user's val, filtered by a callback function.
4
5## Example
20};
21
22export function publicKeys() {
23 try {
24 return JSON.parse(Deno.env.get("JWKS_PUBLIC"));
38});
39
40export default async function(req: Request) {
41 return Response.json(publicKeys());
42}
3import { useState } from "https://esm.sh/hono/jsx/dom";
4
5export default function Counter(props: { initialCount?: number }) {
6 const [count, setCount] = useState(props.initialCount || 0);
7 return (
A helper function to build a file's email
Simple functional CSS library for Val Town
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",