@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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @sensiblestats/widget-react
2
2
 
3
+ ## 0.163.0
4
+
5
+ ### Minor Changes
6
+
7
+ - `StatsWidget` takes `scriptUrls` (was `scriptUrl`): a window error or rejected promise counts as the widget's when its file or stack names any of them.
8
+
9
+ ## 0.162.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Client events: `widget_loaded.loadMs` counts from the mount, or from a `loadStart` prop the embed and `/m` pass. A first-render throw still sends `widget_error`. `market_suspended_shown` records each suspension spell, and market card impressions are keyed on the sport.
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies
18
+ - @sensiblestats/widget-sdk@0.119.0
19
+
3
20
  ## 0.161.0
4
21
 
5
22
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -1422,7 +1422,7 @@ function parseCustomTotal(text2, format2) {
1422
1422
  }
1423
1423
 
1424
1424
  // src/version.generated.ts
1425
- var WIDGET_REACT_VERSION = "0.161.0";
1425
+ var WIDGET_REACT_VERSION = "0.163.0";
1426
1426
 
1427
1427
  // src/config.ts
1428
1428
  var COLOR_KEYS = ["accent", "cta", "surface", "ink"];
@@ -7330,6 +7330,9 @@ function impressionOnce(key) {
7330
7330
  seen.add(key);
7331
7331
  return true;
7332
7332
  }
7333
+ function impressionForget(key) {
7334
+ seen.delete(key);
7335
+ }
7333
7336
  function useImpressions(entries) {
7334
7337
  const record2 = useRecord();
7335
7338
  const entriesRef = (0, import_react41.useRef)(entries);
@@ -7626,7 +7629,7 @@ function MarketOddsCard({ vm, ui, slip, monitor, inSlipIds, hideHeader, pinRef }
7626
7629
  const staleTime = isStale && live ? fmtHhMm(live.asOfUtc, ui.locale, clockOf(ui), ui.timeZone) : null;
7627
7630
  const record2 = useRecord();
7628
7631
  const origin = useSlipSurface();
7629
- const scope = `${origin?.impressionScope ?? origin?.turnId ?? origin?.surface ?? "none"}|${vm.id}`;
7632
+ const scope = `${origin?.impressionScope ?? origin?.turnId ?? origin?.surface ?? "none"}|${vm.sport ?? "football"}|${vm.id}`;
7630
7633
  const matchId = String(vm.matchId);
7631
7634
  const slipReason = !vm.addToSlipEnabled || isClosed ? null : isStale ? "hold" : slip.onAddToSlip && !slipOpenFor(slip, vm.sport) ? "closed" : slip.onAddToSlip && nflStarted(vm, Date.now()) ? "started" : null;
7632
7635
  const shown2 = [];
@@ -9112,7 +9115,7 @@ function safely(fn) {
9112
9115
  }
9113
9116
  }
9114
9117
  function useLoadTelemetry(input) {
9115
- const { client, stringsState, stringsAttempt, resolvedTag, language, scriptUrl } = input;
9118
+ const { client, stringsState, stringsAttempt, resolvedTag, language, scriptUrls } = input;
9116
9119
  const signedIn = !!input.operatorUserId;
9117
9120
  const inputRef = (0, import_react62.useRef)(input);
9118
9121
  inputRef.current = input;
@@ -9144,7 +9147,7 @@ function useLoadTelemetry(input) {
9144
9147
  (0, import_react62.useEffect)(() => {
9145
9148
  if (!hasClient || loadedRef.current) return;
9146
9149
  loadedRef.current = true;
9147
- recordRef.current({ name: "widget_loaded", props: { loadMs: Math.max(0, Date.now() - inputRef.current.scriptStart) } });
9150
+ recordRef.current({ name: "widget_loaded", props: { loadMs: Math.max(0, Date.now() - inputRef.current.loadStart) } });
9148
9151
  }, [hasClient]);
9149
9152
  (0, import_react62.useEffect)(() => {
9150
9153
  if (!hasClient) return;
@@ -9193,15 +9196,18 @@ function useLoadTelemetry(input) {
9193
9196
  if (failedLimit(`${endpoint}|${status2}`)) recordRef.current({ name: "request_failed", props: { endpoint, status: status2 } });
9194
9197
  });
9195
9198
  }, [client]);
9199
+ const urlsKey = scriptUrls?.join("\n") ?? "";
9196
9200
  (0, import_react62.useEffect)(() => {
9197
- if (!hasClient || !scriptUrl) return;
9201
+ const urls = urlsKey.split("\n").filter((u) => u.length > 0);
9202
+ if (!hasClient || urls.length === 0) return;
9203
+ const fromWidget = (text2) => urls.some((u) => text2.includes(u));
9198
9204
  const onError = (e) => {
9199
- if (!e.filename || !e.filename.includes(scriptUrl)) return;
9205
+ if (!e.filename || !fromWidget(e.filename)) return;
9200
9206
  reportError({ errorClass: e.error?.name || "Error", component: "window" });
9201
9207
  };
9202
9208
  const onRejection = (e) => {
9203
9209
  const reason = e.reason;
9204
- if (typeof reason?.stack !== "string" || !reason.stack.includes(scriptUrl)) return;
9210
+ if (typeof reason?.stack !== "string" || !fromWidget(reason.stack)) return;
9205
9211
  reportError({ errorClass: typeof reason.name === "string" && reason.name ? reason.name : "Error", component: "promise" });
9206
9212
  };
9207
9213
  window.addEventListener("error", onError);
@@ -9210,7 +9216,7 @@ function useLoadTelemetry(input) {
9210
9216
  window.removeEventListener("error", onError);
9211
9217
  window.removeEventListener("unhandledrejection", onRejection);
9212
9218
  };
9213
- }, [hasClient, scriptUrl, reportError]);
9219
+ }, [hasClient, urlsKey, reportError]);
9214
9220
  return { reportError };
9215
9221
  }
9216
9222
 
@@ -12689,11 +12695,11 @@ function MarketAccordion({ match, monitor, ui, slip }) {
12689
12695
  const suspendedKey = markets.filter((m) => m.suspended).map((m) => m.marketDeveloperName).join("|");
12690
12696
  (0, import_react86.useEffect)(() => {
12691
12697
  for (const m of markets) {
12692
- if (m.suspended && impressionOnce(`market_suspended_shown|${match.sport}|${match.matchId}|${m.marketDeveloperName}`)) {
12693
- record2({ name: "market_suspended_shown", props: { matchId: String(match.matchId), market: m.marketDeveloperName } });
12694
- }
12698
+ const key = `market_suspended_shown|${match.sport}|${match.matchId}|${m.marketDeveloperName}`;
12699
+ if (!m.suspended) impressionForget(key);
12700
+ else if (impressionOnce(key)) record2({ name: "market_suspended_shown", props: { matchId: String(match.matchId), market: m.marketDeveloperName } });
12695
12701
  }
12696
- }, [suspendedKey, match.matchId, record2]);
12702
+ }, [suspendedKey, match.sport, match.matchId, record2]);
12697
12703
  if (markets.length === 0) return null;
12698
12704
  const mk = monitorMatchKey(match.sport, match.matchId);
12699
12705
  const open = monitor.openMarket[mk] ?? null;
@@ -23628,7 +23634,6 @@ var WIDGET_CSS = `.ss-w-root { all: revert; }
23628
23634
  // src/StatsWidget.tsx
23629
23635
  var import_jsx_runtime165 = require("react/jsx-runtime");
23630
23636
  var NO_OWNER = {};
23631
- var SCRIPT_START = Date.now();
23632
23637
  function buildClient(props, onUnavailable) {
23633
23638
  try {
23634
23639
  if ("client" in props && props.client) {
@@ -23652,10 +23657,36 @@ function injectStyles(root) {
23652
23657
  el.textContent = WIDGET_CSS;
23653
23658
  host.appendChild(el);
23654
23659
  }
23660
+ function reportBeforeReady(props, body) {
23661
+ try {
23662
+ let client;
23663
+ let identity;
23664
+ if ("client" in props && props.client) {
23665
+ client = props.client;
23666
+ } else {
23667
+ const cfg = props.config;
23668
+ client = new import_widget_sdk42.StatsWidgetClient(toClientOptions(cfg));
23669
+ identity = { operatorUserId: cfg.userContext?.operatorUserId, anonymousUserId: cfg.userContext?.anonymousUserId };
23670
+ }
23671
+ const surface = props.mobile ? "mobile" : props.surface ?? "react";
23672
+ const logger = client.createEventLogger(identity, {
23673
+ context: () => ({ widgetVersion: WIDGET_REACT_VERSION, surface, ...props.mobile?.client ? { client: props.mobile.client } : {} })
23674
+ });
23675
+ logger.log({ name: "widget_error", props: body });
23676
+ void logger.flushNow().finally(() => logger.dispose());
23677
+ } catch {
23678
+ }
23679
+ }
23655
23680
  function StatsWidget(props) {
23656
23681
  const sink = (0, import_react131.useRef)(null);
23657
- const report = (0, import_react131.useCallback)((body) => sink.current?.(body), []);
23658
- return /* @__PURE__ */ (0, import_jsx_runtime165.jsx)(TelemetryBoundary, { component: "widget", report, children: /* @__PURE__ */ (0, import_jsx_runtime165.jsx)(StatsWidgetBody, { ...props, errorSink: sink }) });
23682
+ const propsRef = (0, import_react131.useRef)(props);
23683
+ propsRef.current = props;
23684
+ const report = (0, import_react131.useCallback)((body) => {
23685
+ if (sink.current) sink.current(body);
23686
+ else reportBeforeReady(propsRef.current, body);
23687
+ }, []);
23688
+ const mountStart = (0, import_react131.useRef)(Date.now()).current;
23689
+ return /* @__PURE__ */ (0, import_jsx_runtime165.jsx)(TelemetryBoundary, { component: "widget", report, children: /* @__PURE__ */ (0, import_jsx_runtime165.jsx)(StatsWidgetBody, { ...props, errorSink: sink, mountStart }) });
23659
23690
  }
23660
23691
  function StatsWidgetBody(props) {
23661
23692
  const injectedClient = "client" in props ? props.client : void 0;
@@ -24156,8 +24187,8 @@ function StatsWidgetBody(props) {
24156
24187
  hasSlipHandler: !!props.config?.onAddToSlip,
24157
24188
  panelOpen,
24158
24189
  mobile: props.mobile !== void 0,
24159
- scriptUrl: props.scriptUrl,
24160
- scriptStart: SCRIPT_START
24190
+ scriptUrls: props.scriptUrls,
24191
+ loadStart: props.loadStart ?? props.mountStart
24161
24192
  });
24162
24193
  props.errorSink.current = reportError;
24163
24194
  (0, import_react131.useEffect)(() => {