@sailfish-ai/recorder 1.2.0 → 1.2.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/README.md CHANGED
@@ -1,3 +1,3 @@
1
1
  # JS/TS Record-Only Package
2
2
 
3
- ## TODO - Rename all Sailfish to GrepLion!
3
+ ## TODO - Rename all Sailfish to GrepLion
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ import { fetchCaptureSettings, sendDomainsToNotPropagateHeaderTo, startRecording
6
6
  import { initializeRecording } from "./recording";
7
7
  // Default list of domains to ignore
8
8
  const DOMAINS_TO_NOT_PROPAGATE_HEADER_TO_DEFAULT = [
9
+ "t.co",
9
10
  "identitytoolkit.googleapis.com",
10
11
  ];
11
12
  const DOMAINS_TO_NOT_RECORD_NETWORK_REQUESTS_TO = [];
@@ -92,7 +93,12 @@ function storeCredentialsAndConnection({ apiKey, backendApi, }) {
92
93
  }
93
94
  // Utility function to match domains or paths with wildcard support
94
95
  export function matchUrlWithWildcard(url, patterns) {
95
- const strippedUrl = url.replace(/^[a-zA-Z]+:\/\//, "");
96
+ if (!url || typeof url !== "string") {
97
+ throw new Error("Invalid URL input");
98
+ }
99
+ // Ensure the URL has a protocol. If not, prepend "http://"
100
+ const formattedUrl = url.match(/^[a-zA-Z]+:\/\//) ? url : `http://${url}`;
101
+ const strippedUrl = formattedUrl.replace(/^[a-zA-Z]+:\/\//, "");
96
102
  const parsedUrl = new URL("http://" + strippedUrl); // Add a dummy protocol for URL parsing
97
103
  const { hostname, pathname, port } = parsedUrl;
98
104
  // Handle stripping 'www.' and port
@@ -151,26 +157,31 @@ export function matchUrlWithWildcard(url, patterns) {
151
157
  });
152
158
  }
153
159
  // Updated XMLHttpRequest interceptor with single check function
160
+ // Updated XMLHttpRequest interceptor to bypass for CORS-sensitive domains
154
161
  function setupXMLHttpRequestInterceptor(domainsToNotPropagateHeaderTo, domainsToPropagateHeadersTo = []) {
155
162
  const originalSend = XMLHttpRequest.prototype.send;
156
163
  const sessionId = getOrSetSessionId();
164
+ // Combine default and passed ignore domains
157
165
  const combinedIgnoreDomains = [
158
166
  ...DOMAINS_TO_NOT_PROPAGATE_HEADER_TO_DEFAULT,
159
167
  ...domainsToNotPropagateHeaderTo,
160
168
  ];
161
169
  XMLHttpRequest.prototype.send = function (...args) {
162
170
  const url = this._url;
163
- // Check if URL matches the propagation and exclusion patterns
164
- const shouldSkipHeader = matchUrlWithWildcard(url, combinedIgnoreDomains);
171
+ // Bypass logic for domains listed in the combinedIgnoreDomains
172
+ if (matchUrlWithWildcard(url, combinedIgnoreDomains)) {
173
+ return originalSend.apply(this, args);
174
+ }
175
+ // Check if the domain should propagate headers
165
176
  const shouldPropagateHeader = domainsToPropagateHeadersTo.length === 0 ||
166
177
  matchUrlWithWildcard(url, domainsToPropagateHeadersTo);
167
- if (sessionId && shouldPropagateHeader && !shouldSkipHeader) {
178
+ if (sessionId && shouldPropagateHeader) {
168
179
  this.setRequestHeader("X-Sf3-Rid", sessionId);
169
180
  }
170
- originalSend.apply(this, args);
181
+ return originalSend.apply(this, args);
171
182
  };
172
183
  }
173
- // Updated fetch interceptor with single check function
184
+ // Updated fetch interceptor to bypass for CORS-sensitive domains
174
185
  function setupFetchInterceptor(domainsToNotPropagateHeaderTo, domainsToPropagateHeadersTo = []) {
175
186
  const originalFetch = window.fetch;
176
187
  const sessionId = getOrSetSessionId();
@@ -190,12 +201,14 @@ function setupFetchInterceptor(domainsToNotPropagateHeaderTo, domainsToPropagate
190
201
  else {
191
202
  return originalFetch.apply(this, arguments);
192
203
  }
193
- // Check if URL matches the propagation and exclusion patterns
194
- const shouldSkipHeader = matchUrlWithWildcard(url, combinedIgnoreDomains);
204
+ // Bypass logic for domains listed in the combinedIgnoreDomains
205
+ if (matchUrlWithWildcard(url, combinedIgnoreDomains)) {
206
+ return originalFetch.apply(this, arguments);
207
+ }
208
+ // Check if the domain should propagate headers
195
209
  const shouldPropagateHeader = domainsToPropagateHeadersTo.length === 0 ||
196
210
  matchUrlWithWildcard(url, domainsToPropagateHeadersTo);
197
- // Proceed with fetch if header should propagate and not be excluded
198
- if (sessionId && shouldPropagateHeader && !shouldSkipHeader) {
211
+ if (sessionId && shouldPropagateHeader) {
199
212
  if (input instanceof Request) {
200
213
  const clonedRequest = input.clone();
201
214
  const newHeaders = new Headers(clonedRequest.headers);
@@ -219,7 +232,6 @@ function setupFetchInterceptor(domainsToNotPropagateHeaderTo, domainsToPropagate
219
232
  };
220
233
  }
221
234
  // Main Recording Function
222
- // Main Recording Function
223
235
  export async function startRecording({ apiKey, backendApi, domainsToPropagateHeaderTo = [], domainsToNotPropagateHeaderTo = [], }) {
224
236
  let sessionId = getOrSetSessionId();
225
237
  storeCredentialsAndConnection({ apiKey, backendApi });