@claudinho/core 0.8.16 → 0.8.17

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.
Files changed (2) hide show
  1. package/dist/index.js +43 -10
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4465,7 +4465,8 @@ var PolymarketProvider = class {
4465
4465
  opts;
4466
4466
  name = "polymarket";
4467
4467
  async findSignal(match, options) {
4468
- return (await this.resolveOne(match, options)).signal;
4468
+ const deadline = options?.deadlineMs != null ? Date.now() + options.deadlineMs : Number.POSITIVE_INFINITY;
4469
+ return (await this.resolveOne(match, options, deadline)).signal;
4469
4470
  }
4470
4471
  async findSignals(matches, options) {
4471
4472
  const signals = /* @__PURE__ */ new Map();
@@ -4473,7 +4474,7 @@ var PolymarketProvider = class {
4473
4474
  const deadline = options?.deadlineMs != null ? Date.now() + options.deadlineMs : Number.POSITIVE_INFINITY;
4474
4475
  for (const m of matches) {
4475
4476
  if (Date.now() >= deadline) break;
4476
- const r = await this.resolveOne(m, options);
4477
+ const r = await this.resolveOne(m, options, deadline);
4477
4478
  if (r.checked) checked.add(m.id);
4478
4479
  if (r.signal) signals.set(m.id, r.signal);
4479
4480
  }
@@ -4485,13 +4486,16 @@ var PolymarketProvider = class {
4485
4486
  * provider/network error — so transient failures are retried, not
4486
4487
  * negative-cached.
4487
4488
  */
4488
- async resolveOne(match, options) {
4489
+ async resolveOne(match, options, deadline = Number.POSITIVE_INFINITY) {
4489
4490
  const entry = (this.opts.mapping ?? BUNDLED_MAPPING)[match.id];
4490
4491
  const slugs = entry?.eventSlug ? [entry.eventSlug] : deriveEventSlugs(match);
4491
4492
  if (slugs.length === 0) return { checked: true };
4493
+ const configured = options?.timeoutMs ?? this.opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
4492
4494
  try {
4493
4495
  for (const slug of slugs) {
4494
- const event = await this.fetchEvent(slug, options?.timeoutMs);
4496
+ const remaining = deadline - Date.now();
4497
+ if (remaining <= 0) return { checked: false };
4498
+ const event = await this.fetchEvent(slug, Math.min(configured, remaining));
4495
4499
  const signal = event ? this.toSignal(match, slug, event, options) : void 0;
4496
4500
  if (signal) return { signal, checked: true };
4497
4501
  }
@@ -4571,6 +4575,27 @@ var PolymarketProvider = class {
4571
4575
  return signal.ambiguous ? void 0 : signal;
4572
4576
  }
4573
4577
  };
4578
+ var POLYMARKET_TOKEN = {
4579
+ SUI: "che",
4580
+ // Switzerland
4581
+ NED: "nld",
4582
+ // Netherlands
4583
+ URU: "ury",
4584
+ // Uruguay
4585
+ POR: "prt",
4586
+ // Portugal
4587
+ CRO: "hrv",
4588
+ // Croatia
4589
+ COD: "cdr",
4590
+ // DR Congo
4591
+ CPV: "cvi"
4592
+ // Cabo Verde
4593
+ };
4594
+ function pmTokens(code) {
4595
+ const c = code.toLowerCase();
4596
+ const alias = POLYMARKET_TOKEN[code.toUpperCase()];
4597
+ return alias && alias !== c ? [alias, c] : [c];
4598
+ }
4574
4599
  function deriveEventSlugs(match) {
4575
4600
  const home = match.home.code.toLowerCase();
4576
4601
  const away = match.away.code.toLowerCase();
@@ -4578,10 +4603,18 @@ function deriveEventSlugs(match) {
4578
4603
  if (!/^[a-z]{3}$/.test(home) || !/^[a-z]{3}$/.test(away)) return [];
4579
4604
  const utcDate = match.kickoff.slice(0, 10);
4580
4605
  if (!/^\d{4}-\d{2}-\d{2}$/.test(utcDate)) return [];
4581
- return [
4582
- `fifwc-${home}-${away}-${utcDate}`,
4583
- `fifwc-${home}-${away}-${shiftUtcDate(utcDate, -1)}`
4584
- ];
4606
+ const dates = [utcDate, shiftUtcDate(utcDate, -1)];
4607
+ const homeToks = pmTokens(match.home.code);
4608
+ const awayToks = pmTokens(match.away.code);
4609
+ const slugs = [];
4610
+ for (const d of dates) {
4611
+ for (const h of homeToks) {
4612
+ for (const a of awayToks) {
4613
+ slugs.push(`fifwc-${h}-${a}-${d}`);
4614
+ }
4615
+ }
4616
+ }
4617
+ return [...new Set(slugs)];
4585
4618
  }
4586
4619
  function slugToken(m) {
4587
4620
  return (m.slug ?? "").toLowerCase().split("-").pop() ?? "";
@@ -4590,10 +4623,10 @@ function isDrawMarket(m) {
4590
4623
  return slugToken(m) === "draw" || (m.groupItemTitle ?? "").trim().toLowerCase().startsWith("draw");
4591
4624
  }
4592
4625
  function pickMarket(markets, teamCode, teamName) {
4593
- const code = teamCode.toLowerCase();
4626
+ const tokens = pmTokens(teamCode);
4594
4627
  const name = teamName.trim().toLowerCase();
4595
4628
  const teamMarkets = markets.filter((m) => !isDrawMarket(m));
4596
- const bySlug = teamMarkets.find((m) => slugToken(m) === code);
4629
+ const bySlug = teamMarkets.find((m) => tokens.includes(slugToken(m)));
4597
4630
  if (bySlug) return bySlug;
4598
4631
  return teamMarkets.find((m) => (m.groupItemTitle ?? "").trim().toLowerCase() === name);
4599
4632
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claudinho/core",
3
- "version": "0.8.16",
3
+ "version": "0.8.17",
4
4
  "description": "Domain model, provider adapters (ESPN), standings, bundled schedule, and the read-only Polymarket market-signal sidecar powering Claudinho. Not affiliated with FIFA or Anthropic.",
5
5
  "type": "module",
6
6
  "license": "MIT",