Skip to content

Commit 57e1905

Browse files
committed
Release v0.4.0
Origin-SHA: 519a082a8e67851cd9177606b48235fb64be5073
1 parent b74a89d commit 57e1905

5 files changed

Lines changed: 49 additions & 7 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pnpm run check-types # TypeScript type checking
2424
| `src/helpers.ts` | Topic construction for Phoenix channel subscriptions |
2525
| `src/index.ts` | Public exports |
2626
| `test/client.spec.ts` | Unit tests with mock WebSocket |
27+
| `test/helpers.ts` | Test utilities for accessing private client internals (socket, channels) |
2728
| `test/mock-ws.ts` | Mock WebSocket server for testing |
2829

2930
## Review Checklist

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @opensea/stream-js
22

3+
## 0.4.0
4+
5+
### Minor Changes
6+
7+
- 4ff61ae: Add server-side event type filtering support. The `onEvents` method now passes `event_types` array in Phoenix channel join params, enabling the backend to filter events at subscription time. Individual `on*` methods remain backward-compatible.
8+
39
## 0.3.1
410

511
### Patch Changes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opensea/stream-js",
3-
"version": "0.3.1",
3+
"version": "0.4.0",
44
"description": "A TypeScript SDK to receive pushed updates from OpenSea over websocket",
55
"license": "MIT",
66
"author": "OpenSea Developers",

src/client.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,12 @@ export class OpenSeaStreamClient {
8787
return this.socket.disconnect(callback)
8888
}
8989

90-
private createChannel = (topic: string): Channel => {
91-
const channel = this.socket.channel(topic)
90+
private createChannel = (
91+
topic: string,
92+
eventTypes?: EventType[],
93+
): Channel => {
94+
const params = eventTypes ? { event_types: eventTypes } : {}
95+
const channel = this.socket.channel(topic, params)
9296
channel
9397
.join()
9498
.receive("ok", () => this.info(`Successfully joined channel "${topic}"`))
@@ -98,11 +102,11 @@ export class OpenSeaStreamClient {
98102
return channel
99103
}
100104

101-
private getChannel = (topic: string): Channel => {
105+
private getChannel = (topic: string, eventTypes?: EventType[]): Channel => {
102106
let channel = this.channels.get(topic)
103107
if (!channel) {
104108
this.debug(`Creating channel for topic: "${topic}"`)
105-
channel = this.createChannel(topic)
109+
channel = this.createChannel(topic, eventTypes)
106110
}
107111
return channel
108112
}
@@ -111,12 +115,13 @@ export class OpenSeaStreamClient {
111115
eventType: EventType,
112116
collectionSlug: string,
113117
callback: Callback<Event>,
118+
eventTypes?: EventType[],
114119
) => {
115120
this.socket.connect()
116121

117122
const topic = collectionTopic(collectionSlug)
118123
this.debug(`Fetching channel ${topic}`)
119-
const channel = this.getChannel(topic)
124+
const channel = this.getChannel(topic, eventTypes)
120125
this.debug(`Subscribing to ${eventType} events on ${topic}`)
121126

122127
const onClientEvent = this.onEvent
@@ -231,7 +236,7 @@ export class OpenSeaStreamClient {
231236
callback: Callback<BaseStreamMessage<unknown>>,
232237
) => {
233238
const subscriptions = eventTypes.map(eventType =>
234-
this.on(eventType, collectionSlug, callback),
239+
this.on(eventType, collectionSlug, callback, eventTypes),
235240
)
236241

237242
return () => {

test/client.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,33 @@ describe("middleware", () => {
343343
streamClient.disconnect()
344344
})
345345
})
346+
347+
describe("server-side event type filtering", () => {
348+
test("onEvents passes event_types in join params", () => {
349+
streamClient = new OpenSeaStreamClient(clientOpts)
350+
351+
const socket = getSocket(streamClient)
352+
const channelSpy = vi.spyOn(socket, "channel")
353+
354+
streamClient.onEvents(
355+
"c1",
356+
[EventType.ITEM_LISTED, EventType.ITEM_SOLD],
357+
vi.fn(),
358+
)
359+
360+
expect(channelSpy).toHaveBeenCalledWith("collection:c1", {
361+
event_types: [EventType.ITEM_LISTED, EventType.ITEM_SOLD],
362+
})
363+
})
364+
365+
test("individual on* methods do not pass event_types", () => {
366+
streamClient = new OpenSeaStreamClient(clientOpts)
367+
368+
const socket = getSocket(streamClient)
369+
const channelSpy = vi.spyOn(socket, "channel")
370+
371+
streamClient.onItemListed("c1", vi.fn())
372+
373+
expect(channelSpy).toHaveBeenCalledWith("collection:c1", {})
374+
})
375+
})

0 commit comments

Comments
 (0)