capacitor-native-update
Version:
Native Update Plugin for Capacitor
52 lines • 1.65 kB
JavaScript
export class ConfigManager {
constructor() {
this.config = this.getDefaultConfig();
}
static getInstance() {
if (!ConfigManager.instance) {
ConfigManager.instance = new ConfigManager();
}
return ConfigManager.instance;
}
getDefaultConfig() {
return {
filesystem: null,
preferences: null,
baseUrl: '',
allowedHosts: [],
maxBundleSize: 100 * 1024 * 1024, // 100MB
downloadTimeout: 30000, // 30 seconds
retryAttempts: 3,
retryDelay: 1000, // 1 second
enableSignatureValidation: true,
publicKey: '',
cacheExpiration: 24 * 60 * 60 * 1000, // 24 hours
enableLogging: false,
};
}
configure(config) {
this.config = Object.assign(Object.assign({}, this.config), config);
this.validateConfig();
}
validateConfig() {
if (this.config.maxBundleSize <= 0) {
throw new Error('maxBundleSize must be greater than 0');
}
if (this.config.downloadTimeout <= 0) {
throw new Error('downloadTimeout must be greater than 0');
}
if (this.config.retryAttempts < 0) {
throw new Error('retryAttempts must be non-negative');
}
if (this.config.retryDelay < 0) {
throw new Error('retryDelay must be non-negative');
}
}
get(key) {
return this.config[key];
}
isConfigured() {
return !!(this.config.filesystem && this.config.preferences);
}
}
//# sourceMappingURL=config.js.map