PlatformContext
Unified backend facade for interacting with database collections, object schemas, external integrations, workflows, and communications.
The PlatformContext is a unified facade for all Valstorm platform operations. It provides a standardized interface to interact with platform services such as database operations, schema management, communications, and external integrations.
1. Overview & Initialization
The PlatformContext class aggregates domain-specific sub-contexts, each handling a particular aspect of the ecosystem. It is designed to be injected into FastAPI routes or used within system functions to provide a secure, tenant-scoped execution environment.
from valstorm_platform.platform_context import PlatformContext
# Current user session context
platform = PlatformContext(current_user)In FastAPI routes, use the dependency injection handler:
from valstorm_platform.platform_context import get_platform_context, PlatformContext
from fastapi import Depends
@router.get("/my-route")
async def my_route(ctx: PlatformContext = Depends(get_platform_context)):
results = await ctx.query.sql("SELECT id, name FROM contact LIMIT 10")
return results2. Core Sub-Contexts
1. records (RecordContext)
Handles Create, Update, and Delete (CUD) operations on MongoDB collections with strict schema validation:
create(api_name, input_data, async_run=False, **kwargs)update(api_name, input_data, async_run=False, **kwargs)delete(api_name, input_data, async_run=False, **kwargs)bulk_write(api_name, operations, **kwargs)
2. query (QueryContext)
Executes SQL queries or raw MongoDB aggregation pipelines:
sql(query, bypass_cache=False, **kwargs): Executes a SQL query against the query engine.mongo(collection, pipeline, **kwargs): Executes a MongoDB aggregation pipeline directly against the tenant database.resolve_lookup(api_name, record_id): Resolves a record ID into a full lookup dictionary.
3. schemas (SchemaContext)
Provides access to tenant object schemas and field definitions:
get(api_name): Get the schema definition for a specific object.list(): List all active object schemas for the organization.list_all(): Get complete schema definitions including field types, relationships, and validation rules.
4. communications (CommunicationContext)
Aggregates telephony and notification channels:
send_sms(to_phone, message, **kwargs): Dispatches SMS via configured Twilio telephony.notifications.notify(list[SendNotificationSetting]): Dispatches real-time in-app notification toasts and badges.
5. integrations (IntegrationContext)
Unified connectors for external SaaS platforms:
salesforce: Query, create, and update records in connected Salesforce instances.google: Access Google Workspace services (Google Drive, Gmail, Docs).microsoft: Microsoft 365 calendar, mail, and event sync.
6. workflows (WorkflowContext)
Invokes system functions and automation flows:
run_function(function_name, kwargs, **kwargs_extra)run_workflow(workflow_id, data, **kwargs)safe_execute(func, *args, **kwargs): Safely executes an async function with full error capture.
7. files (FileContext)
Manages Virtual File Service documents and S3 assets:
upload(path, data, **kwargs)delete_s3(location)s3_client: Direct access to underlying S3 client.