@sensiblestats/widget-react 0.160.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.160.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"];
@@ -1790,8 +1790,7 @@ function normalizeUi(cfg, loaded) {
1790
1790
  };
1791
1791
  }
1792
1792
  function toClientOptions(cfg) {
1793
- const opts = { operatorId: cfg.operatorId, publicKey: cfg.publicKey, client: `${cfg.transport?.client ?? "widget-react"}/${WIDGET_REACT_VERSION}` };
1794
- if (cfg.baseUrl !== void 0) opts.baseUrl = cfg.baseUrl;
1793
+ const opts = { operatorId: cfg.operatorId, publicKey: cfg.publicKey, baseUrl: cfg.baseUrl, client: `${cfg.transport?.client ?? "widget-react"}/${WIDGET_REACT_VERSION}` };
1795
1794
  if (cfg.transport?.fetch !== void 0) opts.fetch = cfg.transport.fetch;
1796
1795
  const timeZone = validZone(cfg.timeZone);
1797
1796
  if (timeZone !== void 0) opts.timeZone = timeZone;
@@ -7292,6 +7291,9 @@ function impressionOnce(key) {
7292
7291
  seen.add(key);
7293
7292
  return true;
7294
7293
  }
7294
+ function impressionForget(key) {
7295
+ seen.delete(key);
7296
+ }
7295
7297
  function useImpressions(entries) {
7296
7298
  const record2 = useRecord();
7297
7299
  const entriesRef = useRef22(entries);
@@ -7588,7 +7590,7 @@ function MarketOddsCard({ vm, ui, slip, monitor, inSlipIds, hideHeader, pinRef }
7588
7590
  const staleTime = isStale && live ? fmtHhMm(live.asOfUtc, ui.locale, clockOf(ui), ui.timeZone) : null;
7589
7591
  const record2 = useRecord();
7590
7592
  const origin = useSlipSurface();
7591
- 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}`;
7592
7594
  const matchId = String(vm.matchId);
7593
7595
  const slipReason = !vm.addToSlipEnabled || isClosed ? null : isStale ? "hold" : slip.onAddToSlip && !slipOpenFor(slip, vm.sport) ? "closed" : slip.onAddToSlip && nflStarted(vm, Date.now()) ? "started" : null;
7594
7596
  const shown2 = [];
@@ -9106,7 +9108,7 @@ function useLoadTelemetry(input) {
9106
9108
  useEffect33(() => {
9107
9109
  if (!hasClient || loadedRef.current) return;
9108
9110
  loadedRef.current = true;
9109
- 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) } });
9110
9112
  }, [hasClient]);
9111
9113
  useEffect33(() => {
9112
9114
  if (!hasClient) return;
@@ -12651,11 +12653,11 @@ function MarketAccordion({ match, monitor, ui, slip }) {
12651
12653
  const suspendedKey = markets.filter((m) => m.suspended).map((m) => m.marketDeveloperName).join("|");
12652
12654
  useEffect43(() => {
12653
12655
  for (const m of markets) {
12654
- if (m.suspended && impressionOnce(`market_suspended_shown|${match.sport}|${match.matchId}|${m.marketDeveloperName}`)) {
12655
- record2({ name: "market_suspended_shown", props: { matchId: String(match.matchId), market: m.marketDeveloperName } });
12656
- }
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 } });
12657
12659
  }
12658
- }, [suspendedKey, match.matchId, record2]);
12660
+ }, [suspendedKey, match.sport, match.matchId, record2]);
12659
12661
  if (markets.length === 0) return null;
12660
12662
  const mk = monitorMatchKey(match.sport, match.matchId);
12661
12663
  const open = monitor.openMarket[mk] ?? null;
@@ -23590,7 +23592,6 @@ var WIDGET_CSS = `.ss-w-root { all: revert; }
23590
23592
  // src/StatsWidget.tsx
23591
23593
  import { jsx as jsx165 } from "react/jsx-runtime";
23592
23594
  var NO_OWNER = {};
23593
- var SCRIPT_START = Date.now();
23594
23595
  function buildClient(props, onUnavailable) {
23595
23596
  try {
23596
23597
  if ("client" in props && props.client) {
@@ -23614,10 +23615,36 @@ function injectStyles(root) {
23614
23615
  el.textContent = WIDGET_CSS;
23615
23616
  host.appendChild(el);
23616
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
+ }
23617
23638
  function StatsWidget(props) {
23618
23639
  const sink = useRef54(null);
23619
- const report = useCallback32((body) => sink.current?.(body), []);
23620
- 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 }) });
23621
23648
  }
23622
23649
  function StatsWidgetBody(props) {
23623
23650
  const injectedClient = "client" in props ? props.client : void 0;
@@ -24119,7 +24146,7 @@ function StatsWidgetBody(props) {
24119
24146
  panelOpen,
24120
24147
  mobile: props.mobile !== void 0,
24121
24148
  scriptUrl: props.scriptUrl,
24122
- scriptStart: SCRIPT_START
24149
+ loadStart: props.loadStart ?? props.mountStart
24123
24150
  });
24124
24151
  props.errorSink.current = reportError;
24125
24152
  useEffect64(() => {