@sailfish-ai/recorder 1.1.1 → 1.1.3

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
@@ -141,7 +141,7 @@ export function matchUrlWithWildcard(url, patterns) {
141
141
  }
142
142
  // Updated XMLHttpRequest interceptor with single check function
143
143
  function setupXMLHttpRequestInterceptor(domainsToNotPropagateHeaderTo) {
144
- const originalOpen = XMLHttpRequest.prototype.open;
144
+ // Store references to the original (or patched) send method
145
145
  const originalSend = XMLHttpRequest.prototype.send;
146
146
  const sessionId = getOrSetSessionId();
147
147
  // Combine default and passed domains
@@ -149,10 +149,7 @@ function setupXMLHttpRequestInterceptor(domainsToNotPropagateHeaderTo) {
149
149
  ...DOMAINS_TO_NOT_PROPAGATE_HEADER_TO_DEFAULT,
150
150
  ...domainsToNotPropagateHeaderTo,
151
151
  ];
152
- XMLHttpRequest.prototype.open = function (...args) {
153
- this._url = args[1]; // Store the request URL
154
- originalOpen.apply(this, args);
155
- };
152
+ // Override XMLHttpRequest's send method
156
153
  XMLHttpRequest.prototype.send = function (...args) {
157
154
  const url = this._url;
158
155
  // Check if URL matches any domain or path pattern
@@ -165,6 +162,7 @@ function setupXMLHttpRequestInterceptor(domainsToNotPropagateHeaderTo) {
165
162
  }
166
163
  // Updated fetch interceptor with single check function
167
164
  function setupFetchInterceptor(domainsToNotPropagateHeaderTo) {
165
+ // Store a reference to the original fetch function
168
166
  const originalFetch = window.fetch;
169
167
  const sessionId = getOrSetSessionId();
170
168
  // Combine default and passed domains
@@ -172,9 +170,10 @@ function setupFetchInterceptor(domainsToNotPropagateHeaderTo) {
172
170
  ...DOMAINS_TO_NOT_PROPAGATE_HEADER_TO_DEFAULT,
173
171
  ...domainsToNotPropagateHeaderTo,
174
172
  ];
175
- window.fetch = async function (input, init = {}) {
173
+ // Define our fetch wrapper
174
+ window.fetch = function (input, init) {
176
175
  let url;
177
- // Check if input is a string (URL) or a Request object
176
+ // Determine the URL based on input type
178
177
  if (typeof input === "string") {
179
178
  url = input;
180
179
  }
@@ -182,17 +181,47 @@ function setupFetchInterceptor(domainsToNotPropagateHeaderTo) {
182
181
  url = input.url;
183
182
  }
184
183
  else {
185
- throw new Error("Invalid input type for fetch");
184
+ // Unknown input type; defer to the original fetch
185
+ return originalFetch.apply(this, arguments);
186
186
  }
187
187
  // Check if URL matches any domain or path pattern
188
188
  const shouldSkipHeader = matchUrlWithWildcard(url, combinedIgnoreDomains);
189
- if (sessionId && !shouldSkipHeader) {
190
- init.headers = {
191
- ...init.headers,
192
- "X-Sf3-Rid": sessionId,
193
- };
189
+ // Use the original fetch if the domain matches the ignore patterns
190
+ if (shouldSkipHeader) {
191
+ // Call the original fetch with the original arguments
192
+ return originalFetch.apply(this, arguments);
193
+ }
194
+ // Only modify the request if we need to add the header
195
+ if (sessionId) {
196
+ if (input instanceof Request) {
197
+ // Clone the original request
198
+ const clonedRequest = input.clone();
199
+ // Clone the headers and add the custom header
200
+ const newHeaders = new Headers(clonedRequest.headers);
201
+ newHeaders.set("X-Sf3-Rid", sessionId);
202
+ // Create a new Request with the modified headers
203
+ const modifiedRequest = new Request(clonedRequest, {
204
+ headers: newHeaders,
205
+ });
206
+ // Call the original fetch with the modified Request
207
+ return originalFetch.call(this, modifiedRequest);
208
+ }
209
+ else {
210
+ // Input is a URL string
211
+ // Clone and modify the init object
212
+ const modifiedInit = { ...init };
213
+ // Clone the headers
214
+ const newHeaders = new Headers(init?.headers || {});
215
+ newHeaders.set("X-Sf3-Rid", sessionId);
216
+ modifiedInit.headers = newHeaders;
217
+ // Call the original fetch with the modified init
218
+ return originalFetch.call(this, input, modifiedInit);
219
+ }
220
+ }
221
+ else {
222
+ // No sessionId; call the original fetch
223
+ return originalFetch.apply(this, arguments);
194
224
  }
195
- return originalFetch(input, init);
196
225
  };
197
226
  }
198
227
  // Main Recording Function