Skip to content

added cron job to for daily failed email digest#714

Merged
N2D4 merged 11 commits intohexclave:devfrom
BilalG1:failed-emails-digest
Jun 17, 2025
Merged

added cron job to for daily failed email digest#714
N2D4 merged 11 commits intohexclave:devfrom
BilalG1:failed-emails-digest

Conversation

@BilalG1
Copy link
Copy Markdown
Collaborator

@BilalG1 BilalG1 commented Jun 17, 2025

Important

Add cron job and API endpoint for daily failed email digest with authorization and tests.

  • Cron Job:
    • Added cron job in vercel.json to trigger /api/latest/internal/failed-emails-digest daily at midnight.
  • API Endpoint:
    • New POST endpoint in route.ts to handle failed email digests, requiring STACK_CRON_SECRET for authorization.
    • Uses getFailedEmailsByTenancy from crud.tsx to fetch failed emails from the last 24 hours.
    • Sends email digest to tenant owners using sendEmail.
  • Environment:
    • Added STACK_CRON_SECRET to .env.development for authorization.
  • Tests:
    • Added tests in failed-emails-digest.test.ts for authorization and successful processing of failed emails.

This description was created by Ellipsis for c4ef137. You can customize this summary. It will automatically update as commits are pushed.

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 17, 2025

@BilalG1 is attempting to deploy a commit to the Stack Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jun 17, 2025

CLA assistant check
All committers have signed the CLA.

@BilalG1 BilalG1 changed the base branch from main to dev June 17, 2025 01:51
@N2D4 N2D4 assigned N2D4 and BilalG1 Jun 17, 2025
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
stack-backend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 17, 2025 10:27pm
stack-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 17, 2025 10:27pm
stack-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 17, 2025 10:27pm
stack-docs ❌ Failed (Inspect) Jun 17, 2025 10:27pm

@recurseml
Copy link
Copy Markdown

recurseml Bot commented Jun 17, 2025

😱 Found 2 issues. Time to roll up your sleeves! 😱

🗒️ View all ignored comments in this repo
  • The constraint 'TokenStoreType extends string' is too restrictive. It should likely be 'TokenStoreType extends string | object' to match the condition check in line 113 where TokenStoreType is checked against {}
  • Return type mismatch - the interface declares useUsers() returning ServerUser[] but the Team interface that this extends declares useUsers() returning TeamUser[]
  • There is a syntax error in the super constructor call due to the ellipsis operator used incorrectly. Objects aren't being merged correctly. This syntax usage can lead to runtime errors when trying to pass the merged object to 'super()'. Verify that the intended alterations to the object occur before or outside of the super() call if needed.
  • Throwing an error when no active span is found is too aggressive. The log function should gracefully fallback to console.log or another logging mechanism when there's no active span, since not all execution contexts will have an active span. This makes the code less resilient and could break functionality in non-traced environments.

📚 Relevant Docs

  • Function sets backendContext with a new configuration but doesn't pass 'defaultProjectKeys'. Since defaultProjectKeys is required in the type definition and cannot be updated (throws error if tried to set), this will cause a type error.
  • The schema is using array syntax for pick() which is incorrect for Yup schemas. The pick() method in Yup expects individual arguments, not an array. Should be changed to: emailConfigSchema.pick('type', 'host', 'port', 'username', 'sender_name', 'sender_email')

📚 Relevant Docs

  • Creating a refresh token with current timestamp as expiration means it expires immediately. Should set a future date for token expiration.
  • The 'tools' object is initialized as an empty object, even though 'tools' is presumably expected to contain tool definitions. This could cause the server capabilities to lack necessary tool configurations, thus potentially impacting functionalities that depend on certain tool setups.

📚 Relevant Docs

  • 'STACK_SECRET_SERVER_KEY' is potentially being included in every request header without checking its existence again here. Although it's checked during initialization, this could lead to security issues as it's exposed in all communications where the header is logged or captured.

📚 Relevant Docs

  • When adding 'use client' directive at the beginning, it doesn't check if file.text already contains the 'use client' directive. This could lead to duplicate 'use client' directives if the file already has one.

📚 Relevant Docs

Comment thread apps/backend/src/app/api/latest/internal/failed-emails-digest/crud.tsx Outdated
Comment thread apps/backend/src/app/api/latest/internal/failed-emails-digest/route.ts Outdated
Copy link
Copy Markdown
Contributor

@N2D4 N2D4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff!

Comment thread apps/backend/.env.development Outdated
Comment thread apps/backend/src/app/api/latest/internal/failed-emails-digest/crud.tsx Outdated
Comment thread apps/backend/src/app/api/latest/internal/failed-emails-digest/crud.tsx Outdated
Comment thread apps/backend/src/app/api/latest/internal/failed-emails-digest/route.ts Outdated
Comment thread apps/backend/src/app/api/latest/internal/failed-emails-digest/route.ts Outdated
Comment thread apps/backend/vercel.json Outdated
@N2D4 N2D4 marked this pull request as draft June 17, 2025 04:41
@N2D4 N2D4 marked this pull request as ready for review June 17, 2025 04:41
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

Added daily failed email digest functionality with cron job and secure API endpoint to notify tenant owners of delivery issues.

  • New internal endpoint /api/latest/internal/failed-emails-digest with STACK_CRON_SECRET authorization
  • Raw SQL query in apps/backend/src/app/api/latest/internal/failed-emails-digest/crud.tsx using dynamic parameters without proper object safety
  • Vercel cron job configured to run daily at midnight
  • E2E tests in apps/e2e/tests/backend/endpoints/api/v1/internal/failed-emails-digest.test.ts verifying authorization and email processing
  • Environment variable STACK_CRON_SECRET added to .env.development for local testing

5 files reviewed, 1 comment
Edit PR Review Bot Settings | Greptile

Copy link
Copy Markdown
Contributor

@N2D4 N2D4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to merge when tests pass!

@N2D4 N2D4 disabled auto-merge June 17, 2025 22:38
@N2D4 N2D4 merged commit 71c35fd into hexclave:dev Jun 17, 2025
16 of 17 checks passed
N2D4 added a commit to willothy/stack that referenced this pull request Jun 23, 2025
Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants