@sensiblestats/widget-react 0.161.0 → 0.162.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.162.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 = [];
@@ -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;
@@ -12650,11 +12653,11 @@ function MarketAccordion({ match, monitor, ui, slip }) {
12650
12653
  const suspendedKey = markets.filter((m) => m.suspended).map((m) => m.marketDeveloperName).join("|");
12651
12654
  useEffect43(() => {
12652
12655
  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
- }
12656
+ const key = `market_suspended_shown|${match.sport}|${match.matchId}|${m.marketDeveloperName}`;
12657
+ if (!m.suspended) impressionForget(key);
12658
+ else if (impressionOnce(key)) record2({ name: "market_suspended_shown", props: { matchId: String(match.matchId), market: m.marketDeveloperName } });
12656
12659
  }
12657
- }, [suspendedKey, match.matchId, record2]);
12660
+ }, [suspendedKey, match.sport, match.matchId, record2]);
12658
12661
  if (markets.length === 0) return null;
12659
12662
  const mk = monitorMatchKey(match.sport, match.matchId);
12660
12663
  const open = monitor.openMarket[mk] ?? null;
@@ -23589,7 +23592,6 @@ var WIDGET_CSS = `.ss-w-root { all: revert; }
23589
23592
  // src/StatsWidget.tsx
23590
23593
  import { jsx as jsx165 } from "react/jsx-runtime";
23591
23594
  var NO_OWNER = {};
23592
- var SCRIPT_START = Date.now();
23593
23595
  function buildClient(props, onUnavailable) {
23594
23596
  try {
23595
23597
  if ("client" in props && props.client) {
@@ -23613,10 +23615,36 @@ function injectStyles(root) {
23613
23615
  el.textContent = WIDGET_CSS;
23614
23616
  host.appendChild(el);
23615
23617
  }
23618
+ function reportBeforeReady(props, body) {
23619
+ try {
23620
+ let client;
23621
+ let identity;
23622
+ if ("client" in props && props.client) {
23623
+ client = props.client;
23624
+ } else {
23625
+ const cfg = props.config;
23626
+ client = new StatsWidgetClient(toClientOptions(cfg));
23627
+ identity = { operatorUserId: cfg.userContext?.operatorUserId, anonymousUserId: cfg.userContext?.anonymousUserId };
23628
+ }
23629
+ const surface = props.mobile ? "mobile" : props.surface ?? "react";
23630
+ const logger = client.createEventLogger(identity, {
23631
+ context: () => ({ widgetVersion: WIDGET_REACT_VERSION, surface, ...props.mobile?.client ? { client: props.mobile.client } : {} })
23632
+ });
23633
+ logger.log({ name: "widget_error", props: body });
23634
+ void logger.flushNow().finally(() => logger.dispose());
23635
+ } catch {
23636
+ }
23637
+ }
23616
23638
  function StatsWidget(props) {
23617
23639
  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 }) });
23640
+ const propsRef = useRef54(props);
23641
+ propsRef.current = props;
23642
+ const report = useCallback32((body) => {
23643
+ if (sink.current) sink.current(body);
23644
+ else reportBeforeReady(propsRef.current, body);
23645
+ }, []);
23646
+ const mountStart = useRef54(Date.now()).current;
23647
+ return /* @__PURE__ */ jsx165(TelemetryBoundary, { component: "widget", report, children: /* @__PURE__ */ jsx165(StatsWidgetBody, { ...props, errorSink: sink, mountStart }) });
23620
23648
  }
23621
23649
  function StatsWidgetBody(props) {
23622
23650
  const injectedClient = "client" in props ? props.client : void 0;
@@ -24118,7 +24146,7 @@ function StatsWidgetBody(props) {
24118
24146
  panelOpen,
24119
24147
  mobile: props.mobile !== void 0,
24120
24148
  scriptUrl: props.scriptUrl,
24121
- scriptStart: SCRIPT_START
24149
+ loadStart: props.loadStart ?? props.mountStart
24122
24150
  });
24123
24151
  props.errorSink.current = reportError;
24124
24152
  useEffect64(() => {