@sailfish-ai/recorder 1.2.5 → 1.2.7

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
@@ -93,6 +93,7 @@ function storeCredentialsAndConnection({ apiKey, backendApi, }) {
93
93
  }
94
94
  // Utility function to match domains or paths with wildcard support
95
95
  export function matchUrlWithWildcard(url, patterns) {
96
+ console.log(`Calling matchUrlWithWildcard against ${url}`);
96
97
  if (!url || typeof url !== "string") {
97
98
  throw new Error("Invalid URL input");
98
99
  }
@@ -157,80 +158,57 @@ export function matchUrlWithWildcard(url, patterns) {
157
158
  });
158
159
  }
159
160
  // Updated XMLHttpRequest interceptor with single check function
160
- // Updated XMLHttpRequest interceptor to bypass for CORS-sensitive domains
161
161
  function setupXMLHttpRequestInterceptor(domainsToNotPropagateHeaderTo, domainsToPropagateHeadersTo = []) {
162
162
  const originalOpen = XMLHttpRequest.prototype.open;
163
163
  const originalSend = XMLHttpRequest.prototype.send;
164
164
  const sessionId = getOrSetSessionId();
165
- // Combine default and passed ignore domains
165
+ // Combined ignore and propagate logic
166
166
  const combinedIgnoreDomains = [
167
167
  ...DOMAINS_TO_NOT_PROPAGATE_HEADER_TO_DEFAULT,
168
168
  ...domainsToNotPropagateHeaderTo,
169
169
  ];
170
170
  // Store URL during open()
171
171
  XMLHttpRequest.prototype.open = function (method, url, ...args) {
172
- // Ensure the URL is a string, otherwise handle gracefully
173
- if (typeof url === "string" && url.length > 0) {
174
- this._requestUrl = url; // Capture the valid URL
175
- }
176
- else {
177
- console.warn("Invalid or non-string URL passed to XMLHttpRequest:", url);
178
- this._requestUrl = null; // Handle invalid or non-string URL
179
- }
172
+ console.log("Sailfish XMLHttpRequest.prototype.open");
173
+ this._requestUrl = typeof url === "string" && url.length > 0 ? url : null;
180
174
  return originalOpen.apply(this, [method, url, ...args]);
181
175
  };
182
176
  // Intercept send()
183
177
  XMLHttpRequest.prototype.send = function (...args) {
178
+ console.log("Sailfish XMLHttpRequest.prototype.send");
184
179
  const url = this._requestUrl;
185
- // If no valid URL was captured, proceed without modification
186
- if (!url) {
180
+ if (!url)
187
181
  return originalSend.apply(this, args);
188
- }
189
- // Bypass logic for domains listed in the combinedIgnoreDomains
182
+ // Check if domain should be ignored based on combined ignore list
190
183
  if (matchUrlWithWildcard(url, combinedIgnoreDomains)) {
184
+ console.log([`[XML] [InIgnoreDomains] IGNORE --> ${url}`]);
191
185
  return originalSend.apply(this, args);
192
186
  }
193
- // Check if the domain should propagate headers
187
+ // Check if domain should propagate headers
194
188
  const shouldPropagateHeader = domainsToPropagateHeadersTo.length === 0 ||
195
189
  matchUrlWithWildcard(url, domainsToPropagateHeadersTo);
196
190
  if (sessionId && shouldPropagateHeader) {
191
+ console.log([`[XML] [InPropagateDomans] PROPAGATE FOR --> ${url}`]);
197
192
  this.setRequestHeader("X-Sf3-Rid", sessionId);
198
193
  }
194
+ console.log([`[XML] [NOT InPropagateDomans] IGNORE --> ${url}`]);
199
195
  return originalSend.apply(this, args);
200
196
  };
201
197
  }
202
- // Updated fetch interceptor to bypass for CORS-sensitive domains
203
- function setupFetchInterceptor(domainsToNotPatchFetchFor, domainsToPropagateHeadersTo = []) {
198
+ // Updated fetch interceptor with exclusion handling
199
+ function setupFetchInterceptor(domainsToNotPropagateHeadersTo, domainsToPropagateHeadersTo = []) {
204
200
  const originalFetch = window.fetch;
205
201
  const sessionId = getOrSetSessionId();
206
- // Combine default and passed ignore domains
207
202
  const combinedIgnoreDomains = [
208
203
  ...DOMAINS_TO_NOT_PROPAGATE_HEADER_TO_DEFAULT,
209
- ...domainsToNotPatchFetchFor,
204
+ ...domainsToNotPropagateHeadersTo,
210
205
  ];
211
- // Cache results of domain checks to reduce performance overhead
212
206
  const cache = new Map();
213
- // Function to check if the input is a non-standard fetch input (Blob, FormData, etc.)
214
- function isNonStandardRequestInfo(input) {
215
- return (input instanceof Blob ||
216
- input instanceof FormData ||
217
- input instanceof ArrayBuffer);
218
- }
219
- // Function to check if fetch is polyfilled (e.g., in older browsers or Node.js)
220
- function isPolyfilledFetch() {
221
- return !window.fetch.toString().includes("[native code]");
222
- }
223
- // Log a warning if fetch is polyfilled
224
- if (isPolyfilledFetch()) {
225
- console.log("Fetch is polyfilled, behavior may differ from native fetch.");
226
- }
227
- // Proxy to conditionally intercept fetch based on domains
228
207
  window.fetch = new Proxy(originalFetch, {
229
208
  apply: (target, thisArg, args) => {
230
209
  let input = args[0];
231
210
  let init = args[1] || {};
232
211
  let url;
233
- // Handle different types of `input` for fetch
234
212
  if (typeof input === "string") {
235
213
  url = input;
236
214
  }
@@ -240,52 +218,39 @@ function setupFetchInterceptor(domainsToNotPatchFetchFor, domainsToPropagateHead
240
218
  else if (input instanceof URL) {
241
219
  url = input.href;
242
220
  }
243
- else if (isNonStandardRequestInfo(input)) {
244
- // Pass through non-standard inputs like Blob, FormData, etc.
245
- return target.apply(thisArg, args);
246
- }
247
221
  else {
248
- // Unsupported input type, skip interception
249
- console.warn("Unsupported input type for fetch:", input);
250
- return target.apply(thisArg, args);
222
+ console.log("Unsupported args -->", args);
223
+ return target.apply(thisArg, args); // Skip unsupported inputs
251
224
  }
252
- // Check the cache for domain results to avoid redundant checks
225
+ // Cache check
253
226
  if (cache.has(url)) {
254
227
  const cachedResult = cache.get(url);
255
228
  if (cachedResult === "ignore") {
229
+ console.log(`[CACHE] IGNORE --> ${url}`);
256
230
  return target.apply(thisArg, args);
257
231
  }
258
232
  if (cachedResult === "propagate") {
233
+ console.log(`[CACHE] PROPAGATE FOR --> ${url}`);
259
234
  return injectHeader(target, thisArg, args, input, init, sessionId);
260
235
  }
261
236
  }
262
- // ** Security Restriction Handling **
263
- try {
264
- // ** Check if we should skip patching fetch entirely for this domain **
265
- if (matchUrlWithWildcard(url, combinedIgnoreDomains)) {
266
- // Cache the result for this domain to avoid future checks
267
- cache.set(url, "ignore");
268
- return target.apply(thisArg, args);
269
- }
270
- // Check if the domain should propagate the header
271
- const shouldPropagateHeader = domainsToPropagateHeadersTo.length === 0 ||
272
- matchUrlWithWildcard(url, domainsToPropagateHeadersTo);
273
- // ** Skip CORS-sensitive requests **
274
- if (!shouldPropagateHeader) {
275
- // Cache the result for this domain to avoid future checks
276
- cache.set(url, "ignore");
277
- return target.apply(thisArg, args);
278
- }
279
- // Cache the result for this domain
280
- cache.set(url, "propagate");
281
- // ** Proceed to inject X-Sf3-Rid header **
282
- return injectHeader(target, thisArg, args, input, init, sessionId);
237
+ // Check domain exclusion
238
+ if (matchUrlWithWildcard(url, combinedIgnoreDomains)) {
239
+ console.log(`[InIgnoreDomains] IGNORE --> ${url}`);
240
+ cache.set(url, "ignore");
241
+ return target.apply(thisArg, args);
283
242
  }
284
- catch (error) {
285
- // ** Handle security restrictions and fallback to the original fetch **
286
- console.error("Failed to intercept fetch due to security restrictions:", error);
243
+ // Check domain propagation
244
+ const shouldPropagateHeader = domainsToPropagateHeadersTo.length === 0 ||
245
+ matchUrlWithWildcard(url, domainsToPropagateHeadersTo);
246
+ if (!shouldPropagateHeader) {
247
+ console.log(`[NOT InPropagateDomans] IGNORE --> ${url}`);
248
+ cache.set(url, "ignore");
287
249
  return target.apply(thisArg, args);
288
250
  }
251
+ cache.set(url, "propagate");
252
+ console.log(`[InPropagateDomans] PROPAGATE FOR --> ${url}`);
253
+ return injectHeader(target, thisArg, args, input, init, sessionId);
289
254
  },
290
255
  });
291
256
  // Helper function to inject the X-Sf3-Rid header
@@ -299,6 +264,7 @@ function setupFetchInterceptor(domainsToNotPatchFetchFor, domainsToPropagateHead
299
264
  const modifiedRequest = new Request(clonedRequest, {
300
265
  headers: newHeaders,
301
266
  });
267
+ console.log(`[modified call] newHeaders --> `, newHeaders);
302
268
  return target.call(thisArg, modifiedRequest, init);
303
269
  }
304
270
  else {
@@ -307,10 +273,12 @@ function setupFetchInterceptor(domainsToNotPatchFetchFor, domainsToPropagateHead
307
273
  const newHeaders = new Headers(init.headers || {});
308
274
  newHeaders.set("X-Sf3-Rid", sessionId);
309
275
  modifiedInit.headers = newHeaders;
276
+ console.log(`[modified call] newHeaders --> `, newHeaders);
310
277
  return target.call(thisArg, input, modifiedInit);
311
278
  }
312
279
  }
313
280
  else {
281
+ console.log("[UNMODIFIED CALL]");
314
282
  return target.apply(thisArg, args);
315
283
  }
316
284
  }