@sensiblestats/widget-react 0.161.0 → 0.163.0

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
@@ -1383,7 +1383,7 @@ function parseCustomTotal(text2, format2) {
1383
1383
  }
1384
1384
 
1385
1385
  // src/version.generated.ts
1386
- var WIDGET_REACT_VERSION = "0.161.0";
1386
+ var WIDGET_REACT_VERSION = "0.163.0";
1387
1387
 
1388
1388
  // src/config.ts
1389
1389
  var COLOR_KEYS = ["accent", "cta", "surface", "ink"];
@@ -7291,6 +7291,9 @@ function impressionOnce(key) {
7291
7291
  seen.add(key);
7292
7292
  return true;
7293
7293
  }
7294
+ function impressionForget(key) {
7295
+ seen.delete(key);
7296
+ }
7294
7297
  function useImpressions(entries) {
7295
7298
  const record2 = useRecord();
7296
7299
  const entriesRef = useRef22(entries);
@@ -7587,7 +7590,7 @@ function MarketOddsCard({ vm, ui, slip, monitor, inSlipIds, hideHeader, pinRef }
7587
7590
  const staleTime = isStale && live ? fmtHhMm(live.asOfUtc, ui.locale, clockOf(ui), ui.timeZone) : null;
7588
7591
  const record2 = useRecord();
7589
7592
  const origin = useSlipSurface();
7590
- const scope = `${origin?.impressionScope ?? origin?.turnId ?? origin?.surface ?? "none"}|${vm.id}`;
7593
+ const scope = `${origin?.impressionScope ?? origin?.turnId ?? origin?.surface ?? "none"}|${vm.sport ?? "football"}|${vm.id}`;
7591
7594
  const matchId = String(vm.matchId);
7592
7595
  const slipReason = !vm.addToSlipEnabled || isClosed ? null : isStale ? "hold" : slip.onAddToSlip && !slipOpenFor(slip, vm.sport) ? "closed" : slip.onAddToSlip && nflStarted(vm, Date.now()) ? "started" : null;
7593
7596
  const shown2 = [];
@@ -9073,7 +9076,7 @@ function safely(fn) {
9073
9076
  }
9074
9077
  }
9075
9078
  function useLoadTelemetry(input) {
9076
- const { client, stringsState, stringsAttempt, resolvedTag, language, scriptUrl } = input;
9079
+ const { client, stringsState, stringsAttempt, resolvedTag, language, scriptUrls } = input;
9077
9080
  const signedIn = !!input.operatorUserId;
9078
9081
  const inputRef = useRef29(input);
9079
9082
  inputRef.current = input;
@@ -9105,7 +9108,7 @@ function useLoadTelemetry(input) {
9105
9108
  useEffect33(() => {
9106
9109
  if (!hasClient || loadedRef.current) return;
9107
9110
  loadedRef.current = true;
9108
- recordRef.current({ name: "widget_loaded", props: { loadMs: Math.max(0, Date.now() - inputRef.current.scriptStart) } });
9111
+ recordRef.current({ name: "widget_loaded", props: { loadMs: Math.max(0, Date.now() - inputRef.current.loadStart) } });
9109
9112
  }, [hasClient]);
9110
9113
  useEffect33(() => {
9111
9114
  if (!hasClient) return;
@@ -9154,15 +9157,18 @@ function useLoadTelemetry(input) {
9154
9157
  if (failedLimit(`${endpoint}|${status2}`)) recordRef.current({ name: "request_failed", props: { endpoint, status: status2 } });
9155
9158
  });
9156
9159
  }, [client]);
9160
+ const urlsKey = scriptUrls?.join("\n") ?? "";
9157
9161
  useEffect33(() => {
9158
- if (!hasClient || !scriptUrl) return;
9162
+ const urls = urlsKey.split("\n").filter((u) => u.length > 0);
9163
+ if (!hasClient || urls.length === 0) return;
9164
+ const fromWidget = (text2) => urls.some((u) => text2.includes(u));
9159
9165
  const onError = (e) => {
9160
- if (!e.filename || !e.filename.includes(scriptUrl)) return;
9166
+ if (!e.filename || !fromWidget(e.filename)) return;
9161
9167
  reportError({ errorClass: e.error?.name || "Error", component: "window" });
9162
9168
  };
9163
9169
  const onRejection = (e) => {
9164
9170
  const reason = e.reason;
9165
- if (typeof reason?.stack !== "string" || !reason.stack.includes(scriptUrl)) return;
9171
+ if (typeof reason?.stack !== "string" || !fromWidget(reason.stack)) return;
9166
9172
  reportError({ errorClass: typeof reason.name === "string" && reason.name ? reason.name : "Error", component: "promise" });
9167
9173
  };
9168
9174
  window.addEventListener("error", onError);
@@ -9171,7 +9177,7 @@ function useLoadTelemetry(input) {
9171
9177
  window.removeEventListener("error", onError);
9172
9178
  window.removeEventListener("unhandledrejection", onRejection);
9173
9179
  };
9174
- }, [hasClient, scriptUrl, reportError]);
9180
+ }, [hasClient, urlsKey, reportError]);
9175
9181
  return { reportError };
9176
9182
  }
9177
9183
 
@@ -12650,11 +12656,11 @@ function MarketAccordion({ match, monitor, ui, slip }) {
12650
12656
  const suspendedKey = markets.filter((m) => m.suspended).map((m) => m.marketDeveloperName).join("|");
12651
12657
  useEffect43(() => {
12652
12658
  for (const m of markets) {
12653
- if (m.suspended && impressionOnce(`market_suspended_shown|${match.sport}|${match.matchId}|${m.marketDeveloperName}`)) {
12654
- record2({ name: "market_suspended_shown", props: { matchId: String(match.matchId), market: m.marketDeveloperName } });
12655
- }
12659
+ const key = `market_suspended_shown|${match.sport}|${match.matchId}|${m.marketDeveloperName}`;
12660
+ if (!m.suspended) impressionForget(key);
12661
+ else if (impressionOnce(key)) record2({ name: "market_suspended_shown", props: { matchId: String(match.matchId), market: m.marketDeveloperName } });
12656
12662
  }
12657
- }, [suspendedKey, match.matchId, record2]);
12663
+ }, [suspendedKey, match.sport, match.matchId, record2]);
12658
12664
  if (markets.length === 0) return null;
12659
12665
  const mk = monitorMatchKey(match.sport, match.matchId);
12660
12666
  const open = monitor.openMarket[mk] ?? null;
@@ -23589,7 +23595,6 @@ var WIDGET_CSS = `.ss-w-root { all: revert; }
23589
23595
  // src/StatsWidget.tsx
23590
23596
  import { jsx as jsx165 } from "react/jsx-runtime";
23591
23597
  var NO_OWNER = {};
23592
- var SCRIPT_START = Date.now();
23593
23598
  function buildClient(props, onUnavailable) {
23594
23599
  try {
23595
23600
  if ("client" in props && props.client) {
@@ -23613,10 +23618,36 @@ function injectStyles(root) {
23613
23618
  el.textContent = WIDGET_CSS;
23614
23619
  host.appendChild(el);
23615
23620
  }
23621
+ function reportBeforeReady(props, body) {
23622
+ try {
23623
+ let client;
23624
+ let identity;
23625
+ if ("client" in props && props.client) {
23626
+ client = props.client;
23627
+ } else {
23628
+ const cfg = props.config;
23629
+ client = new StatsWidgetClient(toClientOptions(cfg));
23630
+ identity = { operatorUserId: cfg.userContext?.operatorUserId, anonymousUserId: cfg.userContext?.anonymousUserId };
23631
+ }
23632
+ const surface = props.mobile ? "mobile" : props.surface ?? "react";
23633
+ const logger = client.createEventLogger(identity, {
23634
+ context: () => ({ widgetVersion: WIDGET_REACT_VERSION, surface, ...props.mobile?.client ? { client: props.mobile.client } : {} })
23635
+ });
23636
+ logger.log({ name: "widget_error", props: body });
23637
+ void logger.flushNow().finally(() => logger.dispose());
23638
+ } catch {
23639
+ }
23640
+ }
23616
23641
  function StatsWidget(props) {
23617
23642
  const sink = useRef54(null);
23618
- const report = useCallback32((body) => sink.current?.(body), []);
23619
- return /* @__PURE__ */ jsx165(TelemetryBoundary, { component: "widget", report, children: /* @__PURE__ */ jsx165(StatsWidgetBody, { ...props, errorSink: sink }) });
23643
+ const propsRef = useRef54(props);
23644
+ propsRef.current = props;
23645
+ const report = useCallback32((body) => {
23646
+ if (sink.current) sink.current(body);
23647
+ else reportBeforeReady(propsRef.current, body);
23648
+ }, []);
23649
+ const mountStart = useRef54(Date.now()).current;
23650
+ return /* @__PURE__ */ jsx165(TelemetryBoundary, { component: "widget", report, children: /* @__PURE__ */ jsx165(StatsWidgetBody, { ...props, errorSink: sink, mountStart }) });
23620
23651
  }
23621
23652
  function StatsWidgetBody(props) {
23622
23653
  const injectedClient = "client" in props ? props.client : void 0;
@@ -24117,8 +24148,8 @@ function StatsWidgetBody(props) {
24117
24148
  hasSlipHandler: !!props.config?.onAddToSlip,
24118
24149
  panelOpen,
24119
24150
  mobile: props.mobile !== void 0,
24120
- scriptUrl: props.scriptUrl,
24121
- scriptStart: SCRIPT_START
24151
+ scriptUrls: props.scriptUrls,
24152
+ loadStart: props.loadStart ?? props.mountStart
24122
24153
  });
24123
24154
  props.errorSink.current = reportError;
24124
24155
  useEffect64(() => {