@mundogamernetwork/shared-ui 1.17.17 → 1.18.0

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.
@@ -1,12 +1,13 @@
1
1
  <script setup lang="ts">
2
2
  import { trackPressKitEvent } from '../../../services/pressKitService';
3
3
  import { mgApiUrl } from '../../../services/httpService';
4
+ import { fetchCreatorNetworkProgram, creatorNetworkProgramLink } from '../../../services/creatorNetworkProgramService';
4
5
 
5
6
  definePageMeta({ layout: 'blank' });
6
7
 
7
8
  const route = useRoute();
8
9
  const slug = route.params.slug as string;
9
- const { t } = useI18n();
10
+ const { t, te } = useI18n();
10
11
 
11
12
  const runtimeConfig = useRuntimeConfig();
12
13
  const cfg = (runtimeConfig.public?.mgSharedUi || {}) as Record<string, any>;
@@ -62,6 +63,19 @@ const { data: moreKitsData } = await useAsyncData(
62
63
  );
63
64
 
64
65
  const kit = computed(() => kitData.value?.data || kitData.value || null);
66
+
67
+ // Does the game have a Creator Network program open? Asked after the page is up and never awaited by
68
+ // it: a missing or slow answer simply means no badge. The strings live in each app's own lang files, so
69
+ // an app that does not carry them yet shows nothing instead of raw keys.
70
+ // The public kit carries its game as `game.id` (it does not carry a top-level `game_id`).
71
+ const kitGameId = computed(() => kit.value?.game?.id ?? kit.value?.game_id ?? null);
72
+ const { data: program } = useAsyncData(
73
+ `press-kit-program-${slug}`,
74
+ () => fetchCreatorNetworkProgram(apiBase, kitGameId.value),
75
+ { lazy: true, server: false, watch: [kitGameId] },
76
+ );
77
+ const programLink = computed(() => (program.value?.open ? creatorNetworkProgramLink(program.value.url, 'press-kit') : null));
78
+ const showProgram = computed(() => !!programLink.value && te('kit.press.creator_program_cta'));
65
79
  const loading = pending;
66
80
 
67
81
  // A request that FAILED is not the same as a kit that does not EXIST. Collapsing
@@ -355,6 +369,7 @@ const navSections = computed(() => {
355
369
  if (team.value.length) s.push({ id: 'team', label: 'kit.press.team' });
356
370
  if (hasEcosystem.value) s.push({ id: 'events', label: 'kit.press.showcases' });
357
371
  if (k.game_id && keyPoolsVisible.value) s.push({ id: 'review-key', label: 'kit.press.request_review_key' });
372
+ if (showProgram.value) s.push({ id: 'creator-network', label: 'kit.press.creator_program_nav' });
358
373
  if (k.press_contact_email) s.push({ id: 'contact', label: 'kit.press.contact' });
359
374
  return s;
360
375
  });
@@ -509,6 +524,9 @@ useHead(() => ({
509
524
  <img v-if="kit.cover_image_url" class="kit-cover-poster" :src="kit.cover_image_url" :alt="kit.name" />
510
525
  <div class="kit-cover-text">
511
526
  <span v-if="kit.release_status" class="kit-eyebrow">{{ String(kit.release_status).replace(/_/g, ' ') }}</span>
527
+ <a v-if="showProgram" class="kit-program-pill" :href="programLink!" @click="track('click')">
528
+ <span class="kit-program-dot" aria-hidden="true" />{{ $t('kit.press.creator_program_open') }}
529
+ </a>
512
530
  <h1 class="kit-cover-title">{{ kit.name }}</h1>
513
531
  <p v-if="kit.tagline" class="kit-tagline">{{ kit.tagline }}</p>
514
532
  <p v-if="kit.developer" class="kit-kicker">{{ kit.developer }}</p>
@@ -522,6 +540,7 @@ useHead(() => ({
522
540
  offered when the kit is actually linked to a game with open pools, same
523
541
  gate as the section itself, so this never links to an empty/broken state. -->
524
542
  <a v-if="kit.game_id" class="kit-btn kit-btn-ghost" href="#review-key" @click.prevent="scrollToSection('review-key')">{{ $t('kit.press.request_review_key') }}</a>
543
+ <a v-if="showProgram" class="kit-btn kit-btn-outline-accent" :href="programLink!" @click="track('click')">{{ $t('kit.press.creator_program_cta') }}</a>
525
544
  <a
526
545
  v-if="interviewHref"
527
546
  class="kit-btn kit-btn-ghost"
@@ -736,6 +755,15 @@ useHead(() => ({
736
755
  </div>
737
756
  </section>
738
757
 
758
+ <!-- Creator Network: offered only while the program has a seat to give (see showProgram) -->
759
+ <section v-if="showProgram" id="creator-network" class="kit-block kit-program-block">
760
+ <h2>{{ $t('kit.press.creator_program_title') }}</h2>
761
+ <div class="kit-program-card">
762
+ <p>{{ $t('kit.press.creator_program_desc', { game: kit.name }) }}</p>
763
+ <a class="kit-btn kit-btn-primary" :href="programLink!" @click="track('click')">{{ $t('kit.press.creator_program_cta') }}</a>
764
+ </div>
765
+ </section>
766
+
739
767
  <!-- Key pools embed — shown when game has active pools -->
740
768
  <section v-if="kit.game_id" v-show="keyPoolsVisible" id="review-key" class="kit-block kit-keys-section">
741
769
  <h2 class="kit-keys-title">{{ $t('kit.press.get_key_title') }}</h2>
@@ -0,0 +1,96 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Renders a "Novidades" comunicado exactly as the fronts do, for the admin's
4
+ * preview (iframe) and for QA.
5
+ *
6
+ * • Admin: the parent window posts
7
+ * { type: "mg-whats-new-preview", payload: <GET /admin/whats-new/{id}/preview body>,
8
+ * theme?: "light"|"dark", lang?: "pt-BR" }
9
+ * and this page answers { type: "mg-whats-new-preview-ready" } once it listens.
10
+ * • QA: /whats-new-preview?demo=image|video|embed|text&lang=pt-BR&theme=dark
11
+ *
12
+ * Nothing is fetched, stored or reported from here, and the payload goes
13
+ * through the same safe renderer (no HTML, https-only links/media).
14
+ */
15
+ import { normalizeWnPost, type WnPost } from "../utils/whatsNew";
16
+
17
+ definePageMeta({ layout: false });
18
+ useHead({ meta: [{ name: "robots", content: "noindex,nofollow" }] });
19
+
20
+ const route = useRoute();
21
+ const colorMode = useColorMode();
22
+
23
+ const post = ref<WnPost | null>(null);
24
+ const lang = ref<string>(String(route.query.lang || "") || "en");
25
+
26
+ const DEMO_BASE = {
27
+ id: 0,
28
+ version: 1,
29
+ kind: "release",
30
+ title: "Game Jams, redesigned",
31
+ summary: "Hi, Ana! Creating a jam now takes **4 steps**, and every cover is checked before publishing. [Read more](/game-jams)",
32
+ published_at: "2026-10-22T14:00:00Z",
33
+ display_mode: "once",
34
+ sections: [
35
+ { type: "feature", title: "", items: [{ body: "Creation wizard in **4 steps**.", link_url: null }, { body: "Jam preview on the site and in the app.", link_url: null }] },
36
+ { type: "improvement", title: "", items: [{ body: "Cover images need at least **1200x600**.", link_url: null }] },
37
+ { type: "fix", title: "", items: [{ body: "Registration dates now respect the time zone.", link_url: null }] },
38
+ { type: "note", title: "", items: [{ body: "Nothing is lost; messages sent later appear normally.", link_url: null }] },
39
+ ],
40
+ cta: { label: "Create my jam", type: "app_route", target: "/game-jams/new" },
41
+ links: [
42
+ { kind: "social", label: "Discord", url: "https://discord.gg/example" },
43
+ { kind: "social", label: "Instagram", url: "https://instagram.com/example" },
44
+ ],
45
+ history_url: "https://example.com/news",
46
+ } as const;
47
+
48
+ function demo(kind: string): WnPost | null {
49
+ const media: Record<string, any> = {
50
+ image: { type: "image", url: "https://placehold.co/1600x900/4a47d6/ffffff.png?text=Game+Jams", poster_url: null, width: 1600, height: 900, duration_s: null, embed: null, description: "The new Game Jams creation wizard." },
51
+ video: { type: "video_upload", url: "https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4", poster_url: "https://placehold.co/1280x720/1e2a4a/ffffff.png?text=Video", width: 1280, height: 720, duration_s: 18, embed: null, description: "A short, silent tour of the creation wizard." },
52
+ embed: { type: "video_embed", url: null, poster_url: "https://placehold.co/1280x720/d9468a/ffffff.png?text=Watch", width: 1280, height: 720, duration_s: null, embed: { provider: "youtube", id: "dQw4w9WgXcQ", watch_url: null }, description: "The team presents the redesign." },
53
+ };
54
+ if (!(kind in media) && kind !== "text") return null;
55
+ return normalizeWnPost({ ...DEMO_BASE, media: media[kind] ?? null, cta: kind === "text" ? null : DEMO_BASE.cta, links: kind === "text" ? [] : DEMO_BASE.links });
56
+ }
57
+
58
+ function applyTheme(theme: unknown) {
59
+ if (theme === "light" || theme === "dark") colorMode.preference = theme;
60
+ }
61
+
62
+ function onMessage(event: MessageEvent) {
63
+ const data: any = event.data;
64
+ if (!data || data.type !== "mg-whats-new-preview") return;
65
+ const payload = normalizeWnPost(data.payload?.data ?? data.payload);
66
+ if (!payload) return;
67
+ if (typeof data.lang === "string") lang.value = data.lang;
68
+ applyTheme(data.theme);
69
+ post.value = payload;
70
+ }
71
+
72
+ onMounted(() => {
73
+ // @nuxtjs/color-mode restores the stored preference after mount and would win
74
+ // over the query, so apply the requested theme again once it has settled.
75
+ applyTheme(route.query.theme);
76
+ setTimeout(() => applyTheme(route.query.theme), 150);
77
+ if (route.query.demo) post.value = demo(String(route.query.demo));
78
+ window.addEventListener("message", onMessage);
79
+ if (window.parent !== window) window.parent.postMessage({ type: "mg-whats-new-preview-ready" }, "*");
80
+ });
81
+
82
+ onBeforeUnmount(() => window.removeEventListener("message", onMessage));
83
+ </script>
84
+
85
+ <template>
86
+ <div class="mg-wn-preview-page">
87
+ <MgWhatsNewModal preview :preview-post="post" :locale="lang" />
88
+ </div>
89
+ </template>
90
+
91
+ <style lang="scss" scoped>
92
+ .mg-wn-preview-page {
93
+ min-height: 100dvh;
94
+ background: var(--mg-wn-surface-2);
95
+ }
96
+ </style>
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Whether a game has a Creator Network program open, for the public pages that can offer it
3
+ * (the press kit page). The answer comes from the agency API, by the community game id the page
4
+ * already knows: GET public/game-network/by-game/{id}.
5
+ */
6
+
7
+ export interface CreatorNetworkProgram {
8
+ enabled: boolean;
9
+ /** True only when the network is on AND a seat can still be promised: the only flag a page should act on. */
10
+ open: boolean;
11
+ url: string | null;
12
+ accent_color: string | null;
13
+ }
14
+
15
+ /** The program of a game, or null when there is none to show or the answer could not be had (never throws). */
16
+ export async function fetchCreatorNetworkProgram(
17
+ apiBase: string,
18
+ gameId: number | string | null | undefined,
19
+ ): Promise<CreatorNetworkProgram | null> {
20
+ if (!apiBase || !gameId) return null;
21
+
22
+ try {
23
+ const res = await $fetch<{ data?: CreatorNetworkProgram }>(
24
+ `${apiBase.replace(/\/$/, '')}/public/game-network/by-game/${encodeURIComponent(String(gameId))}`,
25
+ );
26
+ return res?.data ?? null;
27
+ } catch {
28
+ return null;
29
+ }
30
+ }
31
+
32
+ /**
33
+ * The join link, tagged with where the visitor came from (the studio's funnel reads `campaign_label`).
34
+ * Only an http(s) address is ever returned, so a bad value can never become a `javascript:` link.
35
+ */
36
+ export function creatorNetworkProgramLink(url: string | null | undefined, label: string): string | null {
37
+ if (!url) return null;
38
+
39
+ try {
40
+ const link = new URL(url);
41
+ if (link.protocol !== 'https:' && link.protocol !== 'http:') return null;
42
+ link.searchParams.set('campaign_label', label);
43
+ return link.toString();
44
+ } catch {
45
+ return null;
46
+ }
47
+ }
@@ -5,12 +5,24 @@ interface SerializeObject {
5
5
  [key: string]: string | { [key: string]: string | string[] };
6
6
  }
7
7
 
8
- const getApiBaseUrl = () => {
9
- const config = useRuntimeConfig();
10
- return config.public.mgSharedUi?.apiBaseURL || import.meta.env.VITE_API_BASE_URL;
8
+ // The institutional documents (terms of use, privacy policy, cookies policy...) live in api-main
9
+ // (`GET /document-website-latest`); the per-product APIs (academy, agency, tv...) do not expose that
10
+ // route. Calling `mgSharedUi.apiBaseURL` (the app's own API) made the shared `[slug]` page answer 404
11
+ // for every document in every front that does not point that URL at api-main, so use the network
12
+ // (main) base URL like institutionalService does.
13
+ const getNetworkBaseUrl = () => {
14
+ // useRuntimeConfig() needs the active Nuxt instance and throws when called from an async Pinia
15
+ // action after the SSR context is gone; fall back to the build-time env in that case.
16
+ try {
17
+ const fromConfig = useRuntimeConfig().public.mgSharedUi?.networkBaseUrl;
18
+ if (fromConfig) return fromConfig as string;
19
+ } catch (_) {
20
+ // outside Nuxt context — use the env fallback below
21
+ }
22
+ return import.meta.env.VITE_BASE_URL_NETWORK;
11
23
  };
12
24
 
13
25
  export const fetchDocuments = async (params: SerializeObject): Promise<any> => {
14
26
  const paramsSerialized = serialize(params);
15
- return httpService.get(`/document-website-latest${paramsSerialized}`, { baseURL: getApiBaseUrl() });
27
+ return httpService.get(`/document-website-latest${paramsSerialized}`, { baseURL: getNetworkBaseUrl() });
16
28
  };
@@ -0,0 +1,170 @@
1
+ import { defineStore } from "pinia";
2
+ import {
3
+ WN_MAX_BATCH,
4
+ chunkEvents,
5
+ newDeviceId,
6
+ toApiLang,
7
+ type WnEventName,
8
+ type WnPost,
9
+ type WnReceiptEvent,
10
+ } from "../utils/whatsNew";
11
+
12
+ const DEVICE_KEY = "mg_wn_device_id";
13
+ const LAST_SHOWN_KEY = "mg_wn_last_shown_at";
14
+
15
+ function readStorage(key: string): string | null {
16
+ try {
17
+ return localStorage.getItem(key);
18
+ } catch {
19
+ return null;
20
+ }
21
+ }
22
+
23
+ function writeStorage(key: string, value: string) {
24
+ try {
25
+ localStorage.setItem(key, value);
26
+ } catch {
27
+ // private mode / quota — the server is the source of truth anyway
28
+ }
29
+ }
30
+
31
+ /** Anonymous random id, generated once per browser; never derived from the user. */
32
+ export function getDeviceId(): string {
33
+ const existing = readStorage(DEVICE_KEY);
34
+ if (existing) return existing;
35
+ const id = newDeviceId();
36
+ writeStorage(DEVICE_KEY, id);
37
+ return id;
38
+ }
39
+
40
+ function getConfig() {
41
+ const runtimeConfig = useRuntimeConfig();
42
+ const shared: any = runtimeConfig.public.mgSharedUi || {};
43
+ return {
44
+ networkBaseUrl: (shared.networkBaseUrl || import.meta.env.VITE_BASE_URL_NETWORK || "") as string,
45
+ platformId: Number(shared.systemId || import.meta.env.VITE_SYSTEM_ID),
46
+ };
47
+ }
48
+
49
+ // Kept outside state: never serialized, never shared between tabs.
50
+ let pendingEvents: WnReceiptEvent[] = [];
51
+ let flushTimer: ReturnType<typeof setTimeout> | null = null;
52
+
53
+ export const useWhatsNewStore = defineStore("whats-new-store", {
54
+ // The definition is cached in memory only (it carries the user's first name).
55
+ state: () => ({
56
+ post: null as WnPost | null,
57
+ remaining: 0,
58
+ fetchedFor: null as string | null,
59
+ loading: false,
60
+ shownThisSession: false,
61
+ open: false,
62
+ }),
63
+
64
+ actions: {
65
+ lastShownAt(): number | null {
66
+ const raw = readStorage(LAST_SHOWN_KEY);
67
+ const n = raw ? Number(raw) : NaN;
68
+ return Number.isFinite(n) ? n : null;
69
+ },
70
+
71
+ /** One `pending` call per session / login identity. */
72
+ async fetchPending(identity: string, locale: string) {
73
+ if (this.fetchedFor === identity || this.loading) return;
74
+ const { networkBaseUrl, platformId } = getConfig();
75
+ if (!networkBaseUrl || !platformId) return;
76
+
77
+ this.loading = true;
78
+ this.fetchedFor = identity;
79
+ try {
80
+ const params = new URLSearchParams({
81
+ platform_id: String(platformId),
82
+ surface: "web",
83
+ lang: toApiLang(locale),
84
+ device_id: getDeviceId(),
85
+ });
86
+ const res: any = await $fetch(`${networkBaseUrl}/whats-new/pending?${params.toString()}`, {
87
+ credentials: "include",
88
+ timeout: 8000,
89
+ retry: 0,
90
+ });
91
+ // Logged out / switched user while the request was in flight.
92
+ if (this.fetchedFor !== identity) return;
93
+ this.post = res?.data ?? null;
94
+ this.remaining = Number(res?.remaining ?? 0);
95
+ } catch {
96
+ // Non-critical: a failed call just means no comunicado this session.
97
+ this.post = null;
98
+ this.fetchedFor = null;
99
+ } finally {
100
+ this.loading = false;
101
+ }
102
+ },
103
+
104
+ /** Opens the modal: marks the session, stamps the 24h gap and records `view`. */
105
+ show() {
106
+ if (!this.post) return;
107
+ this.open = true;
108
+ this.shownThisSession = true;
109
+ writeStorage(LAST_SHOWN_KEY, String(Date.now()));
110
+ this.track("view");
111
+ },
112
+
113
+ hide() {
114
+ this.open = false;
115
+ this.flush();
116
+ },
117
+
118
+ reset() {
119
+ this.post = null;
120
+ this.remaining = 0;
121
+ this.fetchedFor = null;
122
+ this.open = false;
123
+ },
124
+
125
+ track(event: WnEventName, target?: string) {
126
+ if (!this.post) return;
127
+ const { platformId } = getConfig();
128
+ if (!platformId) return;
129
+ const entry: WnReceiptEvent = {
130
+ post_id: this.post.id,
131
+ post_version: this.post.version,
132
+ event,
133
+ platform_id: platformId,
134
+ surface: "web",
135
+ device_id: getDeviceId(),
136
+ occurred_at: new Date().toISOString(),
137
+ };
138
+ if (target) entry.target = target;
139
+ pendingEvents.push(entry);
140
+ if (pendingEvents.length >= WN_MAX_BATCH) this.flush();
141
+ else if (!flushTimer) flushTimer = setTimeout(() => this.flush(), 1500);
142
+ },
143
+
144
+ /** Sends queued events in batches of ≤20. keepalive lets it survive a page unload. */
145
+ flush() {
146
+ if (flushTimer) {
147
+ clearTimeout(flushTimer);
148
+ flushTimer = null;
149
+ }
150
+ if (!pendingEvents.length) return;
151
+ const { networkBaseUrl } = getConfig();
152
+ const events = pendingEvents;
153
+ pendingEvents = [];
154
+ if (!networkBaseUrl) return;
155
+ for (const batch of chunkEvents(events)) {
156
+ fetch(`${networkBaseUrl}/whats-new/receipts`, {
157
+ method: "POST",
158
+ credentials: "include",
159
+ keepalive: true,
160
+ headers: { "Content-Type": "application/json", Accept: "application/json" },
161
+ body: JSON.stringify({ events: batch }),
162
+ }).catch(() => {});
163
+ }
164
+ },
165
+ },
166
+ });
167
+
168
+ if (import.meta.hot) {
169
+ import.meta.hot.accept(acceptHMRUpdate(useWhatsNewStore, import.meta.hot));
170
+ }