fansunited-data-layer 0.14.2 → 0.14.3
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/fansunited/http.js +0 -2
- package/api/fansunited/http.js.map +1 -1
- package/api/sportal365-sports/http.d.ts.map +1 -1
- package/api/sportal365-sports/http.js +0 -1
- package/api/sportal365-sports/http.js.map +1 -1
- package/config/types.d.ts +0 -1
- package/config/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/lib/api/fansunited/http.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAa,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC3B,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,uBAAuB;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IACvD,+CAA+C;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,2DAA2D;IAC3D,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,kEAAkE;IAClE,MAAM,CAAC,EAAE,eAAe,CAAC;CAC5B;AAED,MAAM,WAAW,oBAAoB;IACjC;;;;;;;;;;OAUG;IACH,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAC/C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB,
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/lib/api/fansunited/http.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAa,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC3B,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,uBAAuB;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IACvD,+CAA+C;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,2DAA2D;IAC3D,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,kEAAkE;IAClE,MAAM,CAAC,EAAE,eAAe,CAAC;CAC5B;AAED,MAAM,WAAW,oBAAoB;IACjC;;;;;;;;;;OAUG;IACH,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAC/C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB,CA8ErE"}
|
package/api/fansunited/http.js
CHANGED
|
@@ -31,7 +31,6 @@ function createHttpClient(domain) {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
const timeout = 3e4;
|
|
35
34
|
const response = await fetch(url.toString(), {
|
|
36
35
|
method: "GET",
|
|
37
36
|
headers: {
|
|
@@ -40,7 +39,6 @@ function createHttpClient(domain) {
|
|
|
40
39
|
// Merge custom headers (they can override defaults)
|
|
41
40
|
...options.headers
|
|
42
41
|
},
|
|
43
|
-
signal: AbortSignal.timeout(timeout),
|
|
44
42
|
// Next.js cache options for ISR/on-demand revalidation
|
|
45
43
|
...options.next && { next: options.next }
|
|
46
44
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sources":["../../../src/lib/api/fansunited/http.ts"],"sourcesContent":["/**\n * HTTP client for Fans United APIs\n */\n\nimport { getConfig, type DataLayerConfig } from \"../../config\";\n\n/**\n * Next.js cache options for ISR/on-demand revalidation\n */\nexport interface NextCacheOptions {\n revalidate?: number | false;\n tags?: string[];\n}\n\nexport interface RequestOptions {\n /** API path (e.g., '/v1/competitions') */\n path: string;\n /** Query parameters */\n params?: Record<string, string | string[] | undefined>;\n /** Custom headers to include in the request */\n headers?: Record<string, string>;\n /** Next.js cache options for ISR/on-demand revalidation */\n next?: NextCacheOptions;\n /** Optional data layer config (uses singleton if not provided) */\n config?: DataLayerConfig;\n}\n\nexport interface FansUnitedHttpClient {\n /**\n * Make a GET request to a Fans United API\n *\n * Handles:\n * - API key and client ID authentication via query params\n * - Timeout\n * - Error handling\n *\n * @param options - Request options\n * @returns Parsed JSON response\n */\n get<T>(options: RequestOptions): Promise<T>;\n}\n\n/**\n * Create an HTTP client for a specific Fans United API domain\n *\n * @param domain - The base URL for the API (e.g., 'https://football.fansunitedapi.com')\n * @returns HTTP client configured for the specified domain\n *\n * @example\n * ```typescript\n * import { createHttpClient } from '../http';\n * import { FANSUNITED_FOOTBALL_DOMAIN } from '../constants';\n *\n * const footballHttp = createHttpClient(FANSUNITED_FOOTBALL_DOMAIN);\n * const data = await footballHttp.get({ path: '/v1/competitions' });\n * ```\n */\nexport function createHttpClient(domain: string): FansUnitedHttpClient {\n const baseUrl = domain.replace(/\\/$/, \"\");\n\n function buildUrl(path: string): string {\n return `${baseUrl}${path}`;\n }\n\n return {\n async get<T>(options: RequestOptions): Promise<T> {\n const finalConfig = options.config || getConfig();\n const { fansUnited } = finalConfig;\n\n if (!fansUnited) {\n throw new Error(\n \"Fans United configuration is missing. \" +\n \"Add 'fansUnited' with 'apiKey' and 'clientId' to your config.\"\n );\n }\n\n if (!fansUnited.apiKey || !fansUnited.clientId) {\n throw new Error(\"Fans United configuration requires both 'apiKey' and 'clientId'\");\n }\n\n const url = new URL(buildUrl(options.path));\n\n // Add authentication query parameters\n url.searchParams.set(\"key\", fansUnited.apiKey);\n url.searchParams.set(\"client_id\", fansUnited.clientId);\n\n // Add additional query parameters\n if (options.params) {\n for (const [key, value] of Object.entries(options.params)) {\n if (value === undefined) continue;\n\n if (Array.isArray(value)) {\n if (value.length > 0) {\n url.searchParams.set(key, value.join(\",\"));\n }\n } else {\n url.searchParams.set(key, value);\n }\n }\n }\n\n
|
|
1
|
+
{"version":3,"file":"http.js","sources":["../../../src/lib/api/fansunited/http.ts"],"sourcesContent":["/**\n * HTTP client for Fans United APIs\n */\n\nimport { getConfig, type DataLayerConfig } from \"../../config\";\n\n/**\n * Next.js cache options for ISR/on-demand revalidation\n */\nexport interface NextCacheOptions {\n revalidate?: number | false;\n tags?: string[];\n}\n\nexport interface RequestOptions {\n /** API path (e.g., '/v1/competitions') */\n path: string;\n /** Query parameters */\n params?: Record<string, string | string[] | undefined>;\n /** Custom headers to include in the request */\n headers?: Record<string, string>;\n /** Next.js cache options for ISR/on-demand revalidation */\n next?: NextCacheOptions;\n /** Optional data layer config (uses singleton if not provided) */\n config?: DataLayerConfig;\n}\n\nexport interface FansUnitedHttpClient {\n /**\n * Make a GET request to a Fans United API\n *\n * Handles:\n * - API key and client ID authentication via query params\n * - Timeout\n * - Error handling\n *\n * @param options - Request options\n * @returns Parsed JSON response\n */\n get<T>(options: RequestOptions): Promise<T>;\n}\n\n/**\n * Create an HTTP client for a specific Fans United API domain\n *\n * @param domain - The base URL for the API (e.g., 'https://football.fansunitedapi.com')\n * @returns HTTP client configured for the specified domain\n *\n * @example\n * ```typescript\n * import { createHttpClient } from '../http';\n * import { FANSUNITED_FOOTBALL_DOMAIN } from '../constants';\n *\n * const footballHttp = createHttpClient(FANSUNITED_FOOTBALL_DOMAIN);\n * const data = await footballHttp.get({ path: '/v1/competitions' });\n * ```\n */\nexport function createHttpClient(domain: string): FansUnitedHttpClient {\n const baseUrl = domain.replace(/\\/$/, \"\");\n\n function buildUrl(path: string): string {\n return `${baseUrl}${path}`;\n }\n\n return {\n async get<T>(options: RequestOptions): Promise<T> {\n const finalConfig = options.config || getConfig();\n const { fansUnited } = finalConfig;\n\n if (!fansUnited) {\n throw new Error(\n \"Fans United configuration is missing. \" +\n \"Add 'fansUnited' with 'apiKey' and 'clientId' to your config.\"\n );\n }\n\n if (!fansUnited.apiKey || !fansUnited.clientId) {\n throw new Error(\"Fans United configuration requires both 'apiKey' and 'clientId'\");\n }\n\n const url = new URL(buildUrl(options.path));\n\n // Add authentication query parameters\n url.searchParams.set(\"key\", fansUnited.apiKey);\n url.searchParams.set(\"client_id\", fansUnited.clientId);\n\n // Add additional query parameters\n if (options.params) {\n for (const [key, value] of Object.entries(options.params)) {\n if (value === undefined) continue;\n\n if (Array.isArray(value)) {\n if (value.length > 0) {\n url.searchParams.set(key, value.join(\",\"));\n }\n } else {\n url.searchParams.set(key, value);\n }\n }\n }\n\n const response = await fetch(url.toString(), {\n method: \"GET\",\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n // Merge custom headers (they can override defaults)\n ...options.headers,\n },\n // Next.js cache options for ISR/on-demand revalidation\n ...(options.next && { next: options.next }),\n });\n\n if (!response.ok) {\n // Try to get error details from response body\n let errorMessage = `Fans United API error: ${response.status} ${response.statusText}`;\n try {\n const errorBody = await response.text();\n if (errorBody) {\n errorMessage += ` - ${errorBody}`;\n }\n } catch (error) {\n // Log if we can't read the error body, but continue\n console.error(\"[Fans United HTTP] Failed to read error response body:\", {\n error: error instanceof Error ? error.message : String(error),\n status: response.status,\n statusText: response.statusText,\n });\n }\n throw new Error(errorMessage);\n }\n\n return response.json();\n },\n };\n}\n"],"names":[],"mappings":";AAyDO,SAAS,iBAAiB,QAAs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CAC/C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB,
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/lib/api/sportal365-sports/http.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAa,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/D;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC7B,0EAA0E;IAC1E,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAC5B,iEAAiE;IACjE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC3B,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,uBAAuB;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IACvD,+CAA+C;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,2DAA2D;IAC3D,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,kEAAkE;IAClE,MAAM,CAAC,EAAE,eAAe,CAAC;CAC5B;AAED,MAAM,WAAW,oBAAoB;IACjC;;;;;;;;;;;OAWG;IACH,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAC/C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB,CA8DrE"}
|
|
@@ -41,7 +41,6 @@ function createHttpClient(domain) {
|
|
|
41
41
|
// Merge custom headers (they can override defaults)
|
|
42
42
|
...options.headers
|
|
43
43
|
},
|
|
44
|
-
signal: sportal365Sports.timeout ? AbortSignal.timeout(sportal365Sports.timeout) : void 0,
|
|
45
44
|
// Next.js cache options for ISR/on-demand revalidation
|
|
46
45
|
...options.next && { next: options.next }
|
|
47
46
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sources":["../../../src/lib/api/sportal365-sports/http.ts"],"sourcesContent":["/**\n * Sportal365 Sports API - HTTP client factory\n * Creates sport-specific HTTP clients for Sportal365 APIs\n */\n\nimport { getConfig, type DataLayerConfig } from \"../../config\";\n\n/**\n * Next.js cache options for fetch requests\n * @see https://nextjs.org/docs/app/api-reference/functions/fetch#optionsnext\n */\nexport interface NextCacheOptions {\n /** Time in seconds to cache the response. Set to 0 to disable caching. */\n revalidate?: number | false;\n /** Cache tags for on-demand revalidation with revalidateTag() */\n tags?: string[];\n}\n\nexport interface RequestOptions {\n /** API path (e.g., '/v2/matches/123') */\n path: string;\n /** Query parameters */\n params?: Record<string, string | string[] | undefined>;\n /** Custom headers to include in the request */\n headers?: Record<string, string>;\n /** Next.js cache options for ISR/on-demand revalidation */\n next?: NextCacheOptions;\n /** Optional data layer config (uses singleton if not provided) */\n config?: DataLayerConfig;\n}\n\nexport interface Sportal365HttpClient {\n /**\n * Make a GET request to the Sportal365 Sports API\n *\n * Handles:\n * - Authentication (Basic Auth)\n * - Project ID header\n * - Timeout\n * - Error handling\n *\n * @param options - Request options\n * @returns Parsed JSON response\n */\n get<T>(options: RequestOptions): Promise<T>;\n}\n\n/**\n * Create an HTTP client for a specific Sportal365 API domain\n *\n * @param domain - The base URL for the API (e.g., 'https://football.api.sportal365.com')\n * @returns HTTP client configured for the specified domain\n *\n * @example\n * ```typescript\n * import { createHttpClient } from '../http';\n * import { SPORTAL365_FOOTBALL_DOMAIN } from '../constants';\n *\n * const footballHttp = createHttpClient(SPORTAL365_FOOTBALL_DOMAIN);\n * const data = await footballHttp.get({ path: '/v2/matches/123' });\n * ```\n */\nexport function createHttpClient(domain: string): Sportal365HttpClient {\n const baseUrl = domain.replace(/\\/$/, \"\");\n\n function getAuthHeader(config: DataLayerConfig): string {\n const { sportal365Sports } = config;\n if (!sportal365Sports) {\n throw new Error(\"Sportal365 Sports API configuration is missing\");\n }\n const credentials = `${sportal365Sports.username}:${sportal365Sports.password}`;\n return `Basic ${btoa(credentials)}`;\n }\n\n function buildUrl(path: string): string {\n return `${baseUrl}${path}`;\n }\n\n return {\n async get<T>(options: RequestOptions): Promise<T> {\n const finalConfig = options.config || getConfig();\n const { sportal365Sports } = finalConfig;\n\n if (!sportal365Sports) {\n throw new Error(\"Sportal365 Sports API configuration is missing\");\n }\n\n const url = new URL(buildUrl(options.path));\n\n // Add query parameters\n if (options.params) {\n for (const [key, value] of Object.entries(options.params)) {\n if (value === undefined) continue;\n\n if (Array.isArray(value)) {\n if (value.length > 0) {\n url.searchParams.set(key, value.join(\",\"));\n }\n } else {\n url.searchParams.set(key, value);\n }\n }\n }\n\n const response = await fetch(url.toString(), {\n method: \"GET\",\n headers: {\n Authorization: getAuthHeader(finalConfig),\n \"Content-Type\": \"application/json\",\n \"X-Project\": sportal365Sports.projectId,\n // Merge custom headers (they can override defaults)\n ...options.headers,\n },\n
|
|
1
|
+
{"version":3,"file":"http.js","sources":["../../../src/lib/api/sportal365-sports/http.ts"],"sourcesContent":["/**\n * Sportal365 Sports API - HTTP client factory\n * Creates sport-specific HTTP clients for Sportal365 APIs\n */\n\nimport { getConfig, type DataLayerConfig } from \"../../config\";\n\n/**\n * Next.js cache options for fetch requests\n * @see https://nextjs.org/docs/app/api-reference/functions/fetch#optionsnext\n */\nexport interface NextCacheOptions {\n /** Time in seconds to cache the response. Set to 0 to disable caching. */\n revalidate?: number | false;\n /** Cache tags for on-demand revalidation with revalidateTag() */\n tags?: string[];\n}\n\nexport interface RequestOptions {\n /** API path (e.g., '/v2/matches/123') */\n path: string;\n /** Query parameters */\n params?: Record<string, string | string[] | undefined>;\n /** Custom headers to include in the request */\n headers?: Record<string, string>;\n /** Next.js cache options for ISR/on-demand revalidation */\n next?: NextCacheOptions;\n /** Optional data layer config (uses singleton if not provided) */\n config?: DataLayerConfig;\n}\n\nexport interface Sportal365HttpClient {\n /**\n * Make a GET request to the Sportal365 Sports API\n *\n * Handles:\n * - Authentication (Basic Auth)\n * - Project ID header\n * - Timeout\n * - Error handling\n *\n * @param options - Request options\n * @returns Parsed JSON response\n */\n get<T>(options: RequestOptions): Promise<T>;\n}\n\n/**\n * Create an HTTP client for a specific Sportal365 API domain\n *\n * @param domain - The base URL for the API (e.g., 'https://football.api.sportal365.com')\n * @returns HTTP client configured for the specified domain\n *\n * @example\n * ```typescript\n * import { createHttpClient } from '../http';\n * import { SPORTAL365_FOOTBALL_DOMAIN } from '../constants';\n *\n * const footballHttp = createHttpClient(SPORTAL365_FOOTBALL_DOMAIN);\n * const data = await footballHttp.get({ path: '/v2/matches/123' });\n * ```\n */\nexport function createHttpClient(domain: string): Sportal365HttpClient {\n const baseUrl = domain.replace(/\\/$/, \"\");\n\n function getAuthHeader(config: DataLayerConfig): string {\n const { sportal365Sports } = config;\n if (!sportal365Sports) {\n throw new Error(\"Sportal365 Sports API configuration is missing\");\n }\n const credentials = `${sportal365Sports.username}:${sportal365Sports.password}`;\n return `Basic ${btoa(credentials)}`;\n }\n\n function buildUrl(path: string): string {\n return `${baseUrl}${path}`;\n }\n\n return {\n async get<T>(options: RequestOptions): Promise<T> {\n const finalConfig = options.config || getConfig();\n const { sportal365Sports } = finalConfig;\n\n if (!sportal365Sports) {\n throw new Error(\"Sportal365 Sports API configuration is missing\");\n }\n\n const url = new URL(buildUrl(options.path));\n\n // Add query parameters\n if (options.params) {\n for (const [key, value] of Object.entries(options.params)) {\n if (value === undefined) continue;\n\n if (Array.isArray(value)) {\n if (value.length > 0) {\n url.searchParams.set(key, value.join(\",\"));\n }\n } else {\n url.searchParams.set(key, value);\n }\n }\n }\n\n const response = await fetch(url.toString(), {\n method: \"GET\",\n headers: {\n Authorization: getAuthHeader(finalConfig),\n \"Content-Type\": \"application/json\",\n \"X-Project\": sportal365Sports.projectId,\n // Merge custom headers (they can override defaults)\n ...options.headers,\n },\n // Next.js cache options for ISR/on-demand revalidation\n ...(options.next && { next: options.next }),\n });\n\n if (!response.ok) {\n throw new Error(`Sportal365 API error: ${response.status} ${response.statusText}`);\n }\n\n return response.json();\n },\n };\n}\n"],"names":[],"mappings":";AA8DO,SAAS,iBAAiB,QAAsC;AACnE,QAAM,UAAU,OAAO,QAAQ,OAAO,EAAE;AAExC,WAAS,cAAc,QAAiC;AACpD,UAAM,EAAE,qBAAqB;AAC7B,QAAI,CAAC,kBAAkB;AACnB,YAAM,IAAI,MAAM,gDAAgD;AAAA,IACpE;AACA,UAAM,cAAc,GAAG,iBAAiB,QAAQ,IAAI,iBAAiB,QAAQ;AAC7E,WAAO,SAAS,KAAK,WAAW,CAAC;AAAA,EACrC;AAEA,WAAS,SAAS,MAAsB;AACpC,WAAO,GAAG,OAAO,GAAG,IAAI;AAAA,EAC5B;AAEA,SAAO;AAAA,IACH,MAAM,IAAO,SAAqC;AAC9C,YAAM,cAAc,QAAQ,UAAU,UAAA;AACtC,YAAM,EAAE,qBAAqB;AAE7B,UAAI,CAAC,kBAAkB;AACnB,cAAM,IAAI,MAAM,gDAAgD;AAAA,MACpE;AAEA,YAAM,MAAM,IAAI,IAAI,SAAS,QAAQ,IAAI,CAAC;AAG1C,UAAI,QAAQ,QAAQ;AAChB,mBAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,QAAQ,MAAM,GAAG;AACvD,cAAI,UAAU,OAAW;AAEzB,cAAI,MAAM,QAAQ,KAAK,GAAG;AACtB,gBAAI,MAAM,SAAS,GAAG;AAClB,kBAAI,aAAa,IAAI,KAAK,MAAM,KAAK,GAAG,CAAC;AAAA,YAC7C;AAAA,UACJ,OAAO;AACH,gBAAI,aAAa,IAAI,KAAK,KAAK;AAAA,UACnC;AAAA,QACJ;AAAA,MACJ;AAEA,YAAM,WAAW,MAAM,MAAM,IAAI,YAAY;AAAA,QACzC,QAAQ;AAAA,QACR,SAAS;AAAA,UACL,eAAe,cAAc,WAAW;AAAA,UACxC,gBAAgB;AAAA,UAChB,aAAa,iBAAiB;AAAA;AAAA,UAE9B,GAAG,QAAQ;AAAA,QAAA;AAAA;AAAA,QAGf,GAAI,QAAQ,QAAQ,EAAE,MAAM,QAAQ,KAAA;AAAA,MAAK,CAC5C;AAED,UAAI,CAAC,SAAS,IAAI;AACd,cAAM,IAAI,MAAM,yBAAyB,SAAS,MAAM,IAAI,SAAS,UAAU,EAAE;AAAA,MACrF;AAEA,aAAO,SAAS,KAAA;AAAA,IACpB;AAAA,EAAA;AAER;"}
|
package/config/types.d.ts
CHANGED
package/config/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/config/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,sBAAsB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,mFAAmF;IACnF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/config/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,sBAAsB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,mFAAmF;IACnF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC1B,GAAG,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,eAAe;IAC5B,kDAAkD;IAClD,qBAAqB,EAAE,kBAAkB,GAAG,qBAAqB,CAAC;IAElE,0CAA0C;IAC1C,gBAAgB,CAAC,EAAE,sBAAsB,CAAC;IAE1C,gCAAgC;IAChC,OAAO,CAAC,EAAE,aAAa,CAAC;IAExB;;;;OAIG;IACH,UAAU,CAAC,EAAE;QACT,iDAAiD;QACjD,MAAM,EAAE,MAAM,CAAC;QACf,mDAAmD;QACnD,QAAQ,EAAE,MAAM,CAAC;QACjB,+EAA+E;QAC/E,IAAI,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;CACL"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"description": "A TypeScript library for fetching and transforming sports data from multiple API providers. Returns clean, canonical types that are provider-agnostic.",
|
|
5
5
|
"homepage": "https://fansunited.com/",
|
|
6
6
|
"private": false,
|
|
7
|
-
"version": "0.14.
|
|
7
|
+
"version": "0.14.3",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"sideEffects": false,
|
|
10
10
|
"module": "./fansunited-data-layer.js",
|