@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/index.js CHANGED
@@ -6,14 +6,16 @@ var getMutationData = (event) => {
6
6
  if (!data || data.source !== 0) return null;
7
7
  return data;
8
8
  };
9
- var LIB_VERSION = "v43.1";
9
+ var LIB_VERSION = "v43.4";
10
10
  var EXCLUDED_ORGANIZATIONS = {
11
- NORTHIUS: "68f7bc5a815d853ecb2ce914"
11
+ // Add organizations here as needed:
12
+ // EXAMPLE_ORG: 'organization_id_here',
12
13
  };
13
14
  var EXCLUDED_ORG_IDS = new Set(Object.values(EXCLUDED_ORGANIZATIONS));
14
15
  var DEFAULT_CONFIG = {
15
16
  baseUrl: "https://ingest.infinitewatch.ai",
16
17
  endpoint: "https://ingest.infinitewatch.ai/v1/ingest",
18
+ endpointInsights: "https://iw-backend-live.fly.dev",
17
19
  endpointConfig: "https://ingest.infinitewatch.ai/v1/ingest/config",
18
20
  sessionId: null,
19
21
  userId: null,
@@ -358,17 +360,26 @@ var createWebCore = () => {
358
360
  if (sessionHeartbeatTimer) {
359
361
  clearInterval(sessionHeartbeatTimer);
360
362
  }
361
- if (config.sessionHeartbeatInterval) {
362
- sessionHeartbeatTimer = setInterval(() => {
363
- if (isSessionActive) {
364
- if (config.refresh) {
365
- updateSessionActivity();
366
- } else {
367
- saveSessionToStorage();
363
+ const checkInterval = config.sessionHeartbeatInterval || 6e4;
364
+ sessionHeartbeatTimer = setInterval(() => {
365
+ if (isSessionActive) {
366
+ if (sessionStartTime) {
367
+ const totalDuration = now() - sessionStartTime;
368
+ if (totalDuration > config.sessionTimeout) {
369
+ log(
370
+ `Session expired (exceeded max duration of ${config.sessionTimeout / 6e4} minutes), stopping session`
371
+ );
372
+ stopRecordingSession();
373
+ return;
368
374
  }
369
375
  }
370
- }, config.sessionHeartbeatInterval);
371
- }
376
+ if (config.refresh) {
377
+ updateSessionActivity();
378
+ } else {
379
+ saveSessionToStorage();
380
+ }
381
+ }
382
+ }, checkInterval);
372
383
  };
373
384
  const stopSessionHeartbeat = () => {
374
385
  if (sessionHeartbeatTimer) {
@@ -762,34 +773,18 @@ var createWebCore = () => {
762
773
  return;
763
774
  }
764
775
  sessionId = hardSessionId || sessionId;
765
- const event = {
766
- type: 9999,
767
- timestamp: now(),
768
- data: {}
769
- };
770
- const payload = {
771
- session_id: sessionId,
772
- user_id: userId,
773
- organization_id: organizationId,
774
- events: [event],
775
- client_version: LIB_VERSION
776
- };
777
- if (externalId) {
778
- payload.external_id = externalId;
776
+ if (!sessionId || !organizationId) {
777
+ return;
779
778
  }
779
+ const base = (config.endpointInsights || config.baseUrl || "").toString().replace(/\/$/, "");
780
+ if (!base) return;
781
+ const endpointUrl = `${base}/v1/sessions/${encodeURIComponent(sessionId)}/insights`;
782
+ const payload = { organization_id: organizationId };
780
783
  const payloadString = JSON.stringify(payload);
781
- const payloadSizeKB = new Blob([payloadString]).size / BYTES_IN_KILOBYTE;
782
784
  try {
783
- const endpointUrl = buildEndpointUrl(
784
- config.endpoint,
785
- "f",
786
- false,
787
- payloadSizeKB,
788
- false
789
- );
790
785
  const response = await fetch(endpointUrl, {
791
786
  method: "POST",
792
- headers: { "Content-Type": "text/plain" },
787
+ headers: { "Content-Type": "application/json" },
793
788
  body: payloadString,
794
789
  mode: "cors",
795
790
  credentials: "omit"
@@ -912,7 +907,8 @@ var createWebCore = () => {
912
907
  const IDLE_MS = 15e3;
913
908
  const BLOCKED_NET_HOSTS = /* @__PURE__ */ new Set([
914
909
  "ingest.infinitewatch.ai",
915
- "ingest.humanbehavior.co"
910
+ "ingest.humanbehavior.co",
911
+ "iw-backend-live.fly.dev"
916
912
  ]);
917
913
  let __iw_lastUserIntentAt = now();
918
914
  let __iw_intentInstalled = false;
@@ -1677,6 +1673,7 @@ var createWebCore = () => {
1677
1673
  hasStoredSession: !!loadSessionFromStorage()
1678
1674
  };
1679
1675
  };
1676
+ const getSessionId = () => sessionId;
1680
1677
  const isBlocked = () => {
1681
1678
  return contractStatus !== null || quotaStatus !== null || config.defaultSamplingPercent === 0;
1682
1679
  };
@@ -1689,6 +1686,8 @@ var createWebCore = () => {
1689
1686
  hardStop: hardStopSession,
1690
1687
  flush,
1691
1688
  identify,
1689
+ generateInsights,
1690
+ getSessionId,
1692
1691
  getSessionInfo,
1693
1692
  isBlocked,
1694
1693
  getContractStatus,