Infrastructure medium complexity backend
3
Dependencies
0
Dependents
1
Entities
1
Integrations

Description

Supabase Edge Function that runs on a daily cron schedule to query all peer mentors with upcoming or lapsed certification expiry dates. It invokes the expiry notification orchestrator for threshold-based notification dispatch and triggers the mentor visibility suppressor for expired certifications.

Feature: Certificate Expiry Notifications

expiry-check-edge-function

Summaries

The Certificate Expiry Check Edge Function is the automated engine that drives the organization's proactive certification compliance strategy. Running every day without manual intervention, it scans the entire peer mentor workforce for upcoming and lapsed certifications, triggers targeted notifications to coordinators at critical thresholds, and automatically suppresses expired mentors from active service matching. This automation eliminates the operational cost of manual compliance monitoring, reduces the risk of human error in identifying at-risk mentors, and ensures that the organization's response to certification gaps is consistent, timely, and auditable. It transforms certification oversight from a reactive administrative burden into a reliable, self-managing compliance process.

Medium complexity with three upstream dependencies: certification-expiry-repository, expiry-notification-orchestrator, and mentor-visibility-suppressor—all of which must be complete and tested before end-to-end integration of this edge function. The cron schedule must be configured in Supabase project settings and verified in both staging and production environments. Key delivery risks include: cron misconfiguration leading to missed daily runs, edge function execution timeouts if the mentor dataset is large (Supabase edge functions have a default timeout), and failure isolation if one dependency throws—the function must not abort the entire batch on a single record failure. Observability is critical: logExecutionResult must produce structured logs consumable by the monitoring stack.

A manual trigger endpoint (handler via HTTP POST) should be included to support operational testing without waiting for the cron window.

Implemented as a Supabase Edge Function (Deno runtime) registered on a daily cron trigger. The handler entry point validates the request (cron invocation vs. manual HTTP trigger), then calls runDailyExpiryCheck, which invokes certificationExpiryRepository.getUpcomingExpirations for each configured threshold window (60/30/7 days) and getExpiredMentors. Results are passed to processExpirationBatch, which iterates records and calls expiryNotificationOrchestrator for notification dispatch and mentorVisibilitySuppressor for expired records.

Each record is processed in a try/catch to ensure one failure does not abort the batch. logExecutionResult writes a structured JSON log including batch size, success count, failure count, and per-failure error details. The function should be idempotent: repeated runs on the same day should not produce duplicate notifications, relying on notificationRecordRepository's threshold deduplication. Environment variables must supply the Supabase service role key and any configurable threshold values.

Responsibilities

  • Execute daily on a cron schedule via Supabase
  • Query certification expiry repository for upcoming and lapsed expirations
  • Invoke notification orchestrator for threshold notifications
  • Trigger mentor visibility suppression for expired certificates
  • Log execution results for observability

Interfaces

handler(req: Request) -> Response
runDailyExpiryCheck()
processExpirationBatch(expirations: List<ExpiryRecord>)
logExecutionResult(result: ExpiryCheckResult)

Related Data Entities (1)

Data entities managed by this component

Used Integrations (1)

External integrations and APIs this component relies on

API Contract

View full contract →
REST /api/v1/expiry-checks 5 endpoints
GET /api/v1/expiry-checks
GET /api/v1/expiry-checks/:check_id
POST /api/v1/expiry-checks
PUT /api/v1/expiry-checks/:check_id
DELETE /api/v1/expiry-checks/:check_id