@infinitewatch/web-core 1.1.0 → 1.1.2

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/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.1";
11
+ var LIB_VERSION = "v43.4";
12
12
  var EXCLUDED_ORGANIZATIONS = {
13
- NORTHIUS: "68f7bc5a815d853ecb2ce914"
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,
@@ -360,17 +362,26 @@
360
362
  if (sessionHeartbeatTimer) {
361
363
  clearInterval(sessionHeartbeatTimer);
362
364
  }
363
- if (config.sessionHeartbeatInterval) {
364
- sessionHeartbeatTimer = setInterval(() => {
365
- if (isSessionActive) {
366
- if (config.refresh) {
367
- updateSessionActivity();
368
- } else {
369
- saveSessionToStorage();
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;
370
376
  }
371
377
  }
372
- }, config.sessionHeartbeatInterval);
373
- }
378
+ if (config.refresh) {
379
+ updateSessionActivity();
380
+ } else {
381
+ saveSessionToStorage();
382
+ }
383
+ }
384
+ }, checkInterval);
374
385
  };
375
386
  const stopSessionHeartbeat = () => {
376
387
  if (sessionHeartbeatTimer) {
@@ -764,34 +775,18 @@
764
775
  return;
765
776
  }
766
777
  sessionId = hardSessionId || sessionId;
767
- const event = {
768
- type: 9999,
769
- timestamp: now(),
770
- data: {}
771
- };
772
- const payload = {
773
- session_id: sessionId,
774
- user_id: userId,
775
- organization_id: organizationId,
776
- events: [event],
777
- client_version: LIB_VERSION
778
- };
779
- if (externalId) {
780
- payload.external_id = externalId;
778
+ if (!sessionId || !organizationId) {
779
+ return;
781
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 };
782
785
  const payloadString = JSON.stringify(payload);
783
- const payloadSizeKB = new Blob([payloadString]).size / BYTES_IN_KILOBYTE;
784
786
  try {
785
- const endpointUrl = buildEndpointUrl(
786
- config.endpoint,
787
- "f",
788
- false,
789
- payloadSizeKB,
790
- false
791
- );
792
787
  const response = await fetch(endpointUrl, {
793
788
  method: "POST",
794
- headers: { "Content-Type": "text/plain" },
789
+ headers: { "Content-Type": "application/json" },
795
790
  body: payloadString,
796
791
  mode: "cors",
797
792
  credentials: "omit"
@@ -914,7 +909,8 @@
914
909
  const IDLE_MS = 15e3;
915
910
  const BLOCKED_NET_HOSTS = /* @__PURE__ */ new Set([
916
911
  "ingest.infinitewatch.ai",
917
- "ingest.humanbehavior.co"
912
+ "ingest.humanbehavior.co",
913
+ "iw-backend-live.fly.dev"
918
914
  ]);
919
915
  let __iw_lastUserIntentAt = now();
920
916
  let __iw_intentInstalled = false;
@@ -1679,6 +1675,7 @@
1679
1675
  hasStoredSession: !!loadSessionFromStorage()
1680
1676
  };
1681
1677
  };
1678
+ const getSessionId = () => sessionId;
1682
1679
  const isBlocked = () => {
1683
1680
  return contractStatus !== null || quotaStatus !== null || config.defaultSamplingPercent === 0;
1684
1681
  };
@@ -1691,6 +1688,8 @@
1691
1688
  hardStop: hardStopSession,
1692
1689
  flush,
1693
1690
  identify,
1691
+ generateInsights,
1692
+ getSessionId,
1694
1693
  getSessionInfo,
1695
1694
  isBlocked,
1696
1695
  getContractStatus,
@@ -1751,7 +1750,9 @@
1751
1750
  stop: makeProxy("stop"),
1752
1751
  hardStop: makeProxy("hardStop"),
1753
1752
  flush: makeProxy("flush"),
1754
- identify: makeProxy("identify")
1753
+ identify: makeProxy("identify"),
1754
+ generateInsights: makeProxy("generateInsights"),
1755
+ getSessionId: makeProxy("getSessionId")
1755
1756
  };
1756
1757
  iwWindow.InfiniteWatch = { ...existing || {}, ...shim };
1757
1758
  if (!hasQueuedInit) {