stack/packages/stack-shared/src/utils
BilalG1 d14317c787
batch sending (#875)
<!--

Make sure you've read the CONTRIBUTING.md guidelines:
https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md

-->

<!-- ELLIPSIS_HIDDEN -->


----

> [!IMPORTANT]
> Implement batch email rendering and sending with enhanced processing
and error handling.
> 
>   - **Behavior**:
> - Implement batch email rendering and sending in `route.tsx` using
`renderEmailsWithTemplateBatched()` and `sendEmailResendBatched()`.
> - Add per-recipient notification category resolution and unsubscribe
link generation.
> - Support templates from IDs, raw HTML, or drafts with dynamic theme
handling.
> - Enhanced result reporting, including users without primary emails.
>   - **Functions**:
> - Add `renderEmailsWithTemplateBatched()` in `email-rendering.tsx` for
batch email rendering.
> - Add `sendEmailResendBatched()` in `emails.tsx` for batch email
sending.
>     - Add `getChunks()` in `arrays.tsx` to split arrays into chunks.
>   - **Tests**:
> - Add timed waits in `send-email.test.ts` and
`unsubscribe-link.test.ts` to stabilize email delivery checks.
>   - **Dependencies**:
> - Add `@react-email/render` and `resend` to `package.json` for email
rendering and sending.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=stack-auth%2Fstack-auth&utm_source=github&utm_medium=referral)<sup>
for ff1dea6c31. You can
[customize](https://app.ellipsis.dev/stack-auth/settings/summaries) this
summary. It will automatically update as commits are pushed.</sup>

----


<!-- ELLIPSIS_HIDDEN -->

<!-- RECURSEML_SUMMARY:START -->
## Review by RecurseML

_🔍 Review performed on
[3c34140..1267879](3c34140aba...1267879cfd)_

| Severity | Location | Issue |
|----------|----------|-------|
| ![Medium](https://img.shields.io/badge/Medium-yellow?style=plastic) |
[apps/e2e/tests/backend/endpoints/api/v1/send-email.test.ts:593](https://github.com/stack-auth/stack-auth/pull/875#discussion_r2317293698)
| Asynchronous wait function not wrapped with runAsynchronously |
| ![Medium](https://img.shields.io/badge/Medium-yellow?style=plastic) |
[apps/e2e/tests/backend/endpoints/api/v1/send-email.test.ts:743](https://github.com/stack-auth/stack-auth/pull/875#discussion_r2317293796)
| Asynchronous wait function not wrapped with runAsynchronously |

<details>
<summary> Files analyzed, no issues (4)</summary>

  • `apps/backend/src/app/api/latest/emails/send-email/route.tsx`
  • `apps/backend/src/lib/email-rendering.tsx`
  • `apps/backend/src/lib/emails.tsx`
  • `packages/stack-shared/src/utils/arrays.tsx`
</details>

<details>
<summary>⏭️ Files skipped (low suspicion) (2)</summary>

  • `apps/backend/package.json`
  • `pnpm-lock.yaml`
</details>

[![Need help? Join our
Discord](https://img.shields.io/badge/Need%20help%3F%20Join%20our%20Discord-5865F2?style=plastic&logo=discord&logoColor=white)](https://discord.gg/n3SsVDAW6U)
<!-- RECURSEML_SUMMARY:END -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- New Features
- Batch email rendering and sending to multiple recipients with
background processing.
- Per-recipient notification category resolution and unsubscribe link
generation.
- Support for templates from IDs, raw HTML, or drafts with dynamic theme
handling.
  - Enhanced result reporting, including users without primary emails.
- Chores
  - Added dependencies for email rendering and bulk sending.
- Tests
- Stabilized email delivery checks with timed waits across relevant e2e
tests.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
2025-09-11 15:42:51 -07:00
..
api-keys.tsx tsup for stack-shared (#647) 2025-04-28 21:26:52 -07:00
arrays.tsx batch sending (#875) 2025-09-11 15:42:51 -07:00
base64.tsx Add inline unit tests to utility functions in stack-shared (#467) 2025-02-26 16:11:30 -08:00
booleans.tsx Add inline unit tests to utility functions in stack-shared (#467) 2025-02-26 16:11:30 -08:00
browser-compat.tsx Better specs for Docker GH Action 2024-12-11 19:02:49 -08:00
bytes.tsx Data vaults (#871) 2025-08-30 23:42:56 -07:00
caches.tsx [DEVIN: Konsti] Add in-source unit tests to stack-shared utilities (#485) 2025-02-28 01:47:37 +00:00
compile-time.tsx Split stack-app.ts file into multiple files (#492) 2025-03-02 21:20:42 -08:00
crypto.tsx Data vaults (#871) 2025-08-30 23:42:56 -07:00
currencies.tsx payments schema changes, ledger algo, stackable items (#862) 2025-08-27 20:13:22 +00:00
currency-constants.tsx payments schema changes, ledger algo, stackable items (#862) 2025-08-27 20:13:22 +00:00
dates.tsx payments schema changes, ledger algo, stackable items (#862) 2025-08-27 20:13:22 +00:00
dom.tsx Fix lint errors 2024-06-06 13:35:29 +02:00
env.tsx JS lib docs (#444) 2025-02-20 00:48:05 +01:00
errors.tsx Even more better error messages 2025-07-30 13:16:14 -07:00
esbuild.tsx Fix STACK-BACKEND-FF 2025-09-09 15:33:59 -07:00
featurebase.tsx Feature/stack companion (#769) 2025-08-12 15:12:20 -05:00
fs.tsx added writeFileSyncIfChanged to all the codegen 2025-02-19 12:11:17 -08:00
functions.tsx [DEVIN: Konsti] Add in-source unit tests to stack-shared utilities (#485) 2025-02-28 01:47:37 +00:00
geo.tsx Active Sessions Page (#528) 2025-03-12 22:35:32 +01:00
globals.tsx Source of Truth (#660) 2025-07-11 17:59:03 -07:00
hashes.tsx Fix docker (#664) 2025-05-08 01:31:03 +02:00
html.tsx Feature/stack companion (#769) 2025-08-12 15:12:20 -05:00
http.tsx [DEVIN: Konsti] Add in-source unit tests to stack-shared utilities (#485) 2025-02-28 01:47:37 +00:00
ips.tsx [DEVIN: Konsti] Add in-source unit tests to stack-shared utilities (#485) 2025-02-28 01:47:37 +00:00
json.tsx Widget subgrids 2025-07-13 22:16:42 -07:00
jwt.tsx Better OAuth error logging 2025-09-08 22:17:33 -07:00
locks.tsx Added sign out lock (#374) 2024-12-20 18:38:04 +01:00
maps.tsx [DEVIN: Konsti] Add in-source unit tests to stack-shared utilities (#485) 2025-02-28 01:47:37 +00:00
math.tsx Add inline unit tests to utility functions in stack-shared (#467) 2025-02-26 16:11:30 -08:00
node-http.tsx Force dynamic 2024-12-01 01:31:22 -08:00
numbers.tsx Workflows (#873) 2025-09-03 01:22:08 -07:00
oauth.tsx Add an OAuth provider for Twitch (#728) 2025-07-23 02:31:47 +02:00
objects.tsx Several project config improvements (#811) 2025-07-29 04:13:46 -07:00
passkey.tsx Passkey support (#321) 2024-10-28 16:56:46 -07:00
promises.tsx Workflows (#873) 2025-09-03 01:22:08 -07:00
proxies.tsx Reduce test flakeyness (#517) 2025-03-07 13:34:50 -08:00
react.tsx Payments UX update (#863) 2025-08-27 17:28:01 -07:00
results.tsx Better RetryErrors (#553) 2025-04-04 09:40:28 -07:00
sentry.tsx Increase Sentry maxValueLength 2024-12-11 18:56:42 -08:00
stores.tsx Added sign out lock (#374) 2024-12-20 18:38:04 +01:00
strings.nicify.test.ts Better RetryErrors (#553) 2025-04-04 09:40:28 -07:00
strings.tsx Exclude anonymous users from metrics 2025-08-27 11:38:47 -07:00
telemetry.tsx Add tracing to ESBuild 2025-07-31 16:22:55 -07:00
types.tsx Email Drafts (#849) 2025-09-10 22:57:18 +00:00
unicode.tsx [DEVIN: Konsti] Add in-source unit tests to stack-shared utilities (#485) 2025-02-28 01:47:37 +00:00
urls.tsx Wildcard domains (#830) 2025-08-19 22:59:21 -07:00
uuids.tsx [DEVIN: Konsti] Add in-source unit tests to stack-shared utilities (#485) 2025-02-28 01:47:37 +00:00