@getlimelight/sdk 0.4.1 → 0.4.2

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.d.mts CHANGED
@@ -470,6 +470,26 @@ interface ParsedStackTrace {
470
470
  raw: string;
471
471
  }
472
472
 
473
+ interface RequestBridgeConfig {
474
+ url: string;
475
+ method?: HttpMethod | string;
476
+ headers?: Record<string, string>;
477
+ body?: any;
478
+ name?: string;
479
+ graphql?: {
480
+ operationName?: string;
481
+ operationType?: GraphqlOprtation | "query" | "mutation" | "subscription";
482
+ variables?: any;
483
+ query?: string;
484
+ };
485
+ }
486
+ interface ResponseBridgeConfig {
487
+ status: number;
488
+ statusText?: string;
489
+ headers?: Record<string, string>;
490
+ body?: any;
491
+ }
492
+
473
493
  declare class LimelightClient {
474
494
  private ws;
475
495
  private config;
@@ -485,6 +505,7 @@ declare class LimelightClient {
485
505
  private consoleInterceptor;
486
506
  private renderInterceptor;
487
507
  private stateInterceptor;
508
+ private requestBridge;
488
509
  constructor();
489
510
  /**
490
511
  * Configures the Limelight client with the provided settings.
@@ -545,6 +566,29 @@ declare class LimelightClient {
545
566
  * @returns {void}
546
567
  */
547
568
  reset(): void;
569
+ /**
570
+ * Manually register a request with Limelight.
571
+ * Use this when your app makes network requests outside of fetch/XHR
572
+ * (e.g., through native modules).
573
+ *
574
+ * @param config - Request configuration
575
+ * @returns A request ID to use with endRequest() or failRequest()
576
+ */
577
+ startRequest(config: RequestBridgeConfig): string;
578
+ /**
579
+ * Complete a manually tracked request with a successful response.
580
+ *
581
+ * @param requestId - The ID returned from startRequest()
582
+ * @param response - Response data
583
+ */
584
+ endRequest(requestId: string, response: ResponseBridgeConfig): void;
585
+ /**
586
+ * Complete a manually tracked request with an error.
587
+ *
588
+ * @param requestId - The ID returned from startRequest()
589
+ * @param error - The error that occurred
590
+ */
591
+ failRequest(requestId: string, error: Error | string): void;
548
592
  }
549
593
  declare const Limelight: LimelightClient;
550
594
 
@@ -562,4 +606,4 @@ declare global {
562
606
  }
563
607
  }
564
608
 
565
- 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 };
609
+ 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 RequestBridgeConfig, type ResponseBridgeConfig, type SerializedBody, type Session, type StackFrame };
package/dist/index.d.ts CHANGED
@@ -470,6 +470,26 @@ interface ParsedStackTrace {
470
470
  raw: string;
471
471
  }
472
472
 
473
+ interface RequestBridgeConfig {
474
+ url: string;
475
+ method?: HttpMethod | string;
476
+ headers?: Record<string, string>;
477
+ body?: any;
478
+ name?: string;
479
+ graphql?: {
480
+ operationName?: string;
481
+ operationType?: GraphqlOprtation | "query" | "mutation" | "subscription";
482
+ variables?: any;
483
+ query?: string;
484
+ };
485
+ }
486
+ interface ResponseBridgeConfig {
487
+ status: number;
488
+ statusText?: string;
489
+ headers?: Record<string, string>;
490
+ body?: any;
491
+ }
492
+
473
493
  declare class LimelightClient {
474
494
  private ws;
475
495
  private config;
@@ -485,6 +505,7 @@ declare class LimelightClient {
485
505
  private consoleInterceptor;
486
506
  private renderInterceptor;
487
507
  private stateInterceptor;
508
+ private requestBridge;
488
509
  constructor();
489
510
  /**
490
511
  * Configures the Limelight client with the provided settings.
@@ -545,6 +566,29 @@ declare class LimelightClient {
545
566
  * @returns {void}
546
567
  */
547
568
  reset(): void;
569
+ /**
570
+ * Manually register a request with Limelight.
571
+ * Use this when your app makes network requests outside of fetch/XHR
572
+ * (e.g., through native modules).
573
+ *
574
+ * @param config - Request configuration
575
+ * @returns A request ID to use with endRequest() or failRequest()
576
+ */
577
+ startRequest(config: RequestBridgeConfig): string;
578
+ /**
579
+ * Complete a manually tracked request with a successful response.
580
+ *
581
+ * @param requestId - The ID returned from startRequest()
582
+ * @param response - Response data
583
+ */
584
+ endRequest(requestId: string, response: ResponseBridgeConfig): void;
585
+ /**
586
+ * Complete a manually tracked request with an error.
587
+ *
588
+ * @param requestId - The ID returned from startRequest()
589
+ * @param error - The error that occurred
590
+ */
591
+ failRequest(requestId: string, error: Error | string): void;
548
592
  }
549
593
  declare const Limelight: LimelightClient;
550
594
 
@@ -562,4 +606,4 @@ declare global {
562
606
  }
563
607
  }
564
608
 
565
- 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 };
609
+ 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 RequestBridgeConfig, type ResponseBridgeConfig, type SerializedBody, type Session, type StackFrame };
package/dist/index.js CHANGED
@@ -84,17 +84,17 @@ var BodyFormat = /* @__PURE__ */ ((BodyFormat2) => {
84
84
  BodyFormat2["UNSERIALIZABLE"] = "UNSERIALIZABLE";
85
85
  return BodyFormat2;
86
86
  })(BodyFormat || {});
87
- var HttpMethod = /* @__PURE__ */ ((HttpMethod4) => {
88
- HttpMethod4["GET"] = "GET";
89
- HttpMethod4["POST"] = "POST";
90
- HttpMethod4["PUT"] = "PUT";
91
- HttpMethod4["PATCH"] = "PATCH";
92
- HttpMethod4["DELETE"] = "DELETE";
93
- HttpMethod4["HEAD"] = "HEAD";
94
- HttpMethod4["OPTIONS"] = "OPTIONS";
95
- HttpMethod4["TRACE"] = "TRACE";
96
- HttpMethod4["CONNECT"] = "CONNECT";
97
- return HttpMethod4;
87
+ var HttpMethod = /* @__PURE__ */ ((HttpMethod5) => {
88
+ HttpMethod5["GET"] = "GET";
89
+ HttpMethod5["POST"] = "POST";
90
+ HttpMethod5["PUT"] = "PUT";
91
+ HttpMethod5["PATCH"] = "PATCH";
92
+ HttpMethod5["DELETE"] = "DELETE";
93
+ HttpMethod5["HEAD"] = "HEAD";
94
+ HttpMethod5["OPTIONS"] = "OPTIONS";
95
+ HttpMethod5["TRACE"] = "TRACE";
96
+ HttpMethod5["CONNECT"] = "CONNECT";
97
+ return HttpMethod5;
98
98
  })(HttpMethod || {});
99
99
  var HttpStatusClass = /* @__PURE__ */ ((HttpStatusClass2) => {
100
100
  HttpStatusClass2[HttpStatusClass2["INFORMATIONAL"] = 100] = "INFORMATIONAL";
@@ -235,6 +235,15 @@ var parseGraphQL = (body) => {
235
235
  }
236
236
  };
237
237
 
238
+ // src/helpers/graphql/normalizeOperationType.ts
239
+ var normalizeOperationType = (type) => {
240
+ if (!type) return null;
241
+ if (type === "query") return "query";
242
+ if (type === "mutation") return "mutation";
243
+ if (type === "subscription") return "subscription";
244
+ return type;
245
+ };
246
+
238
247
  // src/constants/index.ts
239
248
  var SENSITIVE_HEADERS = [
240
249
  "authorization",
@@ -258,7 +267,7 @@ var SENSITIVE_HEADERS = [
258
267
  var LIMELIGHT_WEB_WSS_URL = "wss://api.getlimelight.io";
259
268
  var LIMELIGHT_DESKTOP_WSS_URL = "ws://localhost:8484";
260
269
  var WS_PATH = "/limelight";
261
- var SDK_VERSION = true ? "0.4.1" : "test-version";
270
+ var SDK_VERSION = true ? "0.4.2" : "test-version";
262
271
  var RENDER_THRESHOLDS = {
263
272
  HOT_VELOCITY: 5,
264
273
  HIGH_RENDER_COUNT: 50,
@@ -1932,6 +1941,165 @@ var StateInterceptor = class {
1932
1941
  }
1933
1942
  };
1934
1943
 
1944
+ // src/limelight/interceptors/RequestBridge.ts
1945
+ var RequestBridge = class {
1946
+ constructor(sendMessage, getSessionId) {
1947
+ this.sendMessage = sendMessage;
1948
+ this.getSessionId = getSessionId;
1949
+ }
1950
+ pendingRequests = /* @__PURE__ */ new Map();
1951
+ config = null;
1952
+ /**
1953
+ * Updates the config reference (called when LimelightClient configures)
1954
+ * @param config The new Limelight configuration or null to disable
1955
+ */
1956
+ setConfig(config) {
1957
+ this.config = config;
1958
+ }
1959
+ /**
1960
+ * Starts tracking a manual request. Returns a requestId to use with endRequest/failRequest.
1961
+ * @param config The request configuration
1962
+ * @returns The generated request ID
1963
+ */
1964
+ startRequest(config) {
1965
+ const requestId = generateRequestId();
1966
+ const startTime = Date.now();
1967
+ this.pendingRequests.set(requestId, { startTime, config });
1968
+ const method = config.method?.toUpperCase() || "POST";
1969
+ const headers = config.headers || {};
1970
+ const requestBody = serializeBody(
1971
+ typeof config.body === "string" ? config.body : JSON.stringify(config.body),
1972
+ this.config?.disableBodyCapture
1973
+ );
1974
+ let requestEvent = {
1975
+ id: requestId,
1976
+ sessionId: this.getSessionId(),
1977
+ timestamp: startTime,
1978
+ phase: "REQUEST" /* REQUEST */,
1979
+ networkType: "fetch" /* FETCH */,
1980
+ url: config.url,
1981
+ method,
1982
+ headers: redactSensitiveHeaders(headers),
1983
+ body: requestBody,
1984
+ name: config.name || formatRequestName(config.url),
1985
+ initiator: "manual",
1986
+ requestSize: requestBody?.size ?? 0,
1987
+ graphql: config.graphql ? {
1988
+ operationName: config.graphql.operationName,
1989
+ operationType: normalizeOperationType(config.graphql.operationType),
1990
+ variables: config.graphql.variables,
1991
+ query: config.graphql.query
1992
+ } : void 0
1993
+ };
1994
+ if (this.config?.beforeSend) {
1995
+ const modifiedEvent = this.config.beforeSend(requestEvent);
1996
+ if (!modifiedEvent) {
1997
+ this.pendingRequests.delete(requestId);
1998
+ return requestId;
1999
+ }
2000
+ if (modifiedEvent.phase !== "REQUEST" /* REQUEST */) {
2001
+ console.error("[Limelight] beforeSend must return same event type");
2002
+ return requestId;
2003
+ }
2004
+ requestEvent = modifiedEvent;
2005
+ }
2006
+ this.sendMessage(requestEvent);
2007
+ return requestId;
2008
+ }
2009
+ /**
2010
+ * Completes a tracked request with a successful response.
2011
+ * @param requestId The ID returned from startRequest
2012
+ * @param response The response data
2013
+ */
2014
+ endRequest(requestId, response) {
2015
+ const pending = this.pendingRequests.get(requestId);
2016
+ if (!pending) {
2017
+ if (this.config?.enableInternalLogging) {
2018
+ console.warn(
2019
+ `[Limelight] No pending request found for id: ${requestId}`
2020
+ );
2021
+ }
2022
+ return;
2023
+ }
2024
+ this.pendingRequests.delete(requestId);
2025
+ const endTime = Date.now();
2026
+ const duration = endTime - pending.startTime;
2027
+ const responseHeaders = response.headers || {};
2028
+ const responseBody = serializeBody(
2029
+ typeof response.body === "string" ? response.body : JSON.stringify(response.body),
2030
+ this.config?.disableBodyCapture
2031
+ );
2032
+ let responseEvent = {
2033
+ id: requestId,
2034
+ sessionId: this.getSessionId(),
2035
+ timestamp: endTime,
2036
+ phase: "RESPONSE" /* RESPONSE */,
2037
+ networkType: "fetch" /* FETCH */,
2038
+ status: response.status,
2039
+ statusText: response.statusText || "",
2040
+ headers: redactSensitiveHeaders(responseHeaders),
2041
+ body: responseBody,
2042
+ duration,
2043
+ responseSize: responseBody?.size ?? 0,
2044
+ redirected: false,
2045
+ ok: response.status >= 200 && response.status < 300
2046
+ };
2047
+ if (this.config?.beforeSend) {
2048
+ const modifiedEvent = this.config.beforeSend(responseEvent);
2049
+ if (!modifiedEvent) {
2050
+ return;
2051
+ }
2052
+ if (modifiedEvent.phase !== "RESPONSE" /* RESPONSE */) {
2053
+ console.error("[Limelight] beforeSend must return same event type");
2054
+ return;
2055
+ }
2056
+ responseEvent = modifiedEvent;
2057
+ }
2058
+ this.sendMessage(responseEvent);
2059
+ }
2060
+ /**
2061
+ * Completes a tracked request with an error.
2062
+ * @param requestId The ID returned from startRequest
2063
+ * @param error The error object or message
2064
+ */
2065
+ failRequest(requestId, error) {
2066
+ const pending = this.pendingRequests.get(requestId);
2067
+ if (!pending) {
2068
+ if (this.config?.enableInternalLogging) {
2069
+ console.warn(
2070
+ `[Limelight] No pending request found for id: ${requestId}`
2071
+ );
2072
+ }
2073
+ return;
2074
+ }
2075
+ this.pendingRequests.delete(requestId);
2076
+ const errorMessage = error instanceof Error ? error.message : String(error);
2077
+ const errorStack = error instanceof Error ? error.stack : void 0;
2078
+ let errorEvent = {
2079
+ id: requestId,
2080
+ sessionId: this.getSessionId(),
2081
+ timestamp: Date.now(),
2082
+ phase: "ERROR" /* ERROR */,
2083
+ networkType: "fetch" /* FETCH */,
2084
+ errorMessage,
2085
+ stack: errorStack
2086
+ };
2087
+ if (this.config?.beforeSend) {
2088
+ const modifiedEvent = this.config.beforeSend(errorEvent);
2089
+ if (modifiedEvent && modifiedEvent.phase === "ERROR" /* ERROR */) {
2090
+ errorEvent = modifiedEvent;
2091
+ }
2092
+ }
2093
+ this.sendMessage(errorEvent);
2094
+ }
2095
+ /**
2096
+ * Cleans up any pending requests (called on disconnect)
2097
+ */
2098
+ cleanup() {
2099
+ this.pendingRequests.clear();
2100
+ }
2101
+ };
2102
+
1935
2103
  // src/limelight/LimelightClient.ts
1936
2104
  var LimelightClient = class {
1937
2105
  ws = null;
@@ -1948,6 +2116,7 @@ var LimelightClient = class {
1948
2116
  consoleInterceptor;
1949
2117
  renderInterceptor;
1950
2118
  stateInterceptor;
2119
+ requestBridge;
1951
2120
  constructor() {
1952
2121
  this.networkInterceptor = new NetworkInterceptor(
1953
2122
  this.sendMessage.bind(this),
@@ -1969,6 +2138,10 @@ var LimelightClient = class {
1969
2138
  this.sendMessage.bind(this),
1970
2139
  () => this.sessionId
1971
2140
  );
2141
+ this.requestBridge = new RequestBridge(
2142
+ this.sendMessage.bind(this),
2143
+ () => this.sessionId
2144
+ );
1972
2145
  }
1973
2146
  /**
1974
2147
  * Configures the Limelight client with the provided settings.
@@ -1997,6 +2170,7 @@ var LimelightClient = class {
1997
2170
  return;
1998
2171
  }
1999
2172
  this.sessionId = createSessionId();
2173
+ this.requestBridge.setConfig(this.config);
2000
2174
  try {
2001
2175
  if (this.config.enableNetworkInspector) {
2002
2176
  this.networkInterceptor.setup(this.config);
@@ -2204,6 +2378,7 @@ var LimelightClient = class {
2204
2378
  this.consoleInterceptor.cleanup();
2205
2379
  this.renderInterceptor.cleanup();
2206
2380
  this.stateInterceptor.cleanup();
2381
+ this.requestBridge.cleanup();
2207
2382
  this.reconnectAttempts = 0;
2208
2383
  this.messageQueue = [];
2209
2384
  }
@@ -2218,6 +2393,35 @@ var LimelightClient = class {
2218
2393
  this.config = null;
2219
2394
  this.sessionId = "";
2220
2395
  }
2396
+ /**
2397
+ * Manually register a request with Limelight.
2398
+ * Use this when your app makes network requests outside of fetch/XHR
2399
+ * (e.g., through native modules).
2400
+ *
2401
+ * @param config - Request configuration
2402
+ * @returns A request ID to use with endRequest() or failRequest()
2403
+ */
2404
+ startRequest(config) {
2405
+ return this.requestBridge.startRequest(config);
2406
+ }
2407
+ /**
2408
+ * Complete a manually tracked request with a successful response.
2409
+ *
2410
+ * @param requestId - The ID returned from startRequest()
2411
+ * @param response - Response data
2412
+ */
2413
+ endRequest(requestId, response) {
2414
+ this.requestBridge.endRequest(requestId, response);
2415
+ }
2416
+ /**
2417
+ * Complete a manually tracked request with an error.
2418
+ *
2419
+ * @param requestId - The ID returned from startRequest()
2420
+ * @param error - The error that occurred
2421
+ */
2422
+ failRequest(requestId, error) {
2423
+ this.requestBridge.failRequest(requestId, error);
2424
+ }
2221
2425
  };
2222
2426
  var Limelight = new LimelightClient();
2223
2427
  // Annotate the CommonJS export names for ESM import in node: