Skip to content

Batch API#132

Open
eric-pSAP wants to merge 12 commits into
mainfrom
batchAPI
Open

Batch API#132
eric-pSAP wants to merge 12 commits into
mainfrom
batchAPI

Conversation

@eric-pSAP

Copy link
Copy Markdown
Contributor

Batch APIs should be supported such as alert.notify('<Notification Type>', [{recipients: <recipient>, ...<properties>}, ...])

@hyperspace-insights hyperspace-insights Bot 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.

The PR introduces a useful batch notification API with good test coverage, but has several correctness issues that need to be addressed: input mutation in the batch emit path, CSRF token reuse across parallel requests, inconsistent recipient key resolution bypassing the authenticationIdentifier config, a potential recipients field leaking into Properties, silent swallowing of all batch failures without error propagation, and a typo in the README example.

PR Bot Information

Version: 1.22.5

  • File Content Strategy: Full file content
  • Event Trigger: pull_request.opened
  • Correlation ID: f3e56ffc-4e48-449b-b3a5-97c8f223bc37
  • LLM: anthropic--claude-4.6-sonnet

Comment thread srv/service.js Outdated
Comment thread srv/notifyToRest.js Outdated
Comment thread lib/utils.js Outdated
Comment thread lib/utils.js Outdated
Comment thread README.md Outdated
Comment thread srv/notifyToRest.js
@eric-pSAP eric-pSAP marked this pull request as ready for review June 11, 2026 15:55
@hyperspace-insights

Copy link
Copy Markdown
Contributor

Summary

The following content is AI-generated and provides a summary of the pull request:


Add Batch Notification API Support

New Feature

✨ Introduces a Batch Notification API that allows sending multiple notifications in a single notify() call. Passing an array as the second argument (or as the first for default notifications) triggers a single outbox event, reducing transaction overhead when notifying many recipients. Each notification in a batch is dispatched independently — failures do not block the others.

Usage examples:

// Typed batch notification
alert.notify('BookOrdered', [
  { recipients: [ buyer1.id ], data: { title: book.title, buyer: buyer1.name } },
  { recipients: [ buyer2.id ], data: { title: book.title, buyer: buyer2.name } },
])

// Default batch notification
alert.notify([
  { recipients: ['alice@example.com'], title: 'Order confirmed', description: 'Your order is on its way.' },
  { recipients: ['bob@example.com'],   title: 'We have your order', description: 'Your order is being processed.' },
])

Changes

  • srv/service.js: Added batch handling in emit() — when the message is an array, each entry is built into a notification and emitted as a single event.
  • srv/notifyToRest.js: Extended postNotification() to handle arrays via Promise.allSettled, with partial failure support and a new _postOne() helper.
  • srv/notifyToConsole.js: Updated console handler to iterate over batched notifications and validate each one individually.
  • cds-plugin.js: Added a serving hook that intercepts @notification-annotated CDS events emitted on any service and forwards them to the notifications service automatically. Also imports and uses the new buildNotificationFromEvent utility.
  • lib/utils.js: Added buildNotificationFromEvent() to construct a notification from a CDS event definition and event data, plus mapCdsTypeToANSType() for CDS-to-ANS type mapping. Also fixed IsSensitive to be true for all notification properties (was false for title and some others).
  • CHANGELOG.md: Documented the new batch notification API.
  • README.md: Added a "Batch Notifications" section with usage examples for typed and default batch notifications.
  • tests/bookshop/srv/cat-service.js: Added a direct this.emit() call for BookOrderedNotify to test the auto-notification plugin path.
  • tests/bookshop/srv/notifications.cds: Switched from a standalone notificationService to extending CatalogService directly.
  • tests/integration/bookshop.test.js: Added integration tests for batch typed/default notifications, plugin auto-emit, and direct event emit.
  • tests/unit/lib/notifications.test.js: Added unit tests for batch success/partial failure/all-failure scenarios in postNotification.
  • tests/unit/lib/plugin.test.js: Added a full test suite for the new serving hook, covering handler registration, @notification event dispatch, error handling, and plain event skipping.
  • tests/unit/lib/utils.test.js: Added tests for buildNotificationFromEvent and mapCdsTypeToANSType; updated IsSensitive expectations to true.
  • tests/unit/srv/notifyToRest.test.js: Added tests for typed and default batch notify() calls.

  • 🔄 Regenerate and Update Summary
  • ✏️ Insert as PR Description (deletes this comment)
  • 🗑️ Delete comment
PR Bot Information

Version: 1.22.5

  • Correlation ID: 22937577-ccea-4eb3-a6af-936b4f6fea65
  • LLM: anthropic--claude-4.6-sonnet
  • Event Trigger: pull_request.ready_for_review
  • Summary Prompt: Default Prompt
  • Output Template: Default Template
  • File Content Strategy: Full file content

@hyperspace-insights hyperspace-insights Bot 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.

The PR introduces a solid batch notification API with good test coverage, but there are several correctness issues that need to be addressed: caller object mutation in the batch emit path, a shared CSRF token across parallel requests that will cause failures in production, an empty-array crash in postNotification, inconsistent NotificationTypeKey prefixing between the auto-emit and manual notify() paths, and a double-notification in the bookshop test service.

PR Bot Information

Version: 1.22.5

  • Correlation ID: 22937577-ccea-4eb3-a6af-936b4f6fea65
  • File Content Strategy: Full file content
  • Event Trigger: pull_request.ready_for_review
  • LLM: anthropic--claude-4.6-sonnet

Comment thread srv/service.js Outdated
Comment thread srv/notifyToRest.js Outdated
Comment thread srv/notifyToRest.js
Comment thread lib/utils.js Outdated
Comment thread lib/utils.js Outdated
Comment thread cds-plugin.js Outdated
Comment thread cds-plugin.js Outdated
Comment thread tests/bookshop/srv/cat-service.js
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.

1 participant