Skip to content

Add SSE for async operations#2086

Open
johnmeshulam wants to merge 13 commits intomainfrom
sse
Open

Add SSE for async operations#2086
johnmeshulam wants to merge 13 commits intomainfrom
sse

Conversation

@johnmeshulam
Copy link
Copy Markdown
Member

Description

Added SSE for async api operations in the admin app

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • My changes generate no new warnings

Comment thread apps/backend/src/routers/admin/events/settings/index.ts Fixed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces Server-Sent Events (SSE) to report progress for long-running admin operations (publishing events with SendGrid emailing, and generating/downloading results ZIPs), plus corresponding admin UI progress indicators.

Changes:

  • Added shared frontend SSE client helper (connectSseStream) and backend SSE emitter utility.
  • Updated admin “Publish” and “Download results” flows to stream progress and handle async completion via SSE.
  • Changed results download to generate ZIP server-side, store it temporarily, and return a token for a follow-up file download request.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
libs/shared/src/lib/sse.ts Adds fetch-based SSE client helper and shared SseEvent type.
libs/shared/src/index.ts Re-exports SSE helper from shared package.
apps/backend/src/lib/sse.ts Adds backend SSE emitter for consistent SSE responses.
apps/backend/src/lib/temp-download-store.ts Adds in-memory token store for temporary ZIP downloads.
apps/backend/src/lib/results-download.ts Adds progress callback support during ZIP generation.
apps/backend/src/routers/admin/events/settings/index.ts Switches publish/download endpoints to SSE; adds token-based ZIP download endpoint.
apps/backend/src/routers/integrations/sendgrid/publish.ts Adds progress callback support and additional SendGrid-key handling/logging.
apps/admin/.../publish-event-dialog.tsx Adds progress UI (linear progress + message) for publish flow.
apps/admin/.../download-results-dialog.tsx Adds linear progress UI for ZIP generation flow.
apps/admin/.../event-actions-section.tsx Uses SSE client for publish/download actions and triggers file download via token URL.
apps/admin/locale/en.json / pl.json / he.json Adds new localized strings for progress and success-with-emails messaging.
Comments suppressed due to low confidence (1)

apps/backend/src/routers/admin/events/settings/index.ts:65

  • published: true is persisted before SendGrid email sending, but the SendGrid error path sends an SSE failure. This makes the client treat the publish as failed even though it may already be published. Consider moving the published update after emails succeed, rolling it back on email failure, or returning success with email failure details instead of failure.
    const updatedSettings = await db.events.byId(req.eventId).updateSettings({ published: true });
    if (!updatedSettings) {
      throw new Error('Failed to publish event');
    }

Comment thread apps/backend/src/lib/temp-download-store.ts
Comment thread libs/shared/src/lib/sse.ts Outdated
Comment thread apps/backend/src/routers/integrations/sendgrid/publish.ts Outdated
Comment thread apps/backend/src/routers/integrations/sendgrid/publish.ts
Comment thread apps/backend/src/routers/admin/events/settings/index.ts Outdated
Comment thread apps/backend/src/lib/sse.ts
Comment thread libs/shared/src/lib/sse.ts Outdated
johnmeshulam and others added 8 commits April 22, 2026 22:40
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment thread apps/backend/src/routers/admin/events/settings/index.ts Fixed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Server-Sent Events (SSE) to support progress reporting for long-running admin operations (publishing w/ SendGrid emails and generating/downloading results ZIPs), improving UX by streaming start/progress/success/failure states.

Changes:

  • Introduce shared fetch-based SSE client helper and backend SSE emitter.
  • Stream progress updates for SendGrid publish and results ZIP generation.
  • Change results download flow to: POST (generate + get token via SSE) → GET (download by token).

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
libs/shared/src/lib/sse.ts New SSE client helper using fetch + streaming reader.
libs/shared/src/index.ts Re-export SSE helper from shared package.
apps/backend/src/lib/sse.ts New SSE emitter for Express responses.
apps/backend/src/lib/temp-download-store.ts In-memory TTL token store for generated ZIP files.
apps/backend/src/lib/results-download.ts Add progress callback support during ZIP generation.
apps/backend/src/routers/admin/events/settings/index.ts Convert publish/download endpoints to SSE; add token-based download route.
apps/backend/src/routers/integrations/sendgrid/publish.ts Add progress callback during SendGrid email sending.
apps/admin/src/app/[locale]/(dashboard)/events/[slug]/settings/components/event-actions-section.tsx Use SSE client for publish/download; start token-based download.
apps/admin/src/app/[locale]/(dashboard)/events/[slug]/settings/components/publish-event-dialog.tsx Show publish progress UI (message + progress bar).
apps/admin/src/app/[locale]/(dashboard)/events/[slug]/settings/components/download-results-dialog.tsx Show download generation progress UI (progress bar).
apps/admin/locale/en.json New strings for progress/info + publish success w/ emails.
apps/admin/locale/he.json New strings for progress/info + publish success w/ emails.
apps/admin/locale/pl.json New strings for progress/info + publish success w/ emails.
Comments suppressed due to low confidence (1)

apps/backend/src/routers/integrations/sendgrid/publish.ts:95

  • publishEventResults references apiKey but apiKey is no longer defined in this scope (it was moved inside sendEmailToContact). This will fail TypeScript compilation. Either reintroduce const apiKey = process.env.SENDGRID_API_KEY in publishEventResults (and pass it down), or remove this check and make the missing-key behavior consistent with sendEmailToContact.
  if (!settings) {
    throw new Error('Missing integration settings');
  }

  if (!apiKey) {
    throw new Error('SendGrid API key not configured');
  }

Comment on lines +166 to +175
await new Promise<void>((resolve, reject) => {
fileStream!.on('finish', resolve);
fileStream!.on('error', reject);
archive!.on('error', reject);
archive!.pipe(fileStream!);
archive!.finalize();
});

archive.pipe(res);
await archive.finalize();
const token = storeTempFile(tempPath, fileName);
emitter.sendSuccess({ token });
Comment thread apps/backend/src/lib/temp-download-store.ts
Comment thread apps/backend/src/routers/admin/events/settings/index.ts
Comment thread apps/backend/src/lib/sse.ts Outdated
Comment thread apps/backend/src/routers/admin/events/settings/index.ts
johnmeshulam and others added 2 commits April 22, 2026 23:02
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

3 participants