#!/bin/sh
# Triggers the weekly digest email send on the `web` service. Run on a schedule
# by busybox crond (see cron/crontab). Fails loudly (non-zero exit,
# stderr) but crond just tries again next week — no retry loop here on purpose,
# keep this script trivial.
set -eu

: "${WEB_INTERNAL_URL:=http://web:3000}"

if [ -z "${CRON_SECRET:-}" ]; then
  echo "run-digest: CRON_SECRET is not set, refusing to call the digest endpoint" >&2
  exit 1
fi

curl -fsS -X POST \
  -H "Authorization: Bearer ${CRON_SECRET}" \
  "${WEB_INTERNAL_URL}/api/internal/cron/weekly-digest"
