FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
lightweight
lightweightglimpse2-runbook-view-glimpse-save-login-react
Remix of lightweight/glimpse2-runbook-view-glimpse-save-login
Public
Like
glimpse2-runbook-view-glimpse-save-login-react
Home
Code
8
_townie
13
backend
7
frontend
5
shared
3
.vtignore
README.md
deno.json
H
main.tsx
Branches
2
Pull requests
Remixes
History
Environment variables
6
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
backend
/
services
/
README.md
Code
/
backend
/
services
/
README.md
Search
9/10/2025
Viewing readonly version of main branch: v8
View latest version
README.md

Services

External API integrations (pure API calls only).

Separation of Concerns

Services are the data access layer that:

  • Make direct API calls to external systems (Notion, databases, etc.)
  • Handle HTTP transport layer concerns (network errors, response parsing)
  • Return consistent, standardized response formats
  • Are pure functions with no side effects beyond the API call
  • Do NOT handle business logic, environment variables, or orchestrate multiple calls

Standard Response Format

All service functions return:

{ success: boolean, data?: any, // Present on success error?: string, // Present on failure timestamp: string // ISO timestamp of the operation }

Data Structures Passed

Input Parameters

  • Simple primitives: string, number, boolean only
  • No complex objects: Controllers handle object extraction/validation
  • No HTTP contexts: Services are transport-agnostic

Output Data

  • Raw API responses: Unmodified data from external APIs
  • No business logic filtering: Controllers handle data transformation
  • Complete error context: Full error messages from external systems

Notion Service Structure

The Notion service is organized into focused modules:

  • notion/index.ts - Main entry point with client configuration and re-exports
  • notion/database.service.ts - Database-related operations
  • notion/page.service.ts - Page-related operations

Import Options

// Import everything from main entry point import { getPageById, getDatabases } from '../services/notion/index.ts'; // Or import from specific service modules import { getPageById } from '../services/notion/page.service.ts'; import { getDatabases } from '../services/notion/database.service.ts';

Notion Service Functions

Database Operations

getDatabases()

  • Input: None
  • Output: Raw Notion search response with all accessible databases
  • Data Structure:
    { success: true, data: { results: NotionDatabase[], next_cursor: string | null, has_more: boolean }, timestamp: string }

getDatabaseById(databaseId: string)

  • Input: Database UUID string
  • Output: Complete Notion database object with schema
  • Data Structure:
    { success: true, data: { id: string, title: RichText[], properties: { [key: string]: PropertySchema }, // ... full Notion database object }, timestamp: string }

getDatabasePages(databaseId: string)

  • Input: Database UUID string
  • Output: All pages in the database with properties
  • Data Structure:
    { success: true, data: { results: NotionPage[], next_cursor: string | null, has_more: boolean }, timestamp: string }

Page Operations

getPageById(pageId: string)

  • Input: Page UUID string
  • Output: Complete Notion page object with properties
  • Data Structure:
    { success: true, data: { id: string, properties: { [key: string]: PropertyValue }, parent: { database_id: string } | { page_id: string }, // ... full Notion page object }, timestamp: string }

getPageBlocks(pageId: string)

  • Input: Page UUID string
  • Output: Hierarchical block structure with recursive children
  • Data Structure:
    { success: true, data: { results: NotionBlock[] // Each block may have .children array }, timestamp: string }

getPageWithBlocks(pageId: string)

  • Input: Page UUID string
  • Output: Combined page properties and block content
  • Data Structure:
    { success: true, data: { // All page properties id: string, properties: { [key: string]: PropertyValue }, // Plus blocks array blocks: NotionBlock[] }, timestamp: string }

updatePageUrl(pageId: string, url: string)

  • Input: Page UUID and URL string
  • Output: Updated page object
  • Behavior: Updates the "URL" property specifically
  • Data Structure: Same as getPageById response

User Management Operations

findUserByEmail(databaseId: string, email: string)

  • Input: Database UUID and email address string
  • Output: Query results for pages matching email
  • Data Structure:
    { success: true, data: { results: NotionPage[], // Pages with Email property matching next_cursor: string | null, has_more: boolean }, timestamp: string }

createUserRecord(databaseId: string, email: string)

  • Input: Database UUID and email address string
  • Output: Newly created page object
  • Behavior: Creates page with "Email" property set
  • Data Structure: Same as getPageById response

Error Handling

Services return detailed error information:

{ success: false, error: "Notion API error message", // Direct from external API timestamp: string }

Common error scenarios:

  • Network failures: Connection timeouts, DNS issues
  • Authentication: Invalid API keys, expired tokens
  • Authorization: Insufficient permissions for resources
  • Validation: Invalid UUIDs, missing required fields
  • Rate limiting: API quota exceeded
Go to top
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Product
FeaturesPricing
Developers
DocsStatusAPI ExamplesNPM Package Examples
Explore
ShowcaseTemplatesNewest ValsTrending ValsNewsletter
Company
AboutBlogCareersBrandhi@val.town
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.