Files
daily-notification-plugin/docs/examples/COMMON_PATTERNS.md
Matthew Raymer 3a0b9b5692 feat(docs): P3.3-D Add integration examples and common patterns
Created:
- docs/examples/QUICK_START.md: Minimal working example with platform setup
- docs/examples/COMMON_PATTERNS.md: Common patterns (error handling, scheduling, recovery)

Updated docs/00-INDEX.md to link examples section.

Verification:
- Documentation created and linked 
- Examples follow best practices 
2025-12-23 07:18:20 +00:00

1.9 KiB

Common Integration Patterns

Purpose: Common patterns and best practices for Daily Notification Plugin integration.
Owner: Development Team
Last Updated: 2025-12-22
Status: active


Error Handling

import { DailyNotification, DailyNotificationError, ErrorCode } from '@timesafari/daily-notification-plugin';

try {
  await DailyNotification.createSchedule({
    id: 'daily-morning',
    kind: 'notify',
    clockTime: '09:00',
    enabled: true
  });
} catch (error) {
  if (error instanceof DailyNotificationError) {
    switch (error.code) {
      case ErrorCode.PERMISSION_DENIED:
        // Request permission first
        await DailyNotification.requestPermission();
        break;
      case ErrorCode.INVALID_TIME_FORMAT:
        // Fix time format (use HH:mm)
        console.error('Invalid time format');
        break;
      default:
        console.error('Error:', error.message);
    }
  }
}

Scheduling Multiple Notifications

const times = ['09:00', '12:00', '18:00'];

for (const time of times) {
  await DailyNotification.createSchedule({
    id: `daily-${time.replace(':', '')}`,
    kind: 'notify',
    clockTime: time,
    enabled: true
  });
}

Checking Schedule Status

const { schedules } = await DailyNotification.getSchedulesWithStatus();

schedules.forEach(schedule => {
  console.log(`${schedule.id}: ${schedule.status} (scheduled: ${schedule.isActuallyScheduled})`);
});

Recovery After App Restart

The plugin automatically recovers missed notifications on app launch. To check recovery status:

// Recovery happens automatically on app launch
// Check history for recovery events
const { history } = await DailyNotification.getHistory({
  kind: 'recovery',
  limit: 10
});

See also: