@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.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,
@@ -84,6 +86,31 @@ var getDocument = () => {
84
86
  };
85
87
  var isBrowser = () => !!(getWindow() && getDocument());
86
88
  var now = () => Date.now();
89
+ var getCrypto = () => {
90
+ const win = getWindow();
91
+ if (win?.crypto) {
92
+ return win.crypto;
93
+ }
94
+ if (typeof globalThis !== "undefined" && "crypto" in globalThis) {
95
+ return globalThis.crypto;
96
+ }
97
+ return void 0;
98
+ };
99
+ var randomString = (length) => {
100
+ const cryptoApi = getCrypto();
101
+ if (!cryptoApi) {
102
+ return `${now().toString(36)}${"0".repeat(length)}`.slice(0, length);
103
+ }
104
+ const alphabet = "0123456789abcdefghijklmnopqrstuvwxyz";
105
+ const bytes = new Uint8Array(length);
106
+ cryptoApi.getRandomValues(bytes);
107
+ let result = "";
108
+ for (let i = 0; i < bytes.length; i += 1) {
109
+ const byte = bytes[i] ?? 0;
110
+ result += alphabet[byte % alphabet.length];
111
+ }
112
+ return result;
113
+ };
87
114
  var isOrganizationExcluded = (orgId) => {
88
115
  return !!orgId && EXCLUDED_ORG_IDS.has(orgId);
89
116
  };
@@ -132,12 +159,12 @@ var createWebCore = () => {
132
159
  }
133
160
  };
134
161
  const generateSessionId = () => {
135
- const nextId = `session_${now()}_${Math.random().toString(36).slice(2, 11)}`;
162
+ const nextId = `session_${now()}_${randomString(9)}`;
136
163
  log("Generated new session ID:", nextId);
137
164
  return nextId;
138
165
  };
139
166
  const generateUserId = () => {
140
- const nextId = `user_${Math.random().toString(36).slice(2, 11)}`;
167
+ const nextId = `user_${randomString(9)}`;
141
168
  log("Generated new user ID:", nextId);
142
169
  return nextId;
143
170
  };
@@ -333,17 +360,26 @@ var createWebCore = () => {
333
360
  if (sessionHeartbeatTimer) {
334
361
  clearInterval(sessionHeartbeatTimer);
335
362
  }
336
- if (config.sessionHeartbeatInterval) {
337
- sessionHeartbeatTimer = setInterval(() => {
338
- if (isSessionActive) {
339
- if (config.refresh) {
340
- updateSessionActivity();
341
- } else {
342
- 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;
343
374
  }
344
375
  }
345
- }, config.sessionHeartbeatInterval);
346
- }
376
+ if (config.refresh) {
377
+ updateSessionActivity();
378
+ } else {
379
+ saveSessionToStorage();
380
+ }
381
+ }
382
+ }, checkInterval);
347
383
  };
348
384
  const stopSessionHeartbeat = () => {
349
385
  if (sessionHeartbeatTimer) {
@@ -737,34 +773,18 @@ var createWebCore = () => {
737
773
  return;
738
774
  }
739
775
  sessionId = hardSessionId || sessionId;
740
- const event = {
741
- type: 9999,
742
- timestamp: now(),
743
- data: {}
744
- };
745
- const payload = {
746
- session_id: sessionId,
747
- user_id: userId,
748
- organization_id: organizationId,
749
- events: [event],
750
- client_version: LIB_VERSION
751
- };
752
- if (externalId) {
753
- payload.external_id = externalId;
776
+ if (!sessionId || !organizationId) {
777
+ return;
754
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 };
755
783
  const payloadString = JSON.stringify(payload);
756
- const payloadSizeKB = new Blob([payloadString]).size / BYTES_IN_KILOBYTE;
757
784
  try {
758
- const endpointUrl = buildEndpointUrl(
759
- config.endpoint,
760
- "f",
761
- false,
762
- payloadSizeKB,
763
- false
764
- );
765
785
  const response = await fetch(endpointUrl, {
766
786
  method: "POST",
767
- headers: { "Content-Type": "text/plain" },
787
+ headers: { "Content-Type": "application/json" },
768
788
  body: payloadString,
769
789
  mode: "cors",
770
790
  credentials: "omit"
@@ -887,7 +907,8 @@ var createWebCore = () => {
887
907
  const IDLE_MS = 15e3;
888
908
  const BLOCKED_NET_HOSTS = /* @__PURE__ */ new Set([
889
909
  "ingest.infinitewatch.ai",
890
- "ingest.humanbehavior.co"
910
+ "ingest.humanbehavior.co",
911
+ "iw-backend-live.fly.dev"
891
912
  ]);
892
913
  let __iw_lastUserIntentAt = now();
893
914
  let __iw_intentInstalled = false;