@getlimelight/sdk 0.5.3 → 0.6.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.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +69 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -57
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -447,6 +447,10 @@ interface LimelightConfig {
|
|
|
447
447
|
* Flag to enable or disable internal logging for the Limelight SDK
|
|
448
448
|
*/
|
|
449
449
|
enableInternalLogging?: boolean;
|
|
450
|
+
/**
|
|
451
|
+
* Target destination for events. Set to "mcp" to send events to the MCP server at ws://localhost:9229.
|
|
452
|
+
*/
|
|
453
|
+
target?: "mcp";
|
|
450
454
|
/**
|
|
451
455
|
* A callback function to modify or filter events before they are sent to the server
|
|
452
456
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -447,6 +447,10 @@ interface LimelightConfig {
|
|
|
447
447
|
* Flag to enable or disable internal logging for the Limelight SDK
|
|
448
448
|
*/
|
|
449
449
|
enableInternalLogging?: boolean;
|
|
450
|
+
/**
|
|
451
|
+
* Target destination for events. Set to "mcp" to send events to the MCP server at ws://localhost:9229.
|
|
452
|
+
*/
|
|
453
|
+
target?: "mcp";
|
|
450
454
|
/**
|
|
451
455
|
* A callback function to modify or filter events before they are sent to the server
|
|
452
456
|
*/
|
package/dist/index.js
CHANGED
|
@@ -201,6 +201,15 @@ var getInitiator = () => {
|
|
|
201
201
|
}
|
|
202
202
|
};
|
|
203
203
|
|
|
204
|
+
// src/helpers/detection/detectGlobalObject.ts
|
|
205
|
+
var detectGlobalObject = () => {
|
|
206
|
+
if (typeof globalThis !== "undefined") return globalThis;
|
|
207
|
+
if (typeof window !== "undefined") return window;
|
|
208
|
+
if (typeof global !== "undefined") return global;
|
|
209
|
+
if (typeof self !== "undefined") return self;
|
|
210
|
+
throw new Error("Unable to locate global object");
|
|
211
|
+
};
|
|
212
|
+
|
|
204
213
|
// src/helpers/graphql/detectGraphQlOperationType.ts
|
|
205
214
|
var detectGraphQlOperationType = (query) => {
|
|
206
215
|
if (!query) return null;
|
|
@@ -275,8 +284,9 @@ var SENSITIVE_HEADERS = [
|
|
|
275
284
|
];
|
|
276
285
|
var LIMELIGHT_WEB_WSS_URL = "wss://api.getlimelight.io";
|
|
277
286
|
var LIMELIGHT_DESKTOP_WSS_URL = "ws://localhost:8484";
|
|
287
|
+
var LIMELIGHT_MCP_WS_URL = "ws://localhost:9229";
|
|
278
288
|
var WS_PATH = "/limelight";
|
|
279
|
-
var SDK_VERSION = true ? "0.
|
|
289
|
+
var SDK_VERSION = true ? "0.6.1" : "test-version";
|
|
280
290
|
var RENDER_THRESHOLDS = {
|
|
281
291
|
HOT_VELOCITY: 5,
|
|
282
292
|
HIGH_RENDER_COUNT: 50,
|
|
@@ -593,7 +603,7 @@ var ConsoleInterceptor = class {
|
|
|
593
603
|
}
|
|
594
604
|
this.isSetup = true;
|
|
595
605
|
this.config = config;
|
|
596
|
-
const
|
|
606
|
+
const self2 = this;
|
|
597
607
|
const methods = [
|
|
598
608
|
"log" /* LOG */,
|
|
599
609
|
"warn" /* WARN */,
|
|
@@ -606,28 +616,28 @@ var ConsoleInterceptor = class {
|
|
|
606
616
|
const original = console[level];
|
|
607
617
|
this.originalConsole[level] = original;
|
|
608
618
|
console[level] = function(...args) {
|
|
609
|
-
if (
|
|
619
|
+
if (self2.isInternalLog) {
|
|
610
620
|
return original.apply(console, args);
|
|
611
621
|
}
|
|
612
|
-
|
|
622
|
+
self2.isInternalLog = true;
|
|
613
623
|
try {
|
|
614
624
|
const source = detectLogSource();
|
|
615
625
|
const consoleType = detectConsoleType(level, args);
|
|
616
|
-
const stackTrace =
|
|
626
|
+
const stackTrace = self2.captureStackTrace();
|
|
617
627
|
let consoleEvent = {
|
|
618
|
-
id: `${
|
|
628
|
+
id: `${self2.getSessionId()}-${Date.now()}-${self2.counter++}`,
|
|
619
629
|
phase: "CONSOLE",
|
|
620
630
|
type: "CONSOLE" /* CONSOLE */,
|
|
621
631
|
level,
|
|
622
632
|
timestamp: Date.now(),
|
|
623
|
-
sessionId:
|
|
633
|
+
sessionId: self2.getSessionId(),
|
|
624
634
|
source,
|
|
625
635
|
consoleType,
|
|
626
636
|
args: args.map((arg) => safeStringify(arg)),
|
|
627
637
|
stackTrace
|
|
628
638
|
};
|
|
629
|
-
if (
|
|
630
|
-
const modifiedEvent =
|
|
639
|
+
if (self2.config?.beforeSend) {
|
|
640
|
+
const modifiedEvent = self2.config.beforeSend(consoleEvent);
|
|
631
641
|
if (!modifiedEvent) {
|
|
632
642
|
return original.apply(console, args);
|
|
633
643
|
}
|
|
@@ -639,10 +649,10 @@ var ConsoleInterceptor = class {
|
|
|
639
649
|
}
|
|
640
650
|
consoleEvent = modifiedEvent;
|
|
641
651
|
}
|
|
642
|
-
|
|
652
|
+
self2.sendMessage(consoleEvent);
|
|
643
653
|
} catch (error) {
|
|
644
654
|
} finally {
|
|
645
|
-
|
|
655
|
+
self2.isInternalLog = false;
|
|
646
656
|
}
|
|
647
657
|
return original.apply(console, args);
|
|
648
658
|
};
|
|
@@ -700,11 +710,13 @@ var NetworkInterceptor = class {
|
|
|
700
710
|
constructor(sendMessage, getSessionId) {
|
|
701
711
|
this.sendMessage = sendMessage;
|
|
702
712
|
this.getSessionId = getSessionId;
|
|
703
|
-
this.
|
|
713
|
+
this.globalObject = detectGlobalObject();
|
|
714
|
+
this.originalFetch = this.globalObject.fetch.bind(this.globalObject);
|
|
704
715
|
}
|
|
705
716
|
originalFetch;
|
|
706
717
|
config = null;
|
|
707
718
|
isSetup = false;
|
|
719
|
+
globalObject;
|
|
708
720
|
/**
|
|
709
721
|
* Sets up fetch interception by wrapping the global fetch function.
|
|
710
722
|
* Intercepts all fetch requests to capture network events.
|
|
@@ -721,8 +733,8 @@ var NetworkInterceptor = class {
|
|
|
721
733
|
}
|
|
722
734
|
this.isSetup = true;
|
|
723
735
|
this.config = config;
|
|
724
|
-
const
|
|
725
|
-
|
|
736
|
+
const self2 = this;
|
|
737
|
+
this.globalObject.fetch = async function(input, init = {}) {
|
|
726
738
|
const requestId = generateRequestId();
|
|
727
739
|
const startTime = Date.now();
|
|
728
740
|
const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
|
@@ -752,7 +764,7 @@ var NetworkInterceptor = class {
|
|
|
752
764
|
}
|
|
753
765
|
} catch {
|
|
754
766
|
requestBodyToSerialize = void 0;
|
|
755
|
-
if (
|
|
767
|
+
if (self2.config?.enableInternalLogging) {
|
|
756
768
|
console.warn(
|
|
757
769
|
"[Limelight] Failed to read request body from Request object"
|
|
758
770
|
);
|
|
@@ -761,10 +773,10 @@ var NetworkInterceptor = class {
|
|
|
761
773
|
}
|
|
762
774
|
const requestBody = serializeBody(
|
|
763
775
|
requestBodyToSerialize,
|
|
764
|
-
|
|
776
|
+
self2.config?.disableBodyCapture
|
|
765
777
|
);
|
|
766
778
|
let graphqlData = void 0;
|
|
767
|
-
if (
|
|
779
|
+
if (self2.config?.enableGraphQL && isGraphQLRequest(url, requestBody)) {
|
|
768
780
|
const rawBody = requestBody?.raw;
|
|
769
781
|
if (rawBody) {
|
|
770
782
|
graphqlData = parseGraphQL(rawBody) ?? void 0;
|
|
@@ -772,7 +784,7 @@ var NetworkInterceptor = class {
|
|
|
772
784
|
}
|
|
773
785
|
let requestEvent = {
|
|
774
786
|
id: requestId,
|
|
775
|
-
sessionId:
|
|
787
|
+
sessionId: self2.getSessionId(),
|
|
776
788
|
timestamp: startTime,
|
|
777
789
|
phase: "REQUEST" /* REQUEST */,
|
|
778
790
|
networkType: "fetch" /* FETCH */,
|
|
@@ -785,20 +797,20 @@ var NetworkInterceptor = class {
|
|
|
785
797
|
requestSize: requestBody?.size ?? 0,
|
|
786
798
|
graphql: graphqlData
|
|
787
799
|
};
|
|
788
|
-
if (
|
|
789
|
-
const modifiedEvent =
|
|
800
|
+
if (self2.config?.beforeSend) {
|
|
801
|
+
const modifiedEvent = self2.config.beforeSend(requestEvent);
|
|
790
802
|
if (!modifiedEvent) {
|
|
791
|
-
return
|
|
803
|
+
return self2.originalFetch(input, modifiedInit);
|
|
792
804
|
}
|
|
793
805
|
if (modifiedEvent.phase !== "REQUEST" /* REQUEST */) {
|
|
794
806
|
console.error("[Limelight] beforeSend must return same event type");
|
|
795
|
-
return
|
|
807
|
+
return self2.originalFetch(input, modifiedInit);
|
|
796
808
|
}
|
|
797
809
|
requestEvent = modifiedEvent;
|
|
798
810
|
}
|
|
799
|
-
|
|
811
|
+
self2.sendMessage(requestEvent);
|
|
800
812
|
try {
|
|
801
|
-
const response = await
|
|
813
|
+
const response = await self2.originalFetch(input, modifiedInit);
|
|
802
814
|
const clone = response.clone();
|
|
803
815
|
const endTime = Date.now();
|
|
804
816
|
const duration = endTime - startTime;
|
|
@@ -814,11 +826,11 @@ var NetworkInterceptor = class {
|
|
|
814
826
|
}
|
|
815
827
|
const responseBody = serializeBody(
|
|
816
828
|
responseText,
|
|
817
|
-
|
|
829
|
+
self2.config?.disableBodyCapture
|
|
818
830
|
);
|
|
819
831
|
let responseEvent = {
|
|
820
832
|
id: requestId,
|
|
821
|
-
sessionId:
|
|
833
|
+
sessionId: self2.getSessionId(),
|
|
822
834
|
timestamp: endTime,
|
|
823
835
|
phase: "RESPONSE" /* RESPONSE */,
|
|
824
836
|
networkType: "fetch" /* FETCH */,
|
|
@@ -831,8 +843,8 @@ var NetworkInterceptor = class {
|
|
|
831
843
|
redirected: response.redirected,
|
|
832
844
|
ok: response.ok
|
|
833
845
|
};
|
|
834
|
-
if (
|
|
835
|
-
const modifiedEvent =
|
|
846
|
+
if (self2.config?.beforeSend) {
|
|
847
|
+
const modifiedEvent = self2.config.beforeSend(responseEvent);
|
|
836
848
|
if (!modifiedEvent) {
|
|
837
849
|
return response;
|
|
838
850
|
}
|
|
@@ -842,7 +854,7 @@ var NetworkInterceptor = class {
|
|
|
842
854
|
}
|
|
843
855
|
responseEvent = modifiedEvent;
|
|
844
856
|
}
|
|
845
|
-
|
|
857
|
+
self2.sendMessage(responseEvent);
|
|
846
858
|
return response;
|
|
847
859
|
} catch (err) {
|
|
848
860
|
const isAbort = err instanceof Error && (err.name === "AbortError" || err.message.includes("aborted"));
|
|
@@ -850,20 +862,20 @@ var NetworkInterceptor = class {
|
|
|
850
862
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
851
863
|
let errorEvent = {
|
|
852
864
|
id: requestId,
|
|
853
|
-
sessionId:
|
|
865
|
+
sessionId: self2.getSessionId(),
|
|
854
866
|
timestamp: Date.now(),
|
|
855
867
|
phase: isAbort ? "ABORT" /* ABORT */ : "ERROR" /* ERROR */,
|
|
856
868
|
networkType: "fetch" /* FETCH */,
|
|
857
869
|
errorMessage: isAbort ? "Request aborted" : errorMessage,
|
|
858
870
|
stack: errorStack
|
|
859
871
|
};
|
|
860
|
-
if (
|
|
861
|
-
const modifiedEvent =
|
|
872
|
+
if (self2.config?.beforeSend) {
|
|
873
|
+
const modifiedEvent = self2.config.beforeSend(errorEvent);
|
|
862
874
|
if (modifiedEvent && (modifiedEvent.phase === "ERROR" /* ERROR */ || modifiedEvent.phase === "ABORT" /* ABORT */)) {
|
|
863
875
|
errorEvent = modifiedEvent;
|
|
864
876
|
}
|
|
865
877
|
}
|
|
866
|
-
|
|
878
|
+
self2.sendMessage(errorEvent);
|
|
867
879
|
throw err;
|
|
868
880
|
}
|
|
869
881
|
};
|
|
@@ -880,7 +892,7 @@ var NetworkInterceptor = class {
|
|
|
880
892
|
return;
|
|
881
893
|
}
|
|
882
894
|
this.isSetup = false;
|
|
883
|
-
|
|
895
|
+
this.globalObject.fetch = this.originalFetch;
|
|
884
896
|
}
|
|
885
897
|
};
|
|
886
898
|
|
|
@@ -914,7 +926,7 @@ var XHRInterceptor = class {
|
|
|
914
926
|
}
|
|
915
927
|
this.isSetup = true;
|
|
916
928
|
this.config = config;
|
|
917
|
-
const
|
|
929
|
+
const self2 = this;
|
|
918
930
|
XMLHttpRequest.prototype.open = function(method, url) {
|
|
919
931
|
this._limelightData = {
|
|
920
932
|
id: generateRequestId(),
|
|
@@ -924,7 +936,7 @@ var XHRInterceptor = class {
|
|
|
924
936
|
startTime: Date.now(),
|
|
925
937
|
listeners: /* @__PURE__ */ new Map()
|
|
926
938
|
};
|
|
927
|
-
return
|
|
939
|
+
return self2.originalXHROpen.apply(
|
|
928
940
|
this,
|
|
929
941
|
arguments
|
|
930
942
|
);
|
|
@@ -936,21 +948,21 @@ var XHRInterceptor = class {
|
|
|
936
948
|
this._limelightData.skipIntercept = true;
|
|
937
949
|
}
|
|
938
950
|
}
|
|
939
|
-
return
|
|
951
|
+
return self2.originalXHRSetRequestHeader.apply(this, arguments);
|
|
940
952
|
};
|
|
941
953
|
XMLHttpRequest.prototype.send = function(body) {
|
|
942
954
|
const data = this._limelightData;
|
|
943
955
|
if (data?.skipIntercept) {
|
|
944
|
-
return
|
|
956
|
+
return self2.originalXHRSend.apply(this, arguments);
|
|
945
957
|
}
|
|
946
958
|
if (data) {
|
|
947
959
|
const requestBody = serializeBody(
|
|
948
960
|
body,
|
|
949
|
-
|
|
961
|
+
self2.config?.disableBodyCapture
|
|
950
962
|
);
|
|
951
963
|
let requestEvent = {
|
|
952
964
|
id: data.id,
|
|
953
|
-
sessionId:
|
|
965
|
+
sessionId: self2.getSessionId(),
|
|
954
966
|
timestamp: data.startTime,
|
|
955
967
|
phase: "REQUEST" /* REQUEST */,
|
|
956
968
|
networkType: "xhr" /* XHR */,
|
|
@@ -962,18 +974,18 @@ var XHRInterceptor = class {
|
|
|
962
974
|
initiator: getInitiator(),
|
|
963
975
|
requestSize: requestBody?.size ?? 0
|
|
964
976
|
};
|
|
965
|
-
if (
|
|
966
|
-
const modifiedEvent =
|
|
977
|
+
if (self2.config?.beforeSend) {
|
|
978
|
+
const modifiedEvent = self2.config.beforeSend(requestEvent);
|
|
967
979
|
if (!modifiedEvent) {
|
|
968
|
-
return
|
|
980
|
+
return self2.originalXHRSend.apply(this, arguments);
|
|
969
981
|
}
|
|
970
982
|
if (modifiedEvent.phase !== "REQUEST" /* REQUEST */) {
|
|
971
983
|
console.error("[Limelight] beforeSend must return same event type");
|
|
972
|
-
return
|
|
984
|
+
return self2.originalXHRSend.apply(this, arguments);
|
|
973
985
|
}
|
|
974
986
|
requestEvent = modifiedEvent;
|
|
975
987
|
}
|
|
976
|
-
|
|
988
|
+
self2.sendMessage(requestEvent);
|
|
977
989
|
let responseSent = false;
|
|
978
990
|
const cleanup = () => {
|
|
979
991
|
if (data.listeners) {
|
|
@@ -989,7 +1001,7 @@ var XHRInterceptor = class {
|
|
|
989
1001
|
responseSent = true;
|
|
990
1002
|
const endTime = Date.now();
|
|
991
1003
|
const duration = endTime - data.startTime;
|
|
992
|
-
const responseHeaders =
|
|
1004
|
+
const responseHeaders = self2.parseResponseHeaders(
|
|
993
1005
|
this.getAllResponseHeaders()
|
|
994
1006
|
);
|
|
995
1007
|
let responseData;
|
|
@@ -1005,11 +1017,11 @@ var XHRInterceptor = class {
|
|
|
1005
1017
|
}
|
|
1006
1018
|
const responseBody = serializeBody(
|
|
1007
1019
|
responseData,
|
|
1008
|
-
|
|
1020
|
+
self2.config?.disableBodyCapture
|
|
1009
1021
|
);
|
|
1010
1022
|
let responseEvent = {
|
|
1011
1023
|
id: data.id,
|
|
1012
|
-
sessionId:
|
|
1024
|
+
sessionId: self2.getSessionId(),
|
|
1013
1025
|
timestamp: endTime,
|
|
1014
1026
|
phase: "RESPONSE" /* RESPONSE */,
|
|
1015
1027
|
networkType: "xhr" /* XHR */,
|
|
@@ -1022,8 +1034,8 @@ var XHRInterceptor = class {
|
|
|
1022
1034
|
redirected: false,
|
|
1023
1035
|
ok: this.status >= 200 && this.status < 300
|
|
1024
1036
|
};
|
|
1025
|
-
if (
|
|
1026
|
-
const modifiedEvent =
|
|
1037
|
+
if (self2.config?.beforeSend) {
|
|
1038
|
+
const modifiedEvent = self2.config.beforeSend(responseEvent);
|
|
1027
1039
|
if (!modifiedEvent) {
|
|
1028
1040
|
return;
|
|
1029
1041
|
}
|
|
@@ -1035,7 +1047,7 @@ var XHRInterceptor = class {
|
|
|
1035
1047
|
}
|
|
1036
1048
|
responseEvent = modifiedEvent;
|
|
1037
1049
|
}
|
|
1038
|
-
|
|
1050
|
+
self2.sendMessage(responseEvent);
|
|
1039
1051
|
cleanup.call(this);
|
|
1040
1052
|
};
|
|
1041
1053
|
const sendError = (errorMessage, phase = "ERROR" /* ERROR */) => {
|
|
@@ -1043,19 +1055,19 @@ var XHRInterceptor = class {
|
|
|
1043
1055
|
responseSent = true;
|
|
1044
1056
|
let errorEvent = {
|
|
1045
1057
|
id: data.id,
|
|
1046
|
-
sessionId:
|
|
1058
|
+
sessionId: self2.getSessionId(),
|
|
1047
1059
|
timestamp: Date.now(),
|
|
1048
1060
|
phase,
|
|
1049
1061
|
networkType: "xhr" /* XHR */,
|
|
1050
1062
|
errorMessage
|
|
1051
1063
|
};
|
|
1052
|
-
if (
|
|
1053
|
-
const modifiedEvent =
|
|
1064
|
+
if (self2.config?.beforeSend) {
|
|
1065
|
+
const modifiedEvent = self2.config.beforeSend(errorEvent);
|
|
1054
1066
|
if (modifiedEvent && modifiedEvent.phase === "ERROR" /* ERROR */) {
|
|
1055
1067
|
errorEvent = modifiedEvent;
|
|
1056
1068
|
}
|
|
1057
1069
|
}
|
|
1058
|
-
|
|
1070
|
+
self2.sendMessage(errorEvent);
|
|
1059
1071
|
cleanup.call(this);
|
|
1060
1072
|
};
|
|
1061
1073
|
const readyStateChangeHandler = function() {
|
|
@@ -1094,7 +1106,7 @@ var XHRInterceptor = class {
|
|
|
1094
1106
|
data.listeners.set("timeout", timeoutHandler);
|
|
1095
1107
|
data.listeners.set("loadend", loadEndHandler);
|
|
1096
1108
|
}
|
|
1097
|
-
return
|
|
1109
|
+
return self2.originalXHRSend.apply(this, arguments);
|
|
1098
1110
|
};
|
|
1099
1111
|
}
|
|
1100
1112
|
/**
|
|
@@ -2324,7 +2336,7 @@ var LimelightClient = class {
|
|
|
2324
2336
|
*/
|
|
2325
2337
|
configure(config) {
|
|
2326
2338
|
const isEnabled = config?.enabled ?? isDevelopment();
|
|
2327
|
-
const configServerUrl = config?.serverUrl ? config.serverUrl : config?.projectKey ? `${LIMELIGHT_WEB_WSS_URL}${WS_PATH}` : `${LIMELIGHT_DESKTOP_WSS_URL}${WS_PATH}`;
|
|
2339
|
+
const configServerUrl = config?.serverUrl ? config.serverUrl : config?.target === "mcp" ? LIMELIGHT_MCP_WS_URL : config?.projectKey ? `${LIMELIGHT_WEB_WSS_URL}${WS_PATH}` : `${LIMELIGHT_DESKTOP_WSS_URL}${WS_PATH}`;
|
|
2328
2340
|
this.config = {
|
|
2329
2341
|
...config,
|
|
2330
2342
|
appName: config?.appName ?? "Limelight App",
|