// Notion Configuration for Puppet Production Studio
// This file manages Notion database IDs and page configurations
export const NOTION_CONFIG = {
// Character database (already exists)
CHARACTERS_MASTER_DB: process.env.CHARACTERS_MASTER_DB || process.env.NOTION_CHARACTERS_DB_ID,
// Storyline databases (to be created if not exist)
STORYLINES_DB: process.env.NOTION_STORYLINES_DB_ID,
SCENES_DB: process.env.NOTION_SCENES_DB_ID,
CHARACTER_DEVELOPMENT_DB: process.env.NOTION_CHARACTER_DEV_DB_ID,
// Parent pages for new databases
STORYLINES_PARENT_PAGE: process.env.NOTION_STORYLINES_PAGE_ID,
SCENES_PARENT_PAGE: process.env.NOTION_SCENES_PAGE_ID,
CHARACTER_DEV_PARENT_PAGE: process.env.NOTION_CHARACTER_DEV_PAGE_ID,
// Default parent page if specific ones aren't set
DEFAULT_PARENT_PAGE: process.env.NOTION_DEFAULT_PARENT_PAGE || process.env.NOTION_WORKSPACE_ID
};
export const NOTION_DATABASE_NAMES = {
STORYLINES: 'Puppet Storylines',
SCENES: 'Story Scenes',
CHARACTER_DEVELOPMENT: 'Character Development Tracking'
};
// Helper to validate Notion configuration
export function validateNotionConfig() {
const issues = [];
const warnings = [];
if (!NOTION_CONFIG.CHARACTERS_MASTER_DB) {
issues.push('CHARACTERS_MASTER_DB or NOTION_CHARACTERS_DB_ID not configured - using fallback database which may not exist');
}
if (!NOTION_CONFIG.DEFAULT_PARENT_PAGE) {
warnings.push('DEFAULT_PARENT_PAGE or NOTION_WORKSPACE_ID not configured - needed for creating storyline databases');
}
return {
isValid: issues.length === 0,
issues: issues,
warnings: warnings,
config: NOTION_CONFIG,
fallbackDatabaseId: '5b96c172-96b2-4b53-a52c-60d4874779f4'
};
}
// Enhanced function to test Notion database connectivity
export async function testNotionDatabaseConnection(notionClient, databaseId = null) {
const testDatabaseId = databaseId || NOTION_CONFIG.CHARACTERS_MASTER_DB || '5b96c172-96b2-4b53-a52c-60d4874779f4';
try {
console.log(`🔍 Testing Notion database connection to: ${testDatabaseId}`);
// Test database access
const database = await notionClient.databases.retrieve({
database_id: testDatabaseId
});
console.log(`âś… Database found: "${database.title[0]?.text?.content || 'Untitled'}"`);
// Check required schema fields
const requiredFields = [
'Character Name',
'Character Type',
'Description',
'Physical Traits',
'Production Status'
];
const missingFields = [];
const schemaIssues = [];
for (const field of requiredFields) {
if (!database.properties[field]) {
missingFields.push(field);
} else {
// Validate field types
const property = database.properties[field];
if (field === 'Character Name' && property.type !== 'title') {
schemaIssues.push(`${field} should be 'title' type, found '${property.type}'`);
} else if (field === 'Character Type' && property.type !== 'select') {
schemaIssues.push(`${field} should be 'select' type, found '${property.type}'`);
} else if (field === 'Production Status' && property.type !== 'select') {
schemaIssues.push(`${field} should be 'select' type, found '${property.type}'`);
}
}
}
return {
success: true,
databaseId: testDatabaseId,
databaseTitle: database.title[0]?.text?.content || 'Untitled',
schemaValid: missingFields.length === 0 && schemaIssues.length === 0,
missingFields,
schemaIssues,
message: missingFields.length === 0 && schemaIssues.length === 0
? 'Database connection and schema validation successful'
: 'Database accessible but schema issues found'
};
} catch (error) {
return {
success: false,
databaseId: testDatabaseId,
error: error.message,
message: `Failed to connect to Notion database: ${error.message}`
};
}
}