fansunited-data-layer 0.0.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.
package/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # React + TypeScript + Vite
2
+
3
+ This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
+
5
+ Currently, two official plugins are available:
6
+
7
+ - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
8
+ - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9
+
10
+ ## React Compiler
11
+
12
+ The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
13
+
14
+ ## Expanding the ESLint configuration
15
+
16
+ If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
17
+
18
+ ```js
19
+ export default defineConfig([
20
+ globalIgnores(['dist']),
21
+ {
22
+ files: ['**/*.{ts,tsx}'],
23
+ extends: [
24
+ // Other configs...
25
+
26
+ // Remove tseslint.configs.recommended and replace with this
27
+ tseslint.configs.recommendedTypeChecked,
28
+ // Alternatively, use this for stricter rules
29
+ tseslint.configs.strictTypeChecked,
30
+ // Optionally, add this for stylistic rules
31
+ tseslint.configs.stylisticTypeChecked,
32
+
33
+ // Other configs...
34
+ ],
35
+ languageOptions: {
36
+ parserOptions: {
37
+ project: ['./tsconfig.node.json', './tsconfig.app.json'],
38
+ tsconfigRootDir: import.meta.dirname,
39
+ },
40
+ // other options...
41
+ },
42
+ },
43
+ ])
44
+ ```
45
+
46
+ You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
47
+
48
+ ```js
49
+ // eslint.config.js
50
+ import reactX from 'eslint-plugin-react-x'
51
+ import reactDom from 'eslint-plugin-react-dom'
52
+
53
+ export default defineConfig([
54
+ globalIgnores(['dist']),
55
+ {
56
+ files: ['**/*.{ts,tsx}'],
57
+ extends: [
58
+ // Other configs...
59
+ // Enable lint rules for React
60
+ reactX.configs['recommended-typescript'],
61
+ // Enable lint rules for React DOM
62
+ reactDom.configs.recommended,
63
+ ],
64
+ languageOptions: {
65
+ parserOptions: {
66
+ project: ['./tsconfig.node.json', './tsconfig.app.json'],
67
+ tsconfigRootDir: import.meta.dirname,
68
+ },
69
+ // other options...
70
+ },
71
+ },
72
+ ])
73
+ ```
@@ -0,0 +1,529 @@
1
+ let c = null;
2
+ function U(t) {
3
+ c = t;
4
+ }
5
+ function i() {
6
+ if (!c)
7
+ throw new Error(
8
+ "Data layer config not initialized. Call setConfig() in your root layout."
9
+ );
10
+ return c;
11
+ }
12
+ function Y() {
13
+ return c !== null;
14
+ }
15
+ function f() {
16
+ const { sportal365Sports: t } = i();
17
+ if (!t)
18
+ throw new Error("Sportal365 Sports API configuration is missing");
19
+ const e = `${t.username}:${t.password}`;
20
+ return `Basic ${btoa(e)}`;
21
+ }
22
+ function y(t) {
23
+ const { sportal365Sports: e } = i();
24
+ if (!e)
25
+ throw new Error("Sportal365 Sports API configuration is missing");
26
+ return `${e.domain.replace(/\/$/, "")}${t}`;
27
+ }
28
+ async function r(t) {
29
+ const { sportal365Sports: e } = i();
30
+ if (!e)
31
+ throw new Error("Sportal365 Sports API configuration is missing");
32
+ const o = new URL(y(t.path));
33
+ if (t.params)
34
+ for (const [a, d] of Object.entries(t.params))
35
+ d !== void 0 && (Array.isArray(d) ? d.length > 0 && o.searchParams.set(a, d.join(",")) : o.searchParams.set(a, d));
36
+ const n = await fetch(o.toString(), {
37
+ method: "GET",
38
+ headers: {
39
+ Authorization: f(),
40
+ "Content-Type": "application/json",
41
+ "X-Project-Id": e.projectId
42
+ },
43
+ signal: e.timeout ? AbortSignal.timeout(e.timeout) : void 0
44
+ });
45
+ if (!n.ok)
46
+ throw new Error(
47
+ `Sportal365 API error: ${n.status} ${n.statusText}`
48
+ );
49
+ return n.json();
50
+ }
51
+ function l(t) {
52
+ if (t)
53
+ return {
54
+ id: t.id,
55
+ name: t.name,
56
+ slug: t.slug,
57
+ position: t.position,
58
+ gender: t.gender,
59
+ assets: t.assets ? {
60
+ photo: t.assets.thumb?.url,
61
+ photoTransparent: t.assets.thumb_transparent_background?.url
62
+ } : void 0
63
+ };
64
+ }
65
+ const h = {
66
+ // Scoring events
67
+ GOAL: "GOAL",
68
+ PENALTY_GOAL: "PENALTY_GOAL",
69
+ OWN_GOAL: "OWN_GOAL",
70
+ DISALLOWED_GOAL: "DISALLOWED_GOAL",
71
+ PENALTY_SHOOTOUT_SCORED: "PENALTY_SHOOTOUT_SCORED",
72
+ PENALTY_SHOOTOUT_MISSED: "PENALTY_SHOOTOUT_MISSED",
73
+ // Card events
74
+ YELLOW_CARD: "YELLOW_CARD",
75
+ RED_CARD: "RED_CARD",
76
+ YELLOW_RED_CARD: "YELLOW_RED_CARD",
77
+ // Substitution
78
+ SUBSTITUTION: "SUBSTITUTION",
79
+ // Match flow events
80
+ KICKOFF: "KICKOFF",
81
+ HALFTIME: "HALFTIME",
82
+ START_SECOND_HALF: "START_SECOND_HALF",
83
+ FINISHED: "FINISHED",
84
+ INJURY_TIME: "INJURY_TIME",
85
+ // Penalty events
86
+ PENALTY_AWARDED: "PENALTY_AWARDED",
87
+ PENALTY_MISSED: "PENALTY_MISSED",
88
+ PENALTY_SAVED: "PENALTY_SAVED"
89
+ };
90
+ function u(t) {
91
+ const e = h[t.type_code];
92
+ return e ? {
93
+ id: t.id,
94
+ type: e,
95
+ competitorPosition: t.team_position === "HOME" ? "ONE" : "TWO",
96
+ minute: t.minute,
97
+ injuryMinute: t.injury_minute,
98
+ primaryPlayer: l(t.primary_player),
99
+ secondaryPlayer: l(t.secondary_player),
100
+ score: t.score ? { competitorOne: String(t.score.home), competitorTwo: String(t.score.away) } : void 0
101
+ } : (console.warn(`Unknown event type: ${t.type_code}`), null);
102
+ }
103
+ function E(t) {
104
+ return {
105
+ code: {
106
+ FINISHED: "finished",
107
+ NOT_STARTED: "not_started",
108
+ LIVE: "live",
109
+ INTERRUPTED: "interrupted",
110
+ CANCELLED: "cancelled",
111
+ POSTPONED: "postponed",
112
+ UNKNOWN: "not_started",
113
+ ABANDONED: "abandoned"
114
+ }[t.type] ?? "not_started",
115
+ name: t.name,
116
+ shortName: t.short_name,
117
+ type: t.type
118
+ };
119
+ }
120
+ function m(t) {
121
+ return {
122
+ id: t.id,
123
+ name: t.name,
124
+ shortName: t.short_name ?? void 0,
125
+ threeLetterCode: t.three_letter_code,
126
+ slug: t.slug,
127
+ type: t.type ?? "club",
128
+ gender: t.gender,
129
+ assets: t.assets ? {
130
+ logo: t.assets.logo?.url,
131
+ homeKit: t.assets.home_kit?.url,
132
+ awayKit: t.assets.away_kit?.url,
133
+ squadImage: t.assets.squad_image?.url
134
+ } : void 0,
135
+ metadata: t.shirt_color ? { shirtColor: t.shirt_color } : void 0
136
+ };
137
+ }
138
+ function T(t) {
139
+ return {
140
+ kickoffTime: new Date(t.kickoff_time),
141
+ currentMinute: t.minute?.regular_time,
142
+ phaseStartedAt: t.phase_started_at ? new Date(t.phase_started_at) : void 0,
143
+ finishedAt: t.finished_at ? new Date(t.finished_at) : void 0,
144
+ firstHalfStartedAt: t.first_half_started_at ? new Date(t.first_half_started_at) : void 0,
145
+ secondHalfStartedAt: t.second_half_started_at ? new Date(t.second_half_started_at) : void 0,
146
+ extraTimeFirstHalfStartedAt: t.extra_time_first_half_started_at ? new Date(t.extra_time_first_half_started_at) : void 0,
147
+ extraTimeSecondHalfStartedAt: t.extra_time_second_half_started_at ? new Date(t.extra_time_second_half_started_at) : void 0
148
+ };
149
+ }
150
+ function S(t) {
151
+ if (!t) return;
152
+ const e = (n) => n ? { competitorOne: String(n.home), competitorTwo: String(n.away) } : void 0, o = t.total ?? t.regular_time;
153
+ return {
154
+ competitorOne: o?.home != null ? String(o.home) : null,
155
+ competitorTwo: o?.away != null ? String(o.away) : null,
156
+ breakdown: {
157
+ total: e(t.total),
158
+ halfTime: e(t.half_time),
159
+ regularTime: e(t.regular_time),
160
+ extraTime: e(t.extra_time),
161
+ penaltyShootout: e(t.penalty_shootout),
162
+ aggregate: e(t.aggregate)
163
+ }
164
+ };
165
+ }
166
+ function v(t) {
167
+ if (t)
168
+ return {
169
+ id: t.id,
170
+ name: t.name,
171
+ slug: t.slug,
172
+ assets: t.assets?.image?.url ? { image: t.assets.image.url } : void 0
173
+ };
174
+ }
175
+ function A(t) {
176
+ if (t?.length)
177
+ return t.map((e) => ({
178
+ id: e.id,
179
+ name: e.name,
180
+ slug: e.slug,
181
+ role: e.role ?? "REFEREE",
182
+ gender: e.gender
183
+ }));
184
+ }
185
+ function O(t) {
186
+ if (!t.season?.tournament) return;
187
+ const { tournament: e, ...o } = t.season;
188
+ return {
189
+ id: e.id,
190
+ name: e.name,
191
+ slug: e.slug,
192
+ type: e.type,
193
+ region: e.region,
194
+ country: e.country ? {
195
+ id: e.country.id,
196
+ name: e.country.name,
197
+ code: e.country.code ?? void 0,
198
+ flag: e.country.assets?.flag?.url
199
+ } : void 0,
200
+ season: {
201
+ id: o.id,
202
+ name: o.name,
203
+ status: o.status
204
+ },
205
+ stage: t.stage ? {
206
+ id: t.stage.id,
207
+ name: t.stage.name,
208
+ type: t.stage.type
209
+ } : void 0,
210
+ assets: e.assets?.logo?.url ? { logo: e.assets.logo.url } : void 0
211
+ };
212
+ }
213
+ function k(t) {
214
+ if (!t.winner?.match?.id) return;
215
+ const e = {
216
+ "Regular Time": "REGULAR_TIME",
217
+ "Extra Time": "EXTRA_TIME",
218
+ Penalties: "PENALTIES"
219
+ };
220
+ return {
221
+ competitorId: t.winner.match.id,
222
+ reason: t.winner.match.reason?.name ? e[t.winner.match.reason.name] : void 0,
223
+ aggregate: !!t.winner.aggregate
224
+ };
225
+ }
226
+ function b(t) {
227
+ return {
228
+ id: t.id,
229
+ slug: t.slug,
230
+ status: E(t.status),
231
+ timing: T(t),
232
+ competitorOne: m(t.home_team),
233
+ competitorTwo: m(t.away_team),
234
+ competition: O(t),
235
+ round: t.round ? {
236
+ id: t.round.id ?? t.round.key,
237
+ key: t.round.key,
238
+ name: t.round.name,
239
+ type: t.round.type ?? "REGULAR"
240
+ } : void 0,
241
+ group: t.group ? {
242
+ id: t.group.id,
243
+ name: t.group.name
244
+ } : void 0,
245
+ venue: v(t.venue),
246
+ officials: A(t.referees),
247
+ spectators: t.spectators ?? void 0,
248
+ score: S(t.score),
249
+ mainEvents: t.main_events?.map(u).filter((e) => e !== null),
250
+ penaltyShootoutEvents: t.penalty_shootout_events?.map(u).filter((e) => e !== null),
251
+ winner: k(t),
252
+ coverage: t.coverage === "NOT_LIVE" ? "UNKNOWN" : t.coverage,
253
+ lineupStatus: t.lineup_status === "UNCONFIRMED" ? "EXPECTED" : t.lineup_status
254
+ };
255
+ }
256
+ function L(t) {
257
+ const e = t.player;
258
+ return {
259
+ id: e.id,
260
+ name: e.name,
261
+ slug: e.slug,
262
+ position: e.position,
263
+ shirtNumber: t.shirt_number,
264
+ positionX: t.position_x ?? void 0,
265
+ positionY: t.position_y ?? void 0,
266
+ country: e.country ? {
267
+ id: e.country.id,
268
+ name: e.country.name,
269
+ code: e.country.code
270
+ } : void 0,
271
+ birthdate: e.birthdate,
272
+ profile: e.profile ? {
273
+ height: e.profile.height,
274
+ weight: e.profile.weight
275
+ } : void 0,
276
+ events: t.events?.map(u).filter((o) => o !== null)
277
+ };
278
+ }
279
+ function p(t) {
280
+ const e = [], o = [];
281
+ for (const n of t.players) {
282
+ const a = L(n);
283
+ n.type.category === "start" ? e.push(a) : n.type.category === "sub" && o.push(a);
284
+ }
285
+ return {
286
+ competitorId: t.team_id,
287
+ formation: t.formation,
288
+ coach: t.coach ? {
289
+ id: t.coach.id,
290
+ name: t.coach.name,
291
+ slug: t.coach.slug,
292
+ country: t.coach.country ? {
293
+ id: t.coach.country.id,
294
+ name: t.coach.country.name,
295
+ code: t.coach.country.code
296
+ } : void 0,
297
+ birthdate: t.coach.birthdate
298
+ } : void 0,
299
+ starters: e,
300
+ substitutes: o
301
+ };
302
+ }
303
+ function C(t) {
304
+ return {
305
+ matchId: t.match_id,
306
+ confirmed: t.status === "CONFIRMED",
307
+ competitorOne: p(t.home_team),
308
+ competitorTwo: p(t.away_team)
309
+ };
310
+ }
311
+ function s(t, e, o, n) {
312
+ return e == null ? null : { key: t, value: String(e), label: o, unit: n };
313
+ }
314
+ function g(t, e) {
315
+ const o = (e.shots_on ?? 0) + (e.shots_off ?? 0) + (e.shots_blocked ?? 0), n = [
316
+ s("possession", e.possession, "Possession", "%"),
317
+ s("shots_total", o, "Shots"),
318
+ s("shots_on_target", e.shots_on, "Shots on Target"),
319
+ s("shots_off_target", e.shots_off, "Shots off Target"),
320
+ s("shots_blocked", e.shots_blocked, "Shots Blocked"),
321
+ s("corners", e.corners, "Corner Kicks"),
322
+ s("goal_kicks", e.goal_kicks, "Goal Kicks"),
323
+ s("throw_ins", e.throw_in, "Throw Ins"),
324
+ s("offsides", e.offside, "Offsides"),
325
+ s("fouls", e.fouls_committed, "Fouls"),
326
+ s("yellow_cards", e.yellow_cards, "Yellow Cards"),
327
+ s("passes", e.pass, "Passes"),
328
+ s("crosses", e.crosses, "Crosses")
329
+ ];
330
+ return {
331
+ competitorId: t,
332
+ statistics: n.filter((a) => a !== null)
333
+ };
334
+ }
335
+ function D(t) {
336
+ const e = t.find((n) => n.home_team), o = t.find((n) => !n.home_team);
337
+ if (!e || !o)
338
+ throw new Error("Missing competitor statistics");
339
+ return {
340
+ competitorOne: g(String(e.team.id), e.statistics),
341
+ competitorTwo: g(String(o.team.id), o.statistics)
342
+ };
343
+ }
344
+ function N(t) {
345
+ const e = t.urls?.find((o) => o.app_type === "desktop")?.url;
346
+ return {
347
+ id: t.id,
348
+ name: t.name,
349
+ code: t.code,
350
+ value: t.value ?? void 0,
351
+ odds: t.odds,
352
+ oddsOld: t.odds_old,
353
+ movement: t.movement === "STABLE" ? "NONE" : t.movement,
354
+ url: e
355
+ };
356
+ }
357
+ function I(t) {
358
+ return {
359
+ type: {
360
+ id: t.type.id,
361
+ code: t.type.code,
362
+ name: t.type.name
363
+ },
364
+ period: {
365
+ id: t.scope.id,
366
+ type: t.scope.type,
367
+ name: t.scope.name
368
+ },
369
+ selections: t.selections.map(N)
370
+ };
371
+ }
372
+ function P(t) {
373
+ return {
374
+ operator: {
375
+ id: t.bookmaker.id,
376
+ name: t.bookmaker.name,
377
+ url: t.bookmaker.url,
378
+ branding: t.bookmaker.branding ? {
379
+ backgroundColor: t.bookmaker.branding.background_color,
380
+ textColor: t.bookmaker.branding.text_color,
381
+ logo: t.bookmaker.assets?.[0]?.logo
382
+ } : void 0
383
+ },
384
+ type: t.type,
385
+ markets: t.markets.map(I)
386
+ };
387
+ }
388
+ function R(t, e) {
389
+ return {
390
+ matchId: t,
391
+ operators: e.map(P)
392
+ };
393
+ }
394
+ function _(t) {
395
+ if (t == null || t === "")
396
+ return;
397
+ const e = typeof t == "number" ? t : parseInt(t, 10);
398
+ return isNaN(e) ? void 0 : e;
399
+ }
400
+ function M(t) {
401
+ return {
402
+ externalId: t.external_id,
403
+ minute: _(t.elapsed),
404
+ addedTime: _(t.elapsed_plus),
405
+ text: t.auto_text,
406
+ details: t.details,
407
+ meta: {
408
+ type: t.type,
409
+ commentaryType: t.commentary_type,
410
+ subtype1: t.subtype_1,
411
+ subtype2: t.subtype_2,
412
+ timestamp: t.incident_timestamp
413
+ }
414
+ };
415
+ }
416
+ async function x(t, e = {}) {
417
+ const { sportal365Sports: o } = i(), n = await r({
418
+ path: `/v2/matches/${t}`,
419
+ params: {
420
+ language_code: e.languageCode ?? o?.languageCode ?? "en",
421
+ odd_client: e.oddClient,
422
+ odd_type: e.oddType,
423
+ scope_type: e.scopeType,
424
+ odd_format: e.oddFormat,
425
+ market_types: e.marketTypes,
426
+ bookmaker_ids: e.bookmakerIds,
427
+ optional_data: e.optionalData
428
+ }
429
+ });
430
+ return b(n);
431
+ }
432
+ async function H(t, e = {}) {
433
+ const { sportal365Sports: o } = i();
434
+ return (await r({
435
+ path: `/v2/matches/${t}/events`,
436
+ params: {
437
+ language_code: e.languageCode ?? o?.languageCode ?? "en"
438
+ }
439
+ })).events.map(u).filter((a) => a !== null);
440
+ }
441
+ async function $(t, e = {}) {
442
+ const { sportal365Sports: o } = i(), n = await r({
443
+ path: `/v2/matches/${t}/lineups`,
444
+ params: {
445
+ language_code: e.languageCode ?? o?.languageCode ?? "en"
446
+ }
447
+ });
448
+ return C(n);
449
+ }
450
+ async function W(t, e = {}) {
451
+ const { sportal365Sports: o } = i(), n = await r({
452
+ path: `/v2/matches/${t}`,
453
+ params: {
454
+ language_code: e.languageCode ?? o?.languageCode ?? "en",
455
+ odd_client: e.oddClient ?? o?.oddClient,
456
+ odd_type: e.oddType,
457
+ scope_type: e.scopeType ?? "ALL",
458
+ odd_format: e.oddFormat ?? "DECIMAL",
459
+ market_types: e.marketTypes,
460
+ bookmaker_ids: e.bookmakerIds
461
+ }
462
+ });
463
+ return R(t, n.odds ?? []);
464
+ }
465
+ async function G(t, e = {}) {
466
+ const { sportal365Sports: o } = i(), n = await r({
467
+ path: `/events/${t}/teamstats`,
468
+ params: {
469
+ language_code: e.languageCode ?? o?.languageCode ?? "en"
470
+ }
471
+ });
472
+ return D(n);
473
+ }
474
+ async function K(t, e = {}) {
475
+ const { sportal365Sports: o } = i();
476
+ return (await r({
477
+ path: `/matches/${t}/commentary`,
478
+ params: {
479
+ language_code: e.languageCode ?? o?.languageCode ?? "en"
480
+ }
481
+ })).map(M);
482
+ }
483
+ function F(t) {
484
+ return {
485
+ id: t.id,
486
+ name: t.name,
487
+ shortName: t.short_name ?? void 0,
488
+ threeLetterCode: t.three_letter_code,
489
+ slug: t.slug,
490
+ type: t.type === "placeholder" ? "club" : t.type,
491
+ gender: t.gender,
492
+ country: t.country ? {
493
+ id: t.country.id,
494
+ name: t.country.name,
495
+ code: t.country.code ?? void 0,
496
+ flag: t.country.assets?.flag?.url
497
+ } : void 0,
498
+ assets: t.assets ? {
499
+ logo: t.assets.logo?.url,
500
+ homeKit: t.assets.home_kit?.url,
501
+ awayKit: t.assets.away_kit?.url,
502
+ squadImage: t.assets.squad_image?.url
503
+ } : void 0
504
+ };
505
+ }
506
+ async function j(t, e = {}) {
507
+ const { sportal365Sports: o } = i(), n = await r({
508
+ path: `/v2/teams/${t}`,
509
+ params: {
510
+ language_code: e.languageCode ?? o?.languageCode ?? "en",
511
+ optional_data: "form"
512
+ }
513
+ });
514
+ return F(n);
515
+ }
516
+ const B = "0.0.1";
517
+ export {
518
+ i as getConfig,
519
+ x as getFootballMatch,
520
+ K as getFootballMatchCommentary,
521
+ H as getFootballMatchEvents,
522
+ $ as getFootballMatchLineups,
523
+ W as getFootballMatchOdds,
524
+ G as getFootballMatchStatistics,
525
+ j as getFootballTeam,
526
+ Y as isConfigured,
527
+ U as setConfig,
528
+ B as version
529
+ };
@@ -0,0 +1 @@
1
+ (function(s,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(s=typeof globalThis<"u"?globalThis:s||self,d(s.FansUnitedDataLayer={}))})(this,(function(s){"use strict";let d=null;function h(t){d=t}function a(){if(!d)throw new Error("Data layer config not initialized. Call setConfig() in your root layout.");return d}function y(){return d!==null}function E(){const{sportal365Sports:t}=a();if(!t)throw new Error("Sportal365 Sports API configuration is missing");const e=`${t.username}:${t.password}`;return`Basic ${btoa(e)}`}function T(t){const{sportal365Sports:e}=a();if(!e)throw new Error("Sportal365 Sports API configuration is missing");return`${e.domain.replace(/\/$/,"")}${t}`}async function c(t){const{sportal365Sports:e}=a();if(!e)throw new Error("Sportal365 Sports API configuration is missing");const o=new URL(T(t.path));if(t.params)for(const[r,u]of Object.entries(t.params))u!==void 0&&(Array.isArray(u)?u.length>0&&o.searchParams.set(r,u.join(",")):o.searchParams.set(r,u));const n=await fetch(o.toString(),{method:"GET",headers:{Authorization:E(),"Content-Type":"application/json","X-Project-Id":e.projectId},signal:e.timeout?AbortSignal.timeout(e.timeout):void 0});if(!n.ok)throw new Error(`Sportal365 API error: ${n.status} ${n.statusText}`);return n.json()}function m(t){if(t)return{id:t.id,name:t.name,slug:t.slug,position:t.position,gender:t.gender,assets:t.assets?{photo:t.assets.thumb?.url,photoTransparent:t.assets.thumb_transparent_background?.url}:void 0}}const S={GOAL:"GOAL",PENALTY_GOAL:"PENALTY_GOAL",OWN_GOAL:"OWN_GOAL",DISALLOWED_GOAL:"DISALLOWED_GOAL",PENALTY_SHOOTOUT_SCORED:"PENALTY_SHOOTOUT_SCORED",PENALTY_SHOOTOUT_MISSED:"PENALTY_SHOOTOUT_MISSED",YELLOW_CARD:"YELLOW_CARD",RED_CARD:"RED_CARD",YELLOW_RED_CARD:"YELLOW_RED_CARD",SUBSTITUTION:"SUBSTITUTION",KICKOFF:"KICKOFF",HALFTIME:"HALFTIME",START_SECOND_HALF:"START_SECOND_HALF",FINISHED:"FINISHED",INJURY_TIME:"INJURY_TIME",PENALTY_AWARDED:"PENALTY_AWARDED",PENALTY_MISSED:"PENALTY_MISSED",PENALTY_SAVED:"PENALTY_SAVED"};function l(t){const e=S[t.type_code];return e?{id:t.id,type:e,competitorPosition:t.team_position==="HOME"?"ONE":"TWO",minute:t.minute,injuryMinute:t.injury_minute,primaryPlayer:m(t.primary_player),secondaryPlayer:m(t.secondary_player),score:t.score?{competitorOne:String(t.score.home),competitorTwo:String(t.score.away)}:void 0}:(console.warn(`Unknown event type: ${t.type_code}`),null)}function v(t){return{code:{FINISHED:"finished",NOT_STARTED:"not_started",LIVE:"live",INTERRUPTED:"interrupted",CANCELLED:"cancelled",POSTPONED:"postponed",UNKNOWN:"not_started",ABANDONED:"abandoned"}[t.type]??"not_started",name:t.name,shortName:t.short_name,type:t.type}}function p(t){return{id:t.id,name:t.name,shortName:t.short_name??void 0,threeLetterCode:t.three_letter_code,slug:t.slug,type:t.type??"club",gender:t.gender,assets:t.assets?{logo:t.assets.logo?.url,homeKit:t.assets.home_kit?.url,awayKit:t.assets.away_kit?.url,squadImage:t.assets.squad_image?.url}:void 0,metadata:t.shirt_color?{shirtColor:t.shirt_color}:void 0}}function O(t){return{kickoffTime:new Date(t.kickoff_time),currentMinute:t.minute?.regular_time,phaseStartedAt:t.phase_started_at?new Date(t.phase_started_at):void 0,finishedAt:t.finished_at?new Date(t.finished_at):void 0,firstHalfStartedAt:t.first_half_started_at?new Date(t.first_half_started_at):void 0,secondHalfStartedAt:t.second_half_started_at?new Date(t.second_half_started_at):void 0,extraTimeFirstHalfStartedAt:t.extra_time_first_half_started_at?new Date(t.extra_time_first_half_started_at):void 0,extraTimeSecondHalfStartedAt:t.extra_time_second_half_started_at?new Date(t.extra_time_second_half_started_at):void 0}}function A(t){if(!t)return;const e=n=>n?{competitorOne:String(n.home),competitorTwo:String(n.away)}:void 0,o=t.total??t.regular_time;return{competitorOne:o?.home!=null?String(o.home):null,competitorTwo:o?.away!=null?String(o.away):null,breakdown:{total:e(t.total),halfTime:e(t.half_time),regularTime:e(t.regular_time),extraTime:e(t.extra_time),penaltyShootout:e(t.penalty_shootout),aggregate:e(t.aggregate)}}}function b(t){if(t)return{id:t.id,name:t.name,slug:t.slug,assets:t.assets?.image?.url?{image:t.assets.image.url}:void 0}}function k(t){if(t?.length)return t.map(e=>({id:e.id,name:e.name,slug:e.slug,role:e.role??"REFEREE",gender:e.gender}))}function C(t){if(!t.season?.tournament)return;const{tournament:e,...o}=t.season;return{id:e.id,name:e.name,slug:e.slug,type:e.type,region:e.region,country:e.country?{id:e.country.id,name:e.country.name,code:e.country.code??void 0,flag:e.country.assets?.flag?.url}:void 0,season:{id:o.id,name:o.name,status:o.status},stage:t.stage?{id:t.stage.id,name:t.stage.name,type:t.stage.type}:void 0,assets:e.assets?.logo?.url?{logo:e.assets.logo.url}:void 0}}function L(t){if(!t.winner?.match?.id)return;const e={"Regular Time":"REGULAR_TIME","Extra Time":"EXTRA_TIME",Penalties:"PENALTIES"};return{competitorId:t.winner.match.id,reason:t.winner.match.reason?.name?e[t.winner.match.reason.name]:void 0,aggregate:!!t.winner.aggregate}}function D(t){return{id:t.id,slug:t.slug,status:v(t.status),timing:O(t),competitorOne:p(t.home_team),competitorTwo:p(t.away_team),competition:C(t),round:t.round?{id:t.round.id??t.round.key,key:t.round.key,name:t.round.name,type:t.round.type??"REGULAR"}:void 0,group:t.group?{id:t.group.id,name:t.group.name}:void 0,venue:b(t.venue),officials:k(t.referees),spectators:t.spectators??void 0,score:A(t.score),mainEvents:t.main_events?.map(l).filter(e=>e!==null),penaltyShootoutEvents:t.penalty_shootout_events?.map(l).filter(e=>e!==null),winner:L(t),coverage:t.coverage==="NOT_LIVE"?"UNKNOWN":t.coverage,lineupStatus:t.lineup_status==="UNCONFIRMED"?"EXPECTED":t.lineup_status}}function N(t){const e=t.player;return{id:e.id,name:e.name,slug:e.slug,position:e.position,shirtNumber:t.shirt_number,positionX:t.position_x??void 0,positionY:t.position_y??void 0,country:e.country?{id:e.country.id,name:e.country.name,code:e.country.code}:void 0,birthdate:e.birthdate,profile:e.profile?{height:e.profile.height,weight:e.profile.weight}:void 0,events:t.events?.map(l).filter(o=>o!==null)}}function g(t){const e=[],o=[];for(const n of t.players){const r=N(n);n.type.category==="start"?e.push(r):n.type.category==="sub"&&o.push(r)}return{competitorId:t.team_id,formation:t.formation,coach:t.coach?{id:t.coach.id,name:t.coach.name,slug:t.coach.slug,country:t.coach.country?{id:t.coach.country.id,name:t.coach.country.name,code:t.coach.country.code}:void 0,birthdate:t.coach.birthdate}:void 0,starters:e,substitutes:o}}function I(t){return{matchId:t.match_id,confirmed:t.status==="CONFIRMED",competitorOne:g(t.home_team),competitorTwo:g(t.away_team)}}function i(t,e,o,n){return e==null?null:{key:t,value:String(e),label:o,unit:n}}function _(t,e){const o=(e.shots_on??0)+(e.shots_off??0)+(e.shots_blocked??0),n=[i("possession",e.possession,"Possession","%"),i("shots_total",o,"Shots"),i("shots_on_target",e.shots_on,"Shots on Target"),i("shots_off_target",e.shots_off,"Shots off Target"),i("shots_blocked",e.shots_blocked,"Shots Blocked"),i("corners",e.corners,"Corner Kicks"),i("goal_kicks",e.goal_kicks,"Goal Kicks"),i("throw_ins",e.throw_in,"Throw Ins"),i("offsides",e.offside,"Offsides"),i("fouls",e.fouls_committed,"Fouls"),i("yellow_cards",e.yellow_cards,"Yellow Cards"),i("passes",e.pass,"Passes"),i("crosses",e.crosses,"Crosses")];return{competitorId:t,statistics:n.filter(r=>r!==null)}}function M(t){const e=t.find(n=>n.home_team),o=t.find(n=>!n.home_team);if(!e||!o)throw new Error("Missing competitor statistics");return{competitorOne:_(String(e.team.id),e.statistics),competitorTwo:_(String(o.team.id),o.statistics)}}function P(t){const e=t.urls?.find(o=>o.app_type==="desktop")?.url;return{id:t.id,name:t.name,code:t.code,value:t.value??void 0,odds:t.odds,oddsOld:t.odds_old,movement:t.movement==="STABLE"?"NONE":t.movement,url:e}}function F(t){return{type:{id:t.type.id,code:t.type.code,name:t.type.name},period:{id:t.scope.id,type:t.scope.type,name:t.scope.name},selections:t.selections.map(P)}}function R(t){return{operator:{id:t.bookmaker.id,name:t.bookmaker.name,url:t.bookmaker.url,branding:t.bookmaker.branding?{backgroundColor:t.bookmaker.branding.background_color,textColor:t.bookmaker.branding.text_color,logo:t.bookmaker.assets?.[0]?.logo}:void 0},type:t.type,markets:t.markets.map(F)}}function U(t,e){return{matchId:t,operators:e.map(R)}}function f(t){if(t==null||t==="")return;const e=typeof t=="number"?t:parseInt(t,10);return isNaN(e)?void 0:e}function Y(t){return{externalId:t.external_id,minute:f(t.elapsed),addedTime:f(t.elapsed_plus),text:t.auto_text,details:t.details,meta:{type:t.type,commentaryType:t.commentary_type,subtype1:t.subtype_1,subtype2:t.subtype_2,timestamp:t.incident_timestamp}}}async function H(t,e={}){const{sportal365Sports:o}=a(),n=await c({path:`/v2/matches/${t}`,params:{language_code:e.languageCode??o?.languageCode??"en",odd_client:e.oddClient,odd_type:e.oddType,scope_type:e.scopeType,odd_format:e.oddFormat,market_types:e.marketTypes,bookmaker_ids:e.bookmakerIds,optional_data:e.optionalData}});return D(n)}async function $(t,e={}){const{sportal365Sports:o}=a();return(await c({path:`/v2/matches/${t}/events`,params:{language_code:e.languageCode??o?.languageCode??"en"}})).events.map(l).filter(r=>r!==null)}async function W(t,e={}){const{sportal365Sports:o}=a(),n=await c({path:`/v2/matches/${t}/lineups`,params:{language_code:e.languageCode??o?.languageCode??"en"}});return I(n)}async function G(t,e={}){const{sportal365Sports:o}=a(),n=await c({path:`/v2/matches/${t}`,params:{language_code:e.languageCode??o?.languageCode??"en",odd_client:e.oddClient??o?.oddClient,odd_type:e.oddType,scope_type:e.scopeType??"ALL",odd_format:e.oddFormat??"DECIMAL",market_types:e.marketTypes,bookmaker_ids:e.bookmakerIds}});return U(t,n.odds??[])}async function K(t,e={}){const{sportal365Sports:o}=a(),n=await c({path:`/events/${t}/teamstats`,params:{language_code:e.languageCode??o?.languageCode??"en"}});return M(n)}async function j(t,e={}){const{sportal365Sports:o}=a();return(await c({path:`/matches/${t}/commentary`,params:{language_code:e.languageCode??o?.languageCode??"en"}})).map(Y)}function x(t){return{id:t.id,name:t.name,shortName:t.short_name??void 0,threeLetterCode:t.three_letter_code,slug:t.slug,type:t.type==="placeholder"?"club":t.type,gender:t.gender,country:t.country?{id:t.country.id,name:t.country.name,code:t.country.code??void 0,flag:t.country.assets?.flag?.url}:void 0,assets:t.assets?{logo:t.assets.logo?.url,homeKit:t.assets.home_kit?.url,awayKit:t.assets.away_kit?.url,squadImage:t.assets.squad_image?.url}:void 0}}async function B(t,e={}){const{sportal365Sports:o}=a(),n=await c({path:`/v2/teams/${t}`,params:{language_code:e.languageCode??o?.languageCode??"en",optional_data:"form"}});return x(n)}const V="0.0.1";s.getConfig=a,s.getFootballMatch=H,s.getFootballMatchCommentary=j,s.getFootballMatchEvents=$,s.getFootballMatchLineups=W,s.getFootballMatchOdds=G,s.getFootballMatchStatistics=K,s.getFootballTeam=B,s.isConfigured=y,s.setConfig=h,s.version=V,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
package/dist/vite.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "fansunited-data-layer",
3
+ "private": false,
4
+ "version": "0.0.1",
5
+ "type": "module",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "main": "./dist/fansunited-data-layer.umd.cjs",
10
+ "module": "./dist/fansunited-data-layer.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/fansunited-data-layer.js",
16
+ "require": "./dist/fansunited-data-layer.umd.cjs"
17
+ }
18
+ },
19
+ "scripts": {
20
+ "dev": "vite",
21
+ "build": "tsc -b && vite build",
22
+ "build:lib": "vite build && tsc --project tsconfig.lib.json",
23
+ "lint": "eslint .",
24
+ "preview": "vite preview"
25
+ },
26
+ "peerDependencies": {
27
+ "react": "^18.0.0 || ^19.0.0",
28
+ "react-dom": "^18.0.0 || ^19.0.0"
29
+ },
30
+ "devDependencies": {
31
+ "@eslint/js": "^9.39.1",
32
+ "@types/node": "^24.10.1",
33
+ "@types/react": "^19.2.5",
34
+ "@types/react-dom": "^19.2.3",
35
+ "@vitejs/plugin-react": "^5.1.1",
36
+ "eslint": "^9.39.1",
37
+ "eslint-plugin-react-hooks": "^7.0.1",
38
+ "eslint-plugin-react-refresh": "^0.4.24",
39
+ "globals": "^16.5.0",
40
+ "prettier": "^3.7.3",
41
+ "react": "^19.2.0",
42
+ "react-dom": "^19.2.0",
43
+ "typescript": "~5.9.3",
44
+ "typescript-eslint": "^8.46.4",
45
+ "vite": "^7.2.4"
46
+ }
47
+ }