PTHMINT-119: SSE event stream support and EventManager#59
Open
zulquer wants to merge 1 commit intoPTHMINT-118from
Open
PTHMINT-119: SSE event stream support and EventManager#59zulquer wants to merge 1 commit intoPTHMINT-118from
zulquer wants to merge 1 commit intoPTHMINT-118from
Conversation
Introduce Server-Sent Events support and helpers for subscribing to order event streams. Adds a generic SSE client (ServerSentEvent, ServerSentEventStream, StreamingResponse) and an EventStream adapter with Event/EventData response models under api.paths.events.stream. Adds EventManager to provide convenient subscribe_events/subscribe_order_events methods and exposes it via Sdk.get_event_manager(). Order response model now normalizes new plural events_* and legacy event_* fields for compatibility. Also export SSE types from multisafepay.client, include an example script, and add unit and E2E tests covering stream parsing, manager behavior, and compatibility.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a new event streaming API for order events, allowing clients to subscribe to real-time updates using server-sent events (SSE). It includes new response models, event stream handling, and updates for backward compatibility with both singular and plural event field names in order responses.
The most important changes are:
Event Streaming API Implementation:
EventManagerclass (event_manager.py) and its public interface (__init__.py) to manage event stream subscriptions for orders. This provides methods to subscribe to event streams using event tokens and URLs, or directly from order response objects. [1] [2]EventStreamclass (stream/__init__.py) to handle server-sent event streams, including deserialization of payloads and context manager support. This enables iteration over live event messages from the SSE endpoint.Event Response Models:
Event,EventData, andEventDataPayload, including recursive deserialization for nested payloads. [1] [2] [3] [4]Order Response Backward Compatibility:
Orderresponse model to support both singular and plural forms of event-related fields (events_token,event_token, etc.), with normalization logic to ensure compatibility with different API payloads. [1] [2] [3]Example Usage:
subscribe_events.pydemonstrating how to create a Cloud POS order and subscribe to its event stream using the new API.Client Exports:
ServerSentEventandServerSentEventStreamfrom the client package for easier access.