@infinitewatch/web-core 1.0.0 → 1.1.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.cjs +58 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +58 -37
- package/dist/index.js.map +1 -1
- package/dist/watch.js +58 -37
- package/dist/watch.js.map +1 -1
- package/package.json +3 -3
package/dist/watch.js
CHANGED
|
@@ -8,14 +8,16 @@
|
|
|
8
8
|
if (!data || data.source !== 0) return null;
|
|
9
9
|
return data;
|
|
10
10
|
};
|
|
11
|
-
var LIB_VERSION = "v43.
|
|
11
|
+
var LIB_VERSION = "v43.4";
|
|
12
12
|
var EXCLUDED_ORGANIZATIONS = {
|
|
13
|
-
|
|
13
|
+
// Add organizations here as needed:
|
|
14
|
+
// EXAMPLE_ORG: 'organization_id_here',
|
|
14
15
|
};
|
|
15
16
|
var EXCLUDED_ORG_IDS = new Set(Object.values(EXCLUDED_ORGANIZATIONS));
|
|
16
17
|
var DEFAULT_CONFIG = {
|
|
17
18
|
baseUrl: "https://ingest.infinitewatch.ai",
|
|
18
19
|
endpoint: "https://ingest.infinitewatch.ai/v1/ingest",
|
|
20
|
+
endpointInsights: "https://iw-backend-live.fly.dev",
|
|
19
21
|
endpointConfig: "https://ingest.infinitewatch.ai/v1/ingest/config",
|
|
20
22
|
sessionId: null,
|
|
21
23
|
userId: null,
|
|
@@ -86,6 +88,31 @@
|
|
|
86
88
|
};
|
|
87
89
|
var isBrowser = () => !!(getWindow() && getDocument());
|
|
88
90
|
var now = () => Date.now();
|
|
91
|
+
var getCrypto = () => {
|
|
92
|
+
const win = getWindow();
|
|
93
|
+
if (win?.crypto) {
|
|
94
|
+
return win.crypto;
|
|
95
|
+
}
|
|
96
|
+
if (typeof globalThis !== "undefined" && "crypto" in globalThis) {
|
|
97
|
+
return globalThis.crypto;
|
|
98
|
+
}
|
|
99
|
+
return void 0;
|
|
100
|
+
};
|
|
101
|
+
var randomString = (length) => {
|
|
102
|
+
const cryptoApi = getCrypto();
|
|
103
|
+
if (!cryptoApi) {
|
|
104
|
+
return `${now().toString(36)}${"0".repeat(length)}`.slice(0, length);
|
|
105
|
+
}
|
|
106
|
+
const alphabet = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
107
|
+
const bytes = new Uint8Array(length);
|
|
108
|
+
cryptoApi.getRandomValues(bytes);
|
|
109
|
+
let result = "";
|
|
110
|
+
for (let i = 0; i < bytes.length; i += 1) {
|
|
111
|
+
const byte = bytes[i] ?? 0;
|
|
112
|
+
result += alphabet[byte % alphabet.length];
|
|
113
|
+
}
|
|
114
|
+
return result;
|
|
115
|
+
};
|
|
89
116
|
var isOrganizationExcluded = (orgId) => {
|
|
90
117
|
return !!orgId && EXCLUDED_ORG_IDS.has(orgId);
|
|
91
118
|
};
|
|
@@ -134,12 +161,12 @@
|
|
|
134
161
|
}
|
|
135
162
|
};
|
|
136
163
|
const generateSessionId = () => {
|
|
137
|
-
const nextId = `session_${now()}_${
|
|
164
|
+
const nextId = `session_${now()}_${randomString(9)}`;
|
|
138
165
|
log("Generated new session ID:", nextId);
|
|
139
166
|
return nextId;
|
|
140
167
|
};
|
|
141
168
|
const generateUserId = () => {
|
|
142
|
-
const nextId = `user_${
|
|
169
|
+
const nextId = `user_${randomString(9)}`;
|
|
143
170
|
log("Generated new user ID:", nextId);
|
|
144
171
|
return nextId;
|
|
145
172
|
};
|
|
@@ -335,17 +362,26 @@
|
|
|
335
362
|
if (sessionHeartbeatTimer) {
|
|
336
363
|
clearInterval(sessionHeartbeatTimer);
|
|
337
364
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
365
|
+
const checkInterval = config.sessionHeartbeatInterval || 6e4;
|
|
366
|
+
sessionHeartbeatTimer = setInterval(() => {
|
|
367
|
+
if (isSessionActive) {
|
|
368
|
+
if (sessionStartTime) {
|
|
369
|
+
const totalDuration = now() - sessionStartTime;
|
|
370
|
+
if (totalDuration > config.sessionTimeout) {
|
|
371
|
+
log(
|
|
372
|
+
`Session expired (exceeded max duration of ${config.sessionTimeout / 6e4} minutes), stopping session`
|
|
373
|
+
);
|
|
374
|
+
stopRecordingSession();
|
|
375
|
+
return;
|
|
345
376
|
}
|
|
346
377
|
}
|
|
347
|
-
|
|
348
|
-
|
|
378
|
+
if (config.refresh) {
|
|
379
|
+
updateSessionActivity();
|
|
380
|
+
} else {
|
|
381
|
+
saveSessionToStorage();
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}, checkInterval);
|
|
349
385
|
};
|
|
350
386
|
const stopSessionHeartbeat = () => {
|
|
351
387
|
if (sessionHeartbeatTimer) {
|
|
@@ -739,34 +775,18 @@
|
|
|
739
775
|
return;
|
|
740
776
|
}
|
|
741
777
|
sessionId = hardSessionId || sessionId;
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
timestamp: now(),
|
|
745
|
-
data: {}
|
|
746
|
-
};
|
|
747
|
-
const payload = {
|
|
748
|
-
session_id: sessionId,
|
|
749
|
-
user_id: userId,
|
|
750
|
-
organization_id: organizationId,
|
|
751
|
-
events: [event],
|
|
752
|
-
client_version: LIB_VERSION
|
|
753
|
-
};
|
|
754
|
-
if (externalId) {
|
|
755
|
-
payload.external_id = externalId;
|
|
778
|
+
if (!sessionId || !organizationId) {
|
|
779
|
+
return;
|
|
756
780
|
}
|
|
781
|
+
const base = (config.endpointInsights || config.baseUrl || "").toString().replace(/\/$/, "");
|
|
782
|
+
if (!base) return;
|
|
783
|
+
const endpointUrl = `${base}/v1/sessions/${encodeURIComponent(sessionId)}/insights`;
|
|
784
|
+
const payload = { organization_id: organizationId };
|
|
757
785
|
const payloadString = JSON.stringify(payload);
|
|
758
|
-
const payloadSizeKB = new Blob([payloadString]).size / BYTES_IN_KILOBYTE;
|
|
759
786
|
try {
|
|
760
|
-
const endpointUrl = buildEndpointUrl(
|
|
761
|
-
config.endpoint,
|
|
762
|
-
"f",
|
|
763
|
-
false,
|
|
764
|
-
payloadSizeKB,
|
|
765
|
-
false
|
|
766
|
-
);
|
|
767
787
|
const response = await fetch(endpointUrl, {
|
|
768
788
|
method: "POST",
|
|
769
|
-
headers: { "Content-Type": "
|
|
789
|
+
headers: { "Content-Type": "application/json" },
|
|
770
790
|
body: payloadString,
|
|
771
791
|
mode: "cors",
|
|
772
792
|
credentials: "omit"
|
|
@@ -889,7 +909,8 @@
|
|
|
889
909
|
const IDLE_MS = 15e3;
|
|
890
910
|
const BLOCKED_NET_HOSTS = /* @__PURE__ */ new Set([
|
|
891
911
|
"ingest.infinitewatch.ai",
|
|
892
|
-
"ingest.humanbehavior.co"
|
|
912
|
+
"ingest.humanbehavior.co",
|
|
913
|
+
"iw-backend-live.fly.dev"
|
|
893
914
|
]);
|
|
894
915
|
let __iw_lastUserIntentAt = now();
|
|
895
916
|
let __iw_intentInstalled = false;
|