Skip to content

Commit 43f245a

Browse files
committed
Make runtime environment agnostic through single service contracts - PR_26167_175-179-environment-agnostic-runtime-stack
1 parent 48c2fa8 commit 43f245a

57 files changed

Lines changed: 24327 additions & 4032 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

account/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ <h1>Account Home</h1>
2626
<div class="card" data-local-db-page="account-home">
2727
<div class="card-body content-stack">
2828
<div>
29-
<div class="kicker">Local DB</div>
29+
<div class="kicker">Account Service</div>
3030
<h2>Account Summary</h2>
3131
</div>
32-
<p class="status" role="status" data-local-db-status>Loading Local DB account summary.</p>
32+
<p class="status" role="status" data-local-db-status>Loading account summary.</p>
3333
<div class="content-stack" data-local-db-content></div>
3434
</div>
3535
</div>

account/preferences.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ <h1>Preferences</h1>
2626
<div class="card" data-local-db-page="account-preferences">
2727
<div class="card-body content-stack">
2828
<div>
29-
<div class="kicker">Local DB</div>
29+
<div class="kicker">Account Service</div>
3030
<h2>Preferences Contract</h2>
3131
</div>
32-
<p class="status" role="status" data-local-db-status>Loading Local DB preferences contract.</p>
32+
<p class="status" role="status" data-local-db-status>Loading preferences contract.</p>
3333
<div class="content-stack" data-local-db-content></div>
3434
</div>
3535
</div>

account/profile.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ <h1>Profile</h1>
2626
<div class="card" data-local-db-page="account-profile">
2727
<div class="card-body content-stack">
2828
<div>
29-
<div class="kicker">Local DB</div>
29+
<div class="kicker">Account Service</div>
3030
<h2>Profile Identity</h2>
3131
</div>
32-
<p class="status" role="status" data-local-db-status>Loading Local DB profile identity.</p>
32+
<p class="status" role="status" data-local-db-status>Loading profile identity.</p>
3333
<div class="content-stack" data-local-db-content></div>
3434
</div>
3535
</div>

account/security.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ <h1>Security</h1>
2626
<div class="card" data-local-db-page="account-security">
2727
<div class="card-body content-stack">
2828
<div>
29-
<div class="kicker">Local DB</div>
29+
<div class="kicker">Account Service</div>
3030
<h2>Security Contract</h2>
3131
</div>
32-
<p class="status" role="status" data-local-db-status>Loading Local DB security contract.</p>
32+
<p class="status" role="status" data-local-db-status>Loading security contract.</p>
3333
<div class="content-stack" data-local-db-content></div>
3434
</div>
3535
</div>

admin/db-viewer.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { getSessionCurrent } from "../src/engine/api/session-api-client.js";
2+
13
function devRuntimeAllowed() {
24
const host = window.location.hostname;
35
return window.GameFoundryDevRuntime?.enabled === true ||
@@ -8,17 +10,12 @@ function devRuntimeAllowed() {
810

911
function currentSession() {
1012
try {
11-
const provider = window.GameFoundryAuthProvider;
12-
if (!provider || typeof provider.getCurrentUser !== "function") {
13-
return {
14-
diagnostic: "Auth provider contract unavailable. Restore the sign-in/session provider before opening DB Viewer.",
15-
mode: "",
16-
};
17-
}
18-
return provider.getCurrentUser();
13+
return getSessionCurrent();
1914
} catch (error) {
15+
const diagnostic = error instanceof Error ? error.message : String(error || "Unable to read current DB Viewer session.");
16+
console.warn("[admin/operator] DB Viewer session unavailable:", diagnostic);
2017
return {
21-
diagnostic: error instanceof Error ? error.message : String(error || "Unable to read current DB Viewer session."),
18+
diagnostic: "Sign in with an admin account to open DB Viewer.",
2219
mode: "",
2320
};
2421
}
@@ -36,7 +33,7 @@ async function loadLocalDbViewer() {
3633
return;
3734
}
3835
if (!devRuntimeAllowed()) {
39-
showGatewayStatus("DB Viewer is available only in the local dev runtime.");
36+
showGatewayStatus("DB Viewer is available only in the approved admin runtime.");
4037
return;
4138
}
4239
const session = currentSession();

assets/theme-v2/js/account-auth-actions.js

Lines changed: 13 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
import {
2+
ACCOUNT_SERVICE_READY_MESSAGE,
3+
accountActionFailureMessage,
4+
accountActionUnavailableMessage,
5+
requestAccountAuth,
6+
} from "./account-auth-service.js";
7+
18
const form = document.querySelector("[data-account-auth-form]");
29
const emailField = document.querySelector("[data-account-auth-email]");
310
const passwordField = document.querySelector("[data-account-auth-password]");
411
const statusField = document.querySelector("[data-account-auth-status]");
512
const submitButton = document.querySelector("[data-account-auth-submit]");
613
const action = form?.getAttribute("data-account-auth-form") || "";
7-
const ACCOUNT_IDENTITY_SETUP_MESSAGE = "Account identity setup is incomplete. Please contact support.";
8-
const AUTH_UNAVAILABLE_MESSAGE = "The site is currently unavailable. Please try again later.";
9-
const PASSWORD_RESET_RATE_LIMIT_MESSAGE = "Too many reset requests. Please wait and try again later.";
10-
const CREATE_ACCOUNT_PLACEHOLDER_MESSAGE = "Create Account is not available in this preview. Please try again later.";
11-
const PASSWORD_RESET_PLACEHOLDER_MESSAGE = "Password Reset is not available in this preview. Please try again later.";
1214
let authStatus = null;
1315

1416
function setStatus(message) {
@@ -17,69 +19,21 @@ function setStatus(message) {
1719
}
1820
}
1921

20-
function isStaticOnlyLocalEntrypoint() {
21-
return ["127.0.0.1", "localhost"].includes(window.location.hostname) &&
22-
window.location.port === "5500";
23-
}
24-
2522
function setFormEnabled(enabled) {
2623
if (submitButton) {
2724
submitButton.disabled = !enabled;
2825
}
2926
}
3027

31-
async function readJson(response, fallbackMessage) {
32-
let payload = null;
33-
try {
34-
payload = await response.json();
35-
} catch {
36-
payload = null;
37-
}
38-
if (!response.ok || payload?.ok === false) {
39-
if (payload?.error === ACCOUNT_IDENTITY_SETUP_MESSAGE) {
40-
throw new Error(ACCOUNT_IDENTITY_SETUP_MESSAGE);
41-
}
42-
if (payload?.error === PASSWORD_RESET_RATE_LIMIT_MESSAGE) {
43-
throw new Error(PASSWORD_RESET_RATE_LIMIT_MESSAGE);
44-
}
45-
throw new Error(fallbackMessage);
46-
}
47-
return payload?.data || {};
48-
}
49-
50-
async function requestAccountAuth(path, options = {}) {
51-
const response = await fetch(`/api/auth/${path}`, {
52-
body: options.body ? JSON.stringify(options.body) : undefined,
53-
headers: options.body ? { "content-type": "application/json" } : undefined,
54-
method: options.method || "GET",
55-
});
56-
return readJson(response, AUTH_UNAVAILABLE_MESSAGE);
57-
}
58-
5928
function unavailableStatusMessage() {
60-
if (action === "create-account") {
61-
return CREATE_ACCOUNT_PLACEHOLDER_MESSAGE;
62-
}
63-
if (action === "password-reset") {
64-
return PASSWORD_RESET_PLACEHOLDER_MESSAGE;
65-
}
66-
return "Account action is not available in this preview. Please try again later.";
29+
return accountActionUnavailableMessage(action);
6730
}
6831

6932
async function refreshAccountAuthStatus() {
70-
if (isStaticOnlyLocalEntrypoint()) {
71-
authStatus = {
72-
ready: false,
73-
message: unavailableStatusMessage(),
74-
};
75-
setFormEnabled(false);
76-
setStatus(authStatus.message);
77-
return authStatus;
78-
}
7933
try {
80-
authStatus = await requestAccountAuth("status");
34+
authStatus = await requestAccountAuth("status", {}, unavailableStatusMessage());
8135
setFormEnabled(Boolean(authStatus.ready));
82-
setStatus(authStatus.ready ? "Account service is available." : unavailableStatusMessage());
36+
setStatus(authStatus.ready ? ACCOUNT_SERVICE_READY_MESSAGE : unavailableStatusMessage());
8337
} catch {
8438
authStatus = {
8539
ready: false,
@@ -111,7 +65,7 @@ form?.addEventListener("submit", (event) => {
11165
}
11266
const endpoint = actionEndpoint();
11367
if (!endpoint) {
114-
throw new Error("Unknown account action.");
68+
throw new Error(accountActionFailureMessage(action));
11569
}
11670
const body = {
11771
email: emailField?.value || "",
@@ -122,15 +76,15 @@ form?.addEventListener("submit", (event) => {
12276
return requestAccountAuth(endpoint, {
12377
body,
12478
method: "POST",
125-
});
79+
}, accountActionFailureMessage(action));
12680
})
12781
.then((result) => {
12882
if (result) {
12983
setStatus(result.message || "Account action completed.");
13084
}
13185
})
13286
.catch((error) => {
133-
setStatus(error instanceof Error ? error.message : AUTH_UNAVAILABLE_MESSAGE);
87+
setStatus(error instanceof Error ? error.message : accountActionFailureMessage(action));
13488
});
13589
});
13690

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
export const ACCOUNT_SERVICE_READY_MESSAGE = "Account service is available.";
2+
export const ACCOUNT_IDENTITY_SETUP_MESSAGE = "Account identity setup is incomplete. Please contact support.";
3+
export const PASSWORD_RESET_RATE_LIMIT_MESSAGE = "Too many reset requests. Please wait and try again later.";
4+
5+
const ACTION_UNAVAILABLE_MESSAGES = Object.freeze({
6+
"create-account": "Create Account is not available in this preview. Please try again later.",
7+
"password-reset": "Password Reset is not available in this preview. Please try again later.",
8+
"sign-in": "Sign In is not available in this preview. You can continue browsing.",
9+
});
10+
11+
const ACTION_FAILURE_MESSAGES = Object.freeze({
12+
"create-account": "Create Account could not be completed. Please try again later.",
13+
"password-reset": "Password Reset could not be completed. Please try again later.",
14+
"sign-in": "Sign In could not be completed. Please try again later.",
15+
});
16+
17+
function actionMessage(messages, action, fallback) {
18+
return messages[String(action || "")] || fallback;
19+
}
20+
21+
export function accountActionUnavailableMessage(action) {
22+
return actionMessage(
23+
ACTION_UNAVAILABLE_MESSAGES,
24+
action,
25+
"Account action is not available in this preview. Please try again later.",
26+
);
27+
}
28+
29+
export function accountActionFailureMessage(action) {
30+
return actionMessage(
31+
ACTION_FAILURE_MESSAGES,
32+
action,
33+
"Account action could not be completed. Please try again later.",
34+
);
35+
}
36+
37+
async function readJson(response, fallbackMessage) {
38+
let payload = null;
39+
try {
40+
payload = await response.json();
41+
} catch {
42+
payload = null;
43+
}
44+
if (!response.ok || payload?.ok === false) {
45+
if (payload?.error === ACCOUNT_IDENTITY_SETUP_MESSAGE) {
46+
throw new Error(ACCOUNT_IDENTITY_SETUP_MESSAGE);
47+
}
48+
if (payload?.error === PASSWORD_RESET_RATE_LIMIT_MESSAGE) {
49+
throw new Error(PASSWORD_RESET_RATE_LIMIT_MESSAGE);
50+
}
51+
throw new Error(fallbackMessage);
52+
}
53+
return payload?.data || {};
54+
}
55+
56+
export async function requestAccountAuth(path, options = {}, fallbackMessage = accountActionFailureMessage(path)) {
57+
const response = await fetch(`/api/auth/${path}`, {
58+
body: options.body ? JSON.stringify(options.body) : undefined,
59+
headers: options.body ? { "content-type": "application/json" } : undefined,
60+
method: options.method || "GET",
61+
});
62+
return readJson(response, fallbackMessage);
63+
}
64+
65+
export async function requestCurrentSession(fallbackMessage = accountActionFailureMessage("sign-in")) {
66+
const response = await fetch("/api/session/current", {
67+
headers: { "accept": "application/json" },
68+
method: "GET",
69+
});
70+
return readJson(response, fallbackMessage);
71+
}

0 commit comments

Comments
 (0)