@getlimelight/sdk 0.1.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/LICENSE.md +21 -0
- package/README.md +488 -0
- package/dist/index.d.mts +399 -0
- package/dist/index.d.ts +399 -0
- package/dist/index.js +1244 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1207 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +74 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
declare enum NetworkType {
|
|
2
|
+
FETCH = "fetch",
|
|
3
|
+
XHR = "xhr",
|
|
4
|
+
GRAPHQL = "graphql"
|
|
5
|
+
}
|
|
6
|
+
declare enum NetworkPhase {
|
|
7
|
+
CONNECT = "CONNECT",
|
|
8
|
+
REQUEST = "REQUEST",
|
|
9
|
+
RESPONSE = "RESPONSE",
|
|
10
|
+
ERROR = "ERROR"
|
|
11
|
+
}
|
|
12
|
+
declare enum BodyFormat {
|
|
13
|
+
TEXT = "TEXT",
|
|
14
|
+
JSON = "JSON",
|
|
15
|
+
FORM_DATA = "FORM_DATA",
|
|
16
|
+
BLOB = "BLOB",
|
|
17
|
+
ARRAY_BUFFER = "ARRAY_BUFFER",
|
|
18
|
+
NONE = "NONE",
|
|
19
|
+
UNSERIALIZABLE = "UNSERIALIZABLE"
|
|
20
|
+
}
|
|
21
|
+
declare enum HttpMethod {
|
|
22
|
+
GET = "GET",
|
|
23
|
+
POST = "POST",
|
|
24
|
+
PUT = "PUT",
|
|
25
|
+
PATCH = "PATCH",
|
|
26
|
+
DELETE = "DELETE",
|
|
27
|
+
HEAD = "HEAD",
|
|
28
|
+
OPTIONS = "OPTIONS",
|
|
29
|
+
TRACE = "TRACE",
|
|
30
|
+
CONNECT = "CONNECT"
|
|
31
|
+
}
|
|
32
|
+
declare enum HttpStatusClass {
|
|
33
|
+
INFORMATIONAL = 100,
|
|
34
|
+
SUCCESS = 200,
|
|
35
|
+
REDIRECTION = 300,
|
|
36
|
+
CLIENT_ERROR = 400,
|
|
37
|
+
SERVER_ERROR = 500
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Normalized serialized body format
|
|
41
|
+
*/
|
|
42
|
+
interface SerializedBody {
|
|
43
|
+
format: BodyFormat;
|
|
44
|
+
size: number;
|
|
45
|
+
preview: string;
|
|
46
|
+
raw?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Base shape all network events share
|
|
50
|
+
*/
|
|
51
|
+
interface BaseNetworkEvent {
|
|
52
|
+
id: string;
|
|
53
|
+
sessionId: string;
|
|
54
|
+
timestamp: number;
|
|
55
|
+
phase: NetworkPhase;
|
|
56
|
+
networkType: NetworkType;
|
|
57
|
+
graphql?: {
|
|
58
|
+
operationName?: string;
|
|
59
|
+
operationType?: GraphqlOprtation | null;
|
|
60
|
+
variables?: any;
|
|
61
|
+
query?: string;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The REQUEST event your RN client sends first
|
|
66
|
+
*/
|
|
67
|
+
interface NetworkRequest extends BaseNetworkEvent {
|
|
68
|
+
phase: NetworkPhase.REQUEST;
|
|
69
|
+
url: string;
|
|
70
|
+
method: HttpMethod;
|
|
71
|
+
headers: Record<string, string>;
|
|
72
|
+
body?: SerializedBody;
|
|
73
|
+
name: string;
|
|
74
|
+
initiator: string;
|
|
75
|
+
requestSize: number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The RESPONSE event (2nd step)
|
|
79
|
+
*/
|
|
80
|
+
interface NetworkResponse extends BaseNetworkEvent {
|
|
81
|
+
phase: NetworkPhase.RESPONSE;
|
|
82
|
+
status: number;
|
|
83
|
+
statusText: string;
|
|
84
|
+
headers: Record<string, string>;
|
|
85
|
+
body?: SerializedBody;
|
|
86
|
+
duration: number;
|
|
87
|
+
responseSize: number;
|
|
88
|
+
redirected: boolean;
|
|
89
|
+
ok: boolean;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* NETWORK ERROR (3rd possible outcome)
|
|
93
|
+
*/
|
|
94
|
+
interface NetworkErrorEvent extends BaseNetworkEvent {
|
|
95
|
+
phase: NetworkPhase.ERROR;
|
|
96
|
+
errorMessage: string;
|
|
97
|
+
stack?: string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* CONNECT event (session start)
|
|
101
|
+
*/
|
|
102
|
+
interface ConnectEvent {
|
|
103
|
+
phase: NetworkPhase.CONNECT;
|
|
104
|
+
sessionId: string;
|
|
105
|
+
timestamp: number;
|
|
106
|
+
data: {
|
|
107
|
+
appName: string;
|
|
108
|
+
platform: "ios" | "android";
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
declare enum EventType {
|
|
112
|
+
NETWORK = "NETWORK",
|
|
113
|
+
CONSOLE = "CONSOLE"
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* All possible events that can be sent over WebSocket
|
|
117
|
+
*/
|
|
118
|
+
type NetworkEvent = ConnectEvent | NetworkRequest | NetworkResponse | NetworkErrorEvent | GraphQLRequest | GraphQLResponse;
|
|
119
|
+
type LimelightEvent = NetworkEvent | ConsoleEvent;
|
|
120
|
+
interface Session {
|
|
121
|
+
id: string;
|
|
122
|
+
appName: string;
|
|
123
|
+
platform: "ios" | "android";
|
|
124
|
+
connectedAt: number;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Request with its corresponding response (for UI display)
|
|
128
|
+
*/
|
|
129
|
+
interface NetworkRequestWithResponse extends NetworkRequest {
|
|
130
|
+
response?: NetworkResponse;
|
|
131
|
+
status?: number;
|
|
132
|
+
duration?: number;
|
|
133
|
+
error?: NetworkErrorEvent;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Request with its corresponding response (for UI display)
|
|
137
|
+
*/
|
|
138
|
+
interface NetworkRequestWithResponse extends NetworkRequest {
|
|
139
|
+
response?: NetworkResponse;
|
|
140
|
+
status?: number;
|
|
141
|
+
duration?: number;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Console log levels
|
|
146
|
+
*/
|
|
147
|
+
declare enum ConsoleLevel {
|
|
148
|
+
LOG = "log",
|
|
149
|
+
WARN = "warn",
|
|
150
|
+
ERROR = "error",
|
|
151
|
+
INFO = "info",
|
|
152
|
+
DEBUG = "debug",
|
|
153
|
+
TRACE = "trace"
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Where logs originate from
|
|
157
|
+
*/
|
|
158
|
+
declare enum ConsoleSource {
|
|
159
|
+
APP = "app",
|
|
160
|
+
LIBRARY = "library",
|
|
161
|
+
REACT_NATIVE = "react-native",
|
|
162
|
+
NATIVE = "native"
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Type of console log
|
|
166
|
+
*/
|
|
167
|
+
declare enum ConsoleType {
|
|
168
|
+
EXCEPTION = "exception",
|
|
169
|
+
WARNING = "warning",
|
|
170
|
+
NETWORK = "network",
|
|
171
|
+
PERFORMANCE = "performance",
|
|
172
|
+
GENERAL = "general"
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Console log event from the app
|
|
176
|
+
*/
|
|
177
|
+
interface ConsoleEvent {
|
|
178
|
+
id: string;
|
|
179
|
+
phase: "CONSOLE";
|
|
180
|
+
type: EventType.CONSOLE;
|
|
181
|
+
level: ConsoleLevel;
|
|
182
|
+
timestamp: number;
|
|
183
|
+
sessionId: string;
|
|
184
|
+
source: ConsoleSource;
|
|
185
|
+
consoleType: ConsoleType;
|
|
186
|
+
args: string[];
|
|
187
|
+
stackTrace?: string;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* GRAPHQL EXTENSIONS
|
|
192
|
+
*/
|
|
193
|
+
interface GraphQLRequest extends NetworkRequest {
|
|
194
|
+
networkType: NetworkType.GRAPHQL;
|
|
195
|
+
query: string;
|
|
196
|
+
variables?: Record<string, any>;
|
|
197
|
+
operationName?: string;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* GRAPHQL Response
|
|
201
|
+
*/
|
|
202
|
+
interface GraphQLResponse extends NetworkResponse {
|
|
203
|
+
networkType: NetworkType.GRAPHQL;
|
|
204
|
+
data?: any;
|
|
205
|
+
errors?: any[];
|
|
206
|
+
}
|
|
207
|
+
declare enum GraphqlOprtation {
|
|
208
|
+
QUERY = "QUERY",
|
|
209
|
+
MUTATION = "MUTATION",
|
|
210
|
+
SUB = "SUBSCRIPTION"
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Configuration options for Limelight SDK.
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```ts
|
|
218
|
+
* import { LimelightConfig } from "@limelight-sdk/sdk";
|
|
219
|
+
*
|
|
220
|
+
* const config: LimelightConfig = {
|
|
221
|
+
* appName: "MyReactNativeApp",
|
|
222
|
+
* enabled: true,
|
|
223
|
+
* enableNetworkInspector: true,
|
|
224
|
+
* enableConsole: true,
|
|
225
|
+
* enableGraphQL: false,
|
|
226
|
+
* disableBodyCapture: false,
|
|
227
|
+
* beforeSend: (event) => {
|
|
228
|
+
* // Modify event or return null to drop the event
|
|
229
|
+
* return event;
|
|
230
|
+
* },
|
|
231
|
+
* serverUrl: "ws://localhost:8080/limelight",
|
|
232
|
+
* };
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
interface LimelightConfig {
|
|
236
|
+
/**
|
|
237
|
+
* The platform of the application (e.g., "ios", "android").
|
|
238
|
+
*/
|
|
239
|
+
platform?: string;
|
|
240
|
+
/**
|
|
241
|
+
* The URL of the Limelight server to connect to.
|
|
242
|
+
*/
|
|
243
|
+
serverUrl?: string;
|
|
244
|
+
/**
|
|
245
|
+
* The name of the application being monitored.
|
|
246
|
+
*/
|
|
247
|
+
appName?: string;
|
|
248
|
+
/**
|
|
249
|
+
* Flag to enable or disable the Limelight SDK.
|
|
250
|
+
*/
|
|
251
|
+
enabled?: boolean;
|
|
252
|
+
/**
|
|
253
|
+
* Flag to enable or disable network request inspection.
|
|
254
|
+
*/
|
|
255
|
+
enableNetworkInspector?: boolean;
|
|
256
|
+
/**
|
|
257
|
+
* Flag to enable or disable console event capturing.
|
|
258
|
+
*/
|
|
259
|
+
enableConsole?: boolean;
|
|
260
|
+
/**
|
|
261
|
+
* Flag to enable or disable GraphQL request capturing.
|
|
262
|
+
*/
|
|
263
|
+
enableGraphQL?: boolean;
|
|
264
|
+
/**
|
|
265
|
+
* Flag to disable capturing of request and response bodies.
|
|
266
|
+
*/
|
|
267
|
+
disableBodyCapture?: boolean;
|
|
268
|
+
/**
|
|
269
|
+
* A callback function to modify or filter events before they are sent to the server.
|
|
270
|
+
*/
|
|
271
|
+
beforeSend?: (event: LimelightMessage) => LimelightMessage | null;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Represents a connection or disconnection event in the Limelight SDK.
|
|
275
|
+
*/
|
|
276
|
+
interface ConnectionEvent {
|
|
277
|
+
phase: "CONNECT" | "DISCONNECT";
|
|
278
|
+
sessionId: string;
|
|
279
|
+
timestamp: number;
|
|
280
|
+
data?: {
|
|
281
|
+
appName?: string;
|
|
282
|
+
platform?: string;
|
|
283
|
+
reason?: string;
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Union type representing all possible Limelight messages.
|
|
288
|
+
*/
|
|
289
|
+
type LimelightMessage = NetworkRequest | NetworkResponse | NetworkErrorEvent | ConsoleEvent | ConnectionEvent;
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Represents a single frame in a stack trace.
|
|
293
|
+
*/
|
|
294
|
+
interface StackFrame {
|
|
295
|
+
fileName: string;
|
|
296
|
+
lineNumber?: number;
|
|
297
|
+
columnNumber?: number;
|
|
298
|
+
functionName?: string;
|
|
299
|
+
source: string;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Represents a parsed stack trace with its frames and raw string.
|
|
303
|
+
*/
|
|
304
|
+
interface ParsedStackTrace {
|
|
305
|
+
frames: StackFrame[];
|
|
306
|
+
raw: string;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
declare class LimelightClient {
|
|
310
|
+
private ws;
|
|
311
|
+
private config;
|
|
312
|
+
private sessionId;
|
|
313
|
+
private reconnectAttempts;
|
|
314
|
+
private maxReconnectAttempts;
|
|
315
|
+
private reconnectDelay;
|
|
316
|
+
private reconnectTimer;
|
|
317
|
+
private messageQueue;
|
|
318
|
+
private maxQueueSize;
|
|
319
|
+
private networkInterceptor;
|
|
320
|
+
private xhrInterceptor;
|
|
321
|
+
private consoleInterceptor;
|
|
322
|
+
constructor();
|
|
323
|
+
/**
|
|
324
|
+
* Configures the Limelight client with the provided settings.
|
|
325
|
+
* Sets up network, XHR, and console interceptors based on the configuration.
|
|
326
|
+
* @internal
|
|
327
|
+
* @private
|
|
328
|
+
* @param {LimelightConfig} config - Configuration object for Limelight
|
|
329
|
+
* @returns {void}
|
|
330
|
+
*/
|
|
331
|
+
private configure;
|
|
332
|
+
/**
|
|
333
|
+
* Establishes a WebSocket connection to the Limelight server.
|
|
334
|
+
* If a config object is provided, it will configure the client before connecting.
|
|
335
|
+
*
|
|
336
|
+
* If no config is provided and the client hasn't been configured, it will use default settings.
|
|
337
|
+
*
|
|
338
|
+
* Prevents multiple simultaneous connections and handles reconnection logic.
|
|
339
|
+
*
|
|
340
|
+
* @param {LimelightConfig} [config] - Optional configuration object.
|
|
341
|
+
* @returns {void}
|
|
342
|
+
*/
|
|
343
|
+
connect(config?: LimelightConfig): void;
|
|
344
|
+
/**
|
|
345
|
+
* Attempts to reconnect to the Limelight server using exponential backoff.
|
|
346
|
+
* Will retry up to maxReconnectAttempts times with increasing delays.
|
|
347
|
+
* Maximum delay is capped at 30 seconds.
|
|
348
|
+
* @private
|
|
349
|
+
* @returns {void}
|
|
350
|
+
*/
|
|
351
|
+
private attemptReconnect;
|
|
352
|
+
/**
|
|
353
|
+
* Sends all queued messages to the server.
|
|
354
|
+
* Only executes if the WebSocket connection is open.
|
|
355
|
+
* @private
|
|
356
|
+
* @returns {void}
|
|
357
|
+
*/
|
|
358
|
+
private flushMessageQueue;
|
|
359
|
+
/**
|
|
360
|
+
* Sends a message to the Limelight server or queues it if not connected.
|
|
361
|
+
* Messages are automatically queued when the connection is not open.
|
|
362
|
+
* If the queue is full, the oldest message will be dropped.
|
|
363
|
+
* @private
|
|
364
|
+
* @param {LimelightMessage} message - The message to send
|
|
365
|
+
* @returns {void}
|
|
366
|
+
*/
|
|
367
|
+
private sendMessage;
|
|
368
|
+
/**
|
|
369
|
+
* Disconnects from the Limelight server and cleans up resources.
|
|
370
|
+
* Closes the WebSocket connection, removes all interceptors, and resets connection state.
|
|
371
|
+
* Preserves configuration and session ID for potential reconnection.
|
|
372
|
+
* @returns {void}
|
|
373
|
+
*/
|
|
374
|
+
disconnect(): void;
|
|
375
|
+
/**
|
|
376
|
+
* Performs a complete reset of the Limelight client.
|
|
377
|
+
* Disconnects from the server and clears all configuration and session data.
|
|
378
|
+
* After calling reset(), connect() must be called again.
|
|
379
|
+
* @returns {void}
|
|
380
|
+
*/
|
|
381
|
+
reset(): void;
|
|
382
|
+
}
|
|
383
|
+
declare const Limelight: LimelightClient;
|
|
384
|
+
|
|
385
|
+
declare global {
|
|
386
|
+
interface XMLHttpRequest {
|
|
387
|
+
_limelightData?: {
|
|
388
|
+
id: string;
|
|
389
|
+
method: string;
|
|
390
|
+
url: string;
|
|
391
|
+
headers: Record<string, string>;
|
|
392
|
+
startTime: number;
|
|
393
|
+
skipIntercept?: boolean;
|
|
394
|
+
listeners?: Map<string, EventListener>;
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export { type BaseNetworkEvent, BodyFormat, type ConnectEvent, type ConnectionEvent, type ConsoleEvent, ConsoleLevel, ConsoleSource, ConsoleType, EventType, type GraphQLRequest, type GraphQLResponse, GraphqlOprtation, HttpMethod, HttpStatusClass, Limelight, type LimelightConfig, type LimelightEvent, type LimelightMessage, type NetworkErrorEvent, type NetworkEvent, NetworkPhase, type NetworkRequest, type NetworkRequestWithResponse, type NetworkResponse, NetworkType, type ParsedStackTrace, type SerializedBody, type Session, type StackFrame };
|