@mochabug/adapt-web 0.0.65 → 0.0.68
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/cjs/genproto/mochabugapis/adapt/automations/v1/automations_pb.js +1 -1
- package/dist/cjs/genproto/mochabugapis/adapt/automations/v1/automations_pb.js.map +1 -1
- package/dist/cjs/index.js +5 -286
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/pubsub-client.js +501 -0
- package/dist/cjs/pubsub-client.js.map +1 -0
- package/dist/esm/genproto/mochabugapis/adapt/automations/v1/automations_pb.js +1 -1
- package/dist/esm/genproto/mochabugapis/adapt/automations/v1/automations_pb.js.map +1 -1
- package/dist/esm/index.js +2 -281
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/pubsub-client.js +494 -0
- package/dist/esm/pubsub-client.js.map +1 -0
- package/dist/types/genproto/mochabugapis/adapt/automations/v1/automations_pb.d.ts +2 -40
- package/dist/types/index.d.ts +2 -53
- package/dist/types/pubsub-client.d.ts +52 -0
- package/package.json +1 -1
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
import { fromBinary, toJson } from "@bufbuild/protobuf";
|
|
2
|
+
import { timestampDate } from "@bufbuild/protobuf/wkt";
|
|
3
|
+
import WebSocket from "isomorphic-ws";
|
|
4
|
+
import { parse as parseUuid } from "uuid";
|
|
5
|
+
import { SessionSchema, UrlSchema, WebsocketMessageSchema, } from "./genproto/mochabugapis/adapt/automations/v1/automations_pb.js";
|
|
6
|
+
import { getConfig } from "./index.js";
|
|
7
|
+
// Connection states
|
|
8
|
+
export var ConnectionState;
|
|
9
|
+
(function (ConnectionState) {
|
|
10
|
+
ConnectionState["DISCONNECTED"] = "disconnected";
|
|
11
|
+
ConnectionState["CONNECTING"] = "connecting";
|
|
12
|
+
ConnectionState["CONNECTED"] = "connected";
|
|
13
|
+
ConnectionState["CLOSING"] = "closing";
|
|
14
|
+
})(ConnectionState || (ConnectionState = {}));
|
|
15
|
+
// Logger class for consistent logging
|
|
16
|
+
class Logger {
|
|
17
|
+
constructor(debug) {
|
|
18
|
+
this.debug = debug;
|
|
19
|
+
}
|
|
20
|
+
log(level, message, data) {
|
|
21
|
+
if (!this.debug && level === "debug")
|
|
22
|
+
return;
|
|
23
|
+
const timestamp = new Date().toISOString();
|
|
24
|
+
const prefix = `[PubSub ${timestamp}]`;
|
|
25
|
+
const fullMessage = `${prefix} ${message}`;
|
|
26
|
+
if (data !== undefined) {
|
|
27
|
+
console[level](fullMessage, data);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
console[level](fullMessage);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// ACK tracker to prevent duplicate message processing
|
|
35
|
+
class AckTracker {
|
|
36
|
+
constructor(logger) {
|
|
37
|
+
this.logger = logger;
|
|
38
|
+
this.ackedMessages = new Map();
|
|
39
|
+
this.MESSAGE_TTL = 60000; // 60 seconds
|
|
40
|
+
this.cleanupTimer = null;
|
|
41
|
+
}
|
|
42
|
+
start() {
|
|
43
|
+
// Cleanup old messages every 30 seconds
|
|
44
|
+
this.cleanupTimer = setInterval(() => this.cleanup(), 30000);
|
|
45
|
+
}
|
|
46
|
+
stop() {
|
|
47
|
+
if (this.cleanupTimer) {
|
|
48
|
+
clearInterval(this.cleanupTimer);
|
|
49
|
+
this.cleanupTimer = null;
|
|
50
|
+
}
|
|
51
|
+
this.ackedMessages.clear();
|
|
52
|
+
}
|
|
53
|
+
isProcessed(messageId) {
|
|
54
|
+
return this.ackedMessages.has(messageId);
|
|
55
|
+
}
|
|
56
|
+
markProcessed(messageId) {
|
|
57
|
+
this.ackedMessages.set(messageId, Date.now());
|
|
58
|
+
}
|
|
59
|
+
cleanup() {
|
|
60
|
+
const now = Date.now();
|
|
61
|
+
const deadline = now - this.MESSAGE_TTL;
|
|
62
|
+
let removed = 0;
|
|
63
|
+
for (const [messageId, timestamp] of this.ackedMessages.entries()) {
|
|
64
|
+
if (timestamp < deadline) {
|
|
65
|
+
this.ackedMessages.delete(messageId);
|
|
66
|
+
removed++;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (removed > 0) {
|
|
70
|
+
this.logger.log("debug", `Cleaned up ${removed} old ACKed messages`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Reconnection manager with exponential backoff
|
|
75
|
+
class ReconnectionManager {
|
|
76
|
+
constructor(logger) {
|
|
77
|
+
this.logger = logger;
|
|
78
|
+
this.attempts = 0;
|
|
79
|
+
this.timer = null;
|
|
80
|
+
this.INITIAL_DELAY = 1000; // 1 second
|
|
81
|
+
this.MAX_DELAY = 30000; // 30 seconds
|
|
82
|
+
this.MAX_ATTEMPTS = -1; // -1 = infinite
|
|
83
|
+
}
|
|
84
|
+
reset() {
|
|
85
|
+
this.attempts = 0;
|
|
86
|
+
this.cancel();
|
|
87
|
+
}
|
|
88
|
+
cancel() {
|
|
89
|
+
if (this.timer) {
|
|
90
|
+
clearTimeout(this.timer);
|
|
91
|
+
this.timer = null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
scheduleReconnect(callback) {
|
|
95
|
+
if (this.MAX_ATTEMPTS !== -1 && this.attempts >= this.MAX_ATTEMPTS) {
|
|
96
|
+
this.logger.log("error", "Max reconnection attempts reached");
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
this.attempts++;
|
|
100
|
+
const delay = Math.min(this.INITIAL_DELAY * Math.pow(2, this.attempts - 1), this.MAX_DELAY);
|
|
101
|
+
this.logger.log("info", `Scheduling reconnect attempt ${this.attempts} in ${delay}ms`);
|
|
102
|
+
this.timer = setTimeout(() => {
|
|
103
|
+
this.timer = null;
|
|
104
|
+
callback();
|
|
105
|
+
}, delay);
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// WebSocket connection manager
|
|
110
|
+
class WebSocketManager {
|
|
111
|
+
constructor(logger) {
|
|
112
|
+
this.logger = logger;
|
|
113
|
+
this.ws = null;
|
|
114
|
+
this.pingTimer = null;
|
|
115
|
+
this.PING_INTERVAL = 10000; // 10 seconds
|
|
116
|
+
}
|
|
117
|
+
connect(url, onOpen, onMessage, onClose, onError) {
|
|
118
|
+
if (this.ws) {
|
|
119
|
+
throw new Error("WebSocket already exists");
|
|
120
|
+
}
|
|
121
|
+
this.logger.log("info", `Connecting to: ${url}`);
|
|
122
|
+
this.ws = new WebSocket(url);
|
|
123
|
+
this.ws.binaryType = "arraybuffer";
|
|
124
|
+
this.ws.onopen = () => {
|
|
125
|
+
this.logger.log("info", "✓ WebSocket connected");
|
|
126
|
+
this.startPing();
|
|
127
|
+
onOpen();
|
|
128
|
+
};
|
|
129
|
+
this.ws.onmessage = (event) => {
|
|
130
|
+
if (event.data instanceof ArrayBuffer) {
|
|
131
|
+
onMessage(event.data);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
this.logger.log("warn", "Received non-binary message, ignoring");
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
this.ws.onerror = (error) => {
|
|
138
|
+
this.logger.log("error", "WebSocket error:", error);
|
|
139
|
+
onError(error);
|
|
140
|
+
};
|
|
141
|
+
this.ws.onclose = (event) => {
|
|
142
|
+
this.logger.log("info", `WebSocket closed: ${event.code} - ${event.reason}`);
|
|
143
|
+
this.stopPing();
|
|
144
|
+
onClose(event.code, event.reason);
|
|
145
|
+
this.ws = null;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
sendAck(messageId) {
|
|
149
|
+
if (!this.isConnected()) {
|
|
150
|
+
this.logger.log("warn", `Cannot send ACK (not connected): ${messageId}`);
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
// Parse UUID string to bytes (16 bytes)
|
|
155
|
+
const uuid = new Uint8Array(parseUuid(messageId));
|
|
156
|
+
this.ws.send(uuid);
|
|
157
|
+
this.logger.log("debug", `Sent ACK: ${messageId}`);
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
this.logger.log("error", `Failed to send ACK for ${messageId}:`, error);
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
close(code = 1000 /* CloseCode.NORMAL */, reason = "Client disconnecting") {
|
|
166
|
+
this.stopPing();
|
|
167
|
+
if (this.ws) {
|
|
168
|
+
try {
|
|
169
|
+
if (this.ws.readyState === WebSocket.OPEN) {
|
|
170
|
+
this.ws.close(code, reason);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
this.logger.log("error", "Error closing WebSocket:", error);
|
|
175
|
+
}
|
|
176
|
+
this.ws = null;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
isConnected() {
|
|
180
|
+
return this.ws !== null && this.ws.readyState === WebSocket.OPEN;
|
|
181
|
+
}
|
|
182
|
+
startPing() {
|
|
183
|
+
this.stopPing();
|
|
184
|
+
// Send ping every 30 seconds to keep connection alive
|
|
185
|
+
this.pingTimer = setInterval(() => {
|
|
186
|
+
if (this.isConnected()) {
|
|
187
|
+
try {
|
|
188
|
+
this.ws.ping();
|
|
189
|
+
this.logger.log("debug", "Sent ping");
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
this.logger.log("error", "Failed to send ping:", error);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}, this.PING_INTERVAL);
|
|
196
|
+
}
|
|
197
|
+
stopPing() {
|
|
198
|
+
if (this.pingTimer) {
|
|
199
|
+
clearInterval(this.pingTimer);
|
|
200
|
+
this.pingTimer = null;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// Message processor for handling incoming WebSocket messages
|
|
205
|
+
class MessageProcessor {
|
|
206
|
+
constructor(logger, handlers) {
|
|
207
|
+
this.logger = logger;
|
|
208
|
+
this.handlers = handlers;
|
|
209
|
+
}
|
|
210
|
+
process(data) {
|
|
211
|
+
try {
|
|
212
|
+
const message = fromBinary(WebsocketMessageSchema, new Uint8Array(data));
|
|
213
|
+
this.logger.log("debug", `Processing message: ${message.id}`);
|
|
214
|
+
// Process based on message type
|
|
215
|
+
switch (message.message.case) {
|
|
216
|
+
case "output":
|
|
217
|
+
this.processOutput(message.message.value);
|
|
218
|
+
break;
|
|
219
|
+
case "session":
|
|
220
|
+
this.processSession(message.message.value);
|
|
221
|
+
break;
|
|
222
|
+
case "url":
|
|
223
|
+
this.processUrl(message.message.value);
|
|
224
|
+
break;
|
|
225
|
+
default:
|
|
226
|
+
this.logger.log("warn", `Unknown message type: ${message.message.case}`);
|
|
227
|
+
}
|
|
228
|
+
return message.id;
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
this.logger.log("error", "Failed to process message:", error);
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
processOutput(output) {
|
|
236
|
+
if (!this.handlers.onOutput)
|
|
237
|
+
return;
|
|
238
|
+
try {
|
|
239
|
+
this.handlers.onOutput({
|
|
240
|
+
vertex: output.vertex,
|
|
241
|
+
fork: output.fork,
|
|
242
|
+
data: this.parseOutputData(output.data),
|
|
243
|
+
created: output.created ? timestampDate(output.created) : undefined,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
this.logger.log("error", "Error in output handler:", error);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
processSession(session) {
|
|
251
|
+
if (!this.handlers.onSession)
|
|
252
|
+
return;
|
|
253
|
+
try {
|
|
254
|
+
this.handlers.onSession(toJson(SessionSchema, session));
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
this.logger.log("error", "Error in session handler:", error);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
processUrl(url) {
|
|
261
|
+
if (!this.handlers.onUrl)
|
|
262
|
+
return;
|
|
263
|
+
try {
|
|
264
|
+
this.handlers.onUrl(toJson(UrlSchema, url));
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
this.logger.log("error", "Error in URL handler:", error);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
parseOutputData(data) {
|
|
271
|
+
return Object.fromEntries(Object.entries(data).map(([key, value]) => {
|
|
272
|
+
try {
|
|
273
|
+
return [key, JSON.parse(new TextDecoder().decode(value))];
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
this.logger.log("error", `Failed to parse data for key ${key}:`, error);
|
|
277
|
+
return [key, null];
|
|
278
|
+
}
|
|
279
|
+
}));
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
// Main PubsubClient class
|
|
283
|
+
export class PubsubClient {
|
|
284
|
+
constructor(debug = false) {
|
|
285
|
+
this.state = ConnectionState.DISCONNECTED;
|
|
286
|
+
this.sessionConfig = null;
|
|
287
|
+
this.messageProcessor = null;
|
|
288
|
+
this.shouldReconnect = true;
|
|
289
|
+
this.sessionComplete = false;
|
|
290
|
+
this.logger = new Logger(debug);
|
|
291
|
+
this.ackTracker = new AckTracker(this.logger);
|
|
292
|
+
this.reconnectManager = new ReconnectionManager(this.logger);
|
|
293
|
+
this.wsManager = new WebSocketManager(this.logger);
|
|
294
|
+
}
|
|
295
|
+
async subscribe(opts) {
|
|
296
|
+
this.logger.log("debug", "Subscribe called", {
|
|
297
|
+
automation: opts.automation,
|
|
298
|
+
hasToken: !!opts.sessionToken,
|
|
299
|
+
});
|
|
300
|
+
// Validate input
|
|
301
|
+
if (!opts.sessionToken || !opts.automation) {
|
|
302
|
+
throw new Error("Session token and automation are required");
|
|
303
|
+
}
|
|
304
|
+
// Check if already connected to same session
|
|
305
|
+
if (this.isSameSession(opts)) {
|
|
306
|
+
this.logger.log("debug", "Already connected to same session, updating handlers");
|
|
307
|
+
this.updateHandlers(opts);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
// Check state
|
|
311
|
+
if (this.state === ConnectionState.CONNECTING) {
|
|
312
|
+
throw new Error("Already connecting, please wait");
|
|
313
|
+
}
|
|
314
|
+
// Disconnect if connected to different session
|
|
315
|
+
if (this.state === ConnectionState.CONNECTED) {
|
|
316
|
+
await this.unsubscribe();
|
|
317
|
+
}
|
|
318
|
+
// Store configuration
|
|
319
|
+
this.sessionConfig = {
|
|
320
|
+
token: opts.sessionToken,
|
|
321
|
+
automation: opts.automation,
|
|
322
|
+
};
|
|
323
|
+
// Create message processor with handlers
|
|
324
|
+
this.messageProcessor = new MessageProcessor(this.logger, {
|
|
325
|
+
onOutput: opts.onOutput,
|
|
326
|
+
onSession: opts.onSession,
|
|
327
|
+
onUrl: opts.onUrl,
|
|
328
|
+
});
|
|
329
|
+
// Reset state
|
|
330
|
+
this.shouldReconnect = true;
|
|
331
|
+
this.sessionComplete = false;
|
|
332
|
+
this.reconnectManager.reset();
|
|
333
|
+
// Start ACK tracker
|
|
334
|
+
this.ackTracker.start();
|
|
335
|
+
// Connect
|
|
336
|
+
await this.connect();
|
|
337
|
+
}
|
|
338
|
+
async unsubscribe() {
|
|
339
|
+
if (this.state === ConnectionState.DISCONNECTED ||
|
|
340
|
+
this.state === ConnectionState.CLOSING) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
this.logger.log("info", "Unsubscribing...");
|
|
344
|
+
// Update state
|
|
345
|
+
this.state = ConnectionState.CLOSING;
|
|
346
|
+
this.shouldReconnect = false;
|
|
347
|
+
// Cancel any pending reconnects
|
|
348
|
+
this.reconnectManager.cancel();
|
|
349
|
+
// Close WebSocket
|
|
350
|
+
this.wsManager.close();
|
|
351
|
+
// Stop ACK tracker
|
|
352
|
+
this.ackTracker.stop();
|
|
353
|
+
// Clear state
|
|
354
|
+
this.sessionConfig = null;
|
|
355
|
+
this.messageProcessor = null;
|
|
356
|
+
this.state = ConnectionState.DISCONNECTED;
|
|
357
|
+
this.logger.log("info", "Unsubscribed successfully");
|
|
358
|
+
}
|
|
359
|
+
isConnected() {
|
|
360
|
+
return this.state === ConnectionState.CONNECTED;
|
|
361
|
+
}
|
|
362
|
+
getConnectionState() {
|
|
363
|
+
return this.state;
|
|
364
|
+
}
|
|
365
|
+
async connect() {
|
|
366
|
+
if (!this.sessionConfig) {
|
|
367
|
+
throw new Error("No session configuration");
|
|
368
|
+
}
|
|
369
|
+
this.state = ConnectionState.CONNECTING;
|
|
370
|
+
const config = getConfig();
|
|
371
|
+
const { token, automation } = this.sessionConfig;
|
|
372
|
+
const wsUrl = `${config.wsBaseUrl}/${automation.organization}/${automation.group}/${automation.automation}/ws?token=${encodeURIComponent(token)}`;
|
|
373
|
+
try {
|
|
374
|
+
this.wsManager.connect(wsUrl, () => this.handleOpen(), (data) => this.handleMessage(data), (code, reason) => this.handleClose(code, reason), (error) => this.handleError(error));
|
|
375
|
+
}
|
|
376
|
+
catch (error) {
|
|
377
|
+
this.state = ConnectionState.DISCONNECTED;
|
|
378
|
+
throw error;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
handleOpen() {
|
|
382
|
+
this.state = ConnectionState.CONNECTED;
|
|
383
|
+
this.reconnectManager.reset();
|
|
384
|
+
}
|
|
385
|
+
handleMessage(data) {
|
|
386
|
+
if (!this.messageProcessor) {
|
|
387
|
+
this.logger.log("error", "No message processor configured");
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
// Process the message
|
|
391
|
+
const messageId = this.messageProcessor.process(data);
|
|
392
|
+
if (!messageId) {
|
|
393
|
+
return; // Failed to parse
|
|
394
|
+
}
|
|
395
|
+
// Check for duplicate
|
|
396
|
+
if (this.ackTracker.isProcessed(messageId)) {
|
|
397
|
+
this.logger.log("debug", `Duplicate message: ${messageId}`);
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
this.ackTracker.markProcessed(messageId);
|
|
401
|
+
}
|
|
402
|
+
// Always ACK (even for duplicates)
|
|
403
|
+
this.wsManager.sendAck(messageId);
|
|
404
|
+
}
|
|
405
|
+
handleClose(code, reason) {
|
|
406
|
+
this.state = ConnectionState.DISCONNECTED;
|
|
407
|
+
// Analyze close code
|
|
408
|
+
const shouldReconnect = this.analyzeCloseCode(code, reason);
|
|
409
|
+
// Schedule reconnect if appropriate
|
|
410
|
+
if (shouldReconnect && this.shouldReconnect && !this.sessionComplete) {
|
|
411
|
+
this.scheduleReconnect();
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
// Clean shutdown
|
|
415
|
+
this.cleanup();
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
handleError(error) {
|
|
419
|
+
this.logger.log("error", "WebSocket error:", error);
|
|
420
|
+
}
|
|
421
|
+
analyzeCloseCode(code, reason) {
|
|
422
|
+
switch (code) {
|
|
423
|
+
case 1000 /* CloseCode.NORMAL */:
|
|
424
|
+
// Normal closure - session complete or client requested
|
|
425
|
+
this.logger.log("info", "Normal closure");
|
|
426
|
+
this.sessionComplete = true;
|
|
427
|
+
return false;
|
|
428
|
+
case 1001 /* CloseCode.GOING_AWAY */:
|
|
429
|
+
// Server shutting down
|
|
430
|
+
this.logger.log("warn", "Server going away");
|
|
431
|
+
return true;
|
|
432
|
+
case 1002 /* CloseCode.PROTOCOL_ERROR */:
|
|
433
|
+
case 1003 /* CloseCode.UNSUPPORTED_DATA */:
|
|
434
|
+
case 1008 /* CloseCode.POLICY_VIOLATION */:
|
|
435
|
+
// Critical errors - don't reconnect
|
|
436
|
+
this.logger.log("error", `Critical error (${code}): ${reason}`);
|
|
437
|
+
return false;
|
|
438
|
+
case 1006 /* CloseCode.ABNORMAL */:
|
|
439
|
+
// Connection lost - try to reconnect
|
|
440
|
+
this.logger.log("warn", "Connection lost (abnormal closure)");
|
|
441
|
+
return true;
|
|
442
|
+
default:
|
|
443
|
+
// Unknown code - try to reconnect
|
|
444
|
+
this.logger.log("warn", `Unknown close code ${code}: ${reason}`);
|
|
445
|
+
return true;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
scheduleReconnect() {
|
|
449
|
+
const scheduled = this.reconnectManager.scheduleReconnect(() => {
|
|
450
|
+
if (this.shouldReconnect && this.state === ConnectionState.DISCONNECTED) {
|
|
451
|
+
this.connect().catch((error) => {
|
|
452
|
+
this.logger.log("error", "Reconnection failed:", error);
|
|
453
|
+
// Try again
|
|
454
|
+
this.scheduleReconnect();
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
if (!scheduled) {
|
|
459
|
+
// Max attempts reached
|
|
460
|
+
this.cleanup();
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
cleanup() {
|
|
464
|
+
this.shouldReconnect = false;
|
|
465
|
+
this.reconnectManager.cancel();
|
|
466
|
+
this.ackTracker.stop();
|
|
467
|
+
this.wsManager.close();
|
|
468
|
+
this.sessionConfig = null;
|
|
469
|
+
this.messageProcessor = null;
|
|
470
|
+
this.state = ConnectionState.DISCONNECTED;
|
|
471
|
+
}
|
|
472
|
+
isSameSession(opts) {
|
|
473
|
+
if (!this.sessionConfig || this.state !== ConnectionState.CONNECTED) {
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
return (this.sessionConfig.token === opts.sessionToken &&
|
|
477
|
+
this.sessionConfig.automation.organization ===
|
|
478
|
+
opts.automation.organization &&
|
|
479
|
+
this.sessionConfig.automation.group === opts.automation.group &&
|
|
480
|
+
this.sessionConfig.automation.automation === opts.automation.automation);
|
|
481
|
+
}
|
|
482
|
+
updateHandlers(opts) {
|
|
483
|
+
if (!this.messageProcessor) {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
// Update handlers in message processor
|
|
487
|
+
this.messageProcessor = new MessageProcessor(this.logger, {
|
|
488
|
+
onOutput: opts.onOutput,
|
|
489
|
+
onSession: opts.onSession,
|
|
490
|
+
onUrl: opts.onUrl,
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
//# sourceMappingURL=pubsub-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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ionResponse = Message<"mochabugapis.adapt.automations.v1.St
|
|
|
448
448
|
* @generated from field: string token = 1;
|
|
449
449
|
*/
|
|
450
450
|
token: string;
|
|
451
|
-
/**
|
|
452
|
-
* The credentials you may use to connect to the broker and retrieve the session data
|
|
453
|
-
* in real time
|
|
454
|
-
*
|
|
455
|
-
* @generated from field: bytes broker_credentials = 2;
|
|
456
|
-
*/
|
|
457
|
-
brokerCredentials: Uint8Array;
|
|
458
|
-
/**
|
|
459
|
-
* The consumer name to use for the broker
|
|
460
|
-
*
|
|
461
|
-
* @generated from field: string consumer_name = 3;
|
|
462
|
-
*/
|
|
463
|
-
consumerName: string;
|
|
464
|
-
/**
|
|
465
|
-
* The stream name to use for the broker
|
|
466
|
-
*
|
|
467
|
-
* @generated from field: string stream_name = 4;
|
|
468
|
-
*/
|
|
469
|
-
streamName: string;
|
|
470
451
|
/**
|
|
471
452
|
* The timestamp when the session expires, if not set, the session never expires (typically the case for long-running stream vertices)
|
|
472
453
|
*
|
|
473
|
-
* @generated from field: optional google.protobuf.Timestamp expires =
|
|
454
|
+
* @generated from field: optional google.protobuf.Timestamp expires = 2;
|
|
474
455
|
*/
|
|
475
456
|
expires?: Timestamp;
|
|
476
457
|
};
|
|
@@ -486,29 +467,10 @@ export type StartSessionResponseJson = {
|
|
|
486
467
|
* @generated from field: string token = 1;
|
|
487
468
|
*/
|
|
488
469
|
token?: string;
|
|
489
|
-
/**
|
|
490
|
-
* The credentials you may use to connect to the broker and retrieve the session data
|
|
491
|
-
* in real time
|
|
492
|
-
*
|
|
493
|
-
* @generated from field: bytes broker_credentials = 2;
|
|
494
|
-
*/
|
|
495
|
-
brokerCredentials?: string;
|
|
496
|
-
/**
|
|
497
|
-
* The consumer name to use for the broker
|
|
498
|
-
*
|
|
499
|
-
* @generated from field: string consumer_name = 3;
|
|
500
|
-
*/
|
|
501
|
-
consumerName?: string;
|
|
502
|
-
/**
|
|
503
|
-
* The stream name to use for the broker
|
|
504
|
-
*
|
|
505
|
-
* @generated from field: string stream_name = 4;
|
|
506
|
-
*/
|
|
507
|
-
streamName?: string;
|
|
508
470
|
/**
|
|
509
471
|
* The timestamp when the session expires, if not set, the session never expires (typically the case for long-running stream vertices)
|
|
510
472
|
*
|
|
511
|
-
* @generated from field: optional google.protobuf.Timestamp expires =
|
|
473
|
+
* @generated from field: optional google.protobuf.Timestamp expires = 2;
|
|
512
474
|
*/
|
|
513
475
|
expires?: TimestampJson;
|
|
514
476
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AutomationIdJson, GetSessionResponseJson, InheritSessionResponseJson, ReadOutputResponseJson, ReadUrlsResponseJson, SessionJson, StartSessionRequestJson, StartSessionResponseJson, UrlJson } from "./genproto/mochabugapis/adapt/automations/v1/automations_pb.js";
|
|
1
|
+
import { AutomationIdJson, GetSessionResponseJson, InheritSessionResponseJson, ReadOutputResponseJson, ReadUrlsResponseJson, StartSessionRequestJson, StartSessionResponseJson } from "./genproto/mochabugapis/adapt/automations/v1/automations_pb.js";
|
|
3
2
|
export interface AdaptConfig {
|
|
4
3
|
baseUrl: string;
|
|
5
4
|
wsBaseUrl: string;
|
|
@@ -19,54 +18,4 @@ export declare class RestClientError extends Error {
|
|
|
19
18
|
response: Response;
|
|
20
19
|
constructor(response: Response);
|
|
21
20
|
}
|
|
22
|
-
export
|
|
23
|
-
vertex: string;
|
|
24
|
-
fork: string;
|
|
25
|
-
data: {
|
|
26
|
-
[key: string]: ValueJson;
|
|
27
|
-
};
|
|
28
|
-
created?: Date;
|
|
29
|
-
}
|
|
30
|
-
export type SubscriptionOptions = {
|
|
31
|
-
sessionToken: string;
|
|
32
|
-
automation: AutomationIdJson;
|
|
33
|
-
onOutput?: (output: Output) => void;
|
|
34
|
-
onSession?: (session: SessionJson) => void;
|
|
35
|
-
onUrl?: (url: UrlJson) => void;
|
|
36
|
-
debug?: boolean;
|
|
37
|
-
};
|
|
38
|
-
declare enum ConnectionState {
|
|
39
|
-
DISCONNECTED = "disconnected",
|
|
40
|
-
CONNECTING = "connecting",
|
|
41
|
-
CONNECTED = "connected",
|
|
42
|
-
CLOSING = "closing"
|
|
43
|
-
}
|
|
44
|
-
export declare class PubsubClient {
|
|
45
|
-
private ws;
|
|
46
|
-
private sessionToken;
|
|
47
|
-
private automation;
|
|
48
|
-
private outputHandler;
|
|
49
|
-
private sessionHandler;
|
|
50
|
-
private urlHandler;
|
|
51
|
-
private connectionState;
|
|
52
|
-
private debug;
|
|
53
|
-
private reconnectAttempts;
|
|
54
|
-
private maxReconnectAttempts;
|
|
55
|
-
private reconnectTimeWait;
|
|
56
|
-
private maxReconnectTimeWait;
|
|
57
|
-
private shouldReconnect;
|
|
58
|
-
private ackedMessages;
|
|
59
|
-
constructor(debug?: boolean);
|
|
60
|
-
private log;
|
|
61
|
-
subscribe(opts: SubscriptionOptions): Promise<void>;
|
|
62
|
-
private connect;
|
|
63
|
-
private scheduleReconnect;
|
|
64
|
-
private handleMessage;
|
|
65
|
-
private sendAck;
|
|
66
|
-
private cleanupOldAckedMessages;
|
|
67
|
-
private cleanupState;
|
|
68
|
-
unsubscribe(): Promise<void>;
|
|
69
|
-
isConnected(): boolean;
|
|
70
|
-
getConnectionState(): ConnectionState;
|
|
71
|
-
}
|
|
72
|
-
export {};
|
|
21
|
+
export { PubsubClient, ConnectionState, Output, SubscriptionOptions, } from "./pubsub-client.js";
|