@brainfish-ai/web-tracker 0.0.32 → 0.0.33

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.
@@ -281,7 +281,7 @@ function createPacketDecoderStream(maxPayload, binaryType) {
281
281
  }
282
282
  });
283
283
  }
284
- const protocol$1 = 4;
284
+ const protocol = 4;
285
285
  function Emitter(obj) {
286
286
  if (obj) return mixin(obj);
287
287
  }
@@ -1259,7 +1259,7 @@ class SocketWithoutUpgrade extends Emitter {
1259
1259
  */
1260
1260
  createTransport(name) {
1261
1261
  const query = Object.assign({}, this.opts.query);
1262
- query.EIO = protocol$1;
1262
+ query.EIO = protocol;
1263
1263
  query.transport = name;
1264
1264
  if (this.id)
1265
1265
  query.sid = this.id;
@@ -1588,7 +1588,7 @@ class SocketWithoutUpgrade extends Emitter {
1588
1588
  }
1589
1589
  }
1590
1590
  }
1591
- SocketWithoutUpgrade.protocol = protocol$1;
1591
+ SocketWithoutUpgrade.protocol = protocol;
1592
1592
  class SocketWithUpgrade extends SocketWithoutUpgrade {
1593
1593
  constructor() {
1594
1594
  super(...arguments);
@@ -1860,7 +1860,6 @@ const RESERVED_EVENTS$1 = [
1860
1860
  "removeListener"
1861
1861
  // used by the Node.js EventEmitter
1862
1862
  ];
1863
- const protocol = 5;
1864
1863
  var PacketType;
1865
1864
  (function(PacketType2) {
1866
1865
  PacketType2[PacketType2["CONNECT"] = 0] = "CONNECT";
@@ -2111,8 +2110,7 @@ const parser$3 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProp
2111
2110
  Encoder,
2112
2111
  get PacketType() {
2113
2112
  return PacketType;
2114
- },
2115
- protocol
2113
+ }
2116
2114
  }, Symbol.toStringTag, { value: "Module" }));
2117
2115
  function on$2(obj, ev, fn) {
2118
2116
  obj.on(ev, fn);
@@ -3457,6 +3455,19 @@ class TTLSet {
3457
3455
  }
3458
3456
  }
3459
3457
  let latestIdentifyPayload = null;
3458
+ const BRAINFISH_IFRAME_SELECTOR = "#bf-iframe-container .trigger-iframe, #bf-search-bar-iframe-container .trigger-iframe";
3459
+ function getBrainfishIframes() {
3460
+ if (typeof document === "undefined") {
3461
+ return [];
3462
+ }
3463
+ return Array.from(document.querySelectorAll(BRAINFISH_IFRAME_SELECTOR));
3464
+ }
3465
+ function isTrustedBrainfishIframeSource(source) {
3466
+ if (!source) {
3467
+ return false;
3468
+ }
3469
+ return getBrainfishIframes().some((iframe) => iframe.contentWindow === source);
3470
+ }
3460
3471
  if (typeof window !== "undefined") {
3461
3472
  window.addEventListener("message", (event) => {
3462
3473
  const trustedOrigin = "https://agent.brainfi.sh";
@@ -3465,8 +3476,7 @@ if (typeof window !== "undefined") {
3465
3476
  }
3466
3477
  if (event.data?.type === "REQUEST_USER_IDENTITY") {
3467
3478
  if (latestIdentifyPayload && event.source) {
3468
- const iframe = document.querySelector("#bf-iframe-container .trigger-iframe");
3469
- if (!iframe || event.source !== iframe.contentWindow) {
3479
+ if (!isTrustedBrainfishIframeSource(event.source)) {
3470
3480
  console.warn("BrainfishWidgetWarn: Rejected REQUEST_USER_IDENTITY from untrusted iframe source:", event.origin);
3471
3481
  return;
3472
3482
  }
@@ -3635,8 +3645,7 @@ const _TrackerSdk = class _TrackerSdk {
3635
3645
  console.warn("BrainfishWidgetWarn: phone should be in E.164 format (e.g., +14155552671). Providing the correct format ensures accurate user identification.");
3636
3646
  }
3637
3647
  latestIdentifyPayload = payload;
3638
- const iframe = document.querySelector("#bf-iframe-container .trigger-iframe");
3639
- if (iframe) {
3648
+ getBrainfishIframes().forEach((iframe) => {
3640
3649
  const sendMessage = () => {
3641
3650
  if (iframe.contentWindow) {
3642
3651
  iframe.contentWindow.postMessage({
@@ -3649,7 +3658,7 @@ const _TrackerSdk = class _TrackerSdk {
3649
3658
  sendMessage();
3650
3659
  }
3651
3660
  iframe.addEventListener("load", sendMessage);
3652
- }
3661
+ });
3653
3662
  if (Object.keys(payload).length > 1) {
3654
3663
  return this.send({
3655
3664
  type: "user.identify",
@@ -25185,7 +25194,7 @@ function toCamelCase(str) {
25185
25194
  ($1) => $1.toUpperCase().replace("-", "").replace("_", "")
25186
25195
  );
25187
25196
  }
25188
- const VERSION = "0.0.32";
25197
+ const VERSION = "0.0.33";
25189
25198
  class Tracker extends TrackerSdk {
25190
25199
  constructor(options) {
25191
25200
  super({
Binary file