@claudinho/core 0.7.0 → 0.8.1

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 (3) hide show
  1. package/dist/index.d.ts +159 -2
  2. package/dist/index.js +1379 -145
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -54,6 +54,11 @@ interface Match {
54
54
  status: Status;
55
55
  /** Goals/cards when the provider supplies them. */
56
56
  events?: MatchEvent[];
57
+ /**
58
+ * Winner's team code when the provider marks one (e.g. ESPN `competitor.winner`
59
+ * after penalties). Used for knockout advancement when the score is level.
60
+ */
61
+ winnerCode?: string;
57
62
  /** When this snapshot was produced (ISO 8601). */
58
63
  updatedAt: string;
59
64
  }
@@ -119,6 +124,15 @@ declare function nationToFlag(nameOrCode: string | undefined | null): string;
119
124
  */
120
125
  declare function nationToRegion(nameOrCode: string | undefined | null): string | undefined;
121
126
 
127
+ /** Supported UI locales — same set as CLI/MCP `lang`. */
128
+ type Lang = 'en' | 'es' | 'pt' | 'fr';
129
+ /** Normalize MCP/CLI `lang` to a supported catalog (falls back to English). */
130
+ declare function normalizeLang(lang?: string): Lang;
131
+ /** Translate a message key with optional `{placeholder}` interpolation. */
132
+ declare function t(lang: string | undefined, key: string, vars?: Record<string, string>): string;
133
+ /** Localized knockout/group stage label for bracket rendering. */
134
+ declare function stageLabelI18n(lang: string | undefined, stage: string, group?: string): string;
135
+
122
136
  /**
123
137
  * Resolve the effective timezone: explicit arg > CLAUDINHO_TZ env > system.
124
138
  *
@@ -204,13 +218,86 @@ declare function matchFlavor(m: Match, opts?: {
204
218
  locale?: string;
205
219
  }): string;
206
220
 
221
+ /** A participant slot in the bundled bracket topology (pre-resolution). */
222
+ type SlotRef = {
223
+ kind: 'group';
224
+ position: 1 | 2;
225
+ group: string;
226
+ } | {
227
+ kind: 'third';
228
+ groups: string[];
229
+ } | {
230
+ kind: 'winner';
231
+ stage: Stage;
232
+ index: number;
233
+ } | {
234
+ kind: 'loser';
235
+ stage: Stage;
236
+ index: number;
237
+ }
238
+ /** ESPN pre-draw nation label — display only; never confirmed from the bundled schedule. */
239
+ | {
240
+ kind: 'seed';
241
+ label: string;
242
+ code: string;
243
+ };
244
+ interface BracketMatchNode {
245
+ matchId: string;
246
+ stage: Stage;
247
+ /** 1-based index within the stage, ordered by kickoff. */
248
+ index: number;
249
+ home: SlotRef;
250
+ away: SlotRef;
251
+ }
252
+ interface BracketTopology {
253
+ generatedAt: string;
254
+ stages: Stage[];
255
+ matches: BracketMatchNode[];
256
+ }
257
+ /** Knockout rounds in display order (3P before the final). */
258
+ declare const BRACKET_STAGE_ORDER: Stage[];
259
+ type SlotStatus = 'confirmed' | 'projected' | 'tbd';
260
+ /** A resolved bracket participant for display. */
261
+ interface ResolvedParticipant {
262
+ label: string;
263
+ flag: string;
264
+ code?: string;
265
+ status: SlotStatus;
266
+ }
267
+ interface BracketMatchView {
268
+ matchId: string;
269
+ stage: Stage;
270
+ index: number;
271
+ kickoff: string;
272
+ home: ResolvedParticipant;
273
+ away: ResolvedParticipant;
274
+ match: Match;
275
+ }
276
+ interface BracketStageView {
277
+ stage: Stage;
278
+ label: string;
279
+ matches: BracketMatchView[];
280
+ }
281
+ interface BracketView {
282
+ stages: BracketStageView[];
283
+ degraded: boolean;
284
+ standingsDegraded: boolean;
285
+ source?: string;
286
+ }
287
+ interface BracketResult {
288
+ view: BracketView;
289
+ degraded: boolean;
290
+ standingsDegraded: boolean;
291
+ source?: string;
292
+ }
293
+
207
294
  /**
208
295
  * Strip live/final state from a fixture for the bundled skeleton schedule.
209
296
  * The JSON ships kickoffs, teams, venues, and bracket structure only — never
210
297
  * results. Live scores come from the provider overlay; degraded standings use
211
298
  * roster-at-zero, not a stale snapshot table.
212
299
  */
213
- declare function sanitizeBundledFixture(m: Match): Match;
300
+ declare function sanitizeBundledFixture(m: Match, node?: BracketMatchNode): Match;
214
301
  /** The full bundled fixture list. */
215
302
  declare function allFixtures(): Match[];
216
303
  /**
@@ -512,6 +599,14 @@ interface StandingsResult {
512
599
  * asked-for group isn't in it (caller renders "no such group").
513
600
  */
514
601
  declare function getStandings(adapter: ProviderAdapter, group?: string): Promise<StandingsResult>;
602
+ /**
603
+ * Knockout bracket with hybrid slot resolution: confirmed FT winners/losers from
604
+ * the live overlay; group slots project only when the group is fully played.
605
+ */
606
+ declare function getBracket(adapter: ProviderAdapter, opts?: {
607
+ stage?: Stage;
608
+ lang?: string;
609
+ }): Promise<BracketResult>;
515
610
  interface MatchByIdResult {
516
611
  match?: Match;
517
612
  degraded: boolean;
@@ -940,4 +1035,66 @@ interface ShareTableInput {
940
1035
  */
941
1036
  declare function formatShareTable(input: ShareTableInput, options?: ShareSnippetOptions): string;
942
1037
 
943
- export { type BuildSignalInput, DEFAULT_COMPETITION, DEFAULT_FLAVOR, DEFAULT_MAX_AGE_MS, EspnAdapter, type EspnAdapterOptions, FLAVOR_LEVELS, FakeMarketProvider, type FakeMarketProviderOptions, type FavoriteStrength, type FlavorLevel, type FormatOpts, type GroupStandings, LIVE_WINDOW_MS, type LedgerRow, type LiveResult, type MapContext, type MarketFavorite, type MarketMapping, type MarketMappingTable, type MarketOutcome, type MarketOutcomeKind, type MarketProvider, type MarketSignal, type MarketSignalOptions, type MarketSignalsResult, type Match, type MatchByIdResult, type MatchEvent, type Outcome, PolymarketProvider, type PolymarketProviderOptions, type ProviderAdapter, type ProviderCapabilities, type PunditPick, SHARE_DISCLAIMER, SHARE_HASHTAG, type ShareSnippetInput, type ShareSnippetOptions, type ShareStyle, type ShareTableInput, type Stage, type StandingRow, type StandingsResult, type Status, type Team, allFixtures, asFlavorLevel, buildMarketSignal, byKickoff, competitionBase, computeStandings, countdown, currentOrNextFixtureForTeam, deriveFavorite, favoriteStrength, fixturesByDate, fixturesByGroup, fixturesByTeam, fixturesInLiveWindow, flagEmoji, formatDate, formatKickoff, formatShareSnippet, formatShareTable, formatTime, getLiveMatches, getMarketSignal, getMarketSignals, getMatchById, getMatchesForDate, getStandings, groups, hasSaneDistribution, isFinished, isFlavorLevel, isLive, isReliableMarketSignal, isStaleSignal, isValidDate, isValidTimeZone, liveSourceLabel, localDate, makeAdapter, makeMarketProvider, mapEspnEvent, mapsCleanly, marketAttributionText, marketBlock, marketFavoriteText, marketFixtureForTeam, marketLine, marketProbabilityText, marketRelevant, marketSourceLabel, matchFlavor, matchLocation, mergeLive, nationToFlag, nationToRegion, nextFixtureForTeam, normalizeOutcomes, outcomeFromScore, parseStandings, resolveCompetition, resolveMarketSource, resolveTz, sanitizeBundledFixture, scoreline, stageLabel };
1038
+ declare function matchKey(stage: Stage, index: number): string;
1039
+ /**
1040
+ * Build and validate bracket topology from knockout fixtures.
1041
+ * Throws when ESPN introduces an unparsed placeholder or the graph is inconsistent.
1042
+ */
1043
+ declare function buildBracketTopology(matches: Match[], generatedAt: string): BracketTopology;
1044
+
1045
+ /**
1046
+ * Parse an ESPN home/away label into a bracket slot reference (name patterns only).
1047
+ * Real nation flags are mapped to `seed` — never `team` — so the bundled schedule
1048
+ * cannot treat ESPN pre-draw labels as confirmed participants.
1049
+ */
1050
+ declare function parseTeamSlot(team: Team): SlotRef | null;
1051
+
1052
+ /**
1053
+ * Resolve the bundled topology against merged knockout matches and standings.
1054
+ * Group slots project only when the group is fully played; winner/loser slots
1055
+ * require a confirmed FT result on the source match.
1056
+ */
1057
+ declare function buildBracketView(topology: BracketTopology, matches: Match[], tables: GroupStandings[], standingsDegraded: boolean, liveDegraded: boolean, filterStage?: string, lang?: string): BracketView;
1058
+
1059
+ /** The bundled knockout bracket topology (generated by gen:schedule). */
1060
+ declare function loadBracketTopology(): BracketTopology;
1061
+
1062
+ interface BracketFormatOpts {
1063
+ flags?: boolean;
1064
+ tz?: string;
1065
+ locale?: string;
1066
+ }
1067
+ /** One bracket match line for list or tree output. */
1068
+ declare function formatBracketMatchLine(mv: BracketMatchView, opts?: BracketFormatOpts): string;
1069
+ /** Staged list view — default bracket renderer. */
1070
+ declare function formatBracketList(view: BracketView, opts?: BracketFormatOpts & {
1071
+ footer?: boolean;
1072
+ }): string;
1073
+ /**
1074
+ * ASCII bracket with stage connectors. Returns null when the terminal is too narrow —
1075
+ * callers should fall back to {@link formatBracketList}.
1076
+ */
1077
+ declare function formatBracketTree(view: BracketView, opts?: BracketFormatOpts & {
1078
+ width?: number;
1079
+ footer?: boolean;
1080
+ }): string | null;
1081
+ interface ShareBracketInput {
1082
+ view: BracketView;
1083
+ source?: string;
1084
+ installLine?: string;
1085
+ emptyNote?: string;
1086
+ }
1087
+ interface ShareBracketOptions {
1088
+ includeHashtag?: boolean;
1089
+ includeInstallLine?: boolean;
1090
+ stage?: Stage;
1091
+ locale?: string;
1092
+ tz?: string;
1093
+ style?: ShareStyle;
1094
+ }
1095
+ /** Plain-text share card for the knockout bracket. */
1096
+ declare function formatShareBracket(input: ShareBracketInput, options?: ShareBracketOptions): string;
1097
+ /** Compact one-line-per-match bracket for narrow share contexts. */
1098
+ declare function formatBracketCompactLine(mv: BracketMatchView, opts?: BracketFormatOpts): string;
1099
+
1100
+ export { BRACKET_STAGE_ORDER, type BracketFormatOpts, type BracketMatchNode, type BracketMatchView, type BracketResult, type BracketTopology, type BracketView, type BuildSignalInput, DEFAULT_COMPETITION, DEFAULT_FLAVOR, DEFAULT_MAX_AGE_MS, EspnAdapter, type EspnAdapterOptions, FLAVOR_LEVELS, FakeMarketProvider, type FakeMarketProviderOptions, type FavoriteStrength, type FlavorLevel, type FormatOpts, type GroupStandings, LIVE_WINDOW_MS, type Lang, type LedgerRow, type LiveResult, type MapContext, type MarketFavorite, type MarketMapping, type MarketMappingTable, type MarketOutcome, type MarketOutcomeKind, type MarketProvider, type MarketSignal, type MarketSignalOptions, type MarketSignalsResult, type Match, type MatchByIdResult, type MatchEvent, type Outcome, PolymarketProvider, type PolymarketProviderOptions, type ProviderAdapter, type ProviderCapabilities, type PunditPick, type ResolvedParticipant, SHARE_DISCLAIMER, SHARE_HASHTAG, type ShareBracketInput, type ShareBracketOptions, type ShareSnippetInput, type ShareSnippetOptions, type ShareStyle, type ShareTableInput, type SlotRef, type Stage, type StandingRow, type StandingsResult, type Status, type Team, allFixtures, asFlavorLevel, buildBracketTopology, buildBracketView, buildMarketSignal, byKickoff, competitionBase, computeStandings, countdown, currentOrNextFixtureForTeam, deriveFavorite, favoriteStrength, fixturesByDate, fixturesByGroup, fixturesByTeam, fixturesInLiveWindow, flagEmoji, formatBracketCompactLine, formatBracketList, formatBracketMatchLine, formatBracketTree, formatDate, formatKickoff, formatShareBracket, formatShareSnippet, formatShareTable, formatTime, getBracket, getLiveMatches, getMarketSignal, getMarketSignals, getMatchById, getMatchesForDate, getStandings, groups, hasSaneDistribution, isFinished, isFlavorLevel, isLive, isReliableMarketSignal, isStaleSignal, isValidDate, isValidTimeZone, liveSourceLabel, loadBracketTopology, localDate, makeAdapter, makeMarketProvider, mapEspnEvent, mapsCleanly, marketAttributionText, marketBlock, marketFavoriteText, marketFixtureForTeam, marketLine, marketProbabilityText, marketRelevant, marketSourceLabel, matchFlavor, matchKey, matchLocation, mergeLive, nationToFlag, nationToRegion, nextFixtureForTeam, normalizeLang, normalizeOutcomes, outcomeFromScore, parseStandings, parseTeamSlot, resolveCompetition, resolveMarketSource, resolveTz, sanitizeBundledFixture, scoreline, stageLabel, stageLabelI18n, t };