@mundogamernetwork/shared-ui 1.17.18 → 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.
- package/README.md +23 -0
- package/assets/kit/kit-base.css +47 -0
- package/assets/whats-new/tokens.css +43 -0
- package/components/MediaKit/MgRateCardBundleEditor.vue +2 -7
- package/components/MediaKit/MgRateCardEditor.vue +1 -1
- package/components/keys/KeyCampaignDashboardCard.vue +1 -1
- package/components/playtest/PlaytestInviteLanding.vue +17 -6
- package/components/ui/MgBanners.vue +13 -0
- package/components/ui/MgLoginModal.vue +1 -1
- package/components/whats-new/MgWhatsNewDialog.vue +552 -0
- package/components/whats-new/MgWhatsNewMedia.vue +242 -0
- package/components/whats-new/MgWhatsNewModal.vue +285 -0
- package/components/whats-new/MgWhatsNewRichText.vue +90 -0
- package/composables/useForceLogout.ts +0 -1
- package/composables/useLogout.ts +0 -2
- package/composables/useMgCheckout.ts +0 -1
- package/error.vue +1 -1
- package/nuxt.config.ts +11 -2
- package/package.json +5 -11
- package/pages/[slug]/index.vue +1 -1
- package/pages/about.vue +1 -1
- package/pages/blog.vue +1 -1
- package/pages/careers.vue +1 -1
- package/pages/contact.vue +8 -14
- package/pages/faq.vue +1 -1
- package/pages/key-campaigns/index.vue +1 -1
- package/pages/key-campaigns/redeem-key.vue +1 -1
- package/pages/magazine/[slug]/index.vue +1 -1
- package/pages/magazine/[slug]/preview.vue +2 -2
- package/pages/magazine/index.vue +3 -2
- package/pages/partners.vue +1 -1
- package/pages/press.vue +1 -1
- package/pages/presskit/game/[slug].vue +29 -1
- package/pages/roadmap.vue +1 -1
- package/pages/status.vue +1 -1
- package/pages/team.vue +1 -1
- package/pages/whats-new-preview.vue +96 -0
- package/services/campaignService.ts +0 -1
- package/services/creatorNetworkProgramService.ts +47 -0
- package/services/documentService.ts +16 -4
- package/services/httpService.ts +2 -2
- package/services/institutionalService.ts +1 -1
- package/stores/whatsNew.ts +170 -0
- package/types/index.ts +0 -3
- package/utils/clearSession.ts +0 -1
- package/utils/whatsNew.ts +300 -0
- package/utils/whatsNewMessages.ts +133 -0
- package/utils/whatsNewText.ts +10 -0
- package/types/echo.d.ts +0 -7
|
@@ -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
|
+
}
|
package/types/index.ts
CHANGED
|
@@ -114,8 +114,6 @@ export interface MgSharedUiConfig {
|
|
|
114
114
|
systemId: string;
|
|
115
115
|
apiBaseURL: string;
|
|
116
116
|
accountsBaseUrl: string;
|
|
117
|
-
communityApiUrl?: string;
|
|
118
|
-
communitySiteUrl?: string;
|
|
119
117
|
features: {
|
|
120
118
|
chat: boolean;
|
|
121
119
|
notifications: boolean;
|
|
@@ -123,7 +121,6 @@ export interface MgSharedUiConfig {
|
|
|
123
121
|
darkMode: boolean;
|
|
124
122
|
search: boolean;
|
|
125
123
|
statusOnline: boolean;
|
|
126
|
-
gamification?: boolean;
|
|
127
124
|
};
|
|
128
125
|
languages: string[];
|
|
129
126
|
protectedRoutes: string[];
|
package/utils/clearSession.ts
CHANGED
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
* The fix: clear the auth credentials CLIENT-SIDE so the next request is a clean
|
|
10
10
|
* guest request and the user can log in again.
|
|
11
11
|
*/
|
|
12
|
-
import { useAuthStore } from "../stores/auth";
|
|
13
12
|
|
|
14
13
|
// Auth-related cookies set across the MGN ecosystem.
|
|
15
14
|
const AUTH_COOKIES = [
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Novidades da Rede" (What's New) — pure helpers shared by the store, the
|
|
3
|
+
* modal and the vitest suite. Nothing here touches Nuxt auto-imports or the
|
|
4
|
+
* DOM at import time, so it runs unchanged under plain Node.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export type WnSectionType = "feature" | "improvement" | "fix" | "note";
|
|
8
|
+
export type WnMediaType = "image" | "gif" | "video_upload" | "video_embed";
|
|
9
|
+
export type WnEventName = "view" | "dismiss" | "cta_click" | "video_play" | "link_click";
|
|
10
|
+
|
|
11
|
+
export interface WnMedia {
|
|
12
|
+
type: WnMediaType;
|
|
13
|
+
url: string | null;
|
|
14
|
+
poster_url: string | null;
|
|
15
|
+
width: number | null;
|
|
16
|
+
height: number | null;
|
|
17
|
+
duration_s: number | null;
|
|
18
|
+
embed: { provider: "youtube" | "vimeo"; id: string; watch_url?: string | null } | null;
|
|
19
|
+
description: string | null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface WnItem {
|
|
23
|
+
body: string;
|
|
24
|
+
link_url: string | null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface WnSection {
|
|
28
|
+
type: WnSectionType;
|
|
29
|
+
title: string;
|
|
30
|
+
items: WnItem[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface WnPost {
|
|
34
|
+
id: number;
|
|
35
|
+
version: number;
|
|
36
|
+
kind: "release" | "update" | "launch" | "maintenance";
|
|
37
|
+
title: string;
|
|
38
|
+
summary: string | null;
|
|
39
|
+
published_at: string | null;
|
|
40
|
+
display_mode: "once" | "until_dismissed";
|
|
41
|
+
media: WnMedia | null;
|
|
42
|
+
sections: WnSection[];
|
|
43
|
+
cta: { label: string; type: "url" | "app_route"; target: string } | null;
|
|
44
|
+
links: { kind: "social" | "link"; label: string; url: string }[];
|
|
45
|
+
history_url: string | null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// ─── Inline markup: **bold** and [text](url) ────────────────────────────────
|
|
49
|
+
|
|
50
|
+
/** The single link regex shared with every other client (see the contract). */
|
|
51
|
+
export const WN_LINK_SOURCE = String.raw`\[([^\[\]]+)\]\(([^()\s"<>]+)\)`;
|
|
52
|
+
const WN_BOLD_RE = /\*\*(.+?)\*\*/g;
|
|
53
|
+
|
|
54
|
+
export type WnLinkKind = "external" | "internal";
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Only `https://…` (external) and `/path` (internal, never `//host`) may become
|
|
58
|
+
* links. Everything else — http:, javascript:, data:, protocol-relative — is
|
|
59
|
+
* rejected and the caller renders plain text.
|
|
60
|
+
*/
|
|
61
|
+
export function classifyHref(href: string | null | undefined): WnLinkKind | null {
|
|
62
|
+
if (!href || typeof href !== "string") return null;
|
|
63
|
+
const value = href.trim();
|
|
64
|
+
if (/\s/.test(value)) return null;
|
|
65
|
+
if (/^https:\/\/[^/\s]+/i.test(value)) return "external";
|
|
66
|
+
if (value.startsWith("/") && !value.startsWith("//") && !value.startsWith("/\\")) return "internal";
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type WnNode =
|
|
71
|
+
| { type: "text"; text: string }
|
|
72
|
+
| { type: "bold"; text: string }
|
|
73
|
+
| { type: "link"; href: string; kind: WnLinkKind; children: WnNode[] };
|
|
74
|
+
|
|
75
|
+
function parseBold(text: string): WnNode[] {
|
|
76
|
+
const nodes: WnNode[] = [];
|
|
77
|
+
let last = 0;
|
|
78
|
+
for (const match of text.matchAll(WN_BOLD_RE)) {
|
|
79
|
+
const start = match.index ?? 0;
|
|
80
|
+
if (start > last) nodes.push({ type: "text", text: text.slice(last, start) });
|
|
81
|
+
nodes.push({ type: "bold", text: match[1] });
|
|
82
|
+
last = start + match[0].length;
|
|
83
|
+
}
|
|
84
|
+
if (last < text.length) nodes.push({ type: "text", text: text.slice(last) });
|
|
85
|
+
return nodes;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Turns server text into a flat, safe node list. No HTML is ever produced: the
|
|
90
|
+
* renderer builds text nodes, <strong> and <a> from this structure.
|
|
91
|
+
* `allowLinks:false` flattens links to their label (used when the whole item is
|
|
92
|
+
* already a link, to avoid nested anchors).
|
|
93
|
+
*/
|
|
94
|
+
export function parseRich(text: string | null | undefined, allowLinks = true): WnNode[] {
|
|
95
|
+
if (!text) return [];
|
|
96
|
+
const nodes: WnNode[] = [];
|
|
97
|
+
const re = new RegExp(WN_LINK_SOURCE, "g");
|
|
98
|
+
let last = 0;
|
|
99
|
+
for (const match of text.matchAll(re)) {
|
|
100
|
+
const start = match.index ?? 0;
|
|
101
|
+
if (start > last) nodes.push(...parseBold(text.slice(last, start)));
|
|
102
|
+
const kind = allowLinks ? classifyHref(match[2]) : null;
|
|
103
|
+
if (kind) nodes.push({ type: "link", href: match[2], kind, children: parseBold(match[1]) });
|
|
104
|
+
else nodes.push(...parseBold(match[1]));
|
|
105
|
+
last = start + match[0].length;
|
|
106
|
+
}
|
|
107
|
+
if (last < text.length) nodes.push(...parseBold(text.slice(last)));
|
|
108
|
+
return nodes;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Plain-text version (used for aria labels). */
|
|
112
|
+
export function richToPlain(nodes: WnNode[]): string {
|
|
113
|
+
return nodes
|
|
114
|
+
.map((n) => (n.type === "link" ? richToPlain(n.children) : n.text))
|
|
115
|
+
.join("");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// ─── Locale ────────────────────────────────────────────────────────────────
|
|
119
|
+
|
|
120
|
+
export const WN_UI_LOCALES = ["en", "pt-BR", "de", "es", "ro", "ar"] as const;
|
|
121
|
+
export type WnUiLocale = (typeof WN_UI_LOCALES)[number];
|
|
122
|
+
|
|
123
|
+
/** Locale code sent to the API (`lang`). ar-AE → ar; unknown stays as-is. */
|
|
124
|
+
export function toApiLang(code: string | null | undefined): string {
|
|
125
|
+
const raw = String(code || "en").replace("_", "-");
|
|
126
|
+
const lower = raw.toLowerCase();
|
|
127
|
+
if (lower.startsWith("ar")) return "ar";
|
|
128
|
+
if (lower === "pt" || lower.startsWith("pt-")) return "pt-BR";
|
|
129
|
+
const base = lower.split("-")[0];
|
|
130
|
+
if (base === "en" || base === "de" || base === "es" || base === "ro") return base;
|
|
131
|
+
return "en";
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Dictionary used for the fixed modal copy (en, pt-BR, de, es, ro, ar); anything else falls back to en. */
|
|
135
|
+
export function toUiLocale(code: string | null | undefined): WnUiLocale {
|
|
136
|
+
const api = toApiLang(code);
|
|
137
|
+
return (WN_UI_LOCALES as readonly string[]).includes(api) ? (api as WnUiLocale) : "en";
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function isRtl(code: string | null | undefined): boolean {
|
|
141
|
+
return toApiLang(code) === "ar";
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ─── Where the modal may appear ────────────────────────────────────────────
|
|
145
|
+
|
|
146
|
+
const LOCALE_PREFIX_RE = /^\/(en|pt-BR|pt|de|es|ro|ar-AE|ar)(?=\/|$)/i;
|
|
147
|
+
|
|
148
|
+
export function normalizePath(path: string): string {
|
|
149
|
+
let p = (path || "/").split("?")[0].split("#")[0];
|
|
150
|
+
p = p.replace(LOCALE_PREFIX_RE, "");
|
|
151
|
+
if (!p.startsWith("/")) p = "/" + p;
|
|
152
|
+
if (p.length > 1) p = p.replace(/\/+$/, "");
|
|
153
|
+
return p || "/";
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Whole-segment words that mean "a flow the user must not be interrupted in". */
|
|
157
|
+
const BLOCKED_EXACT = new Set(["new", "novo", "nova", "edit", "editar", "submit", "pay", "oauth", "callback"]);
|
|
158
|
+
/** Words that block when they appear as a token of a segment (create-jam, jam-wizard). */
|
|
159
|
+
const BLOCKED_TOKENS = new Set([
|
|
160
|
+
"login", "logout", "signin", "signup", "register", "registro", "cadastro", "entrar",
|
|
161
|
+
"checkout", "payment", "payments", "pagamento", "pagamentos",
|
|
162
|
+
"create", "criar", "publish", "publicar", "upload", "wizard", "editor", "onboarding",
|
|
163
|
+
]);
|
|
164
|
+
|
|
165
|
+
export function isBlockedPath(path: string, extra: (string | RegExp)[] = []): boolean {
|
|
166
|
+
const normalized = normalizePath(path);
|
|
167
|
+
const segments = normalized.split("/").filter(Boolean);
|
|
168
|
+
for (const segment of segments) {
|
|
169
|
+
const lower = segment.toLowerCase();
|
|
170
|
+
if (BLOCKED_EXACT.has(lower)) return true;
|
|
171
|
+
if (lower.split(/[-_]/).some((token) => BLOCKED_TOKENS.has(token))) return true;
|
|
172
|
+
}
|
|
173
|
+
return extra.some((rule) => matchesRoute(normalized, rule));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** String rules are path prefixes ("/" matches only the root); RegExp rules test the normalized path. */
|
|
177
|
+
export function matchesRoute(normalizedPath: string, rule: string | RegExp): boolean {
|
|
178
|
+
if (rule instanceof RegExp) return rule.test(normalizedPath);
|
|
179
|
+
const r = normalizePath(rule);
|
|
180
|
+
if (r === "/") return normalizedPath === "/";
|
|
181
|
+
return normalizedPath === r || normalizedPath.startsWith(r + "/");
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export const WN_IDLE_MS = 2500;
|
|
185
|
+
export const WN_MIN_GAP_MS = 24 * 60 * 60 * 1000;
|
|
186
|
+
|
|
187
|
+
export interface WnGateInput {
|
|
188
|
+
loggedIn: boolean;
|
|
189
|
+
path: string;
|
|
190
|
+
allowedRoutes?: (string | RegExp)[];
|
|
191
|
+
blockedRoutes?: (string | RegExp)[];
|
|
192
|
+
shownThisSession: boolean;
|
|
193
|
+
lastShownAt: number | null;
|
|
194
|
+
now: number;
|
|
195
|
+
suppressed: boolean;
|
|
196
|
+
otherModalOpen: boolean;
|
|
197
|
+
pageVisible: boolean;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export type WnGateResult = "ok" | "logged_out" | "session" | "gap" | "route" | "suppressed" | "other_modal" | "hidden";
|
|
201
|
+
|
|
202
|
+
/** Decides whether a comunicado may open right now. Pure so it can be tested. */
|
|
203
|
+
export function gate(input: WnGateInput): WnGateResult {
|
|
204
|
+
if (!input.loggedIn) return "logged_out";
|
|
205
|
+
if (input.shownThisSession) return "session";
|
|
206
|
+
if (input.lastShownAt !== null && input.now - input.lastShownAt < WN_MIN_GAP_MS) return "gap";
|
|
207
|
+
const normalized = normalizePath(input.path);
|
|
208
|
+
if (isBlockedPath(input.path, input.blockedRoutes)) return "route";
|
|
209
|
+
if (input.allowedRoutes?.length && !input.allowedRoutes.some((rule) => matchesRoute(normalized, rule))) return "route";
|
|
210
|
+
if (input.suppressed) return "suppressed";
|
|
211
|
+
if (input.otherModalOpen) return "other_modal";
|
|
212
|
+
if (!input.pageVisible) return "hidden";
|
|
213
|
+
return "ok";
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// ─── Video embeds ──────────────────────────────────────────────────────────
|
|
217
|
+
|
|
218
|
+
/** Cookie-less player URL, or null when the provider/id is not what we expect. */
|
|
219
|
+
export function embedSrc(provider: string, id: string): string | null {
|
|
220
|
+
if (provider === "youtube" && /^[\w-]{6,20}$/.test(id)) {
|
|
221
|
+
return `https://www.youtube-nocookie.com/embed/${id}?autoplay=1&rel=0&playsinline=1`;
|
|
222
|
+
}
|
|
223
|
+
if (provider === "vimeo" && /^\d{3,12}$/.test(id)) {
|
|
224
|
+
return `https://player.vimeo.com/video/${id}?dnt=1&autoplay=1`;
|
|
225
|
+
}
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// ─── Receipts ──────────────────────────────────────────────────────────────
|
|
230
|
+
|
|
231
|
+
export interface WnReceiptEvent {
|
|
232
|
+
post_id: number;
|
|
233
|
+
post_version: number;
|
|
234
|
+
event: WnEventName;
|
|
235
|
+
platform_id: number;
|
|
236
|
+
surface: "web";
|
|
237
|
+
device_id: string;
|
|
238
|
+
occurred_at: string;
|
|
239
|
+
target?: string;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export const WN_MAX_BATCH = 20;
|
|
243
|
+
|
|
244
|
+
/** Splits a queue into API-sized batches (the endpoint takes 1–20 events). */
|
|
245
|
+
export function chunkEvents<T>(events: T[], size = WN_MAX_BATCH): T[][] {
|
|
246
|
+
const out: T[][] = [];
|
|
247
|
+
for (let i = 0; i < events.length; i += size) out.push(events.slice(i, i + size));
|
|
248
|
+
return out;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export function newDeviceId(): string {
|
|
252
|
+
const c: any = typeof globalThis !== "undefined" ? (globalThis as any).crypto : undefined;
|
|
253
|
+
if (c?.randomUUID) return c.randomUUID();
|
|
254
|
+
// RFC4122 v4 from getRandomValues, last resort Math.random (device id is not a secret).
|
|
255
|
+
const bytes = new Uint8Array(16);
|
|
256
|
+
if (c?.getRandomValues) c.getRandomValues(bytes);
|
|
257
|
+
else for (let i = 0; i < 16; i++) bytes[i] = Math.floor(Math.random() * 256);
|
|
258
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
259
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
260
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
|
|
261
|
+
return `${hex.slice(0, 4).join("")}-${hex.slice(4, 6).join("")}-${hex.slice(6, 8).join("")}-${hex.slice(8, 10).join("")}-${hex.slice(10).join("")}`;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Media/poster URLs must be https (or same-origin paths); anything else is dropped. */
|
|
265
|
+
export function safeMediaUrl(url: string | null | undefined): string | null {
|
|
266
|
+
return classifyHref(url) ? (url as string) : null;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** Shallow shape check for payloads that arrive from outside (admin preview). */
|
|
270
|
+
export function isWnPost(value: any): value is WnPost {
|
|
271
|
+
return (
|
|
272
|
+
!!value &&
|
|
273
|
+
typeof value === "object" &&
|
|
274
|
+
typeof value.title === "string" &&
|
|
275
|
+
Array.isArray(value.sections ?? []) &&
|
|
276
|
+
(value.cta == null || typeof value.cta === "object")
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export function normalizeWnPost(value: any): WnPost | null {
|
|
281
|
+
if (!isWnPost(value)) return null;
|
|
282
|
+
return {
|
|
283
|
+
id: Number(value.id) || 0,
|
|
284
|
+
version: Number(value.version) || 1,
|
|
285
|
+
kind: value.kind || "update",
|
|
286
|
+
title: value.title,
|
|
287
|
+
summary: value.summary ?? null,
|
|
288
|
+
published_at: value.published_at ?? null,
|
|
289
|
+
display_mode: value.display_mode || "once",
|
|
290
|
+
media: value.media ?? null,
|
|
291
|
+
sections: (value.sections ?? []).map((s: any) => ({
|
|
292
|
+
type: s.type || "note",
|
|
293
|
+
title: s.title || "",
|
|
294
|
+
items: (s.items ?? []).map((i: any) => ({ body: String(i.body ?? ""), link_url: i.link_url ?? null })),
|
|
295
|
+
})),
|
|
296
|
+
cta: value.cta ?? null,
|
|
297
|
+
links: value.links ?? [],
|
|
298
|
+
history_url: value.history_url ?? null,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixed copy of the What's New modal, one block per language.
|
|
3
|
+
*
|
|
4
|
+
* Kept as TypeScript (not JSON under locales/) on purpose: @nuxtjs/i18n compiles every
|
|
5
|
+
* JSON it finds in a locales dir into message ASTs, which turned these plain strings into
|
|
6
|
+
* objects. It also ships with the component rather than the host app's vue-i18n messages,
|
|
7
|
+
* because several fronts do not merge the shared-ui locale files.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export const WN_MESSAGES = {
|
|
11
|
+
"en": {
|
|
12
|
+
title: "What's new",
|
|
13
|
+
kind_release: "Release",
|
|
14
|
+
kind_update: "Update",
|
|
15
|
+
kind_launch: "Launch",
|
|
16
|
+
kind_maintenance: "Maintenance",
|
|
17
|
+
feature: "New features",
|
|
18
|
+
improvement: "Improvements",
|
|
19
|
+
fix: "Fixes",
|
|
20
|
+
note: "Notice",
|
|
21
|
+
close: "Close",
|
|
22
|
+
later: "Later",
|
|
23
|
+
view_all: "See all news",
|
|
24
|
+
watch: "Watch",
|
|
25
|
+
play: "Play video",
|
|
26
|
+
pause: "Pause video",
|
|
27
|
+
follow: "Follow the network",
|
|
28
|
+
new_tab: "opens in a new tab",
|
|
29
|
+
media_label: "Media",
|
|
30
|
+
},
|
|
31
|
+
"pt-BR": {
|
|
32
|
+
title: "Novidades",
|
|
33
|
+
kind_release: "Lançamento de versão",
|
|
34
|
+
kind_update: "Atualização",
|
|
35
|
+
kind_launch: "Lançamento",
|
|
36
|
+
kind_maintenance: "Manutenção",
|
|
37
|
+
feature: "Novos recursos",
|
|
38
|
+
improvement: "Melhorias",
|
|
39
|
+
fix: "Correções",
|
|
40
|
+
note: "Aviso",
|
|
41
|
+
close: "Fechar",
|
|
42
|
+
later: "Depois",
|
|
43
|
+
view_all: "Ver todas as novidades",
|
|
44
|
+
watch: "Assistir",
|
|
45
|
+
play: "Reproduzir vídeo",
|
|
46
|
+
pause: "Pausar vídeo",
|
|
47
|
+
follow: "Siga a rede",
|
|
48
|
+
new_tab: "abre em uma nova aba",
|
|
49
|
+
media_label: "Mídia",
|
|
50
|
+
},
|
|
51
|
+
"de": {
|
|
52
|
+
title: "Neuigkeiten",
|
|
53
|
+
kind_release: "Release",
|
|
54
|
+
kind_update: "Update",
|
|
55
|
+
kind_launch: "Start",
|
|
56
|
+
kind_maintenance: "Wartung",
|
|
57
|
+
feature: "Neue Funktionen",
|
|
58
|
+
improvement: "Verbesserungen",
|
|
59
|
+
fix: "Korrekturen",
|
|
60
|
+
note: "Hinweis",
|
|
61
|
+
close: "Schließen",
|
|
62
|
+
later: "Später",
|
|
63
|
+
view_all: "Alle Neuigkeiten ansehen",
|
|
64
|
+
watch: "Ansehen",
|
|
65
|
+
play: "Video abspielen",
|
|
66
|
+
pause: "Video pausieren",
|
|
67
|
+
follow: "Folge dem Netzwerk",
|
|
68
|
+
new_tab: "öffnet in einem neuen Tab",
|
|
69
|
+
media_label: "Medien",
|
|
70
|
+
},
|
|
71
|
+
"es": {
|
|
72
|
+
title: "Novedades",
|
|
73
|
+
kind_release: "Versión",
|
|
74
|
+
kind_update: "Actualización",
|
|
75
|
+
kind_launch: "Lanzamiento",
|
|
76
|
+
kind_maintenance: "Mantenimiento",
|
|
77
|
+
feature: "Nuevas funciones",
|
|
78
|
+
improvement: "Mejoras",
|
|
79
|
+
fix: "Correcciones",
|
|
80
|
+
note: "Aviso",
|
|
81
|
+
close: "Cerrar",
|
|
82
|
+
later: "Después",
|
|
83
|
+
view_all: "Ver todas las novedades",
|
|
84
|
+
watch: "Ver",
|
|
85
|
+
play: "Reproducir vídeo",
|
|
86
|
+
pause: "Pausar vídeo",
|
|
87
|
+
follow: "Sigue la red",
|
|
88
|
+
new_tab: "se abre en una pestaña nueva",
|
|
89
|
+
media_label: "Multimedia",
|
|
90
|
+
},
|
|
91
|
+
"ro": {
|
|
92
|
+
title: "Noutăți",
|
|
93
|
+
kind_release: "Versiune nouă",
|
|
94
|
+
kind_update: "Actualizare",
|
|
95
|
+
kind_launch: "Lansare",
|
|
96
|
+
kind_maintenance: "Mentenanță",
|
|
97
|
+
feature: "Funcții noi",
|
|
98
|
+
improvement: "Îmbunătățiri",
|
|
99
|
+
fix: "Remedieri",
|
|
100
|
+
note: "Notă",
|
|
101
|
+
close: "Închide",
|
|
102
|
+
later: "Mai târziu",
|
|
103
|
+
view_all: "Vezi toate noutățile",
|
|
104
|
+
watch: "Vizionează",
|
|
105
|
+
play: "Redă videoclipul",
|
|
106
|
+
pause: "Oprește videoclipul",
|
|
107
|
+
follow: "Urmărește rețeaua",
|
|
108
|
+
new_tab: "se deschide într-o filă nouă",
|
|
109
|
+
media_label: "Media",
|
|
110
|
+
},
|
|
111
|
+
"ar": {
|
|
112
|
+
title: "الجديد",
|
|
113
|
+
kind_release: "إصدار",
|
|
114
|
+
kind_update: "تحديث",
|
|
115
|
+
kind_launch: "إطلاق",
|
|
116
|
+
kind_maintenance: "صيانة",
|
|
117
|
+
feature: "ميزات جديدة",
|
|
118
|
+
improvement: "تحسينات",
|
|
119
|
+
fix: "إصلاحات",
|
|
120
|
+
note: "تنبيه",
|
|
121
|
+
close: "إغلاق",
|
|
122
|
+
later: "لاحقًا",
|
|
123
|
+
view_all: "عرض كل الأخبار",
|
|
124
|
+
watch: "مشاهدة",
|
|
125
|
+
play: "تشغيل الفيديو",
|
|
126
|
+
pause: "إيقاف الفيديو مؤقتًا",
|
|
127
|
+
follow: "تابع الشبكة",
|
|
128
|
+
new_tab: "يفتح في علامة تبويب جديدة",
|
|
129
|
+
media_label: "وسائط",
|
|
130
|
+
},
|
|
131
|
+
} as const;
|
|
132
|
+
|
|
133
|
+
export type WnMessages = typeof WN_MESSAGES;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WN_MESSAGES } from "./whatsNewMessages";
|
|
2
|
+
import { toUiLocale, type WnUiLocale } from "./whatsNew";
|
|
3
|
+
|
|
4
|
+
export type WnTextKey = keyof (typeof WN_MESSAGES)["en"];
|
|
5
|
+
|
|
6
|
+
export const WN_DICTIONARY: Record<WnUiLocale, Record<string, string>> = WN_MESSAGES;
|
|
7
|
+
|
|
8
|
+
export function wnText(locale: string | null | undefined, key: WnTextKey): string {
|
|
9
|
+
return WN_DICTIONARY[toUiLocale(locale)][key] ?? WN_MESSAGES.en[key];
|
|
10
|
+
}
|