6
7- `index.ts` - Ponto de entrada principal com middleware LastLogin
8- `database/` - Configuração do banco SQLite
9 - `migrations.ts` - Schema das tabelas
10 - `queries.ts` - Funções de consulta tipadas
2import { lastlogin } from "https://esm.town/v/stevekrouse/lastlogin_safe";
3import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
4import { runMigrations } from "./database/migrations.ts";
5import { getTodos, createUser } from "./database/queries.ts";
6import todosRouter from "./routes/todos.ts";
7
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { getTodos, getTodo, createTodo, updateTodo, deleteTodo, createUser } from "../database/queries.ts";
3import type { CreateTodoRequest, UpdateTodoRequest } from "../../shared/types.ts";
4
12 }
13
14 // Ensure user exists in database
15 await createUser(email);
16 c.set('userEmail', email);
12 console.log(data);
13 try {
14 // create a database page in the interactions database
15 const page = await setAction(data);
16 // console.log(page);
10 const page = await notion.pages.create({
11 parent: {
12 database_id: Deno.env.get("GLANCE_INTERACTIONS_DB_ID"),
13 },
14 properties: {
8
9 // get each of the actions from this demo from Notion
10 // data is stored in the "Glancer interactions" database and attached to the demo via relation
11 // we can't really use the relation property b/c that only holds an array of page IDs in Notion
12 // so, in Notion, we use a formula to transform the relation array into a string
221```typescript
222export default async function (interval: Interval) {
223 const pages = await notion.databases.query({
224 database_id: Deno.env.get("GLANCE_DEMOS_DB_ID"),
225 });
226
244});
245
246const databaseId = Deno.env.get("GLANCE_DEMOS_DB_ID");
247```
248
250
251- `NOTION_API_KEY`: Notion integration token
252- `GLANCE_DEMOS_DB_ID`: Notion database ID for demo pages
253- `GLANCE_INTERACTIONS_DB_ID`: Notion database ID for interaction tracking
254
255## Project Conventions
291- `/api/*`: JSON data endpoints for frontend consumption
292- `/demo/*`: Personalized demo page serving with data injection
293- `/tasks/*`: Notion webhook processing and database updates
294
295## External Dependencies
300
301- **Email and Alerting**: Slack notifications and email alerts are configured within Notion
302- **Database Management**: Three core Notion databases power the application:
303 - **Glancer Demos Database**: Stores demo configurations, visitor information, and personalization data
304 - **Glancer Interactions Database**: Warehouses demo events, clicks, and user behavior analytics
305 - **Glancer Agents Database**: Manages agent assignments, availability, and contact information
306
307The Val Town application serves as an automation and presentation layer that extends Notion's native capabilities, providing real-time cobrowsing experiences while maintaining all data persistence and workflow management within the Notion ecosystem.
43- blob storage for the cache, which enables snappy demos
44- cron(s) that keep the cache up-to-date
45- environment variables, which we use to store connection details for Notion, database ids for essential Notion databases (including the demos and interactions databases)
46- logging features
47
63
64- email and other alerting (e.g., Slack)
65- databases, including:
66 - the "Glancer demos" database
67 - the "Glancer interactions" database, which is where certain demo events (e.g., clicks) are warehoused and visualized
68 - the "Glancer agents" database, which handles agent assignments and management
69
70Note that this app integrates with Notion to extend Notion in important ways; namely, automation and logging. Please be clear about that.
12 status: "connected",
13 message: "Successfully connected to Notion API",
14 databases: response.results.map((db) => ({
15 title: db.title?.[0]?.plain_text || "Untitled",
16 id: db.id,
20
21// update the cache
22// this cron updates a blob that stores the JSON that shows the databases that val.town is connected to
23// we present that at root and embed that into Notion
24// to show everyone that the connection is healthy btw Notion and val.town
29 filter: {
30 property: "object",
31 value: "database",
32 },
33 });
6});
7
8export async function getDatabase(id: string) {
9 // get database
10 try {
11 const database = await notion.databases.retrieve({
12 database_id: id,
13 });
14 return database;
15 } catch (error: any) {
16 return {