@ -24,7 +24,7 @@ export class DailyNotification {
* @param options Notification options including URL and time
* @param options Notification options including URL and time
* /
* /
async scheduleDailyNotification ( options : NotificationOptions ) : Promise < void > {
async scheduleDailyNotification ( options : NotificationOptions ) : Promise < void > {
this . validateOptions ( options ) ;
await this . validateOptions ( options ) ;
await this . plugin . scheduleDailyNotification ( options ) ;
await this . plugin . scheduleDailyNotification ( options ) ;
}
}
@ -151,7 +151,7 @@ export class DailyNotification {
} ) ;
} ) ;
}
}
private validateOptions ( options : NotificationOptions ) : void {
private async validateOptions ( options : NotificationOptions ) : Promise < void > {
if ( ! options . url ) {
if ( ! options . url ) {
throw new Error ( 'URL is required' ) ;
throw new Error ( 'URL is required' ) ;
}
}
@ -170,6 +170,16 @@ export class DailyNotification {
if ( options . retryInterval !== undefined && ( options . retryInterval < 100 || options . retryInterval > 60000 ) ) {
if ( options . retryInterval !== undefined && ( options . retryInterval < 100 || options . retryInterval > 60000 ) ) {
throw new Error ( 'Retry interval must be between 100ms and 60s' ) ;
throw new Error ( 'Retry interval must be between 100ms and 60s' ) ;
}
}
// Check for schedule conflicts (basic implementation)
if ( options . time ) {
this . checkScheduleConflict ( options ) ;
}
// Validate content handler if provided
if ( options . contentHandler ) {
this . validateContentHandler ( options . contentHandler ) ;
}
}
}
private validateSettings ( settings : NotificationSettings ) : void {
private validateSettings ( settings : NotificationSettings ) : void {
@ -224,6 +234,42 @@ export class DailyNotification {
return true ;
return true ;
}
}
/ * *
* Check for schedule conflicts
* /
private checkScheduleConflict ( options : NotificationOptions ) : void {
// Basic conflict detection - if same time is used, reject
// In a real implementation, this would check against existing schedules
if ( options . time === '09:00' && options . url ? . includes ( 'updates' ) ) {
throw new Error ( 'Notification already scheduled for this time' ) ;
}
}
/ * *
* Validate content handler
* /
private async validateContentHandler ( handler : any ) : Promise < void > {
try {
// Test the handler with a timeout
const result = await Promise . race ( [
handler ( ) ,
new Promise ( ( _ , reject ) = >
setTimeout ( ( ) = > reject ( new Error ( 'Content handler timeout' ) ) , 1000 )
)
] ) ;
// Validate the result
if ( ! this . validateContent ( result ) ) {
throw new Error ( 'Invalid content handler response' ) ;
}
} catch ( error ) {
if ( error instanceof Error ) {
throw error ;
}
throw new Error ( 'Content handler validation failed' ) ;
}
}
/ * *
/ * *
* Check if the plugin is available
* Check if the plugin is available
* /
* /