@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.cjs CHANGED
@@ -33,14 +33,16 @@ var getMutationData = (event) => {
33
33
  if (!data || data.source !== 0) return null;
34
34
  return data;
35
35
  };
36
- var LIB_VERSION = "v43.1";
36
+ var LIB_VERSION = "v43.4";
37
37
  var EXCLUDED_ORGANIZATIONS = {
38
- NORTHIUS: "68f7bc5a815d853ecb2ce914"
38
+ // Add organizations here as needed:
39
+ // EXAMPLE_ORG: 'organization_id_here',
39
40
  };
40
41
  var EXCLUDED_ORG_IDS = new Set(Object.values(EXCLUDED_ORGANIZATIONS));
41
42
  var DEFAULT_CONFIG = {
42
43
  baseUrl: "https://ingest.infinitewatch.ai",
43
44
  endpoint: "https://ingest.infinitewatch.ai/v1/ingest",
45
+ endpointInsights: "https://iw-backend-live.fly.dev",
44
46
  endpointConfig: "https://ingest.infinitewatch.ai/v1/ingest/config",
45
47
  sessionId: null,
46
48
  userId: null,
@@ -385,17 +387,26 @@ var createWebCore = () => {
385
387
  if (sessionHeartbeatTimer) {
386
388
  clearInterval(sessionHeartbeatTimer);
387
389
  }
388
- if (config.sessionHeartbeatInterval) {
389
- sessionHeartbeatTimer = setInterval(() => {
390
- if (isSessionActive) {
391
- if (config.refresh) {
392
- updateSessionActivity();
393
- } else {
394
- saveSessionToStorage();
390
+ const checkInterval = config.sessionHeartbeatInterval || 6e4;
391
+ sessionHeartbeatTimer = setInterval(() => {
392
+ if (isSessionActive) {
393
+ if (sessionStartTime) {
394
+ const totalDuration = now() - sessionStartTime;
395
+ if (totalDuration > config.sessionTimeout) {
396
+ log(
397
+ `Session expired (exceeded max duration of ${config.sessionTimeout / 6e4} minutes), stopping session`
398
+ );
399
+ stopRecordingSession();
400
+ return;
395
401
  }
396
402
  }
397
- }, config.sessionHeartbeatInterval);
398
- }
403
+ if (config.refresh) {
404
+ updateSessionActivity();
405
+ } else {
406
+ saveSessionToStorage();
407
+ }
408
+ }
409
+ }, checkInterval);
399
410
  };
400
411
  const stopSessionHeartbeat = () => {
401
412
  if (sessionHeartbeatTimer) {
@@ -789,34 +800,18 @@ var createWebCore = () => {
789
800
  return;
790
801
  }
791
802
  sessionId = hardSessionId || sessionId;
792
- const event = {
793
- type: 9999,
794
- timestamp: now(),
795
- data: {}
796
- };
797
- const payload = {
798
- session_id: sessionId,
799
- user_id: userId,
800
- organization_id: organizationId,
801
- events: [event],
802
- client_version: LIB_VERSION
803
- };
804
- if (externalId) {
805
- payload.external_id = externalId;
803
+ if (!sessionId || !organizationId) {
804
+ return;
806
805
  }
806
+ const base = (config.endpointInsights || config.baseUrl || "").toString().replace(/\/$/, "");
807
+ if (!base) return;
808
+ const endpointUrl = `${base}/v1/sessions/${encodeURIComponent(sessionId)}/insights`;
809
+ const payload = { organization_id: organizationId };
807
810
  const payloadString = JSON.stringify(payload);
808
- const payloadSizeKB = new Blob([payloadString]).size / BYTES_IN_KILOBYTE;
809
811
  try {
810
- const endpointUrl = buildEndpointUrl(
811
- config.endpoint,
812
- "f",
813
- false,
814
- payloadSizeKB,
815
- false
816
- );
817
812
  const response = await fetch(endpointUrl, {
818
813
  method: "POST",
819
- headers: { "Content-Type": "text/plain" },
814
+ headers: { "Content-Type": "application/json" },
820
815
  body: payloadString,
821
816
  mode: "cors",
822
817
  credentials: "omit"
@@ -939,7 +934,8 @@ var createWebCore = () => {
939
934
  const IDLE_MS = 15e3;
940
935
  const BLOCKED_NET_HOSTS = /* @__PURE__ */ new Set([
941
936
  "ingest.infinitewatch.ai",
942
- "ingest.humanbehavior.co"
937
+ "ingest.humanbehavior.co",
938
+ "iw-backend-live.fly.dev"
943
939
  ]);
944
940
  let __iw_lastUserIntentAt = now();
945
941
  let __iw_intentInstalled = false;
@@ -1704,6 +1700,7 @@ var createWebCore = () => {
1704
1700
  hasStoredSession: !!loadSessionFromStorage()
1705
1701
  };
1706
1702
  };
1703
+ const getSessionId = () => sessionId;
1707
1704
  const isBlocked = () => {
1708
1705
  return contractStatus !== null || quotaStatus !== null || config.defaultSamplingPercent === 0;
1709
1706
  };
@@ -1716,6 +1713,8 @@ var createWebCore = () => {
1716
1713
  hardStop: hardStopSession,
1717
1714
  flush,
1718
1715
  identify,
1716
+ generateInsights,
1717
+ getSessionId,
1719
1718
  getSessionInfo,
1720
1719
  isBlocked,
1721
1720
  getContractStatus,