anchorPDSatproto.ts1 match
1516// Middleware for authentication
17async function authenticateRequest(c: any) {
18const authHeader = c.req.header("Authorization");
19if (!authHeader || !authHeader.startsWith("Bearer ")) {
anchorPDSauth.test.ts1 match
34// Mock validateToken for testing without network calls
5function mockValidateToken(token: string): Promise<any> {
6return Promise.resolve(null); // Always return null for test tokens
7}
8test/
9โโโ auth.test.ts # Authentication and token validation tests
10โโโ validation.test.ts # Input validation and utility function tests
11โโโ database.test.ts # Database schema and query logic tests
12โโโ integration.test.ts # End-to-end API endpoint tests
55- Geographic coordinate validation
56- Timestamp format validation
57- Utility function testing (UUID generation, URI formatting)
5859### ๐๏ธ Database Tests (`database.test.ts`)
76The test suite covers:
7778โ **Core Functionality**
7980- Record validation and creation
146## Adding New Tests
147148When adding new functionality, ensure tests cover:
1491501. **Happy Path**: Normal operation with valid inputs
5## Overview
67We'll build a lightweight PDS focused on `app.dropanchor.checkin` records using TypeScript + SQLite, with three main phases of functionality.
89## Phase 1: Core Check-In Storage and Feeds
1920**Implementation Steps:**
211. Create authentication middleware function
222. Parse Authorization header and extract token
233. Call user's home PDS to validate token and get DID
265- **Rationale:** Works regardless of feed post settings, provides consistent experience
266267This implementation plan prioritizes working functionality over optimization, allowing for iterative improvements as usage patterns emerge.
268269## Additional Resources
anchorPDSval-town.md12 matches
45- Ask clarifying questions when requirements are ambiguous
6- Provide complete, functional solutions rather than skeleton implementations
7- Test your logic against edge cases before presenting the final solution
8- Ensure all code follows Val Town's specific platform requirements
17- **Never bake in secrets into the code** - always use environment variables
18- Include comments explaining complex logic (avoid commenting obvious operations)
19- Follow modern ES6+ conventions and functional programming practices if possible
2021## Types of triggers
2829```ts
30export default async function (req: Request) {
31return new Response("Hello World");
32}
4041```ts
42export default async function () {
43// Scheduled task code
44}
5253```ts
54export default async function (email: Email) {
55// Process email
56}
59## Val Town Standard Libraries
6061Val Town provides several hosted services and utility functions.
6263### Blob Storage
113```
114115## Val Town Utility Functions
116117Val Town provides several utility functions to help with common project tasks.
118119### Importing Utilities
175โ โโโ database/
176โ โ โโโ migrations.ts # Schema definitions
177โ โ โโโ queries.ts # DB query functions
178โ โ โโโ README.md
179โ โโโ routes/ # Route modules
194โโโ shared/
195โโโ README.md
196โโโ utils.ts # Shared types and functions
197```
198202- Main entry point should be `backend/index.ts`
203- Do NOT use Hono serveStatic middleware
204- **Static asset serving:** Use the utility functions to read and serve project files:
205206```ts
240- Run migrations on startup or comment out for performance
241- Change table names when modifying schemas rather than altering
242- Export clear query functions with proper TypeScript typing
243244## Common Gotchas and Solutions
stevensDemotestDailyBrief.ts1 match
4import { DateTime } from "https://esm.sh/luxon@3.4.4";
56export async function testDailyBrief() {
7try {
8const testChatId = Deno.env.get("TEST_TELEGRAM_CHAT_ID");
2// Run this script manually to create the database table
34export default async function setupTelegramChatDb() {
5try {
6// Import SQLite module
stevensDemosendDailyBrief.ts6 matches
13} from "../memoryUtils.ts";
1415async function generateBriefingContent(anthropic, memories, today, isSunday) {
16try {
17const weekdaysHelp = generateWeekDays(today);
96}
9798export async function sendDailyBriefing(chatId?: string, today?: DateTime) {
99// Get API keys from environment
100const apiKey = Deno.env.get("ANTHROPIC_API_KEY");
135const lastSunday = today.startOf("week").minus({ days: 1 });
136137// Fetch relevant memories using the utility function
138const memories = await getRelevantMemories();
139216}
217218function generateWeekDays(today) {
219let output = [];
220239// console.log(weekDays);
240241// Export a function that calls sendDailyBriefing with no parameters
242// This maintains backward compatibility with existing cron jobs
243export default async function (overrideToday?: DateTime) {
244return await sendDailyBriefing(undefined, overrideToday);
245}
stevensDemoREADME.md2 matches
16In a normal server environment, you would likely use a middleware [like this one](https://hono.dev/docs/getting-started/nodejs#serve-static-files) to serve static files. Some frameworks or deployment platforms automatically make any content inside a `public/` folder public.
1718However in Val Town you need to handle this yourself, and it can be suprisingly difficult to read and serve files in a Val Town Project. This template uses helper functions from [stevekrouse/utils/serve-public](https://www.val.town/x/stevekrouse/utils/branch/main/code/serve-public/README.md), which handle reading project files in a way that will work across branches and forks, automatically transpiles typescript to javascript, and assigns content-types based on the file's extension.
1920### `index.html`
26## CRUD API Routes
2728This app has two CRUD API routes: for reading and inserting into the messages table. They both speak JSON, which is standard. They import their functions from `/backend/database/queries.ts`. These routes are called from the React app to refresh and update data.
2930## Errors
stevensDemoREADME.md2 matches
45* `migrations.ts` - code to set up the database tables the app needs
6* `queries.ts` - functions to run queries against those tables, which are imported and used in the main Hono server in `/backend/index.ts`
78## Migrations
18The queries file is where running the migrations happen in this app. It'd also be reasonable for that to happen in index.ts, or as is said above, for that line to be commented out, and only run when actual changes are made to your database schema.
1920The queries file exports functions to get and write data. It relies on shared types and data imported from the `/shared` directory.