UNPKG

electron-license-kit

Version:

Secure licensing, storage, and utilities for Electron apps with Supabase

442 lines (405 loc) 11.7 kB
import { BrowserWindow } from 'electron'; /** * Core type definitions for electron-license-kit */ interface AppIdentity { name: string; id: string; version: string; description?: string; author?: string; website?: string; } interface BrandingAssets { logo?: string; logoLight?: string; logoDark?: string; splashScreen?: string; } interface ThemeColors { primary: string; primaryHover: string; primaryText: string; background: string; backgroundSecondary: string; backgroundTertiary: string; text: string; textSecondary: string; textTertiary: string; success: string; warning: string; error: string; info: string; border: string; divider: string; titlebar: { background: string; text: string; buttonHover: string; buttonClose: string; }; } interface LicenseConfig { keyPrefix: string; keyPattern: RegExp; offlineGraceDays: number; checkIntervalHours: number; } interface SupabaseConfig { url?: string; anonKey?: string; tableName: string; claimFunction: string; } interface WindowSettings { width: number; height: number; minWidth: number; minHeight: number; frame: boolean; resizable: boolean; } interface FeatureFlags { autoUpdater: boolean; crashReporter: boolean; singleInstance: boolean; devTools: boolean; } interface AppConfig { app: AppIdentity; branding: BrandingAssets; theme: ThemeColors; license: LicenseConfig; supabase: SupabaseConfig; window: WindowSettings; features: FeatureFlags; } interface LicenseData { email: string; tier: string; expiresAt: string | null; lastCheck: string; hwid: string; } interface LicenseStatus { email: string; tier: string; daysRemaining: number | null; isLifetime: boolean; } interface AuthResult { user: { id: string; email: string; }; license: { id: string; license_key: string; tier: string; status: string; hwid: string; expires_at: string | null; }; } interface ValidationResult { valid: boolean; license?: LicenseData; user?: { id: string; email: string; }; source?: 'online' | 'cache'; error?: string; } interface LicenseServiceConfig { supabaseUrl: string; supabaseAnonKey: string; licenseKeyPattern?: RegExp; tableName?: string; claimRpcName?: string; appName?: string; } interface LicenseCacheConfig { cacheDir?: string; cacheFileName?: string; maxAgeDays?: number; appName?: string; } interface SecureStorageConfig { storageDir?: string; fileName: string; encryptionKey?: Buffer; appName?: string; } interface EncryptedData { iv: string; data: string; tag: string; } interface WindowConfig { width?: number; height?: number; minWidth?: number; minHeight?: number; frame?: boolean; backgroundColor?: string; preloadPath: string; htmlPath: string; devTools?: boolean; } interface SingleInstanceConfig { onSecondInstance?: (argv: string[]) => void; } interface SecurityPolicyConfig { allowedExternalDomains?: string[]; enableDevTools?: boolean; } interface HWIDComponents { machineId: string; platform: string; arch: string; cpuModel: string; } /** * Branding configuration helper */ declare const defaultTheme: ThemeColors; declare const defaultConfig: AppConfig; declare function defineConfig(config: Partial<AppConfig>): AppConfig; /** * Built-in theme presets */ declare const presets: { readonly dark: Partial<ThemeColors>; readonly light: Partial<ThemeColors>; readonly midnight: Partial<ThemeColors>; readonly forest: Partial<ThemeColors>; }; /** * Generates CSS variables from theme configuration */ declare function generateCSSVariables(theme: ThemeColors): string; declare function generateStyleTag(theme: ThemeColors): string; /** * Injects theme CSS variables into BrowserWindow */ declare function injectTheme(window: BrowserWindow, theme: ThemeColors): Promise<void>; declare function injectThemeOnReady(window: BrowserWindow, theme: ThemeColors): void; /** * Hardware ID Generator */ declare function getHWIDComponents(): HWIDComponents; declare function generateHWID(): string; /** * License Cache - Encrypted local storage for offline validation */ declare class LicenseCache { private readonly storage; private readonly maxAgeDays; constructor(config?: LicenseCacheConfig); save(data: LicenseData): boolean; load(): LicenseData | null; isValid(): boolean; clear(): boolean; getDaysRemaining(): number | null; } /** * License Service - Supabase integration for license validation */ declare class LicenseService { private readonly supabase; private readonly cache; private readonly keyManager; private readonly keyPattern; private readonly tableName; private readonly claimRpcName; private currentUser; private currentLicense; constructor(config: LicenseServiceConfig); private validateKey; register(email: string, password: string, licenseKey: string): Promise<AuthResult>; login(email: string, password: string): Promise<AuthResult>; validate(): Promise<ValidationResult>; logout(): Promise<void>; getStatus(): LicenseStatus | null; resetPassword(email: string): Promise<boolean>; } /** * Secure Storage - AES-256-GCM encrypted local storage */ declare class SecureStorage<T> { private readonly storageDir; private readonly filePath; private readonly encryptionKey; constructor(config: SecureStorageConfig); private deriveKey; private encrypt; private decrypt; save(data: T): boolean; load(): T | null; exists(): boolean; clear(): boolean; getPath(): string; } /** * Key Manager - Specialized encrypted storage for license keys */ declare class KeyManager { private readonly storage; constructor(appName?: string); save(licenseKey: string): boolean; load(): string | null; exists(): boolean; clear(): boolean; getKeyPath(): string; } /** * Window Manager - Create and configure BrowserWindow */ declare function createMainWindow(config: WindowConfig): BrowserWindow; /** * Window Controls - IPC handlers for minimize/maximize/close */ declare function registerWindowControls(window: BrowserWindow): void; declare function unregisterWindowControls(): void; /** * Single Instance - Prevent multiple app instances */ declare function enforceSingleInstance(config?: SingleInstanceConfig): boolean; /** * Security module - App hardening utilities */ declare function setupSecurityPolicy(window: BrowserWindow, config?: SecurityPolicyConfig): void; declare function createNavigationGuard(window: BrowserWindow): void; declare function validateIpcChannel(channel: string, allowedChannels: string[]): boolean; /** * Logger module - Structured logging with file rotation */ type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'fatal'; interface LoggerConfig { appName: string; logDir?: string; maxFileSize?: number; maxFiles?: number; level?: LogLevel; console?: boolean; } declare class Logger { private readonly logDir; private readonly logFile; private readonly maxFileSize; private readonly maxFiles; private readonly minLevel; private readonly enableConsole; constructor(config: LoggerConfig); private formatMessage; private write; debug(message: string, meta?: object): void; info(message: string, meta?: object): void; warn(message: string, meta?: object): void; error(message: string, meta?: object): void; fatal(message: string, meta?: object): void; rotateLogs(): void; getLogDir(): string; } declare function createLogger(config: LoggerConfig): Logger; /** * Environment file loader */ declare function loadEnvFile(envPath: string): boolean; declare function loadEnvFiles(basePath: string, isPackaged: boolean): string | null; /** * Application paths helper */ interface AppPaths { userData: string; appData: string; logs: string; cache: string; config: string; } declare function getAppPaths(appName: string): AppPaths; /** * App configuration loader * Loads app.config.ts and merges with defaults */ declare function loadAppConfig(configPath?: string): AppConfig; /** * Crash Reporter - Error handling and crash logging */ interface CrashReporterConfig { appName: string; logDir?: string; maxCrashReports?: number; onCrash?: (report: CrashReport) => void; } interface CrashReport { timestamp: string; type: string; message: string; version: string; platform: string; arch: string; nodeVersion: string; electronVersion: string; } declare class CrashReporter { private readonly logDir; private readonly maxReports; private readonly onCrash?; private readonly appName; private initialized; constructor(config: CrashReporterConfig); private getDefaultLogDir; initialize(): void; private handleCrash; log(level: LogLevel, message: string): void; rotateLogs(): void; cleanOldCrashReports(): void; } declare function getCrashReporter(config: CrashReporterConfig): CrashReporter; /** * Auto-Updater module - electron-updater wrapper */ interface UpdaterConfig { autoDownload?: boolean; autoInstallOnQuit?: boolean; checkInterval?: number; } interface UpdateStatus { status: 'checking' | 'available' | 'not-available' | 'downloading' | 'downloaded' | 'error'; version?: string; percent?: number; error?: string; } declare class AutoUpdater { private autoUpdater; private updateAvailable; private updateDownloaded; private enabled; initialize(config?: UpdaterConfig): boolean; private setupEventHandlers; private notifyRenderer; checkForUpdates(): Promise<{ updateAvailable: boolean; version?: string; }>; downloadUpdate(): Promise<boolean>; installUpdate(): void; getStatus(): { enabled: boolean; updateAvailable: boolean; updateDownloaded: boolean; }; } declare function registerUpdaterHandlers(): void; /** * electron-license-kit * * Open-source framework for building secure, licensed Electron applications * with Supabase backend integration. * * @packageDocumentation */ declare const VERSION = "0.1.0"; export { type AppConfig, type AppIdentity, type AppPaths, type AuthResult, AutoUpdater, type BrandingAssets, type CrashReport, CrashReporter, type CrashReporterConfig, type EncryptedData, type FeatureFlags, type HWIDComponents, KeyManager, LicenseCache, type LicenseCacheConfig, type LicenseConfig, type LicenseData, LicenseService, type LicenseServiceConfig, type LicenseStatus, type LogLevel, Logger, type LoggerConfig, SecureStorage, type SecureStorageConfig, type SecurityPolicyConfig, type SingleInstanceConfig, type SupabaseConfig, type ThemeColors, type UpdateStatus, type UpdaterConfig, VERSION, type ValidationResult, type WindowConfig, type WindowSettings, createLogger, createMainWindow, createNavigationGuard, defaultConfig, defaultTheme, defineConfig, enforceSingleInstance, generateCSSVariables, generateHWID, generateStyleTag, getAppPaths, getCrashReporter, getHWIDComponents, injectTheme, injectThemeOnReady, loadAppConfig, loadEnvFile, loadEnvFiles, presets, registerUpdaterHandlers, registerWindowControls, setupSecurityPolicy, unregisterWindowControls, validateIpcChannel };