Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/node-message-broker/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,6 +25,7 @@
"dependencies": {
"@privateaim/errors": "^0.8.42",
"@privateaim/kit": "^0.11.5",
"@privateaim/messenger-http-kit": "^0.11.5",
"@privateaim/messenger-kit": "^0.11.5",
"@privateaim/server-http-kit": "^0.11.5",
"@privateaim/server-kit": "^0.11.5",
Expand Down
59 changes: 41 additions & 18 deletions apps/node-message-broker/src/adapters/hub/client.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,38 +5,61 @@
* view the LICENSE file that was distributed with this source code.
*/

import type { Message, MessagePullResponse } from '@privateaim/messenger-kit';
import type { IHubClient } from '../../core/hub/index.ts';
import type {
MessageAckRequest,
MessageParty,
MessagePullQuery,
MessagePullResponse,
SendMessageRequest,
} from '@privateaim/messenger-kit';
import type {
IHubClient,
IMessengerClient,
IWakeupSource,
} from '../../core/hub/index.ts';

const NOT_IMPLEMENTED = 'HubClient is a Phase 4 stub (Plan 013 Track B): implement against @privateaim/messenger-http-kit + the SSE wakeup stream.';
type HubClientContext = {
client: IMessengerClient,
wakeup: IWakeupSource
};

/**
* Hub-link adapter. Phase 4 implements this with the `@privateaim/messenger-http-kit`
* Hapic client (REST `send` / `pull` / `ack`) authenticating as the node client, plus
* the SSE wakeup stream (`GET /messages/stream`) feeding `onWakeup`.
* Hub-link adapter. REST `send` / `pull` / `ack` go through the
* `@privateaim/messenger-http-kit` client (authenticated as the node client);
* `onWakeup` rides the SSE wakeup source. The node relays opaque end-to-end
* payloads — encryption/decryption is the caller's concern, not the Hub's.
*/
export class HubClient implements IHubClient {
async send(): Promise<Message[]> {
throw new Error(NOT_IMPLEMENTED);
protected client: IMessengerClient;

protected wakeup: IWakeupSource;

constructor(ctx: HubClientContext) {
this.client = ctx.client;
this.wakeup = ctx.wakeup;
}

send(input: SendMessageRequest): Promise<string[]> {
return this.client.message.send(input);
}

async pull(): Promise<MessagePullResponse> {
throw new Error(NOT_IMPLEMENTED);
pull(query?: MessagePullQuery): Promise<MessagePullResponse> {
return this.client.message.pull(query);
}

async ack(): Promise<void> {
throw new Error(NOT_IMPLEMENTED);
ack(input: MessageAckRequest): Promise<void> {
return this.client.message.ack(input);
}

onWakeup(): () => void {
return () => {};
onWakeup(listener: (recipient: MessageParty) => void): () => void {
return this.wakeup.subscribe((event) => listener(event.recipient));
}

async start(): Promise<void> {
// no-op until the Phase 4 SSE subscription lands
start(): Promise<void> {
return this.wakeup.start();
}

async stop(): Promise<void> {
// no-op until the Phase 4 SSE subscription lands
stop(): Promise<void> {
return this.wakeup.stop();
}
}
1 change: 1 addition & 0 deletions apps/node-message-broker/src/adapters/hub/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,3 +6,4 @@
*/

export * from './client.ts';
export * from './sse-wakeup-source.ts';
Loading
Loading