@mundogamernetwork/shared-ui 1.3.0 → 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.0",
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,32 +1,67 @@
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 }
58
+ // Only attach the shared debug token in true local dev — "!== production"
59
+ // also matches "hlg" (staging), which has real logged-in users relying on
60
+ // their own session cookie via withCredentials. Attaching this static
61
+ // token there overrides/corrupts their actual auth, causing a 401 on
62
+ // endpoints that check the request's real identity (e.g. key requests).
28
63
  if (
29
- import.meta.env.VITE_APP_ENV !== "production" &&
64
+ import.meta.env.VITE_APP_ENV === "local" &&
30
65
  typeof window !== "undefined" &&
31
66
  import.meta.env.VITE_BEARER_TOKEN
32
67
  ) {
@@ -41,22 +76,18 @@ function getMainClient(): AxiosInstance {
41
76
  function getAuthClient(): AxiosInstance {
42
77
  if (_authClient) return _authClient
43
78
 
44
- const baseURL =
45
- import.meta.env.VITE_CAMPAIGN_API_URL ||
46
- import.meta.env.VITE_BASE_URL_NETWORK ||
47
- import.meta.env.VITE_API_BASE_URL ||
48
- ""
49
-
50
- _authClient = axios.create({ baseURL, withCredentials: true })
79
+ _authClient = axios.create({ baseURL: getAuthenticatedApiBaseURL(), withCredentials: true })
51
80
 
52
81
  _authClient.interceptors.request.use((config) => {
53
- const SUPPORTED_LOCALES = ["en", "pt-BR", "es", "de", "ro", "ar-AE"]
54
- const seg =
55
- typeof location === "undefined" ? "" : location.pathname.split("/")[1] || ""
56
- const lang = SUPPORTED_LOCALES.includes(seg) ? seg : "en"
82
+ const lang = resolveLang()
57
83
  config.params = { ...config.params, lang }
84
+ // Only attach the shared debug token in true local dev — "!== production"
85
+ // also matches "hlg" (staging), which has real logged-in users relying on
86
+ // their own session cookie via withCredentials. Attaching this static
87
+ // token there overrides/corrupts their actual auth, causing a 401 on
88
+ // endpoints that check the request's real identity (e.g. key requests).
58
89
  if (
59
- import.meta.env.VITE_APP_ENV !== "production" &&
90
+ import.meta.env.VITE_APP_ENV === "local" &&
60
91
  typeof window !== "undefined" &&
61
92
  import.meta.env.VITE_BEARER_TOKEN
62
93
  ) {
@@ -336,6 +367,16 @@ export const fetchCampaignTypes = (params: Record<string, any> = {}) => {
336
367
  * Fetch active platforms (for the platform filter select).
337
368
  */
338
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
+ }
339
380
  return authClient.get("/platforms/currently")
340
381
  }
341
382