- Added VITE_LNBITS_API_URL to .env.example for LNBits API integration. - Updated AUTHENTICATION.md to reflect changes in LNBits base URL configuration. - Refactored ProfileDialog.vue and config files to use VITE_LNBITS_BASE_URL instead of VITE_API_BASE_URL for API calls.
112 lines
No EOL
2.8 KiB
TypeScript
112 lines
No EOL
2.8 KiB
TypeScript
// Centralized configuration management
|
|
// Handles all environment variables and app configuration
|
|
|
|
interface NostrConfig {
|
|
relays: string[]
|
|
adminPubkeys: string[]
|
|
}
|
|
|
|
interface ApiConfig {
|
|
baseUrl: string
|
|
key: string
|
|
}
|
|
|
|
interface PushConfig {
|
|
vapidPublicKey: string
|
|
enabled: boolean
|
|
}
|
|
|
|
interface MarketConfig {
|
|
defaultNaddr: string
|
|
supportedRelays: string[]
|
|
lightningEnabled: boolean
|
|
defaultCurrency: string
|
|
}
|
|
|
|
interface AppConfig {
|
|
nostr: NostrConfig
|
|
api: ApiConfig
|
|
push: PushConfig
|
|
market: MarketConfig
|
|
support: {
|
|
npub: string
|
|
}
|
|
}
|
|
|
|
// Parse JSON environment variables safely
|
|
function parseJsonEnv(envVar: string | undefined, fallback: any = []): any {
|
|
if (!envVar) return fallback
|
|
|
|
try {
|
|
return JSON.parse(envVar)
|
|
} catch (error) {
|
|
console.warn(`Failed to parse environment variable: ${envVar}`)
|
|
return fallback
|
|
}
|
|
}
|
|
|
|
// Create the configuration object
|
|
export const config: AppConfig = {
|
|
nostr: {
|
|
relays: parseJsonEnv(import.meta.env.VITE_NOSTR_RELAYS, []),
|
|
adminPubkeys: parseJsonEnv(import.meta.env.VITE_ADMIN_PUBKEYS, [])
|
|
},
|
|
api: {
|
|
baseUrl: import.meta.env.VITE_LNBITS_BASE_URL || '',
|
|
key: import.meta.env.VITE_API_KEY || ''
|
|
},
|
|
push: {
|
|
vapidPublicKey: import.meta.env.VITE_VAPID_PUBLIC_KEY || '',
|
|
enabled: Boolean(import.meta.env.VITE_PUSH_NOTIFICATIONS_ENABLED)
|
|
},
|
|
market: {
|
|
defaultNaddr: import.meta.env.VITE_MARKET_NADDR || '',
|
|
supportedRelays: parseJsonEnv(import.meta.env.VITE_MARKET_RELAYS, [
|
|
'ws://127.0.0.1:7777',
|
|
'wss://relay.damus.io',
|
|
'wss://relay.snort.social',
|
|
'wss://nostr-pub.wellorder.net',
|
|
'wss://nostr.zebedee.cloud',
|
|
'wss://nostr.walletofsatoshi.com'
|
|
]),
|
|
lightningEnabled: Boolean(import.meta.env.VITE_LIGHTNING_ENABLED),
|
|
defaultCurrency: import.meta.env.VITE_MARKET_DEFAULT_CURRENCY || 'sat'
|
|
},
|
|
support: {
|
|
npub: import.meta.env.VITE_SUPPORT_NPUB || ''
|
|
}
|
|
} as const
|
|
|
|
// Utility functions for common config operations
|
|
export const configUtils = {
|
|
isAdminPubkey: (pubkey: string): boolean => {
|
|
return config.nostr.adminPubkeys.includes(pubkey)
|
|
},
|
|
|
|
hasNostrConfig: (): boolean => {
|
|
return config.nostr.relays.length > 0
|
|
},
|
|
|
|
hasApiConfig: (): boolean => {
|
|
return Boolean(config.api.baseUrl && config.api.key)
|
|
},
|
|
|
|
hasPushConfig: (): boolean => {
|
|
return Boolean(config.push.vapidPublicKey && config.push.enabled)
|
|
},
|
|
|
|
hasMarketConfig: (): boolean => {
|
|
return Boolean(config.market.defaultNaddr)
|
|
},
|
|
|
|
getDefaultRelays: (): string[] => {
|
|
return config.nostr.relays
|
|
},
|
|
|
|
getMarketRelays: (): string[] => {
|
|
return config.market.supportedRelays
|
|
}
|
|
}
|
|
|
|
// Export individual config sections for convenience
|
|
export const { nostr: nostrConfig, api: apiConfig, market: marketConfig } = config |