Skip to content

Rewrite of legacy webhooks#2348

Draft
lkostrowski wants to merge 4 commits into
mainfrom
lkostrowski/replace-notify-webhook
Draft

Rewrite of legacy webhooks#2348
lkostrowski wants to merge 4 commits into
mainfrom
lkostrowski/replace-notify-webhook

Conversation

@lkostrowski

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings April 29, 2026 13:26
@changeset-bot

changeset-bot Bot commented Apr 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2893bb6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
saleor-app-smtp Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Apr 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
saleor-app-smtp Ready Ready Preview, Comment May 13, 2026 7:41am
8 Skipped Deployments
Project Deployment Actions Updated (UTC)
saleor-app-avatax Ignored Ignored Preview, Comment May 13, 2026 7:41am
saleor-app-cms Ignored Ignored Preview, Comment May 13, 2026 7:41am
saleor-app-klaviyo Ignored Ignored Preview May 13, 2026 7:41am
saleor-app-payment-np-atobarai Ignored Ignored Preview, Comment May 13, 2026 7:41am
saleor-app-payment-stripe Ignored Ignored Preview May 13, 2026 7:41am
saleor-app-products-feed Ignored Ignored Preview, Comment May 13, 2026 7:41am
saleor-app-search Ignored Ignored Preview, Comment May 13, 2026 7:41am
saleor-app-segment Ignored Ignored Preview, Comment May 13, 2026 7:41am

Request Review

@codecov

codecov Bot commented Apr 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.98927% with 206 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.65%. Comparing base (17031e8) to head (2893bb6).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
...mtp/src/modules/event-handlers/default-payloads.ts 0.00% 95 Missing ⚠️
...s/smtp/src/modules/smtp/ui/smtp-events-section.tsx 0.00% 23 Missing ⚠️
...s/smtp/configuration/smtp-configuration.service.ts 79.16% 10 Missing ⚠️
...mtp/src/pages/api/webhooks/fulfillment-approved.ts 90.58% 8 Missing ⚠️
...mtp/src/pages/api/webhooks/fulfillment-canceled.ts 90.58% 8 Missing ⚠️
...smtp/src/pages/api/webhooks/fulfillment-created.ts 90.58% 8 Missing ⚠️
...pi/webhooks/fulfillment-tracking-number-updated.ts 90.24% 8 Missing ⚠️
...ges/api/webhooks/account-change-email-requested.ts 92.30% 6 Missing ⚠️
...ges/api/webhooks/account-confirmation-requested.ts 92.30% 6 Missing ⚠️
...src/pages/api/webhooks/account-delete-requested.ts 92.59% 6 Missing ⚠️
... and 7 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2348      +/-   ##
==========================================
+ Coverage   37.84%   38.65%   +0.80%     
==========================================
  Files        1037     1047      +10     
  Lines       66937    68151    +1214     
  Branches     3533     3663     +130     
==========================================
+ Hits        25335    26345    +1010     
- Misses      41221    41425     +204     
  Partials      381      381              
Flag Coverage Δ
avatax 57.57% <ø> (-0.02%) ⬇️
cms 20.36% <ø> (ø)
domain 100.00% <ø> (ø)
dynamo-config-repository 79.29% <ø> (ø)
errors 91.66% <ø> (ø)
logger 28.81% <ø> (ø)
np-atobarai 72.58% <ø> (ø)
products-feed 6.00% <ø> (ø)
search 32.38% <ø> (+0.50%) ⬆️
segment 33.58% <ø> (ø)
shared 56.07% <ø> (ø)
smtp 42.21% <82.98%> (+6.46%) ⬆️
stripe 70.83% <ø> (ø)
webhook-utils 11.02% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 replaces parts of the legacy catch-all notify webhook flow with dedicated, typed Saleor async webhooks (GraphQL subscriptions) for account and fulfillment events, while marking legacy events as deprecated in the dashboard and keeping existing templates working.

Changes:

  • Added 9 dedicated webhook endpoints (and unit tests) for account + fulfillment events using typed GraphQL subscription payloads.
  • Introduced event metadata (label, deprecated, replacedBy) and updated UI/config generation to hide deprecated events for new tenants while hydrating existing tenants with new non-deprecated events.
  • Expanded default templates, example payloads, and webhook management mappings/statuses to support the new events.

Reviewed changes

Copilot reviewed 34 out of 35 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
apps/smtp/src/pages/configuration/smtp/[configurationId]/event/[eventType].tsx Uses new event metadata to render breadcrumb label.
apps/smtp/src/pages/api/webhooks/notify.ts Logs legacy webhook usage and points to replacement event metadata.
apps/smtp/src/pages/api/webhooks/fulfillment-tracking-number-updated.ts New dedicated fulfillment webhook handler (typed payload).
apps/smtp/src/pages/api/webhooks/fulfillment-tracking-number-updated.test.ts Unit tests for the new fulfillment-tracking-number-updated handler.
apps/smtp/src/pages/api/webhooks/fulfillment-created.ts New dedicated fulfillment-created webhook handler (typed payload).
apps/smtp/src/pages/api/webhooks/fulfillment-created.test.ts Unit tests for the new fulfillment-created handler.
apps/smtp/src/pages/api/webhooks/fulfillment-canceled.ts New dedicated fulfillment-canceled webhook handler (typed payload).
apps/smtp/src/pages/api/webhooks/fulfillment-canceled.test.ts Unit tests for the new fulfillment-canceled handler.
apps/smtp/src/pages/api/webhooks/fulfillment-approved.ts New dedicated fulfillment-approved webhook handler (typed payload).
apps/smtp/src/pages/api/webhooks/fulfillment-approved.test.ts Unit tests for the new fulfillment-approved handler.
apps/smtp/src/pages/api/webhooks/account-set-password-requested.ts New dedicated account-set-password-requested webhook handler (typed payload).
apps/smtp/src/pages/api/webhooks/account-set-password-requested.test.ts Unit tests for the new account-set-password-requested handler.
apps/smtp/src/pages/api/webhooks/account-email-changed.ts New dedicated account-email-changed webhook handler (typed payload).
apps/smtp/src/pages/api/webhooks/account-email-changed.test.ts Unit tests for the new account-email-changed handler.
apps/smtp/src/pages/api/webhooks/account-delete-requested.ts New dedicated account-delete-requested webhook handler (typed payload).
apps/smtp/src/pages/api/webhooks/account-delete-requested.test.ts Unit tests for the new account-delete-requested handler.
apps/smtp/src/pages/api/webhooks/account-confirmation-requested.ts New dedicated account-confirmation-requested webhook handler (typed payload).
apps/smtp/src/pages/api/webhooks/account-confirmation-requested.test.ts Unit tests for the new account-confirmation-requested handler.
apps/smtp/src/pages/api/webhooks/account-change-email-requested.ts New dedicated account-change-email-requested webhook handler (typed payload).
apps/smtp/src/pages/api/webhooks/account-change-email-requested.test.ts Unit tests for the new account-change-email-requested handler.
apps/smtp/src/modules/webhook-management/webhook-status-dict.ts Adds status keys for the new dedicated webhooks.
apps/smtp/src/modules/webhook-management/webhook-management-service.ts Registers new webhooks and maps new events to their dedicated webhook names.
apps/smtp/src/modules/webhook-management/sync-webhook-status.test.ts Updates sync-webhook-status tests to include new webhook status keys.
apps/smtp/src/modules/smtp/ui/smtp-events-section.tsx Displays deprecation badge + replacement hint using new event metadata; sorts by metadata label.
apps/smtp/src/modules/smtp/ui/event-form.tsx Updates template option labels to use metadata label.
apps/smtp/src/modules/smtp/default-templates.ts Adds default templates + subjects for new account/fulfillment events.
apps/smtp/src/modules/smtp/configuration/smtp-default-empty-configurations.ts Excludes deprecated events from default config for new tenants.
apps/smtp/src/modules/smtp/configuration/smtp-default-empty-configurations.test.ts Tests default config excludes deprecated events and includes new replacements.
apps/smtp/src/modules/smtp/configuration/smtp-configuration.service.ts Hydrates existing configs at read-time with missing non-deprecated events + defaults.
apps/smtp/src/modules/smtp/configuration/smtp-configuration.service.test.ts Updates tests for hydration behavior and adds dedicated hydration assertions.
apps/smtp/src/modules/event-handlers/message-event-types.ts Extends event types and replaces label map with richer metadata (deprecated/replacedBy).
apps/smtp/src/modules/event-handlers/default-payloads.ts Adds example payloads for new dedicated account/fulfillment events.
apps/smtp/scripts/build-email-previews.ts Uses metadata label when generating preview pages.
apps/smtp/generated/graphql.ts Generated GraphQL types/fragments/subscriptions for new webhook payloads.
.changeset/dedicated-webhooks-replace-notify.md Changeset documenting new dedicated webhooks and deprecation strategy.

Comment on lines +62 to +65
const { payload, authData } = context;
const { fulfillment, order } = payload;

if (!order) {

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

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

fulfillment is optional in the payload type, but the handler doesn’t guard against it being null/undefined. Add an early return (200) when fulfillment is missing to avoid sending emails with incomplete fulfillment context.

Copilot uses AI. Check for mistakes.

const { payload, authData } = context;
const { fulfillment, order } = payload;

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

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

fulfillment is optional in the payload type but isn’t validated. Add an early return when fulfillment is missing so templates don’t render emails without fulfillment details.

Suggested change
if (!fulfillment) {
logger.error("No fulfillment in payload. Aborting.");
return res
.status(200)
.json({ error: "Fulfillment has not been specified in the event payload." });
}

Copilot uses AI. Check for mistakes.
Comment on lines +64 to +67
const { payload, authData } = context;
const { user, channel, redirectUrl, token, shop } = payload;

const recipientEmail = user?.email;

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

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

redirectUrl and token are optional in the generated payload type, but they’re forwarded to templates that build an action link. Add explicit validation (and return 200 with an error) when either is missing to avoid sending emails with broken URLs.

Copilot uses AI. Check for mistakes.
Comment on lines +66 to +70
const { payload, authData } = context;
const { user, channel, redirectUrl, token, shop } = payload;

const recipientEmail = user?.email;

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

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

redirectUrl/token are optional on the payload type, but the handler forwards them to templates that rely on them for the CTA link. Please validate they’re present before sending the message (return 200 + error when missing).

Copilot uses AI. Check for mistakes.
Comment on lines +79 to +83
const channelSlug = order.channel?.slug;

if (!channelSlug) {
logger.error(`The order ${order.number} had no channel set. Aborting.`);

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

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

Test coverage: the handler has a branch for missing order.channel.slug (returns 200 with an error), but the added unit tests don’t cover it. Add a test case with a payload missing order.channel/slug to lock in this behavior.

Copilot uses AI. Check for mistakes.

const { payload, authData } = context;
const { fulfillment, order } = payload;

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

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

fulfillment can be null per the generated payload type, but the handler doesn’t validate it before forwarding into templates. Consider returning early (200) when fulfillment is missing (similar to other webhook handlers that validate their root object).

Suggested change
if (!fulfillment) {
logger.error("No fulfillment in payload. Aborting.");
return res
.status(200)
.json({ error: "Fulfillment has not been specified in the event payload." });
}

Copilot uses AI. Check for mistakes.
Comment on lines +64 to +66
const { payload, authData } = context;
const { user, channel, redirectUrl, token, shop } = payload;

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

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

redirectUrl and token are optional in the generated payload type, but the default template constructs a reset link from them. Add explicit validation and return 200 with an error when either is missing to avoid sending broken emails.

Copilot uses AI. Check for mistakes.
Comment on lines +65 to +67
const { payload, authData } = context;
const { user, channel, redirectUrl, token, shop, newEmail } = payload;

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

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

The template content for this event depends on newEmail, redirectUrl, and token, but the handler only validates the current recipient email + channel. Since these fields are optional in the generated type, add validation and return 200 with an error when any are missing.

Copilot uses AI. Check for mistakes.
Comment on lines +81 to +83
const channelSlug = order.channel?.slug;

if (!channelSlug) {

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

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

Test coverage: there’s an explicit branch when order.channel.slug is missing, but the current unit tests only cover missing order and missing order.userEmail. Add a test for the missing-channel case.

Copilot uses AI. Check for mistakes.
Comment on lines +81 to +83
const channelSlug = order.channel?.slug;

if (!channelSlug) {

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

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

Test coverage: the missing order.channel.slug branch isn’t covered by the new tests. Add a unit test to assert the handler returns 200 with the channel error and does not call sendEventMessages.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants