67 lines
2.7 KiB
TypeScript
67 lines
2.7 KiB
TypeScript
import { initializeAllContainers, registerContainers } from '@bytelyst/cosmos';
|
|
import type { ContainerConfig } from '@bytelyst/cosmos';
|
|
import { config } from './config.js';
|
|
|
|
const CONTAINER_DEFS: Record<string, ContainerConfig> = {
|
|
products: { partitionKeyPath: '/id' },
|
|
users: { partitionKeyPath: '/id' },
|
|
settings: { partitionKeyPath: '/userId' },
|
|
devices: { partitionKeyPath: '/userId' },
|
|
notification_prefs: { partitionKeyPath: '/userId' },
|
|
audit_log: { partitionKeyPath: '/category', defaultTtl: 90 * 86400 },
|
|
feature_flags: { partitionKeyPath: '/id' },
|
|
// Growth modules
|
|
invitation_codes: { partitionKeyPath: '/id' },
|
|
referrals: { partitionKeyPath: '/id' },
|
|
// Billing modules
|
|
subscriptions: { partitionKeyPath: '/userId' },
|
|
payments: { partitionKeyPath: '/userId' },
|
|
licenses: { partitionKeyPath: '/id' },
|
|
plans: { partitionKeyPath: '/id' },
|
|
usage_daily: { partitionKeyPath: '/userId' },
|
|
// API tokens
|
|
api_tokens: { partitionKeyPath: '/id' },
|
|
// Tracker modules
|
|
tracker_items: { partitionKeyPath: '/id' },
|
|
comments: { partitionKeyPath: '/itemId' },
|
|
votes: { partitionKeyPath: '/itemId' },
|
|
// Themes
|
|
themes: { partitionKeyPath: '/id' },
|
|
// Waitlist (pre-launch signups)
|
|
waitlist: { partitionKeyPath: '/email' },
|
|
// Mobile capture primitives (MindLyst-style).
|
|
memory_items: { partitionKeyPath: '/userId' },
|
|
daily_briefs: { partitionKeyPath: '/userId' },
|
|
reflections: { partitionKeyPath: '/userId' },
|
|
brain_insights: { partitionKeyPath: '/userId' },
|
|
// NomGap fasting modules
|
|
fasting_sessions: { partitionKeyPath: '/userId' },
|
|
fasting_protocols: { partitionKeyPath: '/userId' },
|
|
// ChronoMind timers
|
|
timers: { partitionKeyPath: '/userId' },
|
|
routines: { partitionKeyPath: '/userId' },
|
|
households: { partitionKeyPath: '/id' },
|
|
shared_timers: { partitionKeyPath: '/householdId' },
|
|
// Telemetry (client diagnostics — see docs/WINDSURF/CLIENT_TELEMETRY_DESIGN.md)
|
|
telemetry_events: { partitionKeyPath: '/pk', defaultTtl: 30 * 86400 },
|
|
telemetry_error_clusters: { partitionKeyPath: '/pk', defaultTtl: 90 * 86400 },
|
|
telemetry_collection_policies: { partitionKeyPath: '/productId' },
|
|
};
|
|
|
|
export async function initCosmosIfNeeded(): Promise<void> {
|
|
registerContainers(CONTAINER_DEFS);
|
|
|
|
const shouldInit = config.NODE_ENV !== 'production' || process.env.COSMOS_AUTO_INIT === 'true';
|
|
if (!shouldInit) return;
|
|
|
|
try {
|
|
await initializeAllContainers();
|
|
// eslint-disable-next-line no-console
|
|
console.info('[platform-service] Cosmos containers ensured');
|
|
} catch (err) {
|
|
const msg = err instanceof Error ? err.message : String(err);
|
|
// eslint-disable-next-line no-console
|
|
console.warn(`[platform-service] Cosmos init failed: ${msg}`);
|
|
}
|
|
}
|