fansunited-data-layer 0.0.7 → 0.0.8

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 CHANGED
@@ -131,6 +131,50 @@ console.log(team.name);
131
131
  console.log(team.assets?.logo);
132
132
  ```
133
133
 
134
+ ## React Providers (Client Components)
135
+
136
+ For React Server Components (RSC) compatibility, client-side exports are available from a separate entry point:
137
+
138
+ ```typescript
139
+ "use client";
140
+
141
+ import { CompetitionProvider, useCompetition } from "fansunited-data-layer/client";
142
+
143
+ function MatchList() {
144
+ const { matches, getUpcomingMatches } = useCompetition();
145
+ const upcoming = getUpcomingMatches();
146
+
147
+ return (
148
+ <ul>
149
+ {upcoming.map((match) => (
150
+ <li key={match.id}>{match.competitorOne.name} vs {match.competitorTwo.name}</li>
151
+ ))}
152
+ </ul>
153
+ );
154
+ }
155
+
156
+ // Wrap your app with the provider
157
+ function App() {
158
+ return (
159
+ <CompetitionProvider
160
+ competitionId="123"
161
+ matches={matches}
162
+ standings={standings}
163
+ >
164
+ <MatchList />
165
+ </CompetitionProvider>
166
+ );
167
+ }
168
+ ```
169
+
170
+ **Available client exports:**
171
+
172
+ - `CompetitionProvider` - React context provider for competition data
173
+ - `useCompetition` - Hook to access competition context
174
+ - `CompetitionContext` - Raw context (for advanced use cases)
175
+
176
+ **Note:** Server-safe functions (`setConfig`, `getFootballMatch`, etc.) should be imported from the main entry point `'fansunited-data-layer'`, not from `'/client'`.
177
+
134
178
  ## Canonical Types
135
179
 
136
180
  All responses are transformed to provider-agnostic canonical types prefixed with `FUSports`:
@@ -0,0 +1,6 @@
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react");var I={exports:{}},w={};var Z;function te(){if(Z)return w;Z=1;var m=Symbol.for("react.transitional.element"),p=Symbol.for("react.fragment");function T(E,f,u){var _=null;if(u!==void 0&&(_=""+u),f.key!==void 0&&(_=""+f.key),"key"in f){u={};for(var k in f)k!=="key"&&(u[k]=f[k])}else u=f;return f=u.ref,{$$typeof:m,type:E,key:_,ref:f!==void 0?f:null,props:u}}return w.Fragment=p,w.jsx=T,w.jsxs=T,w}var P={};var Q;function re(){return Q||(Q=1,process.env.NODE_ENV!=="production"&&(function(){function m(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===W?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case R:return"Fragment";case N:return"Profiler";case j:return"StrictMode";case $:return"Suspense";case F:return"SuspenseList";case L:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case x:return"Portal";case Y:return e.displayName||"Context";case M:return(e._context.displayName||"Context")+".Consumer";case v:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case D:return t=e.displayName||null,t!==null?t:m(e.type)||"Memo";case h:t=e._payload,e=e._init;try{return m(e(t))}catch{}}return null}function p(e){return""+e}function T(e){try{p(e);var t=!1}catch{t=!0}if(t){t=console;var a=t.error,c=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return a.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",c),p(e)}}function E(e){if(e===R)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===h)return"<...>";try{var t=m(e);return t?"<"+t+">":"<...>"}catch{return"<...>"}}function f(){var e=S.A;return e===null?null:e.getOwner()}function u(){return Error("react-stack-top-frame")}function _(e){if(r.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function k(e,t){function a(){d||(d=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}a.isReactWarning=!0,Object.defineProperty(e,"key",{get:a,configurable:!0})}function y(){var e=m(this.type);return U[e]||(U[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function J(e,t,a,c,q,V){var l=a.ref;return e={$$typeof:O,type:e,key:t,props:a,_owner:c},(l!==void 0?l:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:y}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:q}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:V}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function s(e,t,a,c,q,V){var l=t.children;if(l!==void 0)if(c)if(n(l)){for(c=0;c<l.length;c++)A(l[c]);Object.freeze&&Object.freeze(l)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else A(l);if(r.call(t,"key")){l=m(e);var C=Object.keys(t).filter(function(ee){return ee!=="key"});c=0<C.length?"{key: someKey, "+C.join(": ..., ")+": ...}":"{key: someKey}",H[l+c]||(C=0<C.length?"{"+C.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
2
+ let props = %s;
3
+ <%s {...props} />
4
+ React keys must be passed directly to JSX without using spread:
5
+ let props = %s;
6
+ <%s key={someKey} {...props} />`,c,l,C,l),H[l+c]=!0)}if(l=null,a!==void 0&&(T(a),l=""+a),_(t)&&(T(t.key),l=""+t.key),"key"in t){a={};for(var z in t)z!=="key"&&(a[z]=t[z])}else a=t;return l&&k(a,typeof e=="function"?e.displayName||e.name||"Unknown":e),J(e,l,a,f(),q,V)}function A(e){b(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===h&&(e._payload.status==="fulfilled"?b(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function b(e){return typeof e=="object"&&e!==null&&e.$$typeof===O}var g=o,O=Symbol.for("react.transitional.element"),x=Symbol.for("react.portal"),R=Symbol.for("react.fragment"),j=Symbol.for("react.strict_mode"),N=Symbol.for("react.profiler"),M=Symbol.for("react.consumer"),Y=Symbol.for("react.context"),v=Symbol.for("react.forward_ref"),$=Symbol.for("react.suspense"),F=Symbol.for("react.suspense_list"),D=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),L=Symbol.for("react.activity"),W=Symbol.for("react.client.reference"),S=g.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,r=Object.prototype.hasOwnProperty,n=Array.isArray,i=console.createTask?console.createTask:function(){return null};g={react_stack_bottom_frame:function(e){return e()}};var d,U={},G=g.react_stack_bottom_frame.bind(g,u)(),X=i(E(u)),H={};P.Fragment=R,P.jsx=function(e,t,a){var c=1e4>S.recentlyCreatedOwnerStacks++;return s(e,t,a,!1,c?Error("react-stack-top-frame"):G,c?i(E(e)):X)},P.jsxs=function(e,t,a){var c=1e4>S.recentlyCreatedOwnerStacks++;return s(e,t,a,!0,c?Error("react-stack-top-frame"):G,c?i(E(e)):X)}})()),P}var K;function ne(){return K||(K=1,process.env.NODE_ENV==="production"?I.exports=te():I.exports=re()),I.exports}var oe=ne();const B=o.createContext(null);function ae(){const m=o.useContext(B);if(!m)throw new Error("useCompetition must be used within CompetitionProvider");return m}function se({competitionId:m,seasonId:p,stageId:T,matches:E,standings:f,previousSeasons:u,config:_,autoRefresh:k=!0,refreshInterval:y=3e4,children:J}){const[s,A]=o.useState(E),[b,g]=o.useState(f);o.useEffect(()=>{A(E)},[E]),o.useEffect(()=>{g(f)},[f]),o.useEffect(()=>{if(!k||!s.some(i=>i.status.code==="live"))return;const n=setInterval(async()=>{console.log("[CompetitionProvider] Auto-refresh triggered for live matches")},y);return()=>clearInterval(n)},[k,y,s]);const O=o.useCallback(r=>s.find(n=>n.id===r),[s]),x=o.useCallback(r=>s.filter(n=>n.competitorOne.id===r||n.competitorTwo.id===r),[s]),R=o.useCallback(r=>s.filter(n=>n.timing.kickoffTime.toISOString().startsWith(r)),[s]),j=o.useCallback(r=>s.filter(n=>n.round?.id===r),[s]),N=o.useCallback(()=>s.filter(r=>r.status.code==="live"),[s]),M=o.useCallback(r=>{const n=new Date;let i=s.filter(d=>d.status.code==="not_started"&&d.timing.kickoffTime>n);return r&&(i=i.filter(d=>d.competitorOne.id===r||d.competitorTwo.id===r)),i.sort((d,U)=>d.timing.kickoffTime.getTime()-U.timing.kickoffTime.getTime())},[s]),Y=o.useCallback(r=>{let n=s.filter(i=>i.status.code==="finished");return r&&(n=n.filter(i=>i.competitorOne.id===r||i.competitorTwo.id===r)),n.sort((i,d)=>d.timing.kickoffTime.getTime()-i.timing.kickoffTime.getTime())},[s]),v=o.useCallback(r=>b.find(n=>n.competitor.id===r),[b]),$=o.useCallback(r=>v(r)?.form?.formString,[v]),F=o.useCallback(r=>v(r)?.stats,[v]),D=o.useCallback(r=>[...b].sort((n,i)=>n.rank-i.rank).slice(0,r),[b]),h=o.useCallback(r=>[...b].sort((n,i)=>i.rank-n.rank).slice(0,r),[b]),L=o.useCallback(r=>u?.find(n=>n.id===r)?.matches,[u]),W=o.useCallback(r=>u?.find(n=>n.id===r)?.standings,[u]),S=o.useMemo(()=>({competitionId:m,seasonId:p,stageId:T,matches:s,standings:b,previousSeasons:u,config:_,getMatch:O,getMatchesByTeam:x,getMatchesByDate:R,getMatchesByRound:j,getLiveMatches:N,getUpcomingMatches:M,getFinishedMatches:Y,getTeamStanding:v,getTeamForm:$,getTeamStats:F,getTopTeams:D,getBottomTeams:h,getSeasonMatches:L,getSeasonStandings:W}),[m,p,T,s,b,u,_,O,x,R,j,N,M,Y,v,$,F,D,h,L,W]);return oe.jsx(B.Provider,{value:S,children:J})}exports.CompetitionContext=B;exports.CompetitionProvider=se;exports.useCompetition=ae;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Client-side exports for fansunited-data-layer
3
+ *
4
+ * This module exports React components, hooks, and context providers
5
+ * that require "use client" directive for React Server Components compatibility.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // In a client component
10
+ * "use client";
11
+ * import { CompetitionProvider, useCompetition } from 'fansunited-data-layer/client';
12
+ *
13
+ * function MyComponent() {
14
+ * const { matches, standings } = useCompetition();
15
+ * return <div>...</div>;
16
+ * }
17
+ * ```
18
+ */
19
+ export { CompetitionProvider, useCompetition, CompetitionContext, type CompetitionConfig, type Season, type CompetitionContextValue, type CompetitionProviderProps, } from "./providers";
20
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/lib/client.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EACH,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,KAAK,iBAAiB,EACtB,KAAK,MAAM,EACX,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,GAChC,MAAM,aAAa,CAAC"}
package/dist/client.js ADDED
@@ -0,0 +1,392 @@
1
+ "use client";
2
+ import ne, { createContext as oe, useContext as ae, useState as Z, useEffect as B, useCallback as f, useMemo as se } from "react";
3
+ var q = { exports: {} }, S = {};
4
+ var Q;
5
+ function ie() {
6
+ if (Q) return S;
7
+ Q = 1;
8
+ var m = Symbol.for("react.transitional.element"), b = Symbol.for("react.fragment");
9
+ function _(E, u, l) {
10
+ var v = null;
11
+ if (l !== void 0 && (v = "" + l), u.key !== void 0 && (v = "" + u.key), "key" in u) {
12
+ l = {};
13
+ for (var p in u)
14
+ p !== "key" && (l[p] = u[p]);
15
+ } else l = u;
16
+ return u = l.ref, {
17
+ $$typeof: m,
18
+ type: E,
19
+ key: v,
20
+ ref: u !== void 0 ? u : null,
21
+ props: l
22
+ };
23
+ }
24
+ return S.Fragment = b, S.jsx = _, S.jsxs = _, S;
25
+ }
26
+ var A = {};
27
+ var K;
28
+ function ce() {
29
+ return K || (K = 1, process.env.NODE_ENV !== "production" && (function() {
30
+ function m(e) {
31
+ if (e == null) return null;
32
+ if (typeof e == "function")
33
+ return e.$$typeof === W ? null : e.displayName || e.name || null;
34
+ if (typeof e == "string") return e;
35
+ switch (e) {
36
+ case k:
37
+ return "Fragment";
38
+ case N:
39
+ return "Profiler";
40
+ case C:
41
+ return "StrictMode";
42
+ case $:
43
+ return "Suspense";
44
+ case F:
45
+ return "SuspenseList";
46
+ case L:
47
+ return "Activity";
48
+ }
49
+ if (typeof e == "object")
50
+ switch (typeof e.tag == "number" && console.error(
51
+ "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
52
+ ), e.$$typeof) {
53
+ case j:
54
+ return "Portal";
55
+ case Y:
56
+ return e.displayName || "Context";
57
+ case M:
58
+ return (e._context.displayName || "Context") + ".Consumer";
59
+ case R:
60
+ var r = e.render;
61
+ return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
62
+ case D:
63
+ return r = e.displayName || null, r !== null ? r : m(e.type) || "Memo";
64
+ case h:
65
+ r = e._payload, e = e._init;
66
+ try {
67
+ return m(e(r));
68
+ } catch {
69
+ }
70
+ }
71
+ return null;
72
+ }
73
+ function b(e) {
74
+ return "" + e;
75
+ }
76
+ function _(e) {
77
+ try {
78
+ b(e);
79
+ var r = !1;
80
+ } catch {
81
+ r = !0;
82
+ }
83
+ if (r) {
84
+ r = console;
85
+ var o = r.error, i = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
86
+ return o.call(
87
+ r,
88
+ "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
89
+ i
90
+ ), b(e);
91
+ }
92
+ }
93
+ function E(e) {
94
+ if (e === k) return "<>";
95
+ if (typeof e == "object" && e !== null && e.$$typeof === h)
96
+ return "<...>";
97
+ try {
98
+ var r = m(e);
99
+ return r ? "<" + r + ">" : "<...>";
100
+ } catch {
101
+ return "<...>";
102
+ }
103
+ }
104
+ function u() {
105
+ var e = P.A;
106
+ return e === null ? null : e.getOwner();
107
+ }
108
+ function l() {
109
+ return Error("react-stack-top-frame");
110
+ }
111
+ function v(e) {
112
+ if (t.call(e, "key")) {
113
+ var r = Object.getOwnPropertyDescriptor(e, "key").get;
114
+ if (r && r.isReactWarning) return !1;
115
+ }
116
+ return e.key !== void 0;
117
+ }
118
+ function p(e, r) {
119
+ function o() {
120
+ d || (d = !0, console.error(
121
+ "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
122
+ r
123
+ ));
124
+ }
125
+ o.isReactWarning = !0, Object.defineProperty(e, "key", {
126
+ get: o,
127
+ configurable: !0
128
+ });
129
+ }
130
+ function x() {
131
+ var e = m(this.type);
132
+ return U[e] || (U[e] = !0, console.error(
133
+ "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
134
+ )), e = this.props.ref, e !== void 0 ? e : null;
135
+ }
136
+ function J(e, r, o, i, I, V) {
137
+ var c = o.ref;
138
+ return e = {
139
+ $$typeof: w,
140
+ type: e,
141
+ key: r,
142
+ props: o,
143
+ _owner: i
144
+ }, (c !== void 0 ? c : null) !== null ? Object.defineProperty(e, "ref", {
145
+ enumerable: !1,
146
+ get: x
147
+ }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
148
+ configurable: !1,
149
+ enumerable: !1,
150
+ writable: !0,
151
+ value: 0
152
+ }), Object.defineProperty(e, "_debugInfo", {
153
+ configurable: !1,
154
+ enumerable: !1,
155
+ writable: !0,
156
+ value: null
157
+ }), Object.defineProperty(e, "_debugStack", {
158
+ configurable: !1,
159
+ enumerable: !1,
160
+ writable: !0,
161
+ value: I
162
+ }), Object.defineProperty(e, "_debugTask", {
163
+ configurable: !1,
164
+ enumerable: !1,
165
+ writable: !0,
166
+ value: V
167
+ }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
168
+ }
169
+ function a(e, r, o, i, I, V) {
170
+ var c = r.children;
171
+ if (c !== void 0)
172
+ if (i)
173
+ if (n(c)) {
174
+ for (i = 0; i < c.length; i++)
175
+ y(c[i]);
176
+ Object.freeze && Object.freeze(c);
177
+ } else
178
+ console.error(
179
+ "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
180
+ );
181
+ else y(c);
182
+ if (t.call(r, "key")) {
183
+ c = m(e);
184
+ var O = Object.keys(r).filter(function(te) {
185
+ return te !== "key";
186
+ });
187
+ i = 0 < O.length ? "{key: someKey, " + O.join(": ..., ") + ": ...}" : "{key: someKey}", H[c + i] || (O = 0 < O.length ? "{" + O.join(": ..., ") + ": ...}" : "{}", console.error(
188
+ `A props object containing a "key" prop is being spread into JSX:
189
+ let props = %s;
190
+ <%s {...props} />
191
+ React keys must be passed directly to JSX without using spread:
192
+ let props = %s;
193
+ <%s key={someKey} {...props} />`,
194
+ i,
195
+ c,
196
+ O,
197
+ c
198
+ ), H[c + i] = !0);
199
+ }
200
+ if (c = null, o !== void 0 && (_(o), c = "" + o), v(r) && (_(r.key), c = "" + r.key), "key" in r) {
201
+ o = {};
202
+ for (var z in r)
203
+ z !== "key" && (o[z] = r[z]);
204
+ } else o = r;
205
+ return c && p(
206
+ o,
207
+ typeof e == "function" ? e.displayName || e.name || "Unknown" : e
208
+ ), J(
209
+ e,
210
+ c,
211
+ o,
212
+ u(),
213
+ I,
214
+ V
215
+ );
216
+ }
217
+ function y(e) {
218
+ T(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === h && (e._payload.status === "fulfilled" ? T(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
219
+ }
220
+ function T(e) {
221
+ return typeof e == "object" && e !== null && e.$$typeof === w;
222
+ }
223
+ var g = ne, w = Symbol.for("react.transitional.element"), j = Symbol.for("react.portal"), k = Symbol.for("react.fragment"), C = Symbol.for("react.strict_mode"), N = Symbol.for("react.profiler"), M = Symbol.for("react.consumer"), Y = Symbol.for("react.context"), R = Symbol.for("react.forward_ref"), $ = Symbol.for("react.suspense"), F = Symbol.for("react.suspense_list"), D = Symbol.for("react.memo"), h = Symbol.for("react.lazy"), L = Symbol.for("react.activity"), W = Symbol.for("react.client.reference"), P = g.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, t = Object.prototype.hasOwnProperty, n = Array.isArray, s = console.createTask ? console.createTask : function() {
224
+ return null;
225
+ };
226
+ g = {
227
+ react_stack_bottom_frame: function(e) {
228
+ return e();
229
+ }
230
+ };
231
+ var d, U = {}, G = g.react_stack_bottom_frame.bind(
232
+ g,
233
+ l
234
+ )(), X = s(E(l)), H = {};
235
+ A.Fragment = k, A.jsx = function(e, r, o) {
236
+ var i = 1e4 > P.recentlyCreatedOwnerStacks++;
237
+ return a(
238
+ e,
239
+ r,
240
+ o,
241
+ !1,
242
+ i ? Error("react-stack-top-frame") : G,
243
+ i ? s(E(e)) : X
244
+ );
245
+ }, A.jsxs = function(e, r, o) {
246
+ var i = 1e4 > P.recentlyCreatedOwnerStacks++;
247
+ return a(
248
+ e,
249
+ r,
250
+ o,
251
+ !0,
252
+ i ? Error("react-stack-top-frame") : G,
253
+ i ? s(E(e)) : X
254
+ );
255
+ };
256
+ })()), A;
257
+ }
258
+ var ee;
259
+ function le() {
260
+ return ee || (ee = 1, process.env.NODE_ENV === "production" ? q.exports = ie() : q.exports = ce()), q.exports;
261
+ }
262
+ var ue = le();
263
+ const re = oe(null);
264
+ function me() {
265
+ const m = ae(re);
266
+ if (!m)
267
+ throw new Error("useCompetition must be used within CompetitionProvider");
268
+ return m;
269
+ }
270
+ function de({
271
+ competitionId: m,
272
+ seasonId: b,
273
+ stageId: _,
274
+ matches: E,
275
+ standings: u,
276
+ previousSeasons: l,
277
+ config: v,
278
+ autoRefresh: p = !0,
279
+ refreshInterval: x = 3e4,
280
+ children: J
281
+ }) {
282
+ const [a, y] = Z(E), [T, g] = Z(u);
283
+ B(() => {
284
+ y(E);
285
+ }, [E]), B(() => {
286
+ g(u);
287
+ }, [u]), B(() => {
288
+ if (!p || !a.some((s) => s.status.code === "live")) return;
289
+ const n = setInterval(async () => {
290
+ console.log("[CompetitionProvider] Auto-refresh triggered for live matches");
291
+ }, x);
292
+ return () => clearInterval(n);
293
+ }, [p, x, a]);
294
+ const w = f((t) => a.find((n) => n.id === t), [a]), j = f(
295
+ (t) => a.filter((n) => n.competitorOne.id === t || n.competitorTwo.id === t),
296
+ [a]
297
+ ), k = f(
298
+ (t) => a.filter((n) => n.timing.kickoffTime.toISOString().startsWith(t)),
299
+ [a]
300
+ ), C = f(
301
+ (t) => a.filter((n) => n.round?.id === t),
302
+ [a]
303
+ ), N = f(() => a.filter((t) => t.status.code === "live"), [a]), M = f(
304
+ (t) => {
305
+ const n = /* @__PURE__ */ new Date();
306
+ let s = a.filter((d) => d.status.code === "not_started" && d.timing.kickoffTime > n);
307
+ return t && (s = s.filter((d) => d.competitorOne.id === t || d.competitorTwo.id === t)), s.sort((d, U) => d.timing.kickoffTime.getTime() - U.timing.kickoffTime.getTime());
308
+ },
309
+ [a]
310
+ ), Y = f(
311
+ (t) => {
312
+ let n = a.filter((s) => s.status.code === "finished");
313
+ return t && (n = n.filter((s) => s.competitorOne.id === t || s.competitorTwo.id === t)), n.sort((s, d) => d.timing.kickoffTime.getTime() - s.timing.kickoffTime.getTime());
314
+ },
315
+ [a]
316
+ ), R = f(
317
+ (t) => T.find((n) => n.competitor.id === t),
318
+ [T]
319
+ ), $ = f((t) => R(t)?.form?.formString, [R]), F = f((t) => R(t)?.stats, [R]), D = f(
320
+ (t) => [...T].sort((n, s) => n.rank - s.rank).slice(0, t),
321
+ [T]
322
+ ), h = f(
323
+ (t) => [...T].sort((n, s) => s.rank - n.rank).slice(0, t),
324
+ [T]
325
+ ), L = f(
326
+ (t) => l?.find((n) => n.id === t)?.matches,
327
+ [l]
328
+ ), W = f(
329
+ (t) => l?.find((n) => n.id === t)?.standings,
330
+ [l]
331
+ ), P = se(
332
+ () => ({
333
+ // Core identifiers
334
+ competitionId: m,
335
+ seasonId: b,
336
+ stageId: _,
337
+ // Core data
338
+ matches: a,
339
+ standings: T,
340
+ // Historical data
341
+ previousSeasons: l,
342
+ // Custom configuration
343
+ config: v,
344
+ // Match helpers
345
+ getMatch: w,
346
+ getMatchesByTeam: j,
347
+ getMatchesByDate: k,
348
+ getMatchesByRound: C,
349
+ getLiveMatches: N,
350
+ getUpcomingMatches: M,
351
+ getFinishedMatches: Y,
352
+ // Standings helpers
353
+ getTeamStanding: R,
354
+ getTeamForm: $,
355
+ getTeamStats: F,
356
+ getTopTeams: D,
357
+ getBottomTeams: h,
358
+ // Historical helpers
359
+ getSeasonMatches: L,
360
+ getSeasonStandings: W
361
+ }),
362
+ [
363
+ m,
364
+ b,
365
+ _,
366
+ a,
367
+ T,
368
+ l,
369
+ v,
370
+ w,
371
+ j,
372
+ k,
373
+ C,
374
+ N,
375
+ M,
376
+ Y,
377
+ R,
378
+ $,
379
+ F,
380
+ D,
381
+ h,
382
+ L,
383
+ W
384
+ ]
385
+ );
386
+ return /* @__PURE__ */ ue.jsx(re.Provider, { value: P, children: J });
387
+ }
388
+ export {
389
+ re as CompetitionContext,
390
+ de as CompetitionProvider,
391
+ me as useCompetition
392
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let p=null;function A(t){p=t}function i(){if(!p)throw new Error("Data layer config not initialized. Call setConfig() in your root layout.");return p}function O(){return p!==null}function v(t){const e=t.replace(/\/$/,"");function o(){const{sportal365Sports:s}=i();if(!s)throw new Error("Sportal365 Sports API configuration is missing");const a=`${s.username}:${s.password}`;return`Basic ${btoa(a)}`}function n(s){return`${e}${s}`}return{async get(s){const{sportal365Sports:a}=i();if(!a)throw new Error("Sportal365 Sports API configuration is missing");const d=new URL(n(s.path));if(s.params)for(const[u,m]of Object.entries(s.params))m!==void 0&&(Array.isArray(m)?m.length>0&&d.searchParams.set(u,m.join(",")):d.searchParams.set(u,m));const c=await fetch(d.toString(),{method:"GET",headers:{Authorization:o(),"Content-Type":"application/json","X-Project":a.projectId},signal:a.timeout?AbortSignal.timeout(a.timeout):void 0});if(!c.ok)throw new Error(`Sportal365 API error: ${c.status} ${c.statusText}`);return c.json()}}}const L="https://football.api.sportal365.com",b="https://standing.api.sportal365.com",l=v(L);function f(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 k={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 g(t){const e=k[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:f(t.primary_player),secondaryPlayer:f(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 I(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 y(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 C(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 N(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 D(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 P(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 F(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 R(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 S(t){return{id:t.id,slug:t.slug,status:I(t.status),timing:C(t),competitorOne:y(t.home_team),competitorTwo:y(t.away_team),competition:F(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:D(t.venue),officials:P(t.referees),spectators:t.spectators??void 0,score:N(t.score),mainEvents:t.main_events?.map(g).filter(e=>e!==null),penaltyShootoutEvents:t.penalty_shootout_events?.map(g).filter(e=>e!==null),winner:R(t),coverage:t.coverage==="NOT_LIVE"?"UNKNOWN":t.coverage,lineupStatus:t.lineup_status==="UNCONFIRMED"?"EXPECTED":t.lineup_status}}function M(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(g).filter(o=>o!==null)}}function h(t){const e=[],o=[];for(const n of t.players){const s=M(n);n.type.category==="start"?e.push(s):n.type.category==="sub"&&o.push(s)}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 U(t){return{matchId:t.match_id,confirmed:t.status==="CONFIRMED",competitorOne:h(t.home_team),competitorTwo:h(t.away_team)}}function r(t,e,o,n){return e==null?null:{key:t,value:String(e),label:o,unit:n}}function E(t,e){const o=(e.shots_on??0)+(e.shots_off??0)+(e.shots_blocked??0),n=[r("possession",e.possession,"Possession","%"),r("shots_total",o,"Shots"),r("shots_on_target",e.shots_on,"Shots on Target"),r("shots_off_target",e.shots_off,"Shots off Target"),r("shots_blocked",e.shots_blocked,"Shots Blocked"),r("corners",e.corners,"Corner Kicks"),r("goal_kicks",e.goal_kicks,"Goal Kicks"),r("throw_ins",e.throw_in,"Throw Ins"),r("offsides",e.offside,"Offsides"),r("fouls",e.fouls_committed,"Fouls"),r("yellow_cards",e.yellow_cards,"Yellow Cards"),r("passes",e.pass,"Passes"),r("crosses",e.crosses,"Crosses")];return{competitorId:t,statistics:n.filter(s=>s!==null)}}function $(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:E(String(e.team.id),e.statistics),competitorTwo:E(String(o.team.id),o.statistics)}}function Y(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 G(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(Y)}}function H(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(G)}}function x(t,e){return{matchId:t,operators:e.map(H)}}function T(t){if(t==null||t==="")return;const e=typeof t=="number"?t:parseInt(t,10);return isNaN(e)?void 0:e}function K(t){return{externalId:t.external_id,minute:T(t.elapsed),addedTime:T(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 j(t,e={}){const{sportal365Sports:o}=i(),n=await l.get({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 S(n)}async function W(t,e={}){const{sportal365Sports:o}=i();return(await l.get({path:`/v2/matches/${t}/events`,params:{language_code:e.languageCode??o?.languageCode??"en"}})).events.map(g).filter(s=>s!==null)}async function B(t,e={}){const{sportal365Sports:o}=i(),n=await l.get({path:`/v2/matches/${t}/lineups`,params:{language_code:e.languageCode??o?.languageCode??"en"}});return U(n)}async function V(t,e={}){const{sportal365Sports:o}=i(),n=await l.get({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 x(t,n.odds??[])}async function X(t,e={}){const{sportal365Sports:o}=i(),n=await l.get({path:`/events/${t}/teamstats`,params:{language_code:e.languageCode??o?.languageCode??"en"}});return $(n)}async function q(t,e={}){const{sportal365Sports:o}=i();return(await l.get({path:`/matches/${t}/commentary`,params:{language_code:e.languageCode??o?.languageCode??"en"}})).map(K)}async function z(t){const{sportal365Sports:e}=i();return(await l.get({path:"/v2/matches",params:{language_code:t.languageCode??e?.languageCode??"en",limit:t.limit.toString(),offset:t.offset.toString(),tournament_ids:t.tournamentIds,season_ids:t.seasonIds,stage_ids:t.stageIds,group_ids:t.groupIds,round_ids:t.roundIds,round_filter:t.roundFilter,from_kickoff_time:t.fromKickoffTime,to_kickoff_time:t.toKickoffTime,team_ids:t.teamIds,team_ids_operator:t.teamIdsOperator,referee_id:t.refereeId,venue_id:t.venueId,player_id:t.playerId,status_types:t.statusTypes,status_codes:t.statusCodes,odd_client:t.oddClient??e?.oddClient,odd_type:t.oddType,scope_type:t.scopeType,odd_format:t.oddFormat,market_types:t.marketTypes,bookmaker_ids:t.bookmakerIds,sort_direction:t.sortDirection,optional_data:t.optionalData}})).matches.map(S)}function J(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 Q(t,e={}){const{sportal365Sports:o}=i(),n=await l.get({path:`/v2/teams/${t}`,params:{language_code:e.languageCode??o?.languageCode??"en",optional_data:"form"}});return J(n)}const Z=b.replace(/\/$/,"");function w(){const{sportal365Sports:t}=i();if(!t)throw new Error("Sportal365 Sports API configuration is missing");const e=`${t.username}:${t.password}`;return`Basic ${btoa(e)}`}function tt(t){return`${Z}${t}`}const et={async get(t){const{sportal365Sports:e}=i();if(!e)throw new Error("Sportal365 Sports API configuration is missing");const o=new URL(tt(t.path));if(t.params)for(const[s,a]of Object.entries(t.params))a!==void 0&&(Array.isArray(a)?a.length>0&&o.searchParams.set(s,a.join(",")):o.searchParams.set(s,a));const n=await fetch(o.toString(),{method:"GET",headers:{Authorization:w(),"Content-Type":"application/json","X-Project":e.projectId},signal:e.timeout?AbortSignal.timeout(e.timeout):void 0});if(!n.ok){const s=await n.text();throw new Error(`Sportal365 Standings API error: ${n.status} ${n.statusText} - ${s}`)}return n.json()}};function ot(t){return{RANK:"rank",PLAYED:"played",WINS:"won",DRAWS:"drawn",LOSSES:"lost",GOALS_FOR:"goalsFor",GOALS_AGAINST:"goalsAgainst",GOAL_DIFFERENCE:"goalDifference",POINTS:"points"}[t]??t.toLowerCase()}function _(t){return{CHAMPIONS_LEAGUE:"championsLeague",EUROPA_LEAGUE:"europaLeague",CONFERENCE_LEAGUE:"conferenceLeague",RELEGATION:"relegation",PLAYOFF:"playoff",PROMOTION:"promotion"}[t]??t.toLowerCase().replace(/_/g,"")}function nt(t){switch(t){case"win":return"W";case"loss":return"L";case"draw":return"D"}}function st(t,e){if(!e||e.length===0)return;const o=e.map(s=>{const a=s.participants.find(c=>c.id!==t)??s.participants[0],d=s.result?.[0]?.results?.map(c=>c.value).join("-")??void 0;return{matchId:s.id,result:nt(s.outcome),score:d,opponent:{id:a.id,name:a.name,logo:a.display_asset?.url??a.assets?.logo?.url},date:new Date(s.start_time),competition:s.competition?{id:s.competition.id,name:s.competition.name}:void 0}}),n=o.map(s=>s.result).join("");return{competitorId:t,results:o,formString:n}}function at(t){return{key:_(t.standing_api_rule_type),name:t.name,position:t.type}}function rt(t){const e={};let o=0;for(const d of t.columns){const c=ot(d.type.code),u=parseInt(d.value,10);d.type.code==="RANK"?o=u:e[c]=isNaN(u)?void 0:u}const n=t.rules?.length>0?t.rules.map(d=>_(d.standing_api_rule_type)):void 0,s=st(t.team.id,t.form),a=t.team.assets?.logo?.url;return{rank:o,competitor:{id:t.team.id,name:t.team.name,shortName:t.team.short_name??void 0,logo:a},stats:e,form:s,rules:n}}function it(t){const e=t.map(rt),o=new Map;for(const n of t)if(n.rules)for(const s of n.rules){const a=_(s.standing_api_rule_type);o.has(a)||o.set(a,at(s))}return{entries:e,metadata:{legend:Array.from(o.values())}}}async function dt(t){const o=(await et.get({path:"/standings/football",params:{stage_id:t.stageId,coverage_type:t.coverageType??"ALL",optional_data:t.optionalData}})).data?.[0];if(!o?.standings?.length)return{entries:[],metadata:{legend:[]}};const n=o.standings[0];return n?.standing?.length?it(n.standing):{entries:[],metadata:{legend:[]}}}const ct="0.0.2";exports.getConfig=i;exports.getFootballMatch=j;exports.getFootballMatchCommentary=q;exports.getFootballMatchEvents=W;exports.getFootballMatchLineups=B;exports.getFootballMatchOdds=V;exports.getFootballMatchStatistics=X;exports.getFootballMatches=z;exports.getFootballStandings=dt;exports.getFootballTeam=Q;exports.isConfigured=O;exports.setConfig=A;exports.version=ct;