style: format remaining owned runtime modules

This commit is contained in:
Sameh Khamis committed 2026-09-15 07:26:32 -07:00
1 parent ae99843c14
commit 2aca7aecbb
94 files changed
+8865 -3151

No files matched your search

+69 -26
View File
@@ -19,7 +19,9 @@ import { createSurfaceKeyboard } from './ui/surfaceKeyboard.js';
/** Chip label — pure, exported for tests. */
export function keySetupChipLabel(status) {
const missing = Math.max(0, (status?.total || 0) - (status?.setCount || 0));
return missing > 0 ? `POWER UP · ${missing} ${missing === 1 ? 'KEY' : 'KEYS'} WAITING` : 'POWERED UP';
return missing > 0
? `POWER UP · ${missing} ${missing === 1 ? 'KEY' : 'KEYS'} WAITING`
: 'POWERED UP';
}
/**
@@ -78,13 +80,17 @@ function buildRow(documentRef, key) {
const tier = documentRef.createElement('span');
tier.className = 'key-setup-tier';
tier.textContent = TIER_DOTS[key.tier] || '';
tier.title = key.tier === 'metered' ? 'Metered — a billing-enabled account' : 'Free key — register, paste, done';
tier.title =
key.tier === 'metered'
? 'Metered — a billing-enabled account'
: 'Free key — register, paste, done';
head.append(led, title, tier);
if (key.clientExposed) {
const exposed = documentRef.createElement('span');
exposed.className = 'key-setup-exposed';
exposed.textContent = 'browser-side';
exposed.title = 'This key runs in the browser by design — restrict it at the provider (see SECURITY.md)';
exposed.title =
'This key runs in the browser by design — restrict it at the provider (see SECURITY.md)';
head.append(exposed);
}
if (external) {
@@ -93,7 +99,8 @@ function buildRow(documentRef, key) {
const badge = documentRef.createElement('span');
badge.className = 'key-setup-external';
badge.textContent = 'configured externally';
badge.title = 'Supplied by your environment, Keychain, or launcher — change it where it was set';
badge.title =
'Supplied by your environment, Keychain, or launcher — change it where it was set';
head.append(badge);
}
const get = documentRef.createElement('a');
@@ -144,7 +151,11 @@ function buildRow(documentRef, key) {
* Wire the chip + dialog. Fire-and-forget from main.js; resolves to null when
* the surface has no business existing (prod build, LAN visitor, no markup).
*/
export async function initKeySetup({ documentRef = globalThis.document, fetchImpl, signal } = {}) {
export async function initKeySetup({
documentRef = globalThis.document,
fetchImpl,
signal,
} = {}) {
const chip = documentRef?.getElementById?.('key-setup-chip');
const root = documentRef?.getElementById?.('key-setup');
if (!chip || !root || root.dataset.initialized === 'true') return null;
@@ -161,13 +172,19 @@ export async function initKeySetup({ documentRef = globalThis.document, fetchImp
chip.remove();
root.remove();
};
if (signal?.aborted) { destroy(); return null; }
if (signal?.aborted) {
destroy();
return null;
}
signal?.addEventListener('abort', destroy, { once: true });
const doFetch = fetchImpl || globalThis.fetch?.bind(globalThis);
let status = null;
try {
const response = await doFetch('/api/setup/status', { cache: 'no-store', signal: lifetime.signal });
const response = await doFetch('/api/setup/status', {
cache: 'no-store',
signal: lifetime.signal,
});
if (!response.ok) throw new Error(String(response.status));
status = await response.json();
if (disposed) return null;
@@ -196,12 +213,14 @@ export async function initKeySetup({ documentRef = globalThis.document, fetchImp
chip.hidden = status.setCount >= status.total;
if (!rowsHost) return;
rowsHost.textContent = '';
for (const key of status.keys || []) rowsHost.append(buildRow(documentRef, key));
for (const key of status.keys || [])
rowsHost.append(buildRow(documentRef, key));
};
const visible = () => root.isConnected
&& root.classList.contains('visible')
&& root.getClientRects().length > 0;
const visible = () =>
root.isConnected &&
root.classList.contains('visible') &&
root.getClientRects().length > 0;
const keyboard = createSurfaceKeyboard({
root,
@@ -226,22 +245,29 @@ export async function initKeySetup({ documentRef = globalThis.document, fetchImp
if (!open) return;
open = false;
root.classList.remove('visible');
const hide = () => { if (!open) root.hidden = true; };
const hide = () => {
if (!open) root.hidden = true;
};
root.addEventListener('transitionend', hide, { once: true });
globalThis.setTimeout?.(hide, 400);
if (statusLine) statusLine.textContent = defaultStatusText;
keyboard.deactivate({ restoreFocus: true });
};
const say = (text) => { if (statusLine) statusLine.textContent = text; };
const say = (text) => {
if (statusLine) statusLine.textContent = text;
};
const storeLabel = () => (status?.store === 'pinokio-environment'
? 'your app configuration'
: 'your local .env');
const storeLabel = () =>
status?.store === 'pinokio-environment'
? 'your app configuration'
: 'your local .env';
const submitUpdates = async (updates, doneVerb) => {
if (disposed || busy) return;
const googleWasUnset = !status?.keys?.find((key) => key.id === 'google-maps')?.set;
const googleWasUnset = !status?.keys?.find(
(key) => key.id === 'google-maps',
)?.set;
busy = true;
applyButton?.setAttribute('aria-disabled', 'true');
say('Saving…');
@@ -258,13 +284,17 @@ export async function initKeySetup({ documentRef = globalThis.document, fetchImp
say(payload.error || `Save failed (${response.status}).`);
return;
}
for (const input of root.querySelectorAll('input[data-env-var]')) input.value = '';
for (const input of root.querySelectorAll('input[data-env-var]'))
input.value = '';
render(payload.status);
if (googleWasUnset && payload.saved?.includes('GOOGLE_MAPS_API_KEY')) {
const strip = () => {
try {
const next = stripKeylessBasemapFromHash(globalThis.location?.hash?.slice(1) || '');
if (next !== null) globalThis.history?.replaceState?.(null, '', `#${next}`);
const next = stripKeylessBasemapFromHash(
globalThis.location?.hash?.slice(1) || '',
);
if (next !== null)
globalThis.history?.replaceState?.(null, '', `#${next}`);
} catch {
// Continuity is a nicety, never a blocker.
}
@@ -272,9 +302,14 @@ export async function initKeySetup({ documentRef = globalThis.document, fetchImp
strip();
// The live share writer may re-serialize the still-OSM stack before
// the restart's reload lands, so strip again at the door.
globalThis.addEventListener?.('pagehide', strip, { once: true, signal: lifetime.signal });
globalThis.addEventListener?.('pagehide', strip, {
once: true,
signal: lifetime.signal,
});
}
say(`${doneVerb} ${storeLabel()}. Restarting — this page reloads itself.`);
say(
`${doneVerb} ${storeLabel()}. Restarting — this page reloads itself.`,
);
} catch (error) {
say(`Save failed: ${error?.message || error}`);
} finally {
@@ -287,7 +322,10 @@ export async function initKeySetup({ documentRef = globalThis.document, fetchImp
if (disposed || busy) return;
const inputs = [...root.querySelectorAll('input[data-env-var]')];
const updates = collectKeyUpdates(
inputs.map((input) => ({ envVar: input.dataset.envVar, value: input.value })),
inputs.map((input) => ({
envVar: input.dataset.envVar,
value: input.value,
})),
);
if (!Object.keys(updates).length) {
say('Paste at least one key first.');
@@ -313,8 +351,9 @@ export async function initKeySetup({ documentRef = globalThis.document, fetchImp
// Removal is destructive and — behind a framing defense that should already
// stop it — a clickjack target. A confirm turns a single aligned click into
// a deliberate two-step the lure cannot pre-satisfy.
const ok = typeof globalThis.confirm !== 'function'
|| globalThis.confirm('Remove this key from your saved configuration?');
const ok =
typeof globalThis.confirm !== 'function' ||
globalThis.confirm('Remove this key from your saved configuration?');
if (!ok) return;
void submitUpdates(
Object.fromEntries(envVars.map((name) => [name, null])),
@@ -327,7 +366,11 @@ export async function initKeySetup({ documentRef = globalThis.document, fetchImp
// Re-entry for a fully-keyed setup, demos, and support: ?setup=1 opens the
// dialog even though the chip has retired.
try {
if (new URLSearchParams(globalThis.location?.search || '').get('setup') === '1') openDialog();
if (
new URLSearchParams(globalThis.location?.search || '').get('setup') ===
'1'
)
openDialog();
} catch {
// An unparsable location never blocks init.
}