@mundogamernetwork/shared-ui 1.3.1 → 1.3.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mundogamernetwork/shared-ui",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Mundo Gamer Network - Shared UI Layer (Nuxt 3)",
5
5
  "type": "module",
6
6
  "main": "./nuxt.config.ts",
@@ -13,15 +13,21 @@ const routePath = route.path.split('/');
13
13
  const lang = SUPPORTED_LOCALES.find(l => routePath.includes(l)) || 'en';
14
14
 
15
15
  const config = useRuntimeConfig();
16
- // keyApiUrl overrides apiBaseURL — lets each front point to a specific API base
17
- // (e.g. community uses agency-api, not its own locale-prefixed API base).
16
+ // keyApiUrl overrides apiBaseURL — lets each front point to the API that
17
+ // registered the shared key routes.
18
18
  // Follow the same override pattern as presskit/game/[slug].vue.
19
19
  const cfg = (config.public as any)?.mgSharedUi || config.public;
20
- const apiBase: string =
20
+ const withApiV1 = (base?: string) => {
21
+ if (!base) return '';
22
+ const clean = base.replace(/\/$/, '');
23
+ return /\/api\/v1$/.test(clean) ? clean : `${clean}/api/v1`;
24
+ };
25
+ const apiBase: string = withApiV1(
21
26
  (config.public as any).keyApiUrl ||
22
27
  cfg.keyApiUrl ||
23
28
  (config.public.apiBaseURL as string) ||
24
- '';
29
+ '',
30
+ );
25
31
 
26
32
  const { data: keyData, error: fetchError, pending, refresh } = await useAsyncData(
27
33
  `public-key-${slug}`,
@@ -1,29 +1,59 @@
1
1
  import axios, { type AxiosInstance } from "axios"
2
2
 
3
3
  // Campaign service wraps the key-campaigns API used by TV, community, and agency.
4
- // Two clients:
5
- // mainClient public endpoints (/public/keys*), no auth required for listing
6
- // authClient authenticated endpoints (/api/v1/*), withCredentials
4
+ // Each frontend backend registers the shared key routes through its own provider.
5
+ // Authenticated calls must therefore use the current app API host, otherwise
6
+ // cookies for api.mundogamer.tv/community/agency are not sent to api-main.
7
7
 
8
8
  let _mainClient: AxiosInstance | null = null
9
9
  let _authClient: AxiosInstance | null = null
10
10
 
11
- function getMainClient(): AxiosInstance {
12
- if (_mainClient) return _mainClient
11
+ const SUPPORTED_LOCALES = ["en", "pt-BR", "es", "de", "ro", "ar-AE"]
12
+
13
+ function resolveLang(): string {
14
+ const seg =
15
+ typeof location === "undefined" ? "" : location.pathname.split("/")[1] || ""
16
+ return SUPPORTED_LOCALES.includes(seg) ? seg : "en"
17
+ }
18
+
19
+ function withApiV1(baseURL?: string): string {
20
+ if (!baseURL) return ""
21
+ const base = baseURL.replace(/\/$/, "")
22
+ return /\/api\/v1$/.test(base) ? base : `${base}/api/v1`
23
+ }
13
24
 
14
- const baseURL =
25
+ function withoutApiV1(baseURL?: string): string {
26
+ return (baseURL || "").replace(/\/api\/v1\/?$/, "").replace(/\/$/, "")
27
+ }
28
+
29
+ function getPublicApiBaseURL(): string {
30
+ return withApiV1(
31
+ import.meta.env.VITE_KEY_API_URL ||
15
32
  import.meta.env.VITE_CAMPAIGN_API_URL ||
33
+ import.meta.env.VITE_API_BASE_URL ||
16
34
  import.meta.env.VITE_BASE_URL_NETWORK ||
35
+ "",
36
+ )
37
+ }
38
+
39
+ function getAuthenticatedApiBaseURL(): string {
40
+ return withApiV1(
41
+ import.meta.env.VITE_KEY_AUTH_API_URL ||
42
+ import.meta.env.VITE_KEY_API_URL ||
17
43
  import.meta.env.VITE_API_BASE_URL ||
18
- ""
44
+ import.meta.env.VITE_CAMPAIGN_API_URL ||
45
+ import.meta.env.VITE_BASE_URL_NETWORK ||
46
+ "",
47
+ )
48
+ }
49
+
50
+ function getMainClient(): AxiosInstance {
51
+ if (_mainClient) return _mainClient
19
52
 
20
- _mainClient = axios.create({ baseURL })
53
+ _mainClient = axios.create({ baseURL: getPublicApiBaseURL() })
21
54
 
22
55
  _mainClient.interceptors.request.use((config) => {
23
- const SUPPORTED_LOCALES = ["en", "pt-BR", "es", "de", "ro", "ar-AE"]
24
- const seg =
25
- typeof location === "undefined" ? "" : location.pathname.split("/")[1] || ""
26
- const lang = SUPPORTED_LOCALES.includes(seg) ? seg : "en"
56
+ const lang = resolveLang()
27
57
  config.params = { ...config.params, lang }
28
58
  // Only attach the shared debug token in true local dev — "!== production"
29
59
  // also matches "hlg" (staging), which has real logged-in users relying on
@@ -46,19 +76,10 @@ function getMainClient(): AxiosInstance {
46
76
  function getAuthClient(): AxiosInstance {
47
77
  if (_authClient) return _authClient
48
78
 
49
- const baseURL =
50
- import.meta.env.VITE_CAMPAIGN_API_URL ||
51
- import.meta.env.VITE_BASE_URL_NETWORK ||
52
- import.meta.env.VITE_API_BASE_URL ||
53
- ""
54
-
55
- _authClient = axios.create({ baseURL, withCredentials: true })
79
+ _authClient = axios.create({ baseURL: getAuthenticatedApiBaseURL(), withCredentials: true })
56
80
 
57
81
  _authClient.interceptors.request.use((config) => {
58
- const SUPPORTED_LOCALES = ["en", "pt-BR", "es", "de", "ro", "ar-AE"]
59
- const seg =
60
- typeof location === "undefined" ? "" : location.pathname.split("/")[1] || ""
61
- const lang = SUPPORTED_LOCALES.includes(seg) ? seg : "en"
82
+ const lang = resolveLang()
62
83
  config.params = { ...config.params, lang }
63
84
  // Only attach the shared debug token in true local dev — "!== production"
64
85
  // also matches "hlg" (staging), which has real logged-in users relying on
@@ -346,6 +367,16 @@ export const fetchCampaignTypes = (params: Record<string, any> = {}) => {
346
367
  * Fetch active platforms (for the platform filter select).
347
368
  */
348
369
  export const fetchCampaignPlatforms = () => {
370
+ const communityBaseURL = withoutApiV1(
371
+ import.meta.env.VITE_KEY_PLATFORMS_API_URL ||
372
+ import.meta.env.VITE_BASE_URL_COMMUNITY ||
373
+ (/community/i.test(import.meta.env.VITE_API_BASE_URL || "") ? import.meta.env.VITE_API_BASE_URL : ""),
374
+ )
375
+ if (communityBaseURL) {
376
+ return axios.get(`${communityBaseURL}/${resolveLang()}/platforms/currently`, {
377
+ withCredentials: true,
378
+ })
379
+ }
349
380
  return authClient.get("/platforms/currently")
350
381
  }
351
382