Atproto AMA app
1/**
2 * Configuration for AT Protocol and Lex features
3 */
4
5export interface AskimutConfig {
6 // AT Protocol publishing
7 atProtocol: {
8 enabled: boolean
9 publishQuestions: boolean
10 publishAnswers: boolean
11 publishProfiles: boolean
12 strictValidation: boolean
13 }
14
15 // Lexicon validation
16 validation: {
17 enabled: boolean
18 strictMode: boolean
19 failOnValidationError: boolean
20 }
21
22 // Service endpoints
23 services: {
24 defaultPds: string
25 defaultAppview: string
26 }
27}
28
29/**
30 * Get configuration from environment variables
31 */
32export function getConfig(): AskimutConfig {
33 return {
34 atProtocol: {
35 enabled: process.env.AT_PROTOCOL_ENABLED === 'true',
36 publishQuestions: process.env.AT_PROTOCOL_PUBLISH_QUESTIONS !== 'false', // default true
37 publishAnswers: process.env.AT_PROTOCOL_PUBLISH_ANSWERS !== 'false', // default true
38 publishProfiles: process.env.AT_PROTOCOL_PUBLISH_PROFILES !== 'false', // default true
39 strictValidation: process.env.AT_PROTOCOL_STRICT_VALIDATION !== 'false' // default true
40 },
41
42 validation: {
43 enabled: process.env.LEX_VALIDATION_ENABLED !== 'false', // default true
44 strictMode: process.env.LEX_VALIDATION_STRICT === 'true', // default false
45 failOnValidationError: process.env.LEX_VALIDATION_FAIL_ON_ERROR !== 'false' // default true
46 },
47
48 services: {
49 defaultPds: process.env.AT_PROTOCOL_PDS || 'https://bsky.social',
50 defaultAppview: process.env.AT_PROTOCOL_APPVIEW || 'https://api.bsky.app'
51 }
52 }
53}
54
55/**
56 * Cached configuration instance
57 */
58let cachedConfig: AskimutConfig | null = null
59
60/**
61 * Get cached configuration
62 */
63export function getCachedConfig(): AskimutConfig {
64 if (!cachedConfig) {
65 cachedConfig = getConfig()
66 }
67 return cachedConfig
68}
69
70/**
71 * Reset cached configuration (useful for testing)
72 */
73export function resetConfigCache(): void {
74 cachedConfig = null
75}
76
77/**
78 * Check if AT Protocol publishing is enabled for a specific record type
79 */
80export function isPublishingEnabled(recordType: 'question' | 'answer' | 'profile'): boolean {
81 const config = getCachedConfig()
82 if (!config.atProtocol.enabled) {
83 return false
84 }
85
86 switch (recordType) {
87 case 'question':
88 return config.atProtocol.publishQuestions
89 case 'answer':
90 return config.atProtocol.publishAnswers
91 case 'profile':
92 return config.atProtocol.publishProfiles
93 default:
94 return false
95 }
96}
97
98/**
99 * Check if validation is enabled
100 */
101export function isValidationEnabled(): boolean {
102 return getCachedConfig().validation.enabled
103}
104
105/**
106 * Check if strict validation mode is enabled
107 */
108export function isStrictValidation(): boolean {
109 const config = getCachedConfig()
110 return config.validation.strictMode || config.atProtocol.strictValidation
111}
112
113/**
114 * Check if we should fail on validation errors
115 */
116export function shouldFailOnValidationError(): boolean {
117 return getCachedConfig().validation.failOnValidationError
118}