Public
Like
glimpse2-runbook-view-glimpse-save-login-react
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.
External integrations and data persistence operations.
Services are the external integration layer that:
- Handle external system interactions (APIs, databases, storage)
- Make direct calls to external services (Notion API, blob storage, etc.)
- Handle transport layer concerns (network errors, response parsing)
- Return consistent, standardized response formats
- Are focused operations with no business logic or workflow management
Services do NOT:
- Implement business logic or workflow decisions
- Orchestrate multiple service calls (controllers handle this)
- Handle environment variables or configuration (controllers manage this)
- Transform data for business purposes (controllers handle transformation)
- Notion API operations →
notion/page.service.ts
- Blob storage operations →
blob.service.ts
- Database operations →
database.service.ts
- Email sending →
email.service.ts
- Data formatting →
utils/date.helpers.ts
- Validation logic →
utils/validation.helpers.ts
- String manipulation →
utils/string.helpers.ts
- Mathematical calculations →
utils/math.helpers.ts
- Always interact with systems outside the application
- Handle network operations, API calls, storage operations
- Manage external service authentication and configuration
- No business logic, just external operations
- Deterministic for the same external system state
- No workflow management or decision-making
- Consistent success/error response formats
- Complete error context from external systems
- Raw data from external APIs (no business filtering)
- Each service handles one external system or related operations
- Single responsibility for external integration concerns
All service functions return:
{
success: boolean,
data?: any, // Present on success
error?: string, // Present on failure
timestamp: string // ISO timestamp of the operation
}
index.ts
- Main entry point with client configurationdatabase.service.ts
- Database queries and operationspage.service.ts
- Page retrieval and updates
- Generic blob storage operations
- Type-specific convenience functions
- Key management and cleanup operations
email.service.ts
- Email sending operationscache.service.ts
- Caching operationsfile.service.ts
- File system operations
// Controllers orchestrate services
const pageResult = await getPageById(pageId);
if (!pageResult.success) {
return { success: false, error: pageResult.error };
}
const blobResult = await setAgentBlob(pageId, agentData);
// Controller handles business logic based on service results
// Services focus on external operations only
export async function getPageById(pageId: string): Promise<NotionServiceResponse> {
try {
const response = await notion.pages.retrieve({ page_id: pageId });
return createSuccessResponse(response);
} catch (error) {
return createErrorResponse(error.message);
}
}
setBlobData(key, data)
- Generic blob storagegetBlobData(key)
- Generic blob retrievaldeleteBlobData(key)
- Generic blob deletionlistBlobKeys(prefix)
- List blobs with optional prefix
setAgentBlob(pageId, agentData)
- Agent blob operationsgetAgentBlob(pageId)
- Agent blob retrievalsetViewingBlob(pageId, viewingData)
- Viewing blob operationsgetViewingBlob(pageId)
- Viewing blob retrieval
generateBlobKey(type, id)
- Standardized key patternsparseBlobKey(key)
- Extract type and id from keyscleanupStaleBlobs(type, maxAge)
- Generic cleanup operations
getDatabases()
- List all accessible databasesgetDatabaseById(databaseId)
- Get database schemagetDatabasePages(databaseId)
- Query all pages in databasefindUserByEmail(databaseId, email)
- Find user by emailcreateUserRecord(databaseId, email)
- Create new user recordfindAgentsByPersonId(databaseId, personId)
- Find agents by person
getPageById(pageId)
- Get complete page dataupdatePageUrl(pageId, url)
- Update page URL propertyupdatePageProperty(pageId, properties)
- Update page propertiesupdateGlimpseAgentsProperty(pageId, agents)
- Update agent relationsclearGlimpseDemosProperty(agentId)
- Clear demo relationsgetPageBlocks(pageId)
- Get page content blocksgetPageWithBlocks(pageId)
- Get page with content
Services return detailed error information:
{
success: false,
error: "External API error message", // Direct from external system
timestamp: string
}
Common error scenarios:
- Network failures: Connection timeouts, DNS issues
- Authentication: Invalid API keys, expired tokens
- Authorization: Insufficient permissions for resources
- Validation: Invalid parameters, missing required fields
- Rate limiting: API quota exceeded
- Storage errors: Blob storage failures, quota exceeded