@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.mjs
CHANGED
|
@@ -164,6 +164,15 @@ var getInitiator = () => {
|
|
|
164
164
|
}
|
|
165
165
|
};
|
|
166
166
|
|
|
167
|
+
// src/helpers/detection/detectGlobalObject.ts
|
|
168
|
+
var detectGlobalObject = () => {
|
|
169
|
+
if (typeof globalThis !== "undefined") return globalThis;
|
|
170
|
+
if (typeof window !== "undefined") return window;
|
|
171
|
+
if (typeof global !== "undefined") return global;
|
|
172
|
+
if (typeof self !== "undefined") return self;
|
|
173
|
+
throw new Error("Unable to locate global object");
|
|
174
|
+
};
|
|
175
|
+
|
|
167
176
|
// src/helpers/graphql/detectGraphQlOperationType.ts
|
|
168
177
|
var detectGraphQlOperationType = (query) => {
|
|
169
178
|
if (!query) return null;
|
|
@@ -238,8 +247,9 @@ var SENSITIVE_HEADERS = [
|
|
|
238
247
|
];
|
|
239
248
|
var LIMELIGHT_WEB_WSS_URL = "wss://api.getlimelight.io";
|
|
240
249
|
var LIMELIGHT_DESKTOP_WSS_URL = "ws://localhost:8484";
|
|
250
|
+
var LIMELIGHT_MCP_WS_URL = "ws://localhost:9229";
|
|
241
251
|
var WS_PATH = "/limelight";
|
|
242
|
-
var SDK_VERSION = true ? "0.
|
|
252
|
+
var SDK_VERSION = true ? "0.6.1" : "test-version";
|
|
243
253
|
var RENDER_THRESHOLDS = {
|
|
244
254
|
HOT_VELOCITY: 5,
|
|
245
255
|
HIGH_RENDER_COUNT: 50,
|
|
@@ -556,7 +566,7 @@ var ConsoleInterceptor = class {
|
|
|
556
566
|
}
|
|
557
567
|
this.isSetup = true;
|
|
558
568
|
this.config = config;
|
|
559
|
-
const
|
|
569
|
+
const self2 = this;
|
|
560
570
|
const methods = [
|
|
561
571
|
"log" /* LOG */,
|
|
562
572
|
"warn" /* WARN */,
|
|
@@ -569,28 +579,28 @@ var ConsoleInterceptor = class {
|
|
|
569
579
|
const original = console[level];
|
|
570
580
|
this.originalConsole[level] = original;
|
|
571
581
|
console[level] = function(...args) {
|
|
572
|
-
if (
|
|
582
|
+
if (self2.isInternalLog) {
|
|
573
583
|
return original.apply(console, args);
|
|
574
584
|
}
|
|
575
|
-
|
|
585
|
+
self2.isInternalLog = true;
|
|
576
586
|
try {
|
|
577
587
|
const source = detectLogSource();
|
|
578
588
|
const consoleType = detectConsoleType(level, args);
|
|
579
|
-
const stackTrace =
|
|
589
|
+
const stackTrace = self2.captureStackTrace();
|
|
580
590
|
let consoleEvent = {
|
|
581
|
-
id: `${
|
|
591
|
+
id: `${self2.getSessionId()}-${Date.now()}-${self2.counter++}`,
|
|
582
592
|
phase: "CONSOLE",
|
|
583
593
|
type: "CONSOLE" /* CONSOLE */,
|
|
584
594
|
level,
|
|
585
595
|
timestamp: Date.now(),
|
|
586
|
-
sessionId:
|
|
596
|
+
sessionId: self2.getSessionId(),
|
|
587
597
|
source,
|
|
588
598
|
consoleType,
|
|
589
599
|
args: args.map((arg) => safeStringify(arg)),
|
|
590
600
|
stackTrace
|
|
591
601
|
};
|
|
592
|
-
if (
|
|
593
|
-
const modifiedEvent =
|
|
602
|
+
if (self2.config?.beforeSend) {
|
|
603
|
+
const modifiedEvent = self2.config.beforeSend(consoleEvent);
|
|
594
604
|
if (!modifiedEvent) {
|
|
595
605
|
return original.apply(console, args);
|
|
596
606
|
}
|
|
@@ -602,10 +612,10 @@ var ConsoleInterceptor = class {
|
|
|
602
612
|
}
|
|
603
613
|
consoleEvent = modifiedEvent;
|
|
604
614
|
}
|
|
605
|
-
|
|
615
|
+
self2.sendMessage(consoleEvent);
|
|
606
616
|
} catch (error) {
|
|
607
617
|
} finally {
|
|
608
|
-
|
|
618
|
+
self2.isInternalLog = false;
|
|
609
619
|
}
|
|
610
620
|
return original.apply(console, args);
|
|
611
621
|
};
|
|
@@ -663,11 +673,13 @@ var NetworkInterceptor = class {
|
|
|
663
673
|
constructor(sendMessage, getSessionId) {
|
|
664
674
|
this.sendMessage = sendMessage;
|
|
665
675
|
this.getSessionId = getSessionId;
|
|
666
|
-
this.
|
|
676
|
+
this.globalObject = detectGlobalObject();
|
|
677
|
+
this.originalFetch = this.globalObject.fetch.bind(this.globalObject);
|
|
667
678
|
}
|
|
668
679
|
originalFetch;
|
|
669
680
|
config = null;
|
|
670
681
|
isSetup = false;
|
|
682
|
+
globalObject;
|
|
671
683
|
/**
|
|
672
684
|
* Sets up fetch interception by wrapping the global fetch function.
|
|
673
685
|
* Intercepts all fetch requests to capture network events.
|
|
@@ -684,8 +696,8 @@ var NetworkInterceptor = class {
|
|
|
684
696
|
}
|
|
685
697
|
this.isSetup = true;
|
|
686
698
|
this.config = config;
|
|
687
|
-
const
|
|
688
|
-
|
|
699
|
+
const self2 = this;
|
|
700
|
+
this.globalObject.fetch = async function(input, init = {}) {
|
|
689
701
|
const requestId = generateRequestId();
|
|
690
702
|
const startTime = Date.now();
|
|
691
703
|
const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
|
@@ -715,7 +727,7 @@ var NetworkInterceptor = class {
|
|
|
715
727
|
}
|
|
716
728
|
} catch {
|
|
717
729
|
requestBodyToSerialize = void 0;
|
|
718
|
-
if (
|
|
730
|
+
if (self2.config?.enableInternalLogging) {
|
|
719
731
|
console.warn(
|
|
720
732
|
"[Limelight] Failed to read request body from Request object"
|
|
721
733
|
);
|
|
@@ -724,10 +736,10 @@ var NetworkInterceptor = class {
|
|
|
724
736
|
}
|
|
725
737
|
const requestBody = serializeBody(
|
|
726
738
|
requestBodyToSerialize,
|
|
727
|
-
|
|
739
|
+
self2.config?.disableBodyCapture
|
|
728
740
|
);
|
|
729
741
|
let graphqlData = void 0;
|
|
730
|
-
if (
|
|
742
|
+
if (self2.config?.enableGraphQL && isGraphQLRequest(url, requestBody)) {
|
|
731
743
|
const rawBody = requestBody?.raw;
|
|
732
744
|
if (rawBody) {
|
|
733
745
|
graphqlData = parseGraphQL(rawBody) ?? void 0;
|
|
@@ -735,7 +747,7 @@ var NetworkInterceptor = class {
|
|
|
735
747
|
}
|
|
736
748
|
let requestEvent = {
|
|
737
749
|
id: requestId,
|
|
738
|
-
sessionId:
|
|
750
|
+
sessionId: self2.getSessionId(),
|
|
739
751
|
timestamp: startTime,
|
|
740
752
|
phase: "REQUEST" /* REQUEST */,
|
|
741
753
|
networkType: "fetch" /* FETCH */,
|
|
@@ -748,20 +760,20 @@ var NetworkInterceptor = class {
|
|
|
748
760
|
requestSize: requestBody?.size ?? 0,
|
|
749
761
|
graphql: graphqlData
|
|
750
762
|
};
|
|
751
|
-
if (
|
|
752
|
-
const modifiedEvent =
|
|
763
|
+
if (self2.config?.beforeSend) {
|
|
764
|
+
const modifiedEvent = self2.config.beforeSend(requestEvent);
|
|
753
765
|
if (!modifiedEvent) {
|
|
754
|
-
return
|
|
766
|
+
return self2.originalFetch(input, modifiedInit);
|
|
755
767
|
}
|
|
756
768
|
if (modifiedEvent.phase !== "REQUEST" /* REQUEST */) {
|
|
757
769
|
console.error("[Limelight] beforeSend must return same event type");
|
|
758
|
-
return
|
|
770
|
+
return self2.originalFetch(input, modifiedInit);
|
|
759
771
|
}
|
|
760
772
|
requestEvent = modifiedEvent;
|
|
761
773
|
}
|
|
762
|
-
|
|
774
|
+
self2.sendMessage(requestEvent);
|
|
763
775
|
try {
|
|
764
|
-
const response = await
|
|
776
|
+
const response = await self2.originalFetch(input, modifiedInit);
|
|
765
777
|
const clone = response.clone();
|
|
766
778
|
const endTime = Date.now();
|
|
767
779
|
const duration = endTime - startTime;
|
|
@@ -777,11 +789,11 @@ var NetworkInterceptor = class {
|
|
|
777
789
|
}
|
|
778
790
|
const responseBody = serializeBody(
|
|
779
791
|
responseText,
|
|
780
|
-
|
|
792
|
+
self2.config?.disableBodyCapture
|
|
781
793
|
);
|
|
782
794
|
let responseEvent = {
|
|
783
795
|
id: requestId,
|
|
784
|
-
sessionId:
|
|
796
|
+
sessionId: self2.getSessionId(),
|
|
785
797
|
timestamp: endTime,
|
|
786
798
|
phase: "RESPONSE" /* RESPONSE */,
|
|
787
799
|
networkType: "fetch" /* FETCH */,
|
|
@@ -794,8 +806,8 @@ var NetworkInterceptor = class {
|
|
|
794
806
|
redirected: response.redirected,
|
|
795
807
|
ok: response.ok
|
|
796
808
|
};
|
|
797
|
-
if (
|
|
798
|
-
const modifiedEvent =
|
|
809
|
+
if (self2.config?.beforeSend) {
|
|
810
|
+
const modifiedEvent = self2.config.beforeSend(responseEvent);
|
|
799
811
|
if (!modifiedEvent) {
|
|
800
812
|
return response;
|
|
801
813
|
}
|
|
@@ -805,7 +817,7 @@ var NetworkInterceptor = class {
|
|
|
805
817
|
}
|
|
806
818
|
responseEvent = modifiedEvent;
|
|
807
819
|
}
|
|
808
|
-
|
|
820
|
+
self2.sendMessage(responseEvent);
|
|
809
821
|
return response;
|
|
810
822
|
} catch (err) {
|
|
811
823
|
const isAbort = err instanceof Error && (err.name === "AbortError" || err.message.includes("aborted"));
|
|
@@ -813,20 +825,20 @@ var NetworkInterceptor = class {
|
|
|
813
825
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
814
826
|
let errorEvent = {
|
|
815
827
|
id: requestId,
|
|
816
|
-
sessionId:
|
|
828
|
+
sessionId: self2.getSessionId(),
|
|
817
829
|
timestamp: Date.now(),
|
|
818
830
|
phase: isAbort ? "ABORT" /* ABORT */ : "ERROR" /* ERROR */,
|
|
819
831
|
networkType: "fetch" /* FETCH */,
|
|
820
832
|
errorMessage: isAbort ? "Request aborted" : errorMessage,
|
|
821
833
|
stack: errorStack
|
|
822
834
|
};
|
|
823
|
-
if (
|
|
824
|
-
const modifiedEvent =
|
|
835
|
+
if (self2.config?.beforeSend) {
|
|
836
|
+
const modifiedEvent = self2.config.beforeSend(errorEvent);
|
|
825
837
|
if (modifiedEvent && (modifiedEvent.phase === "ERROR" /* ERROR */ || modifiedEvent.phase === "ABORT" /* ABORT */)) {
|
|
826
838
|
errorEvent = modifiedEvent;
|
|
827
839
|
}
|
|
828
840
|
}
|
|
829
|
-
|
|
841
|
+
self2.sendMessage(errorEvent);
|
|
830
842
|
throw err;
|
|
831
843
|
}
|
|
832
844
|
};
|
|
@@ -843,7 +855,7 @@ var NetworkInterceptor = class {
|
|
|
843
855
|
return;
|
|
844
856
|
}
|
|
845
857
|
this.isSetup = false;
|
|
846
|
-
|
|
858
|
+
this.globalObject.fetch = this.originalFetch;
|
|
847
859
|
}
|
|
848
860
|
};
|
|
849
861
|
|
|
@@ -877,7 +889,7 @@ var XHRInterceptor = class {
|
|
|
877
889
|
}
|
|
878
890
|
this.isSetup = true;
|
|
879
891
|
this.config = config;
|
|
880
|
-
const
|
|
892
|
+
const self2 = this;
|
|
881
893
|
XMLHttpRequest.prototype.open = function(method, url) {
|
|
882
894
|
this._limelightData = {
|
|
883
895
|
id: generateRequestId(),
|
|
@@ -887,7 +899,7 @@ var XHRInterceptor = class {
|
|
|
887
899
|
startTime: Date.now(),
|
|
888
900
|
listeners: /* @__PURE__ */ new Map()
|
|
889
901
|
};
|
|
890
|
-
return
|
|
902
|
+
return self2.originalXHROpen.apply(
|
|
891
903
|
this,
|
|
892
904
|
arguments
|
|
893
905
|
);
|
|
@@ -899,21 +911,21 @@ var XHRInterceptor = class {
|
|
|
899
911
|
this._limelightData.skipIntercept = true;
|
|
900
912
|
}
|
|
901
913
|
}
|
|
902
|
-
return
|
|
914
|
+
return self2.originalXHRSetRequestHeader.apply(this, arguments);
|
|
903
915
|
};
|
|
904
916
|
XMLHttpRequest.prototype.send = function(body) {
|
|
905
917
|
const data = this._limelightData;
|
|
906
918
|
if (data?.skipIntercept) {
|
|
907
|
-
return
|
|
919
|
+
return self2.originalXHRSend.apply(this, arguments);
|
|
908
920
|
}
|
|
909
921
|
if (data) {
|
|
910
922
|
const requestBody = serializeBody(
|
|
911
923
|
body,
|
|
912
|
-
|
|
924
|
+
self2.config?.disableBodyCapture
|
|
913
925
|
);
|
|
914
926
|
let requestEvent = {
|
|
915
927
|
id: data.id,
|
|
916
|
-
sessionId:
|
|
928
|
+
sessionId: self2.getSessionId(),
|
|
917
929
|
timestamp: data.startTime,
|
|
918
930
|
phase: "REQUEST" /* REQUEST */,
|
|
919
931
|
networkType: "xhr" /* XHR */,
|
|
@@ -925,18 +937,18 @@ var XHRInterceptor = class {
|
|
|
925
937
|
initiator: getInitiator(),
|
|
926
938
|
requestSize: requestBody?.size ?? 0
|
|
927
939
|
};
|
|
928
|
-
if (
|
|
929
|
-
const modifiedEvent =
|
|
940
|
+
if (self2.config?.beforeSend) {
|
|
941
|
+
const modifiedEvent = self2.config.beforeSend(requestEvent);
|
|
930
942
|
if (!modifiedEvent) {
|
|
931
|
-
return
|
|
943
|
+
return self2.originalXHRSend.apply(this, arguments);
|
|
932
944
|
}
|
|
933
945
|
if (modifiedEvent.phase !== "REQUEST" /* REQUEST */) {
|
|
934
946
|
console.error("[Limelight] beforeSend must return same event type");
|
|
935
|
-
return
|
|
947
|
+
return self2.originalXHRSend.apply(this, arguments);
|
|
936
948
|
}
|
|
937
949
|
requestEvent = modifiedEvent;
|
|
938
950
|
}
|
|
939
|
-
|
|
951
|
+
self2.sendMessage(requestEvent);
|
|
940
952
|
let responseSent = false;
|
|
941
953
|
const cleanup = () => {
|
|
942
954
|
if (data.listeners) {
|
|
@@ -952,7 +964,7 @@ var XHRInterceptor = class {
|
|
|
952
964
|
responseSent = true;
|
|
953
965
|
const endTime = Date.now();
|
|
954
966
|
const duration = endTime - data.startTime;
|
|
955
|
-
const responseHeaders =
|
|
967
|
+
const responseHeaders = self2.parseResponseHeaders(
|
|
956
968
|
this.getAllResponseHeaders()
|
|
957
969
|
);
|
|
958
970
|
let responseData;
|
|
@@ -968,11 +980,11 @@ var XHRInterceptor = class {
|
|
|
968
980
|
}
|
|
969
981
|
const responseBody = serializeBody(
|
|
970
982
|
responseData,
|
|
971
|
-
|
|
983
|
+
self2.config?.disableBodyCapture
|
|
972
984
|
);
|
|
973
985
|
let responseEvent = {
|
|
974
986
|
id: data.id,
|
|
975
|
-
sessionId:
|
|
987
|
+
sessionId: self2.getSessionId(),
|
|
976
988
|
timestamp: endTime,
|
|
977
989
|
phase: "RESPONSE" /* RESPONSE */,
|
|
978
990
|
networkType: "xhr" /* XHR */,
|
|
@@ -985,8 +997,8 @@ var XHRInterceptor = class {
|
|
|
985
997
|
redirected: false,
|
|
986
998
|
ok: this.status >= 200 && this.status < 300
|
|
987
999
|
};
|
|
988
|
-
if (
|
|
989
|
-
const modifiedEvent =
|
|
1000
|
+
if (self2.config?.beforeSend) {
|
|
1001
|
+
const modifiedEvent = self2.config.beforeSend(responseEvent);
|
|
990
1002
|
if (!modifiedEvent) {
|
|
991
1003
|
return;
|
|
992
1004
|
}
|
|
@@ -998,7 +1010,7 @@ var XHRInterceptor = class {
|
|
|
998
1010
|
}
|
|
999
1011
|
responseEvent = modifiedEvent;
|
|
1000
1012
|
}
|
|
1001
|
-
|
|
1013
|
+
self2.sendMessage(responseEvent);
|
|
1002
1014
|
cleanup.call(this);
|
|
1003
1015
|
};
|
|
1004
1016
|
const sendError = (errorMessage, phase = "ERROR" /* ERROR */) => {
|
|
@@ -1006,19 +1018,19 @@ var XHRInterceptor = class {
|
|
|
1006
1018
|
responseSent = true;
|
|
1007
1019
|
let errorEvent = {
|
|
1008
1020
|
id: data.id,
|
|
1009
|
-
sessionId:
|
|
1021
|
+
sessionId: self2.getSessionId(),
|
|
1010
1022
|
timestamp: Date.now(),
|
|
1011
1023
|
phase,
|
|
1012
1024
|
networkType: "xhr" /* XHR */,
|
|
1013
1025
|
errorMessage
|
|
1014
1026
|
};
|
|
1015
|
-
if (
|
|
1016
|
-
const modifiedEvent =
|
|
1027
|
+
if (self2.config?.beforeSend) {
|
|
1028
|
+
const modifiedEvent = self2.config.beforeSend(errorEvent);
|
|
1017
1029
|
if (modifiedEvent && modifiedEvent.phase === "ERROR" /* ERROR */) {
|
|
1018
1030
|
errorEvent = modifiedEvent;
|
|
1019
1031
|
}
|
|
1020
1032
|
}
|
|
1021
|
-
|
|
1033
|
+
self2.sendMessage(errorEvent);
|
|
1022
1034
|
cleanup.call(this);
|
|
1023
1035
|
};
|
|
1024
1036
|
const readyStateChangeHandler = function() {
|
|
@@ -1057,7 +1069,7 @@ var XHRInterceptor = class {
|
|
|
1057
1069
|
data.listeners.set("timeout", timeoutHandler);
|
|
1058
1070
|
data.listeners.set("loadend", loadEndHandler);
|
|
1059
1071
|
}
|
|
1060
|
-
return
|
|
1072
|
+
return self2.originalXHRSend.apply(this, arguments);
|
|
1061
1073
|
};
|
|
1062
1074
|
}
|
|
1063
1075
|
/**
|
|
@@ -2287,7 +2299,7 @@ var LimelightClient = class {
|
|
|
2287
2299
|
*/
|
|
2288
2300
|
configure(config) {
|
|
2289
2301
|
const isEnabled = config?.enabled ?? isDevelopment();
|
|
2290
|
-
const configServerUrl = config?.serverUrl ? config.serverUrl : config?.projectKey ? `${LIMELIGHT_WEB_WSS_URL}${WS_PATH}` : `${LIMELIGHT_DESKTOP_WSS_URL}${WS_PATH}`;
|
|
2302
|
+
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}`;
|
|
2291
2303
|
this.config = {
|
|
2292
2304
|
...config,
|
|
2293
2305
|
appName: config?.appName ?? "Limelight App",
|