@sygnl/talon 1.0.1

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.
package/dist/index.js ADDED
@@ -0,0 +1,344 @@
1
+ // src/transports/WebSocketTransport.ts
2
+ var WebSocketTransport = class {
3
+ constructor(options) {
4
+ this.ws = null;
5
+ this._state = "disconnected";
6
+ this.reconnectAttempts = 0;
7
+ this.reconnectTimeout = null;
8
+ this.messageHandlers = /* @__PURE__ */ new Set();
9
+ this.stateHandlers = /* @__PURE__ */ new Set();
10
+ this.errorHandlers = /* @__PURE__ */ new Set();
11
+ this.messageQueue = [];
12
+ this.url = options.url;
13
+ this.autoReconnect = options.autoReconnect ?? true;
14
+ this.reconnectDelay = options.reconnectDelay ?? 1e3;
15
+ this.maxReconnectAttempts = options.maxReconnectAttempts ?? 0;
16
+ this.connectionTimeout = options.connectionTimeout ?? 1e4;
17
+ this.debug = options.debug ?? false;
18
+ }
19
+ get state() {
20
+ return this._state;
21
+ }
22
+ async connect() {
23
+ if (this._state === "connected" || this._state === "connecting") {
24
+ this.log("Already connected or connecting");
25
+ return;
26
+ }
27
+ this.setState("connecting");
28
+ this.log(`Connecting to ${this.url}`);
29
+ return new Promise((resolve, reject) => {
30
+ try {
31
+ this.ws = new WebSocket(this.url);
32
+ const timeout = setTimeout(() => {
33
+ reject(new Error("Connection timeout"));
34
+ this.ws?.close();
35
+ }, this.connectionTimeout);
36
+ this.ws.onopen = () => {
37
+ clearTimeout(timeout);
38
+ this.setState("connected");
39
+ this.reconnectAttempts = 0;
40
+ this.log("Connected");
41
+ this.flushMessageQueue();
42
+ resolve();
43
+ };
44
+ this.ws.onerror = () => {
45
+ clearTimeout(timeout);
46
+ const error = new Error("WebSocket connection error");
47
+ this.log("Connection error:", error);
48
+ this.emitError(error);
49
+ reject(error);
50
+ };
51
+ this.ws.onclose = () => {
52
+ clearTimeout(timeout);
53
+ this.handleDisconnect();
54
+ };
55
+ this.ws.onmessage = (event) => {
56
+ this.handleMessage(event.data);
57
+ };
58
+ } catch (error) {
59
+ this.setState("error");
60
+ const err = error instanceof Error ? error : new Error("Unknown error");
61
+ this.emitError(err);
62
+ reject(err);
63
+ }
64
+ });
65
+ }
66
+ disconnect() {
67
+ this.log("Disconnecting");
68
+ this.autoReconnect = false;
69
+ if (this.reconnectTimeout) {
70
+ clearTimeout(this.reconnectTimeout);
71
+ this.reconnectTimeout = null;
72
+ }
73
+ if (this.ws) {
74
+ this.ws.close();
75
+ this.ws = null;
76
+ }
77
+ this.setState("disconnected");
78
+ }
79
+ async send(message) {
80
+ if (this._state !== "connected" || !this.ws) {
81
+ this.log("Not connected, queueing message");
82
+ this.messageQueue.push(message);
83
+ return;
84
+ }
85
+ try {
86
+ const payload = JSON.stringify(message);
87
+ this.ws.send(payload);
88
+ this.log("Sent message:", message);
89
+ } catch (error) {
90
+ const err = error instanceof Error ? error : new Error("Send failed");
91
+ this.log("Send error:", err);
92
+ this.emitError(err);
93
+ throw err;
94
+ }
95
+ }
96
+ onMessage(handler) {
97
+ this.messageHandlers.add(handler);
98
+ return () => this.messageHandlers.delete(handler);
99
+ }
100
+ onStateChange(handler) {
101
+ this.stateHandlers.add(handler);
102
+ return () => this.stateHandlers.delete(handler);
103
+ }
104
+ onError(handler) {
105
+ this.errorHandlers.add(handler);
106
+ return () => this.errorHandlers.delete(handler);
107
+ }
108
+ /**
109
+ * Handle incoming WebSocket message
110
+ */
111
+ handleMessage(data) {
112
+ try {
113
+ const message = JSON.parse(data);
114
+ this.log("Received message:", message);
115
+ this.messageHandlers.forEach((handler) => {
116
+ try {
117
+ handler(message);
118
+ } catch (error) {
119
+ this.log("Handler error:", error);
120
+ }
121
+ });
122
+ } catch (error) {
123
+ this.log("Failed to parse message:", error);
124
+ this.emitError(new Error("Invalid message format"));
125
+ }
126
+ }
127
+ /**
128
+ * Handle WebSocket disconnect
129
+ */
130
+ handleDisconnect() {
131
+ this.log("Disconnected");
132
+ this.ws = null;
133
+ if (this.autoReconnect && (this.maxReconnectAttempts === 0 || this.reconnectAttempts < this.maxReconnectAttempts)) {
134
+ this.setState("reconnecting");
135
+ this.scheduleReconnect();
136
+ } else {
137
+ this.setState("disconnected");
138
+ }
139
+ }
140
+ /**
141
+ * Schedule reconnection attempt with exponential backoff
142
+ */
143
+ scheduleReconnect() {
144
+ const delay = this.reconnectDelay * Math.pow(2, this.reconnectAttempts);
145
+ this.log(`Reconnecting in ${delay}ms (attempt ${this.reconnectAttempts + 1})`);
146
+ this.reconnectTimeout = setTimeout(() => {
147
+ this.reconnectAttempts++;
148
+ this.connect().catch((error) => {
149
+ this.log("Reconnect failed:", error);
150
+ this.handleDisconnect();
151
+ });
152
+ }, delay);
153
+ }
154
+ /**
155
+ * Flush queued messages
156
+ */
157
+ flushMessageQueue() {
158
+ if (this.messageQueue.length === 0) {
159
+ return;
160
+ }
161
+ this.log(`Flushing ${this.messageQueue.length} queued messages`);
162
+ const queue = [...this.messageQueue];
163
+ this.messageQueue = [];
164
+ queue.forEach((message) => {
165
+ this.send(message).catch((error) => {
166
+ this.log("Failed to flush message:", error);
167
+ });
168
+ });
169
+ }
170
+ /**
171
+ * Set connection state
172
+ */
173
+ setState(state) {
174
+ if (this._state === state) {
175
+ return;
176
+ }
177
+ this._state = state;
178
+ this.stateHandlers.forEach((handler) => {
179
+ try {
180
+ handler(state);
181
+ } catch (error) {
182
+ this.log("State handler error:", error);
183
+ }
184
+ });
185
+ }
186
+ /**
187
+ * Emit error to handlers
188
+ */
189
+ emitError(error) {
190
+ this.errorHandlers.forEach((handler) => {
191
+ try {
192
+ handler(error);
193
+ } catch (err) {
194
+ this.log("Error handler error:", err);
195
+ }
196
+ });
197
+ }
198
+ /**
199
+ * Debug logging
200
+ */
201
+ log(message, data) {
202
+ if (this.debug && typeof console !== "undefined") {
203
+ console.log(`[WebSocketTransport] ${message}`, data || "");
204
+ }
205
+ }
206
+ };
207
+
208
+ // src/transports/WebhookTransport.ts
209
+ var WebhookTransport = class {
210
+ constructor(options) {
211
+ this._state = "disconnected";
212
+ this.messageHandlers = /* @__PURE__ */ new Set();
213
+ this.stateHandlers = /* @__PURE__ */ new Set();
214
+ this.errorHandlers = /* @__PURE__ */ new Set();
215
+ this.url = options.url;
216
+ this.method = options.method ?? "POST";
217
+ this.headers = {
218
+ "Content-Type": "application/json",
219
+ ...options.headers
220
+ };
221
+ this.timeout = options.timeout ?? 1e4;
222
+ this.retry = options.retry ?? false;
223
+ this.maxRetries = options.maxRetries ?? 3;
224
+ this.retryDelay = options.retryDelay ?? 1e3;
225
+ this.debug = options.debug ?? false;
226
+ }
227
+ get state() {
228
+ return this._state;
229
+ }
230
+ async connect() {
231
+ this.log("Webhook transport ready");
232
+ this.setState("connected");
233
+ }
234
+ disconnect() {
235
+ this.log("Disconnecting webhook transport");
236
+ this.setState("disconnected");
237
+ }
238
+ async send(message) {
239
+ if (this._state !== "connected") {
240
+ throw new Error("Transport not connected");
241
+ }
242
+ let lastError = null;
243
+ const attempts = this.retry ? this.maxRetries + 1 : 1;
244
+ for (let attempt = 0; attempt < attempts; attempt++) {
245
+ try {
246
+ await this.sendRequest(message);
247
+ this.log(`Sent message (attempt ${attempt + 1})`);
248
+ return;
249
+ } catch (error) {
250
+ lastError = error instanceof Error ? error : new Error("Send failed");
251
+ this.log(`Send failed (attempt ${attempt + 1}):`, lastError);
252
+ if (attempt < attempts - 1) {
253
+ const delay = this.retryDelay * Math.pow(2, attempt);
254
+ await new Promise((resolve) => setTimeout(resolve, delay));
255
+ }
256
+ }
257
+ }
258
+ if (lastError) {
259
+ this.emitError(lastError);
260
+ throw lastError;
261
+ }
262
+ }
263
+ onMessage(handler) {
264
+ this.messageHandlers.add(handler);
265
+ return () => this.messageHandlers.delete(handler);
266
+ }
267
+ onStateChange(handler) {
268
+ this.stateHandlers.add(handler);
269
+ return () => this.stateHandlers.delete(handler);
270
+ }
271
+ onError(handler) {
272
+ this.errorHandlers.add(handler);
273
+ return () => this.errorHandlers.delete(handler);
274
+ }
275
+ /**
276
+ * Send HTTP request
277
+ */
278
+ async sendRequest(message) {
279
+ const controller = new AbortController();
280
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
281
+ try {
282
+ const response = await fetch(this.url, {
283
+ method: this.method,
284
+ headers: this.headers,
285
+ body: JSON.stringify(message),
286
+ signal: controller.signal
287
+ });
288
+ clearTimeout(timeoutId);
289
+ if (!response.ok) {
290
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
291
+ }
292
+ this.log(`Request successful: ${response.status}`);
293
+ } catch (error) {
294
+ clearTimeout(timeoutId);
295
+ if (error instanceof Error) {
296
+ if (error.name === "AbortError") {
297
+ throw new Error("Request timeout");
298
+ }
299
+ throw error;
300
+ }
301
+ throw new Error("Request failed");
302
+ }
303
+ }
304
+ /**
305
+ * Set connection state
306
+ */
307
+ setState(state) {
308
+ if (this._state === state) {
309
+ return;
310
+ }
311
+ this._state = state;
312
+ this.stateHandlers.forEach((handler) => {
313
+ try {
314
+ handler(state);
315
+ } catch (error) {
316
+ this.log("State handler error:", error);
317
+ }
318
+ });
319
+ }
320
+ /**
321
+ * Emit error to handlers
322
+ */
323
+ emitError(error) {
324
+ this.errorHandlers.forEach((handler) => {
325
+ try {
326
+ handler(error);
327
+ } catch (err) {
328
+ this.log("Error handler error:", err);
329
+ }
330
+ });
331
+ }
332
+ /**
333
+ * Debug logging
334
+ */
335
+ log(message, data) {
336
+ if (this.debug && typeof console !== "undefined") {
337
+ console.log(`[WebhookTransport] ${message}`, data || "");
338
+ }
339
+ }
340
+ };
341
+
342
+ export { WebSocketTransport, WebhookTransport };
343
+ //# sourceMappingURL=index.js.map
344
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/transports/WebSocketTransport.ts","../src/transports/WebhookTransport.ts"],"names":[],"mappings":";AA+CO,IAAM,qBAAN,MAAmD;AAAA,EAiBxD,YAAY,OAAA,EAAoC;AAfhD,IAAA,IAAA,CAAQ,EAAA,GAAuB,IAAA;AAC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AAQ,EAAE,CAAA;AAAA,IACzD;AAAA,EACF;AACF","file":"index.js","sourcesContent":["import type {\n TalonTransport,\n OutboundMessage,\n InboundMessage,\n TransportState,\n} from '../types';\n\n/**\n * WebSocket transport options\n */\nexport interface WebSocketTransportOptions {\n /** WebSocket URL */\n url: string;\n \n /** Auto-reconnect on disconnect */\n autoReconnect?: boolean;\n \n /** Reconnect delay in ms */\n reconnectDelay?: number;\n \n /** Max reconnect attempts (0 = infinite) */\n maxReconnectAttempts?: number;\n \n /** Connection timeout in ms */\n connectionTimeout?: number;\n \n /** Debug mode */\n debug?: boolean;\n}\n\n/**\n * WebSocket transport for bidirectional communication\n * \n * Features:\n * - Real-time bidirectional communication\n * - Auto-reconnect with exponential backoff\n * - Connection state management\n * - Message queuing during disconnection\n * \n * @example\n * ```typescript\n * const transport = new WebSocketTransport({\n * url: 'wss://edge.sygnl.io',\n * autoReconnect: true\n * });\n * ```\n */\nexport class WebSocketTransport implements TalonTransport {\n private url: string;\n private ws: WebSocket | null = null;\n private _state: TransportState = 'disconnected';\n private autoReconnect: boolean;\n private reconnectDelay: number;\n private maxReconnectAttempts: number;\n private reconnectAttempts = 0;\n private reconnectTimeout: ReturnType<typeof setTimeout> | null = null;\n private connectionTimeout: number;\n private debug: boolean;\n \n private messageHandlers = new Set<(message: InboundMessage) => void>();\n private stateHandlers = new Set<(state: TransportState) => void>();\n private errorHandlers = new Set<(error: Error) => void>();\n private messageQueue: OutboundMessage[] = [];\n\n constructor(options: WebSocketTransportOptions) {\n this.url = options.url;\n this.autoReconnect = options.autoReconnect ?? true;\n this.reconnectDelay = options.reconnectDelay ?? 1000;\n this.maxReconnectAttempts = options.maxReconnectAttempts ?? 0; // 0 = infinite\n this.connectionTimeout = options.connectionTimeout ?? 10000;\n this.debug = options.debug ?? false;\n }\n\n public get state(): TransportState {\n return this._state;\n }\n\n public async connect(): Promise<void> {\n if (this._state === 'connected' || this._state === 'connecting') {\n this.log('Already connected or connecting');\n return;\n }\n\n this.setState('connecting');\n this.log(`Connecting to ${this.url}`);\n\n return new Promise((resolve, reject) => {\n try {\n this.ws = new WebSocket(this.url);\n\n const timeout = setTimeout(() => {\n reject(new Error('Connection timeout'));\n this.ws?.close();\n }, this.connectionTimeout);\n\n this.ws.onopen = () => {\n clearTimeout(timeout);\n this.setState('connected');\n this.reconnectAttempts = 0;\n this.log('Connected');\n \n // Flush queued messages\n this.flushMessageQueue();\n \n resolve();\n };\n\n this.ws.onerror = () => {\n clearTimeout(timeout);\n const error = new Error('WebSocket connection error');\n this.log('Connection error:', error);\n this.emitError(error);\n reject(error);\n };\n\n this.ws.onclose = () => {\n clearTimeout(timeout);\n this.handleDisconnect();\n };\n\n this.ws.onmessage = (event) => {\n this.handleMessage(event.data);\n };\n } catch (error) {\n this.setState('error');\n const err = error instanceof Error ? error : new Error('Unknown error');\n this.emitError(err);\n reject(err);\n }\n });\n }\n\n public disconnect(): void {\n this.log('Disconnecting');\n this.autoReconnect = false; // Disable auto-reconnect on manual disconnect\n \n if (this.reconnectTimeout) {\n clearTimeout(this.reconnectTimeout);\n this.reconnectTimeout = null;\n }\n\n if (this.ws) {\n this.ws.close();\n this.ws = null;\n }\n\n this.setState('disconnected');\n }\n\n public async send(message: OutboundMessage): Promise<void> {\n if (this._state !== 'connected' || !this.ws) {\n // Queue message if not connected\n this.log('Not connected, queueing message');\n this.messageQueue.push(message);\n return;\n }\n\n try {\n const payload = JSON.stringify(message);\n this.ws.send(payload);\n this.log('Sent message:', message);\n } catch (error) {\n const err = error instanceof Error ? error : new Error('Send failed');\n this.log('Send error:', err);\n this.emitError(err);\n throw err;\n }\n }\n\n public onMessage(handler: (message: InboundMessage) => void): () => void {\n this.messageHandlers.add(handler);\n return () => this.messageHandlers.delete(handler);\n }\n\n public onStateChange(handler: (state: TransportState) => void): () => void {\n this.stateHandlers.add(handler);\n return () => this.stateHandlers.delete(handler);\n }\n\n public onError(handler: (error: Error) => void): () => void {\n this.errorHandlers.add(handler);\n return () => this.errorHandlers.delete(handler);\n }\n\n /**\n * Handle incoming WebSocket message\n */\n private handleMessage(data: string): void {\n try {\n const message: InboundMessage = JSON.parse(data);\n this.log('Received message:', message);\n \n this.messageHandlers.forEach((handler) => {\n try {\n handler(message);\n } catch (error) {\n this.log('Handler error:', error);\n }\n });\n } catch (error) {\n this.log('Failed to parse message:', error);\n this.emitError(new Error('Invalid message format'));\n }\n }\n\n /**\n * Handle WebSocket disconnect\n */\n private handleDisconnect(): void {\n this.log('Disconnected');\n this.ws = null;\n\n if (this.autoReconnect && \n (this.maxReconnectAttempts === 0 || this.reconnectAttempts < this.maxReconnectAttempts)) {\n this.setState('reconnecting');\n this.scheduleReconnect();\n } else {\n this.setState('disconnected');\n }\n }\n\n /**\n * Schedule reconnection attempt with exponential backoff\n */\n private scheduleReconnect(): void {\n const delay = this.reconnectDelay * Math.pow(2, this.reconnectAttempts);\n this.log(`Reconnecting in ${delay}ms (attempt ${this.reconnectAttempts + 1})`);\n\n this.reconnectTimeout = setTimeout(() => {\n this.reconnectAttempts++;\n this.connect().catch((error) => {\n this.log('Reconnect failed:', error);\n this.handleDisconnect();\n });\n }, delay);\n }\n\n /**\n * Flush queued messages\n */\n private flushMessageQueue(): void {\n if (this.messageQueue.length === 0) {\n return;\n }\n\n this.log(`Flushing ${this.messageQueue.length} queued messages`);\n const queue = [...this.messageQueue];\n this.messageQueue = [];\n\n queue.forEach((message) => {\n this.send(message).catch((error) => {\n this.log('Failed to flush message:', error);\n });\n });\n }\n\n /**\n * Set connection state\n */\n private setState(state: TransportState): void {\n if (this._state === state) {\n return;\n }\n\n this._state = state;\n this.stateHandlers.forEach((handler) => {\n try {\n handler(state);\n } catch (error) {\n this.log('State handler error:', error);\n }\n });\n }\n\n /**\n * Emit error to handlers\n */\n private emitError(error: Error): void {\n this.errorHandlers.forEach((handler) => {\n try {\n handler(error);\n } catch (err) {\n this.log('Error handler error:', err);\n }\n });\n }\n\n /**\n * Debug logging\n */\n private log(message: string, data?: unknown): void {\n if (this.debug && typeof console !== 'undefined') {\n console.log(`[WebSocketTransport] ${message}`, data || '');\n }\n }\n}\n","import type {\n TalonTransport,\n OutboundMessage,\n InboundMessage,\n TransportState,\n} from '../types';\n\n/**\n * Webhook transport options\n */\nexport interface WebhookTransportOptions {\n /** Webhook URL */\n url: string;\n \n /** HTTP method */\n method?: 'POST' | 'PUT';\n \n /** Custom headers */\n headers?: Record<string, string>;\n \n /** Request timeout in ms */\n timeout?: number;\n \n /** Retry failed requests */\n retry?: boolean;\n \n /** Max retry attempts */\n maxRetries?: number;\n \n /** Retry delay in ms */\n retryDelay?: number;\n \n /** Debug mode */\n debug?: boolean;\n}\n\n/**\n * Webhook transport for fire-and-forget HTTP requests\n * \n * Features:\n * - One-way communication (no responses)\n * - HTTP POST/PUT requests\n * - Optional retry logic\n * - Custom headers support\n * \n * Use this for:\n * - Server-side event delivery\n * - Fire-and-forget scenarios\n * - When WebSocket not available/needed\n * \n * @example\n * ```typescript\n * const transport = new WebhookTransport({\n * url: 'https://edge.sygnl.io/webhook',\n * method: 'POST',\n * retry: true\n * });\n * ```\n */\nexport class WebhookTransport implements TalonTransport {\n private url: string;\n private method: 'POST' | 'PUT';\n private headers: Record<string, string>;\n private timeout: number;\n private retry: boolean;\n private maxRetries: number;\n private retryDelay: number;\n private debug: boolean;\n private _state: TransportState = 'disconnected';\n \n private messageHandlers = new Set<(message: InboundMessage) => void>();\n private stateHandlers = new Set<(state: TransportState) => void>();\n private errorHandlers = new Set<(error: Error) => void>();\n\n constructor(options: WebhookTransportOptions) {\n this.url = options.url;\n this.method = options.method ?? 'POST';\n this.headers = {\n 'Content-Type': 'application/json',\n ...options.headers,\n };\n this.timeout = options.timeout ?? 10000;\n this.retry = options.retry ?? false;\n this.maxRetries = options.maxRetries ?? 3;\n this.retryDelay = options.retryDelay ?? 1000;\n this.debug = options.debug ?? false;\n }\n\n public get state(): TransportState {\n return this._state;\n }\n\n public async connect(): Promise<void> {\n // Webhook is \"connected\" immediately (stateless)\n this.log('Webhook transport ready');\n this.setState('connected');\n }\n\n public disconnect(): void {\n this.log('Disconnecting webhook transport');\n this.setState('disconnected');\n }\n\n public async send(message: OutboundMessage): Promise<void> {\n if (this._state !== 'connected') {\n throw new Error('Transport not connected');\n }\n\n let lastError: Error | null = null;\n const attempts = this.retry ? this.maxRetries + 1 : 1;\n\n for (let attempt = 0; attempt < attempts; attempt++) {\n try {\n await this.sendRequest(message);\n this.log(`Sent message (attempt ${attempt + 1})`);\n return;\n } catch (error) {\n lastError = error instanceof Error ? error : new Error('Send failed');\n this.log(`Send failed (attempt ${attempt + 1}):`, lastError);\n\n if (attempt < attempts - 1) {\n // Wait before retry (exponential backoff)\n const delay = this.retryDelay * Math.pow(2, attempt);\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n }\n }\n\n // All attempts failed\n if (lastError) {\n this.emitError(lastError);\n throw lastError;\n }\n }\n\n public onMessage(handler: (message: InboundMessage) => void): () => void {\n // Webhook is one-way, but keep interface consistent\n this.messageHandlers.add(handler);\n return () => this.messageHandlers.delete(handler);\n }\n\n public onStateChange(handler: (state: TransportState) => void): () => void {\n this.stateHandlers.add(handler);\n return () => this.stateHandlers.delete(handler);\n }\n\n public onError(handler: (error: Error) => void): () => void {\n this.errorHandlers.add(handler);\n return () => this.errorHandlers.delete(handler);\n }\n\n /**\n * Send HTTP request\n */\n private async sendRequest(message: OutboundMessage): Promise<void> {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.timeout);\n\n try {\n const response = await fetch(this.url, {\n method: this.method,\n headers: this.headers,\n body: JSON.stringify(message),\n signal: controller.signal,\n });\n\n clearTimeout(timeoutId);\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}: ${response.statusText}`);\n }\n\n this.log(`Request successful: ${response.status}`);\n } catch (error) {\n clearTimeout(timeoutId);\n \n if (error instanceof Error) {\n if (error.name === 'AbortError') {\n throw new Error('Request timeout');\n }\n throw error;\n }\n \n throw new Error('Request failed');\n }\n }\n\n /**\n * Set connection state\n */\n private setState(state: TransportState): void {\n if (this._state === state) {\n return;\n }\n\n this._state = state;\n this.stateHandlers.forEach((handler) => {\n try {\n handler(state);\n } catch (error) {\n this.log('State handler error:', error);\n }\n });\n }\n\n /**\n * Emit error to handlers\n */\n private emitError(error: Error): void {\n this.errorHandlers.forEach((handler) => {\n try {\n handler(error);\n } catch (err) {\n this.log('Error handler error:', err);\n }\n });\n }\n\n /**\n * Debug logging\n */\n private log(message: string, data?: unknown): void {\n if (this.debug && typeof console !== 'undefined') {\n console.log(`[WebhookTransport] ${message}`, data || '');\n }\n }\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@sygnl/talon",
3
+ "version": "1.0.1",
4
+ "description": "Bidirectional event delivery client with WebSocket and Webhook transports",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ },
15
+ "./transports": {
16
+ "types": "./dist/transports.d.ts",
17
+ "import": "./dist/transports.js",
18
+ "require": "./dist/transports.cjs"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
25
+ "keywords": [
26
+ "websocket",
27
+ "webhook",
28
+ "event",
29
+ "delivery",
30
+ "real-time",
31
+ "bidirectional",
32
+ "workers",
33
+ "cloudflare",
34
+ "Requests"
35
+ ],
36
+ "scripts": {
37
+ "build": "tsup",
38
+ "test": "vitest run",
39
+ "test:watch": "vitest",
40
+ "test:coverage": "vitest run --coverage",
41
+ "typecheck": "tsc --noEmit",
42
+ "prepublishOnly": "npm run build"
43
+ },
44
+ "dependencies": {},
45
+ "devDependencies": {
46
+ "@types/node": "^20.10.0",
47
+ "@types/ws": "^8.5.10",
48
+ "tsup": "^8.0.1",
49
+ "typescript": "^5.3.3",
50
+ "vitest": "^1.0.4",
51
+ "@vitest/coverage-v8": "^1.0.4",
52
+ "happy-dom": "^12.10.3"
53
+ },
54
+ "engines": {
55
+ "node": ">=18"
56
+ },
57
+ "author": "Edge Foundry, Inc.",
58
+ "license": "Apache-2.0",
59
+ "repository": {
60
+ "type": "git",
61
+ "url": "https://github.com/sygnl/talon"
62
+ }
63
+ }