Skip to main content

Event Streams

TypeBase PathTrigger Name
Limited REST resource~{realm}/event-streams/N/A
Server-Sent Event resource~{realm}/event-streams/{id}/streamN/A

Server-sent events is a way to be notified about entity updates in real-time, whithout having to poll the resources of interest continiously. See also Triggers for an alternative way to receive notifications when entities are updates.

The event stream resource is view of the server's all active change data streams that is made to look like a normal REST resource. However, a couple of things is different from other REST resources:

  • The ID is a string of random characters, not a sequence number. This is because the ID is also used as a secret access token.
  • Once an entity has been deleted, it's truly gone and cannot be resurrected. Thus, point-in-time queries are not applicable to this resource, the d query parameter cannot be used to fetch a deleted entity and the deleted property does not exist.
  • Extended properties are not available.
  • listEventStreams does not support query filters or offset/count parameters.
  • Event streams are automatically garbage-collected when no longer in use.
  • The actual SSE resources only supports JSON-encoded events in the stream stream. XML or CSV is not supported.

Endpoints

NameMethodRelative PathPayloadResponseDescription
addEventStreamPOST~{realm}/event-streamsEventStreamStored_EventStreamAdds a new event stream to the list.
listEventStreamsGET~{realm}/event-streamsN/AStored_EventStream[]Retrieves a list of event streams.
getEventStreamGET~{realm}/event-streams/{idN/AStored_EventStreamRetrieves an event stream.
putEventStreamPUT~{realm}/event-streams/{idEventStreamStored_EventStreamReplaces an event stream.
updateEventStreamPATCH~{realm}/event-streams/{idEventStreamStored_EventStreamUpdates specified event stream fields.
removeEventStreamDELETE~{realm}/event-streams/{id}N/AN/ADeletes an event stream.
openEventStreamGET~{realm}/event-streams/{id}/streamN/ADataObjectOperation[]The actual text/event-stream stream of DataObjectOperation objects.

Permissions

PermissionDescription
edit-event-streamsClient is allowed to add new event streams and to modify or delete existing event streams.
show-event-streamsClient is allowed to query the trigger list and to fetch individual event streams.
use-event-streamsClient is allowed to create and look up individual event streams.

Note that:

  1. In addition to the permissions above, when setting up an event stream, you also need read access to the actual resource from where events are streamed.
  2. The actual text/event-stream resource does not require any authentication what-so-ever, since EventSource cannot send custom authentication headers. Because of this, the event stream ID should be considered a secret and is not to be exposed in any way by the client; also, once an event stream has been opened, its ID cannot be reused.

Entities

Interface EventStream

namespace EventStream {
type State = 'pending' | 'active';
}

interface EventStream {
'id'?: string;
'created'?: DateTime;
'updated'?: DateTime;
'updated-by'?: number;
'updated-from'?: number;
'state': EventStream.State;
'queries': QueryTrigger[];
'location'?: number;
'client'?: number;
'user'?: number;
}
PropertyData TypeDescription
idString?The event stream ID of this entity.
createdDateTime?Date and time when this event stream was first created.
updatedDateTime?Date and time when this event stream was last modified. Note: This is an approximation and could be off by up to a minute.
updated-byInt64?ID of User who last modified this event stream.
updated-fromInt64?ID of Till (trusted device) which last modified this event stream.
stateEventStream.StateThe current state of this event stream. active means a client is connected and listening for events.
queriesQueryTrigger[]A list of query objects that specifies what events to stream.
locationInt64?The location from where this event stream was created.
clientInt64?The Till (trusted device) that created the event stream.
userInt64?The User who created the event stream.