@getlimelight/sdk 0.7.9 → 0.7.11
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/README.md +19 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +142 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +142 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/dist/index.mjs
CHANGED
|
@@ -256,7 +256,7 @@ var LIMELIGHT_WEB_WSS_URL = "wss://api.getlimelight.io";
|
|
|
256
256
|
var LIMELIGHT_DESKTOP_WSS_URL = "ws://localhost:8484";
|
|
257
257
|
var LIMELIGHT_MCP_WS_URL = "ws://localhost:9229";
|
|
258
258
|
var WS_PATH = "/limelight";
|
|
259
|
-
var SDK_VERSION = true ? "0.7.
|
|
259
|
+
var SDK_VERSION = true ? "0.7.11" : "test-version";
|
|
260
260
|
var RENDER_THRESHOLDS = {
|
|
261
261
|
HOT_VELOCITY: 5,
|
|
262
262
|
HIGH_RENDER_COUNT: 50,
|
|
@@ -280,6 +280,9 @@ var BINARY_CONTENT_TYPES = [
|
|
|
280
280
|
"application/gzip"
|
|
281
281
|
];
|
|
282
282
|
var MAX_BODY_SIZE = 1024 * 1024;
|
|
283
|
+
var POSTHOG_API_KEY = true ? "phc_I4dF0Du3McRPRCdSiJfvTBMWrbsapXoTP83uaHTA1ry" : "";
|
|
284
|
+
var POSTHOG_HOST = true ? "https://us.i.posthog.com" : "";
|
|
285
|
+
var STORAGE_KEY = "limelight_anon_id";
|
|
283
286
|
|
|
284
287
|
// src/helpers/safety/redactSensitiveHeaders.ts
|
|
285
288
|
var redactSensitiveHeaders = (headers) => {
|
|
@@ -522,6 +525,7 @@ var formatRequestName = (url) => {
|
|
|
522
525
|
|
|
523
526
|
// src/helpers/utils/environment.ts
|
|
524
527
|
var hasDOM = () => typeof window !== "undefined" && typeof document !== "undefined";
|
|
528
|
+
var isServer = () => !hasDOM() && typeof process !== "undefined" && typeof process.versions !== "undefined" && typeof process.versions.node !== "undefined";
|
|
525
529
|
|
|
526
530
|
// src/helpers/render/generateRenderId.ts
|
|
527
531
|
var counter = 0;
|
|
@@ -2910,6 +2914,119 @@ var createWithLimelight = (sendMessage, getSessionId, getConfig, options) => {
|
|
|
2910
2914
|
};
|
|
2911
2915
|
};
|
|
2912
2916
|
|
|
2917
|
+
// src/limelight/telemetry.ts
|
|
2918
|
+
var anonymousId = null;
|
|
2919
|
+
var enabled = false;
|
|
2920
|
+
var framework = "unknown";
|
|
2921
|
+
var detectFramework = () => {
|
|
2922
|
+
try {
|
|
2923
|
+
if (typeof navigator !== "undefined" && "ReactNative" in navigator)
|
|
2924
|
+
return "react-native";
|
|
2925
|
+
if (typeof process !== "undefined" && (process.env?.__NEXT_RUNTIME__ || process.env?.NEXT_RUNTIME))
|
|
2926
|
+
return "next";
|
|
2927
|
+
if (typeof window !== "undefined" && window.__NEXT_DATA__)
|
|
2928
|
+
return "next";
|
|
2929
|
+
if (hasDOM()) return "react";
|
|
2930
|
+
if (isServer()) return "node";
|
|
2931
|
+
} catch {
|
|
2932
|
+
}
|
|
2933
|
+
return "unknown";
|
|
2934
|
+
};
|
|
2935
|
+
var generateId = () => {
|
|
2936
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
2937
|
+
const r = Math.random() * 16 | 0;
|
|
2938
|
+
return (c === "x" ? r : r & 3 | 8).toString(16);
|
|
2939
|
+
});
|
|
2940
|
+
};
|
|
2941
|
+
var getOrCreateAnonymousId = () => {
|
|
2942
|
+
if (anonymousId) return anonymousId;
|
|
2943
|
+
try {
|
|
2944
|
+
if (typeof localStorage !== "undefined") {
|
|
2945
|
+
const stored = localStorage.getItem(STORAGE_KEY);
|
|
2946
|
+
if (stored) {
|
|
2947
|
+
anonymousId = stored;
|
|
2948
|
+
return anonymousId;
|
|
2949
|
+
}
|
|
2950
|
+
anonymousId = generateId();
|
|
2951
|
+
localStorage.setItem(STORAGE_KEY, anonymousId);
|
|
2952
|
+
return anonymousId;
|
|
2953
|
+
}
|
|
2954
|
+
} catch {
|
|
2955
|
+
}
|
|
2956
|
+
try {
|
|
2957
|
+
const _require = globalThis["require"];
|
|
2958
|
+
if (_require) {
|
|
2959
|
+
const fs = _require("fs");
|
|
2960
|
+
const os = _require("os");
|
|
2961
|
+
const path = _require("path");
|
|
2962
|
+
const filePath = path.join(os.homedir(), ".limelight_telemetry_id");
|
|
2963
|
+
try {
|
|
2964
|
+
anonymousId = fs.readFileSync(filePath, "utf-8").trim();
|
|
2965
|
+
if (anonymousId) return anonymousId;
|
|
2966
|
+
} catch {
|
|
2967
|
+
}
|
|
2968
|
+
anonymousId = generateId();
|
|
2969
|
+
fs.writeFileSync(filePath, anonymousId, "utf-8");
|
|
2970
|
+
return anonymousId;
|
|
2971
|
+
}
|
|
2972
|
+
} catch {
|
|
2973
|
+
}
|
|
2974
|
+
anonymousId = generateId();
|
|
2975
|
+
return anonymousId;
|
|
2976
|
+
};
|
|
2977
|
+
var capture = (event, properties = {}) => {
|
|
2978
|
+
if (!enabled) return;
|
|
2979
|
+
try {
|
|
2980
|
+
const payload = {
|
|
2981
|
+
api_key: POSTHOG_API_KEY,
|
|
2982
|
+
event,
|
|
2983
|
+
distinct_id: getOrCreateAnonymousId(),
|
|
2984
|
+
properties: {
|
|
2985
|
+
...properties,
|
|
2986
|
+
sdk_version: SDK_VERSION,
|
|
2987
|
+
framework
|
|
2988
|
+
}
|
|
2989
|
+
};
|
|
2990
|
+
fetch(`${POSTHOG_HOST}/capture/`, {
|
|
2991
|
+
method: "POST",
|
|
2992
|
+
headers: { "Content-Type": "application/json" },
|
|
2993
|
+
body: JSON.stringify(payload)
|
|
2994
|
+
}).catch(() => {
|
|
2995
|
+
});
|
|
2996
|
+
} catch {
|
|
2997
|
+
}
|
|
2998
|
+
};
|
|
2999
|
+
var telemetry = {
|
|
3000
|
+
init(telemetryEnabled) {
|
|
3001
|
+
enabled = telemetryEnabled;
|
|
3002
|
+
if (!enabled) return;
|
|
3003
|
+
framework = detectFramework();
|
|
3004
|
+
capture("sdk_initialized", {
|
|
3005
|
+
framework,
|
|
3006
|
+
device_id: getOrCreateAnonymousId()
|
|
3007
|
+
});
|
|
3008
|
+
},
|
|
3009
|
+
sessionStarted() {
|
|
3010
|
+
capture("session_started");
|
|
3011
|
+
},
|
|
3012
|
+
sessionEnded(durationSeconds, eventCount) {
|
|
3013
|
+
capture("session_ended", {
|
|
3014
|
+
duration_seconds: durationSeconds,
|
|
3015
|
+
event_count: eventCount
|
|
3016
|
+
});
|
|
3017
|
+
},
|
|
3018
|
+
timelineGenerated(eventsCorrelated) {
|
|
3019
|
+
capture("timeline_generated", {
|
|
3020
|
+
events_correlated: eventsCorrelated,
|
|
3021
|
+
framework
|
|
3022
|
+
});
|
|
3023
|
+
},
|
|
3024
|
+
shutdown() {
|
|
3025
|
+
enabled = false;
|
|
3026
|
+
anonymousId = null;
|
|
3027
|
+
}
|
|
3028
|
+
};
|
|
3029
|
+
|
|
2913
3030
|
// src/limelight/LimelightClient.ts
|
|
2914
3031
|
var LimelightClient = class {
|
|
2915
3032
|
ws = null;
|
|
@@ -2921,6 +3038,8 @@ var LimelightClient = class {
|
|
|
2921
3038
|
reconnectTimer = null;
|
|
2922
3039
|
messageQueue = [];
|
|
2923
3040
|
maxQueueSize = 100;
|
|
3041
|
+
sessionStartTime = 0;
|
|
3042
|
+
sessionEventCount = 0;
|
|
2924
3043
|
networkInterceptor;
|
|
2925
3044
|
xhrInterceptor;
|
|
2926
3045
|
httpInterceptor;
|
|
@@ -3003,17 +3122,17 @@ var LimelightClient = class {
|
|
|
3003
3122
|
if (typeof XMLHttpRequest !== "undefined") {
|
|
3004
3123
|
this.xhrInterceptor.setup(this.config);
|
|
3005
3124
|
}
|
|
3006
|
-
if (
|
|
3125
|
+
if (isServer()) {
|
|
3007
3126
|
this.httpInterceptor.setup(this.config);
|
|
3008
3127
|
}
|
|
3009
3128
|
}
|
|
3010
3129
|
if (this.config.enableConsole) {
|
|
3011
3130
|
this.consoleInterceptor.setup(this.config);
|
|
3012
|
-
if (
|
|
3131
|
+
if (isServer()) {
|
|
3013
3132
|
this.errorInterceptor.setup(this.config);
|
|
3014
3133
|
}
|
|
3015
3134
|
}
|
|
3016
|
-
if (this.config.enableRenderInspector &&
|
|
3135
|
+
if (this.config.enableRenderInspector && !isServer()) {
|
|
3017
3136
|
this.renderInterceptor.setup(this.config);
|
|
3018
3137
|
}
|
|
3019
3138
|
if (this.config.stores && this.config.enableStateInspector) {
|
|
@@ -3024,6 +3143,7 @@ var LimelightClient = class {
|
|
|
3024
3143
|
console.error("[Limelight] Failed to setup interceptors:", error);
|
|
3025
3144
|
}
|
|
3026
3145
|
}
|
|
3146
|
+
telemetry.init(this.config.telemetry ?? true);
|
|
3027
3147
|
}
|
|
3028
3148
|
/**
|
|
3029
3149
|
* Establishes a WebSocket connection to the Limelight server.
|
|
@@ -3088,8 +3208,11 @@ var LimelightClient = class {
|
|
|
3088
3208
|
};
|
|
3089
3209
|
this.ws.onopen = () => {
|
|
3090
3210
|
this.reconnectAttempts = 0;
|
|
3211
|
+
this.sessionStartTime = Date.now();
|
|
3212
|
+
this.sessionEventCount = 0;
|
|
3091
3213
|
this.flushMessageQueue();
|
|
3092
3214
|
this.sendMessage(message);
|
|
3215
|
+
telemetry.sessionStarted();
|
|
3093
3216
|
};
|
|
3094
3217
|
this.ws.onmessage = (event) => {
|
|
3095
3218
|
try {
|
|
@@ -3172,6 +3295,12 @@ var LimelightClient = class {
|
|
|
3172
3295
|
* @returns {void}
|
|
3173
3296
|
*/
|
|
3174
3297
|
sendMessage(message) {
|
|
3298
|
+
this.sessionEventCount++;
|
|
3299
|
+
if ("phase" in message && message.phase === "RENDER_SNAPSHOT" && "profiles" in message) {
|
|
3300
|
+
telemetry.timelineGenerated(
|
|
3301
|
+
message.profiles?.length ?? 0
|
|
3302
|
+
);
|
|
3303
|
+
}
|
|
3175
3304
|
if (this.ws?.readyState === 1) {
|
|
3176
3305
|
this.flushMessageQueue();
|
|
3177
3306
|
if (this.ws?.readyState === 1) {
|
|
@@ -3237,7 +3366,15 @@ var LimelightClient = class {
|
|
|
3237
3366
|
this.renderInterceptor.cleanup();
|
|
3238
3367
|
this.stateInterceptor.cleanup();
|
|
3239
3368
|
this.requestBridge.cleanup();
|
|
3369
|
+
if (this.sessionStartTime > 0) {
|
|
3370
|
+
const durationSeconds = Math.round(
|
|
3371
|
+
(Date.now() - this.sessionStartTime) / 1e3
|
|
3372
|
+
);
|
|
3373
|
+
telemetry.sessionEnded(durationSeconds, this.sessionEventCount);
|
|
3374
|
+
}
|
|
3240
3375
|
this.reconnectAttempts = 0;
|
|
3376
|
+
this.sessionStartTime = 0;
|
|
3377
|
+
this.sessionEventCount = 0;
|
|
3241
3378
|
this.messageQueue = [];
|
|
3242
3379
|
}
|
|
3243
3380
|
/**
|
|
@@ -3248,6 +3385,7 @@ var LimelightClient = class {
|
|
|
3248
3385
|
*/
|
|
3249
3386
|
reset() {
|
|
3250
3387
|
this.disconnect();
|
|
3388
|
+
telemetry.shutdown();
|
|
3251
3389
|
this.config = null;
|
|
3252
3390
|
this.sessionId = "";
|
|
3253
3391
|
}
|