@getlimelight/sdk 0.4.0 → 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.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.0" : "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,
@@ -568,7 +577,7 @@ var ConsoleInterceptor = class {
568
577
  */
569
578
  setup(config) {
570
579
  if (this.isSetup) {
571
- if (this.config?.internalLoggingEnabled) {
580
+ if (this.config?.enableInternalLogging) {
572
581
  console.warn("[Limelight] Console interceptor already set up");
573
582
  }
574
583
  return;
@@ -654,7 +663,7 @@ var ConsoleInterceptor = class {
654
663
  */
655
664
  cleanup() {
656
665
  if (!this.isSetup) {
657
- if (this.config?.internalLoggingEnabled) {
666
+ if (this.config?.enableInternalLogging) {
658
667
  console.warn("[Limelight] Console interceptor not set up");
659
668
  }
660
669
  return;
@@ -696,7 +705,7 @@ var NetworkInterceptor = class {
696
705
  */
697
706
  setup(config) {
698
707
  if (this.isSetup) {
699
- if (this.config?.internalLoggingEnabled) {
708
+ if (this.config?.enableInternalLogging) {
700
709
  console.warn("[Limelight] Network interceptor already set up");
701
710
  }
702
711
  return;
@@ -734,7 +743,7 @@ var NetworkInterceptor = class {
734
743
  }
735
744
  } catch {
736
745
  requestBodyToSerialize = void 0;
737
- if (self.config?.internalLoggingEnabled) {
746
+ if (self.config?.enableInternalLogging) {
738
747
  console.warn(
739
748
  "[Limelight] Failed to read request body from Request object"
740
749
  );
@@ -855,7 +864,7 @@ var NetworkInterceptor = class {
855
864
  */
856
865
  cleanup() {
857
866
  if (!this.isSetup) {
858
- if (this.config?.internalLoggingEnabled) {
867
+ if (this.config?.enableInternalLogging) {
859
868
  console.warn("[Limelight] Network interceptor not set up");
860
869
  }
861
870
  return;
@@ -888,7 +897,7 @@ var XHRInterceptor = class {
888
897
  */
889
898
  setup(config) {
890
899
  if (this.isSetup) {
891
- if (this.config?.internalLoggingEnabled) {
900
+ if (this.config?.enableInternalLogging) {
892
901
  console.warn("[Limelight] XHR interceptor already set up");
893
902
  }
894
903
  return;
@@ -1102,7 +1111,7 @@ var XHRInterceptor = class {
1102
1111
  */
1103
1112
  cleanup() {
1104
1113
  if (!this.isSetup) {
1105
- if (this.config?.internalLoggingEnabled) {
1114
+ if (this.config?.enableInternalLogging) {
1106
1115
  console.warn("[Limelight] XHR interceptor not set up");
1107
1116
  }
1108
1117
  return;
@@ -1136,14 +1145,14 @@ var RenderInterceptor = class {
1136
1145
  }
1137
1146
  setup(config) {
1138
1147
  if (this.isSetup) {
1139
- if (this.config?.internalLoggingEnabled) {
1148
+ if (this.config?.enableInternalLogging) {
1140
1149
  console.warn("[Limelight] Render interceptor already set up");
1141
1150
  }
1142
1151
  return;
1143
1152
  }
1144
1153
  this.config = config;
1145
1154
  if (!this.installHook()) {
1146
- if (this.config?.internalLoggingEnabled) {
1155
+ if (this.config?.enableInternalLogging) {
1147
1156
  console.warn("[Limelight] Failed to install render hook");
1148
1157
  }
1149
1158
  return;
@@ -1214,7 +1223,7 @@ var RenderInterceptor = class {
1214
1223
  this.countRenderedComponents(root.current);
1215
1224
  this.walkFiberTree(root.current, null, 0);
1216
1225
  } catch (error) {
1217
- if (this.config?.internalLoggingEnabled) {
1226
+ if (this.config?.enableInternalLogging) {
1218
1227
  console.warn("[Limelight] Error processing fiber tree:", error);
1219
1228
  }
1220
1229
  }
@@ -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.
@@ -1991,12 +2164,13 @@ var LimelightClient = class {
1991
2164
  enableGraphQL: config?.enableGraphQL ?? true,
1992
2165
  enableRenderInspector: config?.enableRenderInspector ?? true,
1993
2166
  enableStateInspector: config?.enableStateInspector ?? true,
1994
- internalLoggingEnabled: config?.internalLoggingEnabled ?? false
2167
+ enableInternalLogging: config?.enableInternalLogging ?? false
1995
2168
  };
1996
2169
  if (!this.config?.enabled) {
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);
@@ -2012,7 +2186,7 @@ var LimelightClient = class {
2012
2186
  this.stateInterceptor.setup(this.config);
2013
2187
  }
2014
2188
  } catch (error) {
2015
- if (this.config?.internalLoggingEnabled) {
2189
+ if (this.config?.enableInternalLogging) {
2016
2190
  console.error("[Limelight] Failed to setup interceptors:", error);
2017
2191
  }
2018
2192
  }
@@ -2034,7 +2208,7 @@ var LimelightClient = class {
2034
2208
  return;
2035
2209
  }
2036
2210
  if (this.ws && this.ws.readyState === WebSocket.OPEN) {
2037
- if (this.config?.internalLoggingEnabled) {
2211
+ if (this.config?.enableInternalLogging) {
2038
2212
  console.warn("[Limelight] Already connected. Call disconnect() first.");
2039
2213
  }
2040
2214
  return;
@@ -2051,7 +2225,7 @@ var LimelightClient = class {
2051
2225
  }
2052
2226
  const { serverUrl, appName, platform } = this.config;
2053
2227
  if (!serverUrl) {
2054
- if (this.config?.internalLoggingEnabled) {
2228
+ if (this.config?.enableInternalLogging) {
2055
2229
  console.error("[Limelight] serverUrl missing in configuration.");
2056
2230
  }
2057
2231
  return;
@@ -2075,7 +2249,7 @@ var LimelightClient = class {
2075
2249
  this.sendMessage(message);
2076
2250
  };
2077
2251
  this.ws.onerror = (error) => {
2078
- if (this.config?.internalLoggingEnabled) {
2252
+ if (this.config?.enableInternalLogging) {
2079
2253
  console.error("[Limelight] WebSocket error:", error);
2080
2254
  }
2081
2255
  };
@@ -2083,7 +2257,7 @@ var LimelightClient = class {
2083
2257
  this.attemptReconnect();
2084
2258
  };
2085
2259
  } catch (error) {
2086
- if (this.config?.internalLoggingEnabled) {
2260
+ if (this.config?.enableInternalLogging) {
2087
2261
  console.error("[Limelight] Failed to connect:", error);
2088
2262
  }
2089
2263
  this.attemptReconnect();
@@ -2127,7 +2301,7 @@ var LimelightClient = class {
2127
2301
  try {
2128
2302
  this.ws.send(safeStringify(message));
2129
2303
  } catch (error) {
2130
- if (this.config?.internalLoggingEnabled) {
2304
+ if (this.config?.enableInternalLogging) {
2131
2305
  console.error("[Limelight] Failed to send queued message:", error);
2132
2306
  }
2133
2307
  }
@@ -2148,7 +2322,7 @@ var LimelightClient = class {
2148
2322
  try {
2149
2323
  this.ws.send(safeStringify(message));
2150
2324
  } catch (error) {
2151
- if (this.config?.internalLoggingEnabled) {
2325
+ if (this.config?.enableInternalLogging) {
2152
2326
  console.error("[Limelight] Failed to send message:", error);
2153
2327
  }
2154
2328
  this.messageQueue.push(message);
@@ -2158,7 +2332,7 @@ var LimelightClient = class {
2158
2332
  }
2159
2333
  } else {
2160
2334
  if (this.messageQueue.length >= this.maxQueueSize) {
2161
- if (this.config?.internalLoggingEnabled) {
2335
+ if (this.config?.enableInternalLogging) {
2162
2336
  console.warn(
2163
2337
  "[Limelight] Message queue full, dropping oldest message"
2164
2338
  );
@@ -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: