@opensea/sdk 11.7.2 → 11.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +46 -14
  2. package/lib/abi/abis.d.ts +16 -0
  3. package/lib/abi/abis.js +13 -1
  4. package/lib/abi/abis.js.map +1 -1
  5. package/lib/api/api.d.ts +11 -3
  6. package/lib/api/api.js +17 -5
  7. package/lib/api/api.js.map +1 -1
  8. package/lib/api/collections.d.ts +7 -0
  9. package/lib/api/collections.js +10 -1
  10. package/lib/api/collections.js.map +1 -1
  11. package/lib/api/fetcher.d.ts +5 -2
  12. package/lib/api/walletAuth.d.ts +7 -0
  13. package/lib/api/walletAuth.js +8 -1
  14. package/lib/api/walletAuth.js.map +1 -1
  15. package/lib/constants.d.ts +6 -0
  16. package/lib/constants.js +7 -1
  17. package/lib/constants.js.map +1 -1
  18. package/lib/index.d.ts +1 -1
  19. package/lib/orders/erc20Fulfillment.d.ts +41 -0
  20. package/lib/orders/erc20Fulfillment.js +190 -0
  21. package/lib/orders/erc20Fulfillment.js.map +1 -0
  22. package/lib/orders/orderUseCase.d.ts +18 -0
  23. package/lib/orders/orderUseCase.js +29 -0
  24. package/lib/orders/orderUseCase.js.map +1 -0
  25. package/lib/orders/privateListings.js +8 -0
  26. package/lib/orders/privateListings.js.map +1 -1
  27. package/lib/sdk/base.d.ts +19 -7
  28. package/lib/sdk/base.js +19 -7
  29. package/lib/sdk/base.js.map +1 -1
  30. package/lib/sdk/cancellation.d.ts +2 -1
  31. package/lib/sdk/cancellation.js +2 -0
  32. package/lib/sdk/cancellation.js.map +1 -1
  33. package/lib/sdk/fulfillment.d.ts +57 -3
  34. package/lib/sdk/fulfillment.js +147 -4
  35. package/lib/sdk/fulfillment.js.map +1 -1
  36. package/lib/sdk/orders.d.ts +16 -3
  37. package/lib/sdk/orders.js +27 -13
  38. package/lib/sdk/orders.js.map +1 -1
  39. package/lib/stream/client.d.ts +67 -0
  40. package/lib/stream/client.js +174 -0
  41. package/lib/stream/client.js.map +1 -0
  42. package/lib/stream/constants.d.ts +3 -0
  43. package/lib/stream/constants.js +8 -0
  44. package/lib/stream/constants.js.map +1 -0
  45. package/lib/stream/helpers.d.ts +1 -0
  46. package/lib/stream/helpers.js +8 -0
  47. package/lib/stream/helpers.js.map +1 -0
  48. package/lib/stream/index.d.ts +17 -0
  49. package/lib/stream/index.js +34 -0
  50. package/lib/stream/index.js.map +1 -0
  51. package/lib/stream/transport/phoenix.d.ts +121 -0
  52. package/lib/stream/transport/phoenix.js +642 -0
  53. package/lib/stream/transport/phoenix.js.map +1 -0
  54. package/lib/stream/transport/types.d.ts +85 -0
  55. package/lib/stream/transport/types.js +24 -0
  56. package/lib/stream/transport/types.js.map +1 -0
  57. package/lib/stream/types.d.ts +269 -0
  58. package/lib/stream/types.js +29 -0
  59. package/lib/stream/types.js.map +1 -0
  60. package/lib/types.d.ts +14 -0
  61. package/lib/utils/units.d.ts +5 -0
  62. package/lib/utils/units.js +48 -9
  63. package/lib/utils/units.js.map +1 -1
  64. package/package.json +11 -10
  65. package/src/abi/abis.ts +13 -0
  66. package/src/api/api.ts +21 -5
  67. package/src/api/collections.ts +14 -1
  68. package/src/api/fetcher.ts +5 -2
  69. package/src/api/walletAuth.ts +9 -0
  70. package/src/constants.ts +8 -0
  71. package/src/index.ts +1 -1
  72. package/src/orders/erc20Fulfillment.ts +218 -0
  73. package/src/orders/orderUseCase.ts +34 -0
  74. package/src/orders/privateListings.ts +15 -0
  75. package/src/sdk/base.ts +20 -6
  76. package/src/sdk/cancellation.ts +4 -1
  77. package/src/sdk/fulfillment.ts +188 -6
  78. package/src/sdk/orders.ts +27 -15
  79. package/src/stream/client.ts +277 -0
  80. package/src/stream/constants.ts +5 -0
  81. package/src/stream/helpers.ts +3 -0
  82. package/src/stream/index.ts +18 -0
  83. package/src/stream/transport/phoenix.ts +815 -0
  84. package/src/stream/transport/types.ts +91 -0
  85. package/src/stream/types.ts +314 -0
  86. package/src/types.ts +14 -0
  87. package/src/utils/units.ts +54 -9
@@ -0,0 +1,642 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PhoenixChannelsTransport = void 0;
4
+ /**
5
+ * Phoenix Channels v2 transport.
6
+ *
7
+ * Implements the subset of the protocol that `wss://stream-api.opensea.io/socket`
8
+ * requires. The stream is receive-only: apart from join, leave, and heartbeat
9
+ * control frames, the client never pushes to the server, so none of the
10
+ * general Phoenix client's push, presence, binary serializer, or longpoll
11
+ * machinery is included.
12
+ *
13
+ * Wire format is a JSON array: `[join_ref, ref, topic, event, payload]`.
14
+ * Control events are `phx_join`, `phx_leave`, `phx_reply`, `phx_error`, and
15
+ * `phx_close`. Heartbeats go to the `phoenix` topic and must be answered
16
+ * before the next interval elapses or the connection is considered dead.
17
+ */
18
+ const VSN = "2.0.0";
19
+ const DEFAULT_TIMEOUT_MS = 10_000;
20
+ const DEFAULT_HEARTBEAT_INTERVAL_MS = 30_000;
21
+ const WS_CLOSE_NORMAL = 1000;
22
+ const WS_OPEN = 1;
23
+ const PHX_JOIN = "phx_join";
24
+ const PHX_LEAVE = "phx_leave";
25
+ const PHX_REPLY = "phx_reply";
26
+ const PHX_ERROR = "phx_error";
27
+ const PHX_CLOSE = "phx_close";
28
+ const HEARTBEAT_TOPIC = "phoenix";
29
+ const HEARTBEAT_EVENT = "heartbeat";
30
+ /** Backoff schedule in ms, indexed by attempt number. Tail is reused. */
31
+ const DEFAULT_RECONNECT_BACKOFF_MS = [
32
+ 10, 50, 100, 150, 200, 250, 500, 1000, 2000,
33
+ ];
34
+ const MAX_RECONNECT_BACKOFF_MS = 5000;
35
+ const defaultReconnectAfterMs = (tries) => DEFAULT_RECONNECT_BACKOFF_MS[tries - 1] ?? MAX_RECONNECT_BACKOFF_MS;
36
+ class PhoenixSubscription {
37
+ transport;
38
+ topic;
39
+ /** Handlers by event name. */
40
+ handlers = new Map();
41
+ /**
42
+ * Server-side event filter sent in the join payload. Widened in place when a
43
+ * later subscriber to the same topic needs events outside the current filter.
44
+ */
45
+ eventTypes;
46
+ /** Ref of the in-flight or completed join, used to correlate replies. */
47
+ joinRef = null;
48
+ joined = false;
49
+ /**
50
+ * Callbacks from every caller that subscribed to this topic. A topic is
51
+ * joined once and shared, so a second subscriber must still be told whether
52
+ * the join succeeded, and every subscriber is notified again after a rejoin.
53
+ */
54
+ callbackList = [];
55
+ /** Backoff state for rejoining after a server-side channel error. */
56
+ rejoinTries = 0;
57
+ rejoinTimer = null;
58
+ constructor(topic, eventTypes, transport) {
59
+ this.transport = transport;
60
+ this.topic = topic;
61
+ this.eventTypes = eventTypes;
62
+ }
63
+ on(event, handler) {
64
+ let handlers = this.handlers.get(event);
65
+ if (!handlers) {
66
+ handlers = new Set();
67
+ this.handlers.set(event, handlers);
68
+ }
69
+ handlers.add(handler);
70
+ return () => this.transport.removeHandler(this.topic, event, handler);
71
+ }
72
+ /**
73
+ * Remove one handler, reporting whether the topic has gone quiet. Unlike
74
+ * the original stream-js client, removing a handler does not tear down the
75
+ * whole topic while sibling handlers are still listening; the transport
76
+ * unsubscribes only once the last handler is gone.
77
+ */
78
+ off(event, handler) {
79
+ const handlers = this.handlers.get(event);
80
+ if (!handlers) {
81
+ return this.handlers.size === 0;
82
+ }
83
+ handlers.delete(handler);
84
+ if (handlers.size === 0) {
85
+ this.handlers.delete(event);
86
+ }
87
+ return this.handlers.size === 0;
88
+ }
89
+ unsubscribe(onUnsubscribed) {
90
+ this.transport.unsubscribeTopic(this.topic, onUnsubscribed);
91
+ }
92
+ dispatch(event, message) {
93
+ const handlers = this.handlers.get(event);
94
+ if (!handlers) {
95
+ return;
96
+ }
97
+ for (const handler of handlers) {
98
+ try {
99
+ handler(message);
100
+ }
101
+ catch (error) {
102
+ // A consumer callback that throws must not take down the socket. This
103
+ // runs inside `WebSocket.onmessage`, so an escaping error becomes an
104
+ // unhandled exception and skips every sibling handler for this event.
105
+ this.transport.reportError(error);
106
+ }
107
+ }
108
+ }
109
+ }
110
+ class PhoenixChannelsTransport {
111
+ endpoint;
112
+ params;
113
+ webSocketCtor;
114
+ timeout;
115
+ heartbeatIntervalMs;
116
+ reconnectAfterMs;
117
+ logger;
118
+ socket = null;
119
+ subscriptions = new Map();
120
+ pendingReplies = new Map();
121
+ errorHandlers = [];
122
+ /**
123
+ * Unsubscribe callbacks still waiting for a `phx_leave` reply. `disconnect()`
124
+ * closes the socket without a round trip, so these are drained there instead;
125
+ * otherwise a caller awaiting unsubscribe confirmation waits forever.
126
+ */
127
+ pendingUnsubscribes = new Set();
128
+ refCounter = 0;
129
+ reconnectTries = 0;
130
+ reconnectTimer = null;
131
+ heartbeatTimer = null;
132
+ pendingHeartbeatRef = null;
133
+ disconnectedIntentionally = false;
134
+ /**
135
+ * Whether the current socket has ever answered us. An open socket is not
136
+ * proof of a working connection: a server that accepts the TCP/WS handshake
137
+ * but never replies would otherwise reset the backoff on every attempt and
138
+ * be hammered at the shortest delay forever.
139
+ */
140
+ connectionProven = false;
141
+ constructor(options) {
142
+ this.endpoint = options.endpoint.replace(/\/+$/, "");
143
+ this.params = options.params ?? {};
144
+ this.timeout = options.timeout ?? DEFAULT_TIMEOUT_MS;
145
+ this.heartbeatIntervalMs =
146
+ options.heartbeatIntervalMs ?? DEFAULT_HEARTBEAT_INTERVAL_MS;
147
+ this.reconnectAfterMs = options.reconnectAfterMs ?? defaultReconnectAfterMs;
148
+ this.logger = options.logger;
149
+ // The global `WebSocket` is structurally compatible but its DOM handler
150
+ // signatures do not assign cleanly to our narrower shape, so resolve it
151
+ // through a single explicit cast rather than widening the interface.
152
+ const resolved = options.transport ??
153
+ globalThis.WebSocket ??
154
+ undefined;
155
+ if (!resolved) {
156
+ throw new Error("No WebSocket implementation found. Node 22+ and all browsers provide one globally; " +
157
+ "on older runtimes pass `connectOptions.transport` (for example the `ws` package).");
158
+ }
159
+ this.webSocketCtor = resolved;
160
+ }
161
+ // ── URL ────────────────────────────────────────────────────────────
162
+ endpointUrl() {
163
+ const query = new URLSearchParams({ ...this.params, vsn: VSN });
164
+ return `${this.endpoint}/websocket?${query.toString()}`;
165
+ }
166
+ protocol() {
167
+ return this.endpoint.startsWith("wss:") ||
168
+ this.endpoint.startsWith("https:")
169
+ ? "wss"
170
+ : "ws";
171
+ }
172
+ // ── Connection lifecycle ───────────────────────────────────────────
173
+ connect() {
174
+ if (this.socket) {
175
+ return;
176
+ }
177
+ this.disconnectedIntentionally = false;
178
+ this.connectionProven = false;
179
+ this.log(`connecting to ${this.endpoint}`);
180
+ const socket = new this.webSocketCtor(this.endpointUrl());
181
+ this.socket = socket;
182
+ socket.onopen = () => this.handleOpen();
183
+ socket.onmessage = event => this.handleMessage(event.data);
184
+ socket.onerror = error => this.emitError(error);
185
+ socket.onclose = event => this.handleClose(event);
186
+ }
187
+ isConnected() {
188
+ return this.socket?.readyState === WS_OPEN;
189
+ }
190
+ disconnect(onDisconnect) {
191
+ this.disconnectedIntentionally = true;
192
+ this.clearReconnectTimer();
193
+ this.stopHeartbeat();
194
+ // clearPendingReplies also settles pending unsubscribe acknowledgements.
195
+ this.clearPendingReplies();
196
+ for (const subscription of this.subscriptions.values()) {
197
+ this.clearRejoinTimer(subscription);
198
+ }
199
+ this.subscriptions.clear();
200
+ const socket = this.socket;
201
+ this.socket = null;
202
+ if (socket) {
203
+ socket.onclose = null;
204
+ socket.onerror = null;
205
+ socket.onmessage = null;
206
+ socket.onopen = null;
207
+ socket.close(WS_CLOSE_NORMAL, "client disconnect");
208
+ }
209
+ onDisconnect?.();
210
+ }
211
+ onError(handler) {
212
+ this.errorHandlers.push(handler);
213
+ }
214
+ /** Surface an error raised by consumer code, used by subscriptions. */
215
+ reportError(error) {
216
+ this.emitError(error);
217
+ }
218
+ /**
219
+ * Run a consumer callback without letting it escape into our state machine.
220
+ *
221
+ * These fire from inside teardown and reply handling, where an escaping
222
+ * exception would skip the work that follows: a throwing unsubscribe
223
+ * callback would abort `handleClose` before `scheduleReconnect`, leaving the
224
+ * client permanently disconnected, and a throwing subscribe callback would
225
+ * starve every later subscriber to the same topic.
226
+ */
227
+ safeInvoke(callback) {
228
+ try {
229
+ callback();
230
+ }
231
+ catch (error) {
232
+ this.reportError(error);
233
+ }
234
+ }
235
+ handleOpen() {
236
+ this.log("socket open");
237
+ // Deliberately not resetting `reconnectTries` here. The backoff resets in
238
+ // `handleReply`, once the server has actually answered something.
239
+ this.startHeartbeat();
240
+ // A fresh socket re-joins everything below, so any per-channel rejoin
241
+ // timer left over from the previous connection is redundant.
242
+ for (const subscription of this.subscriptions.values()) {
243
+ this.clearRejoinTimer(subscription);
244
+ }
245
+ // Establish every topic: the ones subscribed to before the socket opened,
246
+ // and the ones that were live before a drop. Joins are never sent while
247
+ // disconnected, so this is the single place they get written.
248
+ for (const subscription of this.subscriptions.values()) {
249
+ subscription.joined = false;
250
+ this.sendJoin(subscription);
251
+ }
252
+ }
253
+ handleClose(event) {
254
+ this.log(`socket closed (code ${event?.code ?? "unknown"})`);
255
+ this.connectionProven = false;
256
+ this.stopHeartbeat();
257
+ this.clearPendingReplies();
258
+ this.socket = null;
259
+ if (!this.disconnectedIntentionally) {
260
+ this.scheduleReconnect();
261
+ }
262
+ }
263
+ scheduleReconnect() {
264
+ this.clearReconnectTimer();
265
+ this.reconnectTries += 1;
266
+ const delay = this.reconnectAfterMs(this.reconnectTries);
267
+ this.log(`reconnecting in ${delay}ms (attempt ${this.reconnectTries})`);
268
+ this.reconnectTimer = setTimeout(() => {
269
+ this.reconnectTimer = null;
270
+ this.connect();
271
+ }, delay);
272
+ }
273
+ clearReconnectTimer() {
274
+ if (this.reconnectTimer) {
275
+ clearTimeout(this.reconnectTimer);
276
+ this.reconnectTimer = null;
277
+ }
278
+ }
279
+ // ── Heartbeat ──────────────────────────────────────────────────────
280
+ startHeartbeat() {
281
+ this.stopHeartbeat();
282
+ this.pendingHeartbeatRef = null;
283
+ this.heartbeatTimer = setInterval(() => this.sendHeartbeat(), this.heartbeatIntervalMs);
284
+ }
285
+ stopHeartbeat() {
286
+ if (this.heartbeatTimer) {
287
+ clearInterval(this.heartbeatTimer);
288
+ this.heartbeatTimer = null;
289
+ }
290
+ this.pendingHeartbeatRef = null;
291
+ }
292
+ sendHeartbeat() {
293
+ if (!this.isConnected()) {
294
+ return;
295
+ }
296
+ // The previous heartbeat was never answered, so the connection is dead
297
+ // even though the socket still looks open. Tear it down and reconnect.
298
+ if (this.pendingHeartbeatRef !== null) {
299
+ this.log("heartbeat timeout, tearing down connection");
300
+ this.pendingHeartbeatRef = null;
301
+ this.emitError(new Error("Heartbeat timeout"));
302
+ this.teardownForReconnect();
303
+ return;
304
+ }
305
+ const ref = this.nextRef();
306
+ this.pendingHeartbeatRef = ref;
307
+ this.push(null, ref, HEARTBEAT_TOPIC, HEARTBEAT_EVENT, {});
308
+ }
309
+ /** Close the socket without marking the disconnect intentional. */
310
+ teardownForReconnect() {
311
+ const socket = this.socket;
312
+ this.stopHeartbeat();
313
+ this.socket = null;
314
+ if (socket) {
315
+ socket.onclose = null;
316
+ socket.onerror = null;
317
+ socket.onmessage = null;
318
+ socket.onopen = null;
319
+ socket.close(WS_CLOSE_NORMAL, "heartbeat timeout");
320
+ }
321
+ this.clearPendingReplies();
322
+ this.scheduleReconnect();
323
+ }
324
+ // ── Subscriptions ──────────────────────────────────────────────────
325
+ subscribe(topic, options, callbacks) {
326
+ this.connect();
327
+ const existing = this.subscriptions.get(topic);
328
+ if (existing) {
329
+ // The topic is already joined or joining. Register this caller's
330
+ // callbacks too, otherwise a second subscriber never learns the outcome.
331
+ if (callbacks) {
332
+ existing.callbackList.push(callbacks);
333
+ // A settled subscription has no reply left to fire, so report now.
334
+ if (existing.joined) {
335
+ callbacks.onSubscribed?.();
336
+ }
337
+ }
338
+ this.widenFilterIfNeeded(existing, options?.eventTypes);
339
+ return existing;
340
+ }
341
+ const subscription = new PhoenixSubscription(topic, options?.eventTypes, this);
342
+ if (callbacks) {
343
+ subscription.callbackList.push(callbacks);
344
+ }
345
+ this.subscriptions.set(topic, subscription);
346
+ // If the socket is not open yet, `handleOpen` sends the join. Writing it
347
+ // here as well would join the topic twice.
348
+ if (this.isConnected()) {
349
+ this.sendJoin(subscription);
350
+ }
351
+ return subscription;
352
+ }
353
+ sendJoin(subscription) {
354
+ const ref = this.nextRef();
355
+ subscription.joinRef = ref;
356
+ const payload = subscription.eventTypes
357
+ ? { event_types: subscription.eventTypes }
358
+ : {};
359
+ this.awaitReply(ref, (_response, status) => {
360
+ if (status === "ok") {
361
+ subscription.joined = true;
362
+ subscription.rejoinTries = 0;
363
+ this.log(`subscribed to "${subscription.topic}"`);
364
+ for (const callbacks of subscription.callbackList) {
365
+ this.safeInvoke(() => callbacks.onSubscribed?.());
366
+ }
367
+ }
368
+ else {
369
+ this.log(`failed to subscribe to "${subscription.topic}"`);
370
+ const error = new Error(`Subscribe to "${subscription.topic}" failed: ${status}`);
371
+ for (const callbacks of subscription.callbackList) {
372
+ this.safeInvoke(() => callbacks.onSubscribeError?.(error));
373
+ }
374
+ }
375
+ }, reason => {
376
+ for (const callbacks of subscription.callbackList) {
377
+ this.safeInvoke(() => callbacks.onSubscribeError?.(reason));
378
+ }
379
+ });
380
+ this.push(ref, ref, subscription.topic, PHX_JOIN, payload);
381
+ }
382
+ /**
383
+ * Rejoin a topic whose channel died while the socket stayed open. Uses the
384
+ * same backoff schedule as reconnects, so a channel that keeps crashing does
385
+ * not turn into a join loop.
386
+ */
387
+ scheduleRejoin(subscription) {
388
+ this.clearRejoinTimer(subscription);
389
+ subscription.rejoinTries += 1;
390
+ const delay = this.reconnectAfterMs(subscription.rejoinTries);
391
+ this.log(`rejoining "${subscription.topic}" in ${delay}ms (attempt ${subscription.rejoinTries})`);
392
+ subscription.rejoinTimer = setTimeout(() => {
393
+ subscription.rejoinTimer = null;
394
+ // The caller may have unsubscribed, or the socket may have dropped, in
395
+ // which case `handleOpen` owns the rejoin instead.
396
+ if (!this.subscriptions.has(subscription.topic) || !this.isConnected()) {
397
+ return;
398
+ }
399
+ this.sendJoin(subscription);
400
+ }, delay);
401
+ }
402
+ clearRejoinTimer(subscription) {
403
+ if (subscription.rejoinTimer) {
404
+ clearTimeout(subscription.rejoinTimer);
405
+ subscription.rejoinTimer = null;
406
+ }
407
+ }
408
+ /**
409
+ * A topic is joined once and shared, and the join payload carries the
410
+ * server-side `event_types` filter. A later subscriber asking for an event
411
+ * outside that filter would otherwise register a handler the server never
412
+ * feeds, which fails silently. Widen the filter and re-join instead.
413
+ *
414
+ * `undefined` means no filter, so it is the widest value rather than the
415
+ * narrowest: an individual `on*` call subscribes to everything.
416
+ */
417
+ widenFilterIfNeeded(subscription, requested) {
418
+ const current = subscription.eventTypes;
419
+ // Already unfiltered, so every event already arrives.
420
+ if (current === undefined) {
421
+ return;
422
+ }
423
+ let widened;
424
+ if (requested === undefined) {
425
+ // The new subscriber wants everything, so drop the filter entirely.
426
+ widened = undefined;
427
+ }
428
+ else {
429
+ const missing = requested.filter(type => !current.includes(type));
430
+ if (missing.length === 0) {
431
+ return;
432
+ }
433
+ widened = [...current, ...missing];
434
+ }
435
+ subscription.eventTypes = widened;
436
+ this.log(`widening the filter on "${subscription.topic}" to ${widened ? widened.join(", ") : "all events"}`);
437
+ // While disconnected there is nothing to re-issue: `handleOpen` sends the
438
+ // join, and it will use the widened filter.
439
+ if (!this.isConnected()) {
440
+ return;
441
+ }
442
+ // Re-establish the channel so the server applies the new filter. Frames
443
+ // still in flight for the old join ref are dropped by the guard in
444
+ // `handleMessage`, so no stale events reach the widened subscription.
445
+ if (subscription.joinRef !== null) {
446
+ this.push(subscription.joinRef, this.nextRef(), subscription.topic, PHX_LEAVE, {});
447
+ }
448
+ subscription.joined = false;
449
+ this.sendJoin(subscription);
450
+ }
451
+ drainPendingUnsubscribes() {
452
+ const pending = Array.from(this.pendingUnsubscribes);
453
+ this.pendingUnsubscribes.clear();
454
+ for (const callback of pending) {
455
+ this.safeInvoke(callback);
456
+ }
457
+ }
458
+ /** Called by a subscription, and directly by the client. */
459
+ unsubscribeTopic(topic, onUnsubscribed) {
460
+ const subscription = this.subscriptions.get(topic);
461
+ if (!subscription) {
462
+ onUnsubscribed?.();
463
+ return;
464
+ }
465
+ this.clearRejoinTimer(subscription);
466
+ this.subscriptions.delete(topic);
467
+ if (!this.isConnected()) {
468
+ onUnsubscribed?.();
469
+ return;
470
+ }
471
+ // `joinRef` is assigned synchronously by `sendJoin`, and `sendJoin` runs
472
+ // for every subscription either at subscribe time (when connected) or in
473
+ // `handleOpen`. Reaching here with a null ref would mean that invariant
474
+ // broke, and a leave frame with a null join_ref cannot be correlated by
475
+ // the server, so drop it rather than send a malformed frame.
476
+ if (subscription.joinRef === null) {
477
+ onUnsubscribed?.();
478
+ return;
479
+ }
480
+ // Fire at most once, whichever of reply, timeout, or disconnect wins.
481
+ let settled = false;
482
+ const settle = () => {
483
+ if (settled) {
484
+ return;
485
+ }
486
+ settled = true;
487
+ this.pendingUnsubscribes.delete(settle);
488
+ onUnsubscribed?.();
489
+ };
490
+ this.pendingUnsubscribes.add(settle);
491
+ const ref = this.nextRef();
492
+ this.awaitReply(ref, () => {
493
+ this.log(`unsubscribed from "${topic}"`);
494
+ settle();
495
+ },
496
+ // A leave that is never acknowledged still means we have stopped
497
+ // dispatching locally, so treat a timeout as done rather than an error.
498
+ settle);
499
+ this.push(subscription.joinRef, ref, topic, PHX_LEAVE, {});
500
+ }
501
+ /** Remove a single handler, unsubscribing only when the topic goes quiet. */
502
+ removeHandler(topic, event, handler, onUnsubscribed) {
503
+ const subscription = this.subscriptions.get(topic);
504
+ if (!subscription) {
505
+ return;
506
+ }
507
+ const isEmpty = subscription.off(event, handler);
508
+ if (isEmpty) {
509
+ this.unsubscribeTopic(topic, onUnsubscribed);
510
+ }
511
+ }
512
+ // ── Messaging ──────────────────────────────────────────────────────
513
+ handleMessage(data) {
514
+ const frame = this.decode(data);
515
+ if (!frame) {
516
+ return;
517
+ }
518
+ if (frame.event === PHX_REPLY) {
519
+ this.handleReply(frame);
520
+ return;
521
+ }
522
+ const subscription = this.subscriptions.get(frame.topic);
523
+ // Drop frames from a previous instance of this channel. Leaving a topic
524
+ // and re-subscribing to it produces a new join ref, and the server's
525
+ // in-flight frames for the old one are still arriving. Without this, a
526
+ // late `phx_close` for the channel we already left tears down the new
527
+ // subscription, and stale events leak to the new handlers.
528
+ if (subscription &&
529
+ frame.joinRef !== null &&
530
+ subscription.joinRef !== null &&
531
+ frame.joinRef !== subscription.joinRef) {
532
+ this.log(`dropping stale frame for "${frame.topic}"`);
533
+ return;
534
+ }
535
+ if (frame.event === PHX_ERROR || frame.event === PHX_CLOSE) {
536
+ // No subscription means we already left this topic, and the server is
537
+ // acknowledging that. Not an error worth reporting.
538
+ if (!subscription) {
539
+ return;
540
+ }
541
+ // The channel died server-side while the socket stayed up, so a
542
+ // reconnect will never fire. Without an explicit rejoin the topic is
543
+ // silently dead for the rest of the process's life.
544
+ subscription.joined = false;
545
+ this.emitError(new Error(`Channel "${frame.topic}" received ${frame.event}`));
546
+ this.scheduleRejoin(subscription);
547
+ return;
548
+ }
549
+ subscription?.dispatch(frame.event, frame.payload);
550
+ }
551
+ handleReply(frame) {
552
+ if (frame.ref === null) {
553
+ return;
554
+ }
555
+ // The server answered, so this connection works. Anything before this is
556
+ // an unproven connection and must not clear the reconnect backoff.
557
+ if (!this.connectionProven) {
558
+ this.connectionProven = true;
559
+ this.reconnectTries = 0;
560
+ }
561
+ if (frame.ref === this.pendingHeartbeatRef) {
562
+ this.pendingHeartbeatRef = null;
563
+ return;
564
+ }
565
+ const pending = this.pendingReplies.get(frame.ref);
566
+ if (!pending) {
567
+ return;
568
+ }
569
+ this.pendingReplies.delete(frame.ref);
570
+ clearTimeout(pending.timer);
571
+ const payload = frame.payload;
572
+ pending.handler(payload?.response, payload?.status ?? "error");
573
+ }
574
+ awaitReply(ref, handler, onTimeout) {
575
+ const timer = setTimeout(() => {
576
+ this.pendingReplies.delete(ref);
577
+ onTimeout(new Error(`Timed out after ${this.timeout}ms waiting for reply`));
578
+ }, this.timeout);
579
+ this.pendingReplies.set(ref, { handler, timer });
580
+ }
581
+ /**
582
+ * Drop every in-flight reply without invoking its handler. The socket going
583
+ * away is not a rejection: a join whose ack never arrives is re-sent by
584
+ * `handleOpen` after the reconnect, so reporting it as a subscribe failure
585
+ * here would be both wrong and noisy.
586
+ *
587
+ * Unsubscribes are the exception and are settled rather than dropped. A left
588
+ * topic stays left across a reconnect, so its acknowledgement is never coming
589
+ * and a caller waiting on one would hang. Draining here covers every teardown
590
+ * path: `disconnect`, `handleClose`, and `teardownForReconnect`.
591
+ */
592
+ clearPendingReplies() {
593
+ for (const [, pending] of this.pendingReplies) {
594
+ clearTimeout(pending.timer);
595
+ }
596
+ this.pendingReplies.clear();
597
+ this.drainPendingUnsubscribes();
598
+ }
599
+ push(joinRef, ref, topic, event, payload) {
600
+ // Every caller either checks `isConnected()` first or runs from
601
+ // `handleOpen`, so there is nothing to buffer: a frame written while the
602
+ // socket is down would be a bug, not a queued write.
603
+ if (!this.isConnected()) {
604
+ return;
605
+ }
606
+ this.socket?.send(JSON.stringify([joinRef, ref, topic, event, payload]));
607
+ }
608
+ decode(data) {
609
+ if (typeof data !== "string") {
610
+ this.emitError(new Error("Received non-text frame from stream"));
611
+ return null;
612
+ }
613
+ let parsed;
614
+ try {
615
+ parsed = JSON.parse(data);
616
+ }
617
+ catch {
618
+ this.emitError(new Error("Received malformed JSON frame from stream"));
619
+ return null;
620
+ }
621
+ if (!Array.isArray(parsed) || parsed.length < 5) {
622
+ this.emitError(new Error("Received unexpected frame shape from stream"));
623
+ return null;
624
+ }
625
+ const [joinRef, ref, topic, event, payload] = parsed;
626
+ return { joinRef, ref, topic, event, payload };
627
+ }
628
+ nextRef() {
629
+ this.refCounter += 1;
630
+ return String(this.refCounter);
631
+ }
632
+ emitError(error) {
633
+ for (const handler of this.errorHandlers) {
634
+ handler(error);
635
+ }
636
+ }
637
+ log(message) {
638
+ this.logger?.(message);
639
+ }
640
+ }
641
+ exports.PhoenixChannelsTransport = PhoenixChannelsTransport;
642
+ //# sourceMappingURL=phoenix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phoenix.js","sourceRoot":"","sources":["../../../src/stream/transport/phoenix.ts"],"names":[],"mappings":";;;AAUA;;;;;;;;;;;;;GAaG;AAEH,MAAM,GAAG,GAAG,OAAO,CAAA;AACnB,MAAM,kBAAkB,GAAG,MAAM,CAAA;AACjC,MAAM,6BAA6B,GAAG,MAAM,CAAA;AAC5C,MAAM,eAAe,GAAG,IAAI,CAAA;AAC5B,MAAM,OAAO,GAAG,CAAC,CAAA;AAEjB,MAAM,QAAQ,GAAG,UAAU,CAAA;AAC3B,MAAM,SAAS,GAAG,WAAW,CAAA;AAC7B,MAAM,SAAS,GAAG,WAAW,CAAA;AAC7B,MAAM,SAAS,GAAG,WAAW,CAAA;AAC7B,MAAM,SAAS,GAAG,WAAW,CAAA;AAC7B,MAAM,eAAe,GAAG,SAAS,CAAA;AACjC,MAAM,eAAe,GAAG,WAAW,CAAA;AAEnC,yEAAyE;AACzE,MAAM,4BAA4B,GAAG;IACnC,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI;CAC5C,CAAA;AACD,MAAM,wBAAwB,GAAG,IAAI,CAAA;AAErC,MAAM,uBAAuB,GAAG,CAAC,KAAa,EAAU,EAAE,CACxD,4BAA4B,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,wBAAwB,CAAA;AA8BrE,MAAM,mBAAmB;IAyBJ;IAxBH,KAAK,CAAQ;IAC7B,8BAA8B;IACd,QAAQ,GAAG,IAAI,GAAG,EAAqC,CAAA;IACvE;;;OAGG;IACI,UAAU,CAAW;IAC5B,yEAAyE;IAClE,OAAO,GAAkB,IAAI,CAAA;IAC7B,MAAM,GAAG,KAAK,CAAA;IACrB;;;;OAIG;IACa,YAAY,GAAyB,EAAE,CAAA;IACvD,qEAAqE;IAC9D,WAAW,GAA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