fansunited-data-layer 0.5.2 → 0.5.4
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/api/fansunited/http.d.ts.map +1 -1
- package/api/sportal365-sports/football/statistics/index.d.ts.map +1 -1
- package/api/sportal365-sports/football/teams/index.d.ts.map +1 -1
- package/api/sportal365-sports/http.d.ts.map +1 -1
- package/api/sportal365-sports/statistics/index.d.ts.map +1 -1
- package/client.cjs +1 -1
- package/client.js +1 -1
- package/fansunited-data-layer.cjs +1 -1
- package/fansunited-data-layer.js +282 -303
- package/{index-D8MJQXDd.js → index-35LeZQYN.js} +153 -191
- package/index-Hi8oKjxO.cjs +1 -0
- package/package.json +1 -1
- package/index-BWAwKR8L.cjs +0 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
const
|
|
1
|
+
const h = "__FANSUNITED_DATA_LAYER_CONFIG__";
|
|
2
2
|
function de(e) {
|
|
3
|
-
globalThis[
|
|
3
|
+
globalThis[h] = e;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
6
|
-
const e = globalThis[
|
|
5
|
+
function c() {
|
|
6
|
+
const e = globalThis[h];
|
|
7
7
|
if (!e)
|
|
8
8
|
throw new Error("Data layer config not initialized. Call setConfig() in your root layout.");
|
|
9
9
|
return e;
|
|
10
10
|
}
|
|
11
11
|
function ue() {
|
|
12
|
-
return globalThis[
|
|
12
|
+
return globalThis[h] !== void 0;
|
|
13
13
|
}
|
|
14
14
|
function O(e) {
|
|
15
15
|
const t = e.replace(/\/$/, "");
|
|
@@ -25,59 +25,29 @@ function O(e) {
|
|
|
25
25
|
}
|
|
26
26
|
return {
|
|
27
27
|
async get(s) {
|
|
28
|
-
const a = s.config ||
|
|
28
|
+
const a = s.config || c(), { sportal365Sports: u } = a;
|
|
29
29
|
if (!u)
|
|
30
30
|
throw new Error("Sportal365 Sports API configuration is missing");
|
|
31
|
-
const
|
|
31
|
+
const d = new URL(n(s.path));
|
|
32
32
|
if (s.params)
|
|
33
|
-
for (const [
|
|
34
|
-
|
|
35
|
-
const f = {
|
|
36
|
-
Authorization: o(a),
|
|
37
|
-
"Content-Type": "application/json",
|
|
38
|
-
"X-Project": u.projectId,
|
|
39
|
-
// Merge custom headers (they can override defaults)
|
|
40
|
-
...s.headers
|
|
41
|
-
};
|
|
42
|
-
console.log("[Sportal365 HTTP] Making request:", {
|
|
43
|
-
url: r.toString(),
|
|
33
|
+
for (const [l, g] of Object.entries(s.params))
|
|
34
|
+
g !== void 0 && (Array.isArray(g) ? g.length > 0 && d.searchParams.set(l, g.join(",")) : d.searchParams.set(l, g));
|
|
35
|
+
const f = await fetch(d.toString(), {
|
|
44
36
|
method: "GET",
|
|
45
37
|
headers: {
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
Authorization: o(a),
|
|
39
|
+
"Content-Type": "application/json",
|
|
40
|
+
"X-Project": u.projectId,
|
|
41
|
+
// Merge custom headers (they can override defaults)
|
|
42
|
+
...s.headers
|
|
48
43
|
},
|
|
49
|
-
params: s.params
|
|
50
|
-
});
|
|
51
|
-
const c = await fetch(r.toString(), {
|
|
52
|
-
method: "GET",
|
|
53
|
-
headers: f,
|
|
54
44
|
signal: u.timeout ? AbortSignal.timeout(u.timeout) : void 0,
|
|
55
45
|
// Next.js cache options for ISR/on-demand revalidation
|
|
56
46
|
...s.next && { next: s.next }
|
|
57
47
|
});
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
statusText: c.statusText,
|
|
62
|
-
ok: c.ok,
|
|
63
|
-
headers: Object.fromEntries(c.headers.entries())
|
|
64
|
-
}), !c.ok) {
|
|
65
|
-
const y = `Sportal365 API error: ${c.status} ${c.statusText}`;
|
|
66
|
-
throw console.error("[Sportal365 HTTP] Request failed:", {
|
|
67
|
-
url: r.toString(),
|
|
68
|
-
status: c.status,
|
|
69
|
-
statusText: c.statusText
|
|
70
|
-
}), new Error(y);
|
|
71
|
-
}
|
|
72
|
-
const l = await c.json();
|
|
73
|
-
return console.log("[Sportal365 HTTP] Response data:", {
|
|
74
|
-
url: r.toString(),
|
|
75
|
-
dataType: typeof l,
|
|
76
|
-
isArray: Array.isArray(l),
|
|
77
|
-
hasData: !!l,
|
|
78
|
-
keys: typeof l == "object" && l !== null ? Object.keys(l) : void 0,
|
|
79
|
-
data: l
|
|
80
|
-
}), l;
|
|
48
|
+
if (!f.ok)
|
|
49
|
+
throw new Error(`Sportal365 API error: ${f.status} ${f.statusText}`);
|
|
50
|
+
return f.json();
|
|
81
51
|
}
|
|
82
52
|
};
|
|
83
53
|
}
|
|
@@ -121,7 +91,7 @@ const R = {
|
|
|
121
91
|
PENALTY_MISSED: "PENALTY_MISSED",
|
|
122
92
|
PENALTY_SAVED: "PENALTY_SAVED"
|
|
123
93
|
};
|
|
124
|
-
function
|
|
94
|
+
function _(e) {
|
|
125
95
|
const t = R[e.type_code];
|
|
126
96
|
return t ? {
|
|
127
97
|
id: e.id,
|
|
@@ -185,7 +155,7 @@ function D(e) {
|
|
|
185
155
|
type: e.type
|
|
186
156
|
};
|
|
187
157
|
}
|
|
188
|
-
function
|
|
158
|
+
function T(e) {
|
|
189
159
|
return {
|
|
190
160
|
id: e.id,
|
|
191
161
|
name: e.name,
|
|
@@ -223,7 +193,7 @@ function N(e) {
|
|
|
223
193
|
extraTimeSecondHalfStartedAt: e.extra_time_second_half_started_at ? new Date(e.extra_time_second_half_started_at) : void 0
|
|
224
194
|
};
|
|
225
195
|
}
|
|
226
|
-
function
|
|
196
|
+
function F(e) {
|
|
227
197
|
if (!e) return;
|
|
228
198
|
const t = (n) => n ? { competitorOne: String(n.home), competitorTwo: String(n.away) } : void 0, o = e.after_extra_time ?? e.regular_time;
|
|
229
199
|
return {
|
|
@@ -239,7 +209,7 @@ function x(e) {
|
|
|
239
209
|
}
|
|
240
210
|
};
|
|
241
211
|
}
|
|
242
|
-
function
|
|
212
|
+
function x(e) {
|
|
243
213
|
if (e)
|
|
244
214
|
return {
|
|
245
215
|
id: e.id,
|
|
@@ -289,7 +259,7 @@ function M(e) {
|
|
|
289
259
|
providerRef: i(t.uuid)
|
|
290
260
|
};
|
|
291
261
|
}
|
|
292
|
-
function
|
|
262
|
+
function $(e) {
|
|
293
263
|
if (!e.winner?.match?.id) return;
|
|
294
264
|
const t = {
|
|
295
265
|
"Regular Time": "REGULAR_TIME",
|
|
@@ -302,14 +272,14 @@ function H(e) {
|
|
|
302
272
|
aggregate: !!e.winner.aggregate
|
|
303
273
|
};
|
|
304
274
|
}
|
|
305
|
-
function
|
|
275
|
+
function E(e) {
|
|
306
276
|
return {
|
|
307
277
|
id: e.id,
|
|
308
278
|
slug: e.slug,
|
|
309
279
|
status: D(e.status),
|
|
310
280
|
timing: N(e),
|
|
311
|
-
competitorOne:
|
|
312
|
-
competitorTwo:
|
|
281
|
+
competitorOne: T(e.home_team),
|
|
282
|
+
competitorTwo: T(e.away_team),
|
|
313
283
|
competition: M(e),
|
|
314
284
|
round: e.round ? {
|
|
315
285
|
id: e.round.id ?? e.round.key,
|
|
@@ -323,19 +293,19 @@ function k(e) {
|
|
|
323
293
|
name: e.group.name,
|
|
324
294
|
providerRef: i(e.group.uuid)
|
|
325
295
|
} : void 0,
|
|
326
|
-
venue:
|
|
296
|
+
venue: x(e.venue),
|
|
327
297
|
officials: P(e.referees),
|
|
328
298
|
spectators: e.spectators ?? void 0,
|
|
329
|
-
score:
|
|
330
|
-
mainEvents: e.main_events?.map(
|
|
331
|
-
penaltyShootoutEvents: e.penalty_shootout_events?.map(
|
|
332
|
-
winner:
|
|
299
|
+
score: F(e.score),
|
|
300
|
+
mainEvents: e.main_events?.map(_).filter((t) => t !== null),
|
|
301
|
+
penaltyShootoutEvents: e.penalty_shootout_events?.map(_).filter((t) => t !== null),
|
|
302
|
+
winner: $(e),
|
|
333
303
|
coverage: e.coverage === "NOT_LIVE" ? "UNKNOWN" : e.coverage,
|
|
334
304
|
lineupStatus: e.lineup_status === "UNCONFIRMED" ? "EXPECTED" : e.lineup_status,
|
|
335
305
|
providerRef: i(e.uuid)
|
|
336
306
|
};
|
|
337
307
|
}
|
|
338
|
-
function
|
|
308
|
+
function H(e) {
|
|
339
309
|
const t = e.player;
|
|
340
310
|
return {
|
|
341
311
|
id: t.id,
|
|
@@ -360,14 +330,14 @@ function $(e) {
|
|
|
360
330
|
photo: t.assets.thumb?.url,
|
|
361
331
|
photoTransparent: t.assets.thumb_transparent_background?.url
|
|
362
332
|
} : void 0,
|
|
363
|
-
events: e.events?.map(
|
|
333
|
+
events: e.events?.map(_).filter((o) => o !== null),
|
|
364
334
|
providerRef: i(t.uuid)
|
|
365
335
|
};
|
|
366
336
|
}
|
|
367
|
-
function
|
|
337
|
+
function b(e) {
|
|
368
338
|
const t = [], o = [];
|
|
369
339
|
for (const n of e.players) {
|
|
370
|
-
const s =
|
|
340
|
+
const s = H(n);
|
|
371
341
|
n.type.category === "start" ? t.push(s) : n.type.category === "sub" && o.push(s);
|
|
372
342
|
}
|
|
373
343
|
return {
|
|
@@ -390,12 +360,12 @@ function A(e) {
|
|
|
390
360
|
substitutes: o
|
|
391
361
|
};
|
|
392
362
|
}
|
|
393
|
-
function
|
|
363
|
+
function Y(e) {
|
|
394
364
|
return {
|
|
395
365
|
matchId: e.match_id,
|
|
396
366
|
confirmed: e.status === "CONFIRMED",
|
|
397
|
-
competitorOne:
|
|
398
|
-
competitorTwo:
|
|
367
|
+
competitorOne: b(e.home_team),
|
|
368
|
+
competitorTwo: b(e.away_team)
|
|
399
369
|
};
|
|
400
370
|
}
|
|
401
371
|
function m(e, t, o, n) {
|
|
@@ -422,7 +392,7 @@ function I(e, t) {
|
|
|
422
392
|
statistics: n.filter((s) => s !== null)
|
|
423
393
|
};
|
|
424
394
|
}
|
|
425
|
-
function
|
|
395
|
+
function U(e) {
|
|
426
396
|
const t = e.find((n) => n.home_team), o = e.find((n) => !n.home_team);
|
|
427
397
|
if (!t || !o)
|
|
428
398
|
throw new Error("Missing competitor statistics");
|
|
@@ -431,7 +401,7 @@ function Y(e) {
|
|
|
431
401
|
competitorTwo: I(String(o.team.id), o.statistics)
|
|
432
402
|
};
|
|
433
403
|
}
|
|
434
|
-
function
|
|
404
|
+
function q(e) {
|
|
435
405
|
const t = e.urls?.find((o) => o.app_type === "desktop")?.url;
|
|
436
406
|
return {
|
|
437
407
|
id: e.id,
|
|
@@ -444,7 +414,7 @@ function U(e) {
|
|
|
444
414
|
url: t
|
|
445
415
|
};
|
|
446
416
|
}
|
|
447
|
-
function
|
|
417
|
+
function W(e) {
|
|
448
418
|
return {
|
|
449
419
|
type: {
|
|
450
420
|
id: e.type.id,
|
|
@@ -456,16 +426,16 @@ function j(e) {
|
|
|
456
426
|
type: e.scope.type,
|
|
457
427
|
name: e.scope.name
|
|
458
428
|
},
|
|
459
|
-
selections: e.selections.map(
|
|
429
|
+
selections: e.selections.map(q)
|
|
460
430
|
};
|
|
461
431
|
}
|
|
462
|
-
function
|
|
432
|
+
function j(e) {
|
|
463
433
|
if (!e) return !0;
|
|
464
434
|
const t = e.replace("#", ""), o = parseInt(t.substring(0, 2), 16), n = parseInt(t.substring(2, 4), 16), s = parseInt(t.substring(4, 6), 16);
|
|
465
435
|
return (0.2126 * o + 0.7152 * n + 0.0722 * s) / 255 < 0.5;
|
|
466
436
|
}
|
|
467
437
|
function G(e) {
|
|
468
|
-
const t = e.bookmaker.assets?.[0], o = e.bookmaker.branding || t, n = e.bookmaker.branding?.background_color || t?.background_color, s = e.bookmaker.branding?.text_color || (
|
|
438
|
+
const t = e.bookmaker.assets?.[0], o = e.bookmaker.branding || t, n = e.bookmaker.branding?.background_color || t?.background_color, s = e.bookmaker.branding?.text_color || (j(n) ? "#FFFFFF" : "#000000");
|
|
469
439
|
return {
|
|
470
440
|
operator: {
|
|
471
441
|
id: e.bookmaker.id,
|
|
@@ -478,7 +448,7 @@ function G(e) {
|
|
|
478
448
|
} : void 0
|
|
479
449
|
},
|
|
480
450
|
type: e.type,
|
|
481
|
-
markets: e.markets.map(
|
|
451
|
+
markets: e.markets.map(W)
|
|
482
452
|
};
|
|
483
453
|
}
|
|
484
454
|
function K(e, t) {
|
|
@@ -487,7 +457,7 @@ function K(e, t) {
|
|
|
487
457
|
operators: t.map(G)
|
|
488
458
|
};
|
|
489
459
|
}
|
|
490
|
-
function
|
|
460
|
+
function A(e) {
|
|
491
461
|
if (e == null || e === "")
|
|
492
462
|
return;
|
|
493
463
|
const t = typeof e == "number" ? e : parseInt(e, 10);
|
|
@@ -496,8 +466,8 @@ function E(e) {
|
|
|
496
466
|
function V(e) {
|
|
497
467
|
return {
|
|
498
468
|
externalId: e.external_id,
|
|
499
|
-
minute:
|
|
500
|
-
addedTime:
|
|
469
|
+
minute: A(e.elapsed),
|
|
470
|
+
addedTime: A(e.elapsed_plus),
|
|
501
471
|
text: e.auto_text,
|
|
502
472
|
details: e.details,
|
|
503
473
|
meta: {
|
|
@@ -510,7 +480,7 @@ function V(e) {
|
|
|
510
480
|
};
|
|
511
481
|
}
|
|
512
482
|
async function pe(e, t, o) {
|
|
513
|
-
const n = o ||
|
|
483
|
+
const n = o || c(), { sportal365Sports: s } = n, a = await p.get({
|
|
514
484
|
path: `/v2/matches/${e}`,
|
|
515
485
|
params: {
|
|
516
486
|
language_code: t?.languageCode ?? s?.languageCode ?? "en",
|
|
@@ -528,10 +498,10 @@ async function pe(e, t, o) {
|
|
|
528
498
|
next: t?.next,
|
|
529
499
|
config: n
|
|
530
500
|
});
|
|
531
|
-
return
|
|
501
|
+
return E(a);
|
|
532
502
|
}
|
|
533
503
|
async function fe(e, t, o) {
|
|
534
|
-
const n = o ||
|
|
504
|
+
const n = o || c(), { sportal365Sports: s } = n;
|
|
535
505
|
return (await p.get({
|
|
536
506
|
path: `/v2/matches/${e}/events`,
|
|
537
507
|
params: {
|
|
@@ -542,10 +512,10 @@ async function fe(e, t, o) {
|
|
|
542
512
|
},
|
|
543
513
|
next: t?.next,
|
|
544
514
|
config: n
|
|
545
|
-
})).events.map(
|
|
515
|
+
})).events.map(_).filter((u) => u !== null);
|
|
546
516
|
}
|
|
547
|
-
async function
|
|
548
|
-
const n = o ||
|
|
517
|
+
async function _e(e, t, o) {
|
|
518
|
+
const n = o || c(), { sportal365Sports: s } = n, a = await p.get({
|
|
549
519
|
path: `/v2/matches/${e}/lineups`,
|
|
550
520
|
params: {
|
|
551
521
|
language_code: t?.languageCode ?? s?.languageCode ?? "en"
|
|
@@ -556,10 +526,10 @@ async function ye(e, t, o) {
|
|
|
556
526
|
next: t?.next,
|
|
557
527
|
config: n
|
|
558
528
|
});
|
|
559
|
-
return
|
|
529
|
+
return Y(a);
|
|
560
530
|
}
|
|
561
|
-
async function
|
|
562
|
-
const n = o ||
|
|
531
|
+
async function ye(e, t, o) {
|
|
532
|
+
const n = o || c(), { sportal365Sports: s } = n, a = await p.get({
|
|
563
533
|
path: `/v2/matches/${e}`,
|
|
564
534
|
params: {
|
|
565
535
|
language_code: t?.languageCode ?? s?.languageCode ?? "en",
|
|
@@ -579,7 +549,7 @@ async function _e(e, t, o) {
|
|
|
579
549
|
return K(e, a.odds ?? []);
|
|
580
550
|
}
|
|
581
551
|
async function he(e, t, o) {
|
|
582
|
-
const n = o ||
|
|
552
|
+
const n = o || c(), { sportal365Sports: s } = n, a = await p.get({
|
|
583
553
|
path: `/events/${e}/teamstats`,
|
|
584
554
|
params: {
|
|
585
555
|
language_code: t?.languageCode ?? s?.languageCode ?? "en"
|
|
@@ -590,10 +560,10 @@ async function he(e, t, o) {
|
|
|
590
560
|
next: t?.next,
|
|
591
561
|
config: n
|
|
592
562
|
});
|
|
593
|
-
return
|
|
563
|
+
return U(a);
|
|
594
564
|
}
|
|
595
565
|
async function ve(e, t, o) {
|
|
596
|
-
const n = o ||
|
|
566
|
+
const n = o || c(), { sportal365Sports: s } = n;
|
|
597
567
|
return (await p.get({
|
|
598
568
|
path: `/matches/${e}/commentary`,
|
|
599
569
|
params: {
|
|
@@ -607,7 +577,7 @@ async function ve(e, t, o) {
|
|
|
607
577
|
})).map(V);
|
|
608
578
|
}
|
|
609
579
|
async function Se(e, t) {
|
|
610
|
-
const o = t ||
|
|
580
|
+
const o = t || c(), { sportal365Sports: n } = o;
|
|
611
581
|
return (await p.get({
|
|
612
582
|
path: "/v2/matches",
|
|
613
583
|
params: {
|
|
@@ -649,7 +619,7 @@ async function Se(e, t) {
|
|
|
649
619
|
},
|
|
650
620
|
next: e.next,
|
|
651
621
|
config: o
|
|
652
|
-
})).matches.map(
|
|
622
|
+
})).matches.map(E);
|
|
653
623
|
}
|
|
654
624
|
function B(e) {
|
|
655
625
|
return {
|
|
@@ -756,7 +726,7 @@ function B(e) {
|
|
|
756
726
|
form: e.form && e.form.length > 0 ? {
|
|
757
727
|
competitorId: e.id,
|
|
758
728
|
results: e.form.map((t) => {
|
|
759
|
-
const n = t.participants[0].id === e.uuid ? t.participants[1] : t.participants[0], s = t.result[0]?.results.find((
|
|
729
|
+
const n = t.participants[0].id === e.uuid ? t.participants[1] : t.participants[0], s = t.result[0]?.results.find((d) => d.position === "1")?.value, a = t.result[0]?.results.find((d) => d.position === "2")?.value, u = t.outcome === "win" ? "W" : t.outcome === "draw" ? "D" : "L";
|
|
760
730
|
return {
|
|
761
731
|
matchId: t.id,
|
|
762
732
|
result: u,
|
|
@@ -778,7 +748,7 @@ function B(e) {
|
|
|
778
748
|
providerRef: i(e.uuid)
|
|
779
749
|
};
|
|
780
750
|
}
|
|
781
|
-
function
|
|
751
|
+
function X(e) {
|
|
782
752
|
const t = e.player;
|
|
783
753
|
return {
|
|
784
754
|
id: t.id,
|
|
@@ -811,7 +781,7 @@ function z(e) {
|
|
|
811
781
|
// Using player.id as provider reference
|
|
812
782
|
};
|
|
813
783
|
}
|
|
814
|
-
function
|
|
784
|
+
function z(e) {
|
|
815
785
|
return {
|
|
816
786
|
id: e.id,
|
|
817
787
|
name: e.name,
|
|
@@ -831,15 +801,15 @@ function J(e) {
|
|
|
831
801
|
return {
|
|
832
802
|
teamId: e.team.id,
|
|
833
803
|
teamName: e.team.name,
|
|
834
|
-
coach: e.coach ?
|
|
835
|
-
players: e.players.map(
|
|
804
|
+
coach: e.coach ? z(e.coach) : void 0,
|
|
805
|
+
players: e.players.map(X)
|
|
836
806
|
};
|
|
837
807
|
}
|
|
838
808
|
function Q(e) {
|
|
839
809
|
const t = parseInt(e, 10);
|
|
840
810
|
return isNaN(t) ? void 0 : t;
|
|
841
811
|
}
|
|
842
|
-
function
|
|
812
|
+
function r(e, t) {
|
|
843
813
|
const o = e.find((n) => n.name === t);
|
|
844
814
|
return o ? Q(o.value) : void 0;
|
|
845
815
|
}
|
|
@@ -850,37 +820,37 @@ function Z(e, t) {
|
|
|
850
820
|
seasonId: e.season.id,
|
|
851
821
|
teamId: t,
|
|
852
822
|
// Core statistics
|
|
853
|
-
appearances:
|
|
854
|
-
started:
|
|
855
|
-
substituteIn:
|
|
856
|
-
substituteOut:
|
|
857
|
-
minutes:
|
|
858
|
-
minutesSubstitute:
|
|
823
|
+
appearances: r(o, "played"),
|
|
824
|
+
started: r(o, "started"),
|
|
825
|
+
substituteIn: r(o, "substitute_in"),
|
|
826
|
+
substituteOut: r(o, "substitute_out"),
|
|
827
|
+
minutes: r(o, "minutes"),
|
|
828
|
+
minutesSubstitute: r(o, "minutes_substitute"),
|
|
859
829
|
// Scoring
|
|
860
|
-
goals:
|
|
861
|
-
goalsSubstitute:
|
|
862
|
-
penaltyGoals:
|
|
863
|
-
ownGoals:
|
|
864
|
-
assists:
|
|
830
|
+
goals: r(o, "goals"),
|
|
831
|
+
goalsSubstitute: r(o, "goals_substitute"),
|
|
832
|
+
penaltyGoals: r(o, "penalty_goals"),
|
|
833
|
+
ownGoals: r(o, "own_goals"),
|
|
834
|
+
assists: r(o, "assists"),
|
|
865
835
|
// Shooting
|
|
866
|
-
shots:
|
|
867
|
-
shotsOnTarget:
|
|
836
|
+
shots: r(o, "shots"),
|
|
837
|
+
shotsOnTarget: r(o, "shots_on_target"),
|
|
868
838
|
// Discipline
|
|
869
|
-
yellowCards:
|
|
870
|
-
redCards:
|
|
871
|
-
foulsCommitted:
|
|
872
|
-
penaltiesCommitted:
|
|
839
|
+
yellowCards: r(o, "yellow_cards"),
|
|
840
|
+
redCards: r(o, "red_cards"),
|
|
841
|
+
foulsCommitted: r(o, "fouls_committed"),
|
|
842
|
+
penaltiesCommitted: r(o, "penalties_committed"),
|
|
873
843
|
// Penalties
|
|
874
|
-
penaltiesMissed:
|
|
844
|
+
penaltiesMissed: r(o, "penalties_missed"),
|
|
875
845
|
// Defensive
|
|
876
|
-
cleansheets:
|
|
846
|
+
cleansheets: r(o, "cleansheets"),
|
|
877
847
|
// Goalkeeper-specific
|
|
878
|
-
saves:
|
|
879
|
-
conceded:
|
|
880
|
-
caughtBall:
|
|
881
|
-
penaltiesReceived:
|
|
848
|
+
saves: r(o, "saves"),
|
|
849
|
+
conceded: r(o, "conceded"),
|
|
850
|
+
caughtBall: r(o, "caught_ball"),
|
|
851
|
+
penaltiesReceived: r(o, "penalties_received"),
|
|
882
852
|
// Other
|
|
883
|
-
offsides:
|
|
853
|
+
offsides: r(o, "offsides"),
|
|
884
854
|
// Raw statistics array (for any additional stats not mapped above)
|
|
885
855
|
rawStatistics: o.map((n) => ({
|
|
886
856
|
name: n.name,
|
|
@@ -889,43 +859,44 @@ function Z(e, t) {
|
|
|
889
859
|
};
|
|
890
860
|
}
|
|
891
861
|
async function w(e, t) {
|
|
892
|
-
const o = t ||
|
|
862
|
+
const o = t || c(), { sportal365Sports: n } = o, { seasonIds: s, teamId: a, languageCode: u, next: d } = e, f = d ?? { revalidate: 120 }, l = {
|
|
893
863
|
season_ids: s.join(","),
|
|
894
864
|
team_id: a,
|
|
895
865
|
language_code: u ?? n?.languageCode ?? "en"
|
|
896
|
-
}
|
|
897
|
-
console.log("[getFootballPlayerSeasonStatistics] Fetching player statistics:", {
|
|
866
|
+
}, g = await p.get({
|
|
898
867
|
path: "/v2/statistics/players/season",
|
|
899
|
-
params:
|
|
900
|
-
teamId: a,
|
|
901
|
-
seasonIds: s
|
|
902
|
-
});
|
|
903
|
-
const l = await p.get({
|
|
904
|
-
path: "/v2/statistics/players/season",
|
|
905
|
-
params: c,
|
|
868
|
+
params: l,
|
|
906
869
|
headers: {
|
|
907
870
|
"Accept-Language": u ?? n?.languageCode ?? "en"
|
|
908
871
|
},
|
|
909
872
|
next: f,
|
|
910
873
|
config: o
|
|
911
874
|
});
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
875
|
+
if (!g.statistics)
|
|
876
|
+
return console.error("[getFootballPlayerSeasonStatistics] Invalid API response - missing statistics array:", {
|
|
877
|
+
teamId: a,
|
|
878
|
+
seasonIds: s,
|
|
879
|
+
response: g
|
|
880
|
+
}), {};
|
|
881
|
+
if (g.statistics.length === 0)
|
|
882
|
+
return console.warn("[getFootballPlayerSeasonStatistics] API returned empty statistics array:", {
|
|
883
|
+
teamId: a,
|
|
884
|
+
seasonIds: s,
|
|
885
|
+
hint: "This could be due to: wrong credentials, wrong project header, no data for this team/season, or API issue"
|
|
886
|
+
}), {};
|
|
916
887
|
const y = {};
|
|
917
|
-
for (const
|
|
918
|
-
const
|
|
919
|
-
y[
|
|
920
|
-
playerId: v,
|
|
921
|
-
playerName: _.player.name,
|
|
922
|
-
hasStats: !!y[v]
|
|
923
|
-
});
|
|
888
|
+
for (const S of g.statistics) {
|
|
889
|
+
const k = S.player.id;
|
|
890
|
+
y[k] = Z(S, a);
|
|
924
891
|
}
|
|
925
|
-
return console.log(
|
|
892
|
+
return console.log(
|
|
893
|
+
"[getFootballPlayerSeasonStatistics] Successfully fetched statistics for",
|
|
894
|
+
Object.keys(y).length,
|
|
895
|
+
"players"
|
|
896
|
+
), y;
|
|
926
897
|
}
|
|
927
|
-
async function
|
|
928
|
-
const n = o ||
|
|
898
|
+
async function Ce(e, t, o) {
|
|
899
|
+
const n = o || c(), { sportal365Sports: s } = n, a = await p.get({
|
|
929
900
|
path: `/v2/teams/${e}`,
|
|
930
901
|
params: {
|
|
931
902
|
language_code: t?.languageCode ?? s?.languageCode ?? "en",
|
|
@@ -939,10 +910,8 @@ async function Te(e, t, o) {
|
|
|
939
910
|
});
|
|
940
911
|
return B(a);
|
|
941
912
|
}
|
|
942
|
-
async function
|
|
943
|
-
const n = o ||
|
|
944
|
-
console.log("[getFootballTeamSquad] Fetching squad for team:", e, "with options:", t);
|
|
945
|
-
const a = await p.get({
|
|
913
|
+
async function Te(e, t, o) {
|
|
914
|
+
const n = o || c(), { sportal365Sports: s } = n, a = await p.get({
|
|
946
915
|
path: `/v2/teams/${e}/squad`,
|
|
947
916
|
params: {
|
|
948
917
|
language_code: t?.languageCode ?? s?.languageCode ?? "en",
|
|
@@ -953,18 +922,11 @@ async function Ce(e, t, o) {
|
|
|
953
922
|
},
|
|
954
923
|
next: t?.next,
|
|
955
924
|
config: n
|
|
956
|
-
});
|
|
957
|
-
console.log("[getFootballTeamSquad] Squad API response:", {
|
|
958
|
-
teamId: a.team?.id,
|
|
959
|
-
teamName: a.team?.name,
|
|
960
|
-
playerCount: a.players?.length,
|
|
961
|
-
hasCoach: !!a.coach
|
|
962
|
-
});
|
|
963
|
-
const u = J(a);
|
|
925
|
+
}), u = J(a);
|
|
964
926
|
if (t?.seasonIds && t.seasonIds.length > 0) {
|
|
965
927
|
console.log("[getFootballTeamSquad] Fetching player statistics for seasonIds:", t.seasonIds);
|
|
966
928
|
try {
|
|
967
|
-
const
|
|
929
|
+
const d = await w(
|
|
968
930
|
{
|
|
969
931
|
seasonIds: t.seasonIds,
|
|
970
932
|
teamId: e,
|
|
@@ -973,30 +935,30 @@ async function Ce(e, t, o) {
|
|
|
973
935
|
},
|
|
974
936
|
n
|
|
975
937
|
);
|
|
976
|
-
console.log("[getFootballTeamSquad] Player
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
938
|
+
console.log("[getFootballTeamSquad] Received stats map with", Object.keys(d).length, "players"), console.log("[getFootballTeamSquad] Player IDs in stats:", Object.keys(d)), console.log(
|
|
939
|
+
"[getFootballTeamSquad] Player IDs in squad:",
|
|
940
|
+
u.players.map((l) => l.id)
|
|
941
|
+
);
|
|
980
942
|
let f = 0;
|
|
981
|
-
for (const
|
|
982
|
-
const
|
|
983
|
-
|
|
943
|
+
for (const l of u.players) {
|
|
944
|
+
const g = d[l.id];
|
|
945
|
+
g ? (l.seasonStatistics = g, f++, console.log("[getFootballTeamSquad] ✓ Attached stats to player:", l.id, l.name)) : console.log("[getFootballTeamSquad] ✗ No stats found for player:", l.id, l.name);
|
|
984
946
|
}
|
|
985
|
-
console.log("[getFootballTeamSquad]
|
|
947
|
+
console.log("[getFootballTeamSquad] Stats attachment complete:", {
|
|
986
948
|
totalPlayers: u.players.length,
|
|
987
949
|
playersWithStats: f,
|
|
988
950
|
playersWithoutStats: u.players.length - f
|
|
989
951
|
});
|
|
990
|
-
} catch (
|
|
952
|
+
} catch (d) {
|
|
991
953
|
console.error("[getFootballTeamSquad] Failed to fetch player statistics:", {
|
|
992
|
-
error:
|
|
993
|
-
stack:
|
|
954
|
+
error: d instanceof Error ? d.message : String(d),
|
|
955
|
+
stack: d instanceof Error ? d.stack : void 0,
|
|
994
956
|
teamId: e,
|
|
995
957
|
seasonIds: t.seasonIds
|
|
996
958
|
});
|
|
997
959
|
}
|
|
998
960
|
} else
|
|
999
|
-
console.log("[getFootballTeamSquad] No seasonIds provided, skipping
|
|
961
|
+
console.log("[getFootballTeamSquad] No seasonIds provided, skipping stats fetch");
|
|
1000
962
|
return u;
|
|
1001
963
|
}
|
|
1002
964
|
function ee(e) {
|
|
@@ -1084,7 +1046,7 @@ function oe(e) {
|
|
|
1084
1046
|
};
|
|
1085
1047
|
}
|
|
1086
1048
|
async function be(e, t, o) {
|
|
1087
|
-
const n = o ||
|
|
1049
|
+
const n = o || c(), { sportal365Sports: s } = n, a = await p.get({
|
|
1088
1050
|
path: `/tournaments/${e}`,
|
|
1089
1051
|
params: {
|
|
1090
1052
|
language_code: t?.languageCode ?? s?.languageCode ?? "en"
|
|
@@ -1097,8 +1059,8 @@ async function be(e, t, o) {
|
|
|
1097
1059
|
});
|
|
1098
1060
|
return ee(a);
|
|
1099
1061
|
}
|
|
1100
|
-
async function
|
|
1101
|
-
const o = t ||
|
|
1062
|
+
async function Ie(e, t) {
|
|
1063
|
+
const o = t || c(), { sportal365Sports: n } = o;
|
|
1102
1064
|
if (!e?.seasonId && !e?.competitionId)
|
|
1103
1065
|
throw new Error("Either seasonId or competitionId must be provided");
|
|
1104
1066
|
const s = {
|
|
@@ -1116,7 +1078,7 @@ async function Ae(e, t) {
|
|
|
1116
1078
|
});
|
|
1117
1079
|
return oe(a);
|
|
1118
1080
|
}
|
|
1119
|
-
function
|
|
1081
|
+
function v(e) {
|
|
1120
1082
|
return {
|
|
1121
1083
|
championsleague: "championsLeague",
|
|
1122
1084
|
europaleague: "europaLeague",
|
|
@@ -1134,16 +1096,16 @@ function se(e, t) {
|
|
|
1134
1096
|
if (!t || t.length === 0)
|
|
1135
1097
|
return;
|
|
1136
1098
|
const o = t.map((s) => {
|
|
1137
|
-
const a = s.event, u = a.home_team.id === e,
|
|
1099
|
+
const a = s.event, u = a.home_team.id === e, d = u ? a.away_team : a.home_team, f = `${a.goal_home}-${a.goal_away}`;
|
|
1138
1100
|
return {
|
|
1139
1101
|
matchId: a.id.toString(),
|
|
1140
1102
|
result: s.outcome,
|
|
1141
1103
|
score: f,
|
|
1142
1104
|
homeAway: u ? "HOME" : "AWAY",
|
|
1143
1105
|
opponent: {
|
|
1144
|
-
id:
|
|
1145
|
-
name:
|
|
1146
|
-
logo:
|
|
1106
|
+
id: d.id.toString(),
|
|
1107
|
+
name: d.name,
|
|
1108
|
+
logo: d.url_logo
|
|
1147
1109
|
},
|
|
1148
1110
|
date: new Date(a.start_time),
|
|
1149
1111
|
competition: void 0
|
|
@@ -1158,7 +1120,7 @@ function se(e, t) {
|
|
|
1158
1120
|
}
|
|
1159
1121
|
function ae(e) {
|
|
1160
1122
|
return {
|
|
1161
|
-
key:
|
|
1123
|
+
key: v(e.code),
|
|
1162
1124
|
name: e.name,
|
|
1163
1125
|
position: ne(e.type)
|
|
1164
1126
|
};
|
|
@@ -1173,7 +1135,7 @@ function ie(e) {
|
|
|
1173
1135
|
goalsAgainst: e.goals_against,
|
|
1174
1136
|
goalDifference: e.goals_for - e.goals_against,
|
|
1175
1137
|
points: e.points
|
|
1176
|
-
}, o = e.rules?.length > 0 ? e.rules.map((s) =>
|
|
1138
|
+
}, o = e.rules?.length > 0 ? e.rules.map((s) => v(s.code)) : void 0, n = se(e.team.id, e.team.form ?? []);
|
|
1177
1139
|
return {
|
|
1178
1140
|
rank: e.rank,
|
|
1179
1141
|
competitor: {
|
|
@@ -1192,7 +1154,7 @@ function re(e) {
|
|
|
1192
1154
|
for (const n of e)
|
|
1193
1155
|
if (n.rules)
|
|
1194
1156
|
for (const s of n.rules) {
|
|
1195
|
-
const a =
|
|
1157
|
+
const a = v(s.code);
|
|
1196
1158
|
o.has(a) || o.set(a, ae(s));
|
|
1197
1159
|
}
|
|
1198
1160
|
return {
|
|
@@ -1202,8 +1164,8 @@ function re(e) {
|
|
|
1202
1164
|
}
|
|
1203
1165
|
};
|
|
1204
1166
|
}
|
|
1205
|
-
async function
|
|
1206
|
-
const o = t ||
|
|
1167
|
+
async function Ae(e, t) {
|
|
1168
|
+
const o = t || c(), { sportal365Sports: n } = o, s = e.expand?.join(","), a = await p.get({
|
|
1207
1169
|
path: `/tournaments/seasons/stages/${e.stageId}/standing`,
|
|
1208
1170
|
params: {
|
|
1209
1171
|
expand: s,
|
|
@@ -1225,18 +1187,18 @@ export {
|
|
|
1225
1187
|
be as d,
|
|
1226
1188
|
pe as e,
|
|
1227
1189
|
p as f,
|
|
1228
|
-
g,
|
|
1190
|
+
c as g,
|
|
1229
1191
|
ve as h,
|
|
1230
1192
|
fe as i,
|
|
1231
|
-
|
|
1232
|
-
|
|
1193
|
+
_e as j,
|
|
1194
|
+
ye as k,
|
|
1233
1195
|
he as l,
|
|
1234
1196
|
Se as m,
|
|
1235
1197
|
w as n,
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1198
|
+
Ie as o,
|
|
1199
|
+
Ae as p,
|
|
1200
|
+
Ce as q,
|
|
1201
|
+
Te as r,
|
|
1240
1202
|
ge as s,
|
|
1241
1203
|
i as t,
|
|
1242
1204
|
ue as u,
|