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