Skip to content

Commit 038299d

Browse files
committed
chore(eventstream-handler-node): add docs
1 parent 31d299c commit 038299d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

packages/eventstream-handler-node/src/EventSigningStream.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export interface EventSigningStreamOptions extends TransformOptions {
88
eventMarshaller: EventMarshaller;
99
}
1010

11+
/**
12+
* A transform stream that signs the eventstream
13+
*/
1114
export class EventSigningStream extends Transform {
1215
private priorSignature: string;
1316
private eventSigner: EventSigner;

packages/eventstream-handler-node/src/EventStreamPayloadHandler.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ export interface EventStreamPayloadHandlerOptions {
2121
utf8Decoder: Decoder;
2222
}
2323

24+
/**
25+
* A handler that control the eventstream payload flow:
26+
* 1. Pause stream for initial attempt.
27+
* 2. Close the stream is attempt fails.
28+
* 3. Start piping payload when connection is established.
29+
* 4. Sign the payload after payload stream starting to flow.
30+
*/
2431
export class EventStreamPayloadHandler implements IEventStreamPayloadHandler {
2532
private readonly eventSigner: Provider<EventSigner>;
2633
private readonly eventMarshaller: EventMarshaller;
@@ -50,12 +57,16 @@ export class EventStreamPayloadHandler implements IEventStreamPayloadHandler {
5057
try {
5158
result = await next(args);
5259
} catch (e) {
60+
// Close the payload stream otherwise the retry would hang
61+
// because of the previous connection.
5362
request.body.end();
5463
throw e;
5564
}
65+
// If response is successful, start piping the payload stream
5666
const match = (request.headers["authorization"] || "").match(
5767
/Signature=([\w]+)$/
5868
);
69+
// Sign the eventstream based on the signature from initial request.
5970
const priorSignature = (match || [])[1];
6071
const signingStream = new EventSigningStream({
6172
priorSignature,

0 commit comments

Comments
 (0)