@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,174 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpenSeaStreamClient = void 0;
4
+ const constants_1 = require("./constants");
5
+ const helpers_1 = require("./helpers");
6
+ const phoenix_1 = require("./transport/phoenix");
7
+ const types_1 = require("./types");
8
+ /**
9
+ * Client for the OpenSea Stream API.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { OpenSeaStreamClient } from "@opensea/sdk/stream"
14
+ *
15
+ * const client = new OpenSeaStreamClient({ apiKey: "YOUR_API_KEY" })
16
+ *
17
+ * const unsubscribe = client.onItemListed("doodles-official", event => {
18
+ * console.log(event.payload.item.nft_id)
19
+ * })
20
+ * ```
21
+ *
22
+ * @category Main Classes
23
+ */
24
+ class OpenSeaStreamClient {
25
+ transport;
26
+ logLevel;
27
+ onEvent;
28
+ constructor({ network = types_1.Network.MAINNET, apiKey, token, apiUrl, connectOptions, logLevel = types_1.LogLevel.INFO, onError, onEvent = () => true, }) {
29
+ const key = apiKey ?? token;
30
+ if (!key) {
31
+ throw new Error("An OpenSea API key is required. Pass it as `apiKey` when constructing OpenSeaStreamClient.");
32
+ }
33
+ this.logLevel = logLevel;
34
+ this.onEvent = onEvent;
35
+ const endpoint = apiUrl || constants_1.ENDPOINTS[network];
36
+ const { params, ...transportOptions } = connectOptions ?? {};
37
+ this.transport = new phoenix_1.PhoenixChannelsTransport({
38
+ endpoint,
39
+ params: { token: key, ...params },
40
+ ...transportOptions,
41
+ logger: message => this.debug(message),
42
+ });
43
+ this.transport.onError(onError ?? (error => this.error(error)));
44
+ }
45
+ debug(message) {
46
+ if (this.logLevel <= types_1.LogLevel.DEBUG) {
47
+ console.debug("[DEBUG]:", message);
48
+ }
49
+ }
50
+ info(message) {
51
+ if (this.logLevel <= types_1.LogLevel.INFO) {
52
+ console.info("[INFO]:", message);
53
+ }
54
+ }
55
+ error(message) {
56
+ if (this.logLevel <= types_1.LogLevel.ERROR) {
57
+ console.error("[ERROR]:", message);
58
+ }
59
+ }
60
+ connect = () => {
61
+ this.debug("Connecting to socket");
62
+ this.transport.connect();
63
+ };
64
+ disconnect = (callback = () => this.info(`Successfully disconnected from socket`)) => {
65
+ return this.transport.disconnect(callback);
66
+ };
67
+ on = (eventType, collectionSlug, callback, eventTypes) => {
68
+ const topic = (0, helpers_1.collectionTopic)(collectionSlug);
69
+ this.debug(`Subscribing to ${eventType} events on ${topic}`);
70
+ const onClientEvent = this.onEvent;
71
+ const handler = (message) => {
72
+ const event = message;
73
+ if (onClientEvent(collectionSlug, eventType, event)) {
74
+ callback(event);
75
+ }
76
+ };
77
+ const subscription = this.transport.subscribe(topic, { eventTypes }, {
78
+ onSubscribed: () => this.info(`Successfully joined channel "${topic}"`),
79
+ onSubscribeError: reason => {
80
+ this.error(`Failed to join channel "${topic}"`);
81
+ this.debug(reason);
82
+ },
83
+ });
84
+ const off = subscription.on(eventType, handler);
85
+ return () => {
86
+ this.debug(`Unsubscribing from ${eventType} events on ${topic}`);
87
+ // Removes only this handler. The topic is torn down once nothing is
88
+ // listening to it. The original stream-js client left the whole channel
89
+ // here, which silently killed sibling subscriptions on the same
90
+ // collection.
91
+ off();
92
+ };
93
+ };
94
+ onItemMetadataUpdated = (collectionSlug, callback) => {
95
+ this.debug(`Listening for item metadata updates on "${collectionSlug}"`);
96
+ return this.on(types_1.EventType.ITEM_METADATA_UPDATED, collectionSlug, callback);
97
+ };
98
+ onItemCancelled = (collectionSlug, callback) => {
99
+ this.debug(`Listening for item cancellations on "${collectionSlug}"`);
100
+ return this.on(types_1.EventType.ITEM_CANCELLED, collectionSlug, callback);
101
+ };
102
+ onItemListed = (collectionSlug, callback) => {
103
+ this.debug(`Listening for item listings on "${collectionSlug}"`);
104
+ return this.on(types_1.EventType.ITEM_LISTED, collectionSlug, callback);
105
+ };
106
+ onItemSold = (collectionSlug, callback) => {
107
+ this.debug(`Listening for item sales on "${collectionSlug}"`);
108
+ return this.on(types_1.EventType.ITEM_SOLD, collectionSlug, callback);
109
+ };
110
+ onItemTransferred = (collectionSlug, callback) => {
111
+ this.debug(`Listening for item transfers on "${collectionSlug}"`);
112
+ return this.on(types_1.EventType.ITEM_TRANSFERRED, collectionSlug, callback);
113
+ };
114
+ onItemReceivedOffer = (collectionSlug, callback) => {
115
+ this.debug(`Listening for item offers on "${collectionSlug}"`);
116
+ return this.on(types_1.EventType.ITEM_RECEIVED_OFFER, collectionSlug, callback);
117
+ };
118
+ onItemReceivedBid = (collectionSlug, callback) => {
119
+ this.debug(`Listening for item bids on "${collectionSlug}"`);
120
+ return this.on(types_1.EventType.ITEM_RECEIVED_BID, collectionSlug, callback);
121
+ };
122
+ onCollectionOffer = (collectionSlug, callback) => {
123
+ this.debug(`Listening for collection offers on "${collectionSlug}"`);
124
+ return this.on(types_1.EventType.COLLECTION_OFFER, collectionSlug, callback);
125
+ };
126
+ onTraitOffer = (collectionSlug, callback) => {
127
+ this.debug(`Listening for trait offers on "${collectionSlug}"`);
128
+ return this.on(types_1.EventType.TRAIT_OFFER, collectionSlug, callback);
129
+ };
130
+ onOrderInvalidate = (collectionSlug, callback) => {
131
+ this.debug(`Listening for order invalidation events on "${collectionSlug}"`);
132
+ return this.on(types_1.EventType.ORDER_INVALIDATE, collectionSlug, callback);
133
+ };
134
+ onOrderRevalidate = (collectionSlug, callback) => {
135
+ this.debug(`Listening for order revalidation events on "${collectionSlug}"`);
136
+ return this.on(types_1.EventType.ORDER_REVALIDATE, collectionSlug, callback);
137
+ };
138
+ /**
139
+ * Subscribe to several event types on one collection with a single callback,
140
+ * filtered server-side to the requested types.
141
+ *
142
+ * The callback receives `BaseStreamMessage<unknown>`: one subscription can
143
+ * deliver several event types, so there is no single payload type to hand
144
+ * back. `event_type` identifies which arrived, and the payload needs
145
+ * narrowing before use.
146
+ *
147
+ * ```ts
148
+ * client.onEvents(slug, [EventType.ITEM_SOLD, EventType.ITEM_LISTED], event => {
149
+ * if (event.event_type === EventType.ITEM_SOLD) {
150
+ * const sale = event as ItemSoldEvent
151
+ * console.log(sale.payload.sale_price)
152
+ * }
153
+ * })
154
+ * ```
155
+ *
156
+ * Use the typed single-event methods, such as `onItemSold`, when you want the
157
+ * payload typed for you.
158
+ *
159
+ * @param collectionSlug collection slug, or `"*"` for all collections
160
+ * @param eventTypes event types to subscribe to
161
+ * @param callback invoked for every subscribed event type
162
+ * @returns a function that removes all of this call's handlers
163
+ */
164
+ onEvents = (collectionSlug, eventTypes, callback) => {
165
+ const subscriptions = eventTypes.map(eventType => this.on(eventType, collectionSlug, callback, eventTypes));
166
+ return () => {
167
+ for (const unsubscribe of subscriptions) {
168
+ unsubscribe();
169
+ }
170
+ };
171
+ };
172
+ }
173
+ exports.OpenSeaStreamClient = OpenSeaStreamClient;
174
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/stream/client.ts"],"names":[],"mappings":";;;AAAA,2CAAuC;AACvC,uCAA2C;AAC3C,iDAA8D;AAE9D,mCAkBgB;AAEhB;;;;;;;;;;;;;;;GAeG;AACH,MAAa,mBAAmB;IACtB,SAAS,CAAiB;IAC1B,QAAQ,CAAU;IAClB,OAAO,CAAe;IAE9B,YAAY,EACV,OAAO,GAAG,eAAO,CAAC,OAAO,EACzB,MAAM,EACN,KAAK,EACL,MAAM,EACN,cAAc,EACd,QAAQ,GAAG,gBAAQ,CAAC,IAAI,EACxB,OAAO,EACP,OAAO,GAAG,GAAG,EAAE,CAAC,IAAI,GACP;QACb,MAAM,GAAG,GAAG,MAAM,IAAI,KAAK,CAAA;QAC3B,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,KAAK,CACb,4FAA4F,CAC7F,CAAA;QACH,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QAEtB,MAAM,QAAQ,GAAG,MAAM,IA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I,CAAC,KAAK,CAAC,+CAA+C,cAAc,GAAG,CAAC,CAAA;QAC5E,OAAO,IAAI,CAAC,EAAE,CAAC,iBAAS,CAAC,gBAAgB,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAA;IACtE,CAAC,CAAA;IAED;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACI,QAAQ,GAAG,CAChB,cAAsB,EACtB,UAAuB,EACvB,QAA8C,EAC9C,EAAE;QACF,MAAM,aAAa,GAAG,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAC/C,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,cAAc,EAAE,QAAQ,EAAE,UAAU,CAAC,CACzD,CAAA;QAED,OAAO,GAAG,EAAE;YACV,KAAK,MAAM,WAAW,IAAI,aAAa,EAAE,CAAC;gBACxC,WAAW,EAAE,CAAA;YACf,CAAC;QACH,CAAC,CAAA;IACH,CAAC,CAAA;CACF;AA5OD,kDA4OC"}
@@ -0,0 +1,3 @@
1
+ export declare const ENDPOINTS: {
2
+ mainnet: string;
3
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ENDPOINTS = void 0;
4
+ const types_1 = require("./types");
5
+ exports.ENDPOINTS = {
6
+ [types_1.Network.MAINNET]: "wss://stream-api.opensea.io/socket",
7
+ };
8
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/stream/constants.ts"],"names":[],"mappings":";;;AAAA,mCAAiC;AAEpB,QAAA,SAAS,GAAG;IACvB,CAAC,eAAO,CAAC,OAAO,CAAC,EAAE,oCAAoC;CACxD,CAAA"}
@@ -0,0 +1 @@
1
+ export declare const collectionTopic: (slug: string) => string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collectionTopic = void 0;
4
+ const collectionTopic = (slug) => {
5
+ return `collection:${slug}`;
6
+ };
7
+ exports.collectionTopic = collectionTopic;
8
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/stream/helpers.ts"],"names":[],"mappings":";;;AAAO,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,EAAE;IAC9C,OAAO,cAAc,IAAI,EAAE,CAAA;AAC7B,CAAC,CAAA;AAFY,QAAA,eAAe,mBAE3B"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * OpenSea Stream API client.
3
+ *
4
+ * Subscribe to real-time marketplace events over WebSocket.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { OpenSeaStreamClient } from "@opensea/sdk/stream"
9
+ *
10
+ * const client = new OpenSeaStreamClient({ apiKey: "YOUR_API_KEY" })
11
+ * client.onItemSold("doodles-official", event => console.log(event))
12
+ * ```
13
+ *
14
+ * @module
15
+ */
16
+ export * from "./client";
17
+ export * from "./types";
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ /**
3
+ * OpenSea Stream API client.
4
+ *
5
+ * Subscribe to real-time marketplace events over WebSocket.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { OpenSeaStreamClient } from "@opensea/sdk/stream"
10
+ *
11
+ * const client = new OpenSeaStreamClient({ apiKey: "YOUR_API_KEY" })
12
+ * client.onItemSold("doodles-official", event => console.log(event))
13
+ * ```
14
+ *
15
+ * @module
16
+ */
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
29
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ __exportStar(require("./client"), exports);
33
+ __exportStar(require("./types"), exports);
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/stream/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;AAEH,2CAAwB;AACxB,0CAAuB"}
@@ -0,0 +1,121 @@
1
+ import type { StreamMessageHandler, StreamSubscription, StreamTransport, StreamWebSocketConstructor, SubscribeCallbacks, SubscribeOptions } from "./types";
2
+ export interface PhoenixTransportOptions {
3
+ /** Base socket URL, e.g. `wss://stream-api.opensea.io/socket`. */
4
+ endpoint: string;
5
+ /** Query parameters appended to the socket URL, e.g. the API key. */
6
+ params?: Record<string, string>;
7
+ /** WebSocket implementation. Defaults to the global `WebSocket`. */
8
+ transport?: StreamWebSocketConstructor;
9
+ /** Milliseconds to wait for a subscribe acknowledgement. Default 10000. */
10
+ timeout?: number;
11
+ /** Milliseconds between heartbeats. Default 30000. */
12
+ heartbeatIntervalMs?: number;
13
+ /** Backoff for reconnect attempt `tries` (1-indexed). */
14
+ reconnectAfterMs?: (tries: number) => number;
15
+ /** Optional debug logger. */
16
+ logger?: (message: string) => void;
17
+ }
18
+ export declare class PhoenixChannelsTransport implements StreamTransport {
19
+ private readonly endpoint;
20
+ private readonly params;
21
+ private readonly webSocketCtor;
22
+ private readonly timeout;
23
+ private readonly heartbeatIntervalMs;
24
+ private readonly reconnectAfterMs;
25
+ private readonly logger?;
26
+ private socket;
27
+ private readonly subscriptions;
28
+ private readonly pendingReplies;
29
+ private errorHandlers;
30
+ /**
31
+ * Unsubscribe callbacks still waiting for a `phx_leave` reply. `disconnect()`
32
+ * closes the socket without a round trip, so these are drained there instead;
33
+ * otherwise a caller awaiting unsubscribe confirmation waits forever.
34
+ */
35
+ private readonly pendingUnsubscribes;
36
+ private refCounter;
37
+ private reconnectTries;
38
+ private reconnectTimer;
39
+ private heartbeatTimer;
40
+ private pendingHeartbeatRef;
41
+ private disconnectedIntentionally;
42
+ /**
43
+ * Whether the current socket has ever answered us. An open socket is not
44
+ * proof of a working connection: a server that accepts the TCP/WS handshake
45
+ * but never replies would otherwise reset the backoff on every attempt and
46
+ * be hammered at the shortest delay forever.
47
+ */
48
+ private connectionProven;
49
+ constructor(options: PhoenixTransportOptions);
50
+ endpointUrl(): string;
51
+ protocol(): string;
52
+ connect(): void;
53
+ isConnected(): boolean;
54
+ disconnect(onDisconnect?: () => void): void;
55
+ onError(handler: (error: unknown) => void): void;
56
+ /** Surface an error raised by consumer code, used by subscriptions. */
57
+ reportError(error: unknown): void;
58
+ /**
59
+ * Run a consumer callback without letting it escape into our state machine.
60
+ *
61
+ * These fire from inside teardown and reply handling, where an escaping
62
+ * exception would skip the work that follows: a throwing unsubscribe
63
+ * callback would abort `handleClose` before `scheduleReconnect`, leaving the
64
+ * client permanently disconnected, and a throwing subscribe callback would
65
+ * starve every later subscriber to the same topic.
66
+ */
67
+ private safeInvoke;
68
+ private handleOpen;
69
+ private handleClose;
70
+ private scheduleReconnect;
71
+ private clearReconnectTimer;
72
+ private startHeartbeat;
73
+ private stopHeartbeat;
74
+ private sendHeartbeat;
75
+ /** Close the socket without marking the disconnect intentional. */
76
+ private teardownForReconnect;
77
+ subscribe(topic: string, options?: SubscribeOptions, callbacks?: SubscribeCallbacks): StreamSubscription;
78
+ private sendJoin;
79
+ /**
80
+ * Rejoin a topic whose channel died while the socket stayed open. Uses the
81
+ * same backoff schedule as reconnects, so a channel that keeps crashing does
82
+ * not turn into a join loop.
83
+ */
84
+ private scheduleRejoin;
85
+ private clearRejoinTimer;
86
+ /**
87
+ * A topic is joined once and shared, and the join payload carries the
88
+ * server-side `event_types` filter. A later subscriber asking for an event
89
+ * outside that filter would otherwise register a handler the server never
90
+ * feeds, which fails silently. Widen the filter and re-join instead.
91
+ *
92
+ * `undefined` means no filter, so it is the widest value rather than the
93
+ * narrowest: an individual `on*` call subscribes to everything.
94
+ */
95
+ private widenFilterIfNeeded;
96
+ private drainPendingUnsubscribes;
97
+ /** Called by a subscription, and directly by the client. */
98
+ unsubscribeTopic(topic: string, onUnsubscribed?: () => void): void;
99
+ /** Remove a single handler, unsubscribing only when the topic goes quiet. */
100
+ removeHandler(topic: string, event: string, handler: StreamMessageHandler, onUnsubscribed?: () => void): void;
101
+ private handleMessage;
102
+ private handleReply;
103
+ private awaitReply;
104
+ /**
105
+ * Drop every in-flight reply without invoking its handler. The socket going
106
+ * away is not a rejection: a join whose ack never arrives is re-sent by
107
+ * `handleOpen` after the reconnect, so reporting it as a subscribe failure
108
+ * here would be both wrong and noisy.
109
+ *
110
+ * Unsubscribes are the exception and are settled rather than dropped. A left
111
+ * topic stays left across a reconnect, so its acknowledgement is never coming
112
+ * and a caller waiting on one would hang. Draining here covers every teardown
113
+ * path: `disconnect`, `handleClose`, and `teardownForReconnect`.
114
+ */
115
+ private clearPendingReplies;
116
+ private push;
117
+ private decode;
118
+ private nextRef;
119
+ private emitError;
120
+ private log;
121
+ }