/** * @module bootstrap * * Startup code for ibgib-specific things: initializing the metaspace and * starting the space-gib app. * * Called dynamically by index.mts AFTER initial page render, so the heavy * ibgib import graph doesn't block first paint. */ import { bootstrapIbGibApp } from "@ibgib/web-gib/dist/app-bootstrap/bootstrap.mjs"; import { APP_CONFIG, GLOBAL_LOG_A_LOT } from "./constants.mjs"; import { getIbGibGlobalThis_SpaceGib } from "./helpers.web.mjs"; import { SpaceGibApp_V1 } from "./witness/app/space-gib/space-gib-app-v1.mjs"; import { PARAM_INFOS } from "./witness/app/space-gib/space-gib-constants.mjs"; import { DEFAULT_SPACE_GIB_APP_DATA_V1, DEFAULT_SPACE_GIB_APP_REL8NS_V1, } from "./witness/app/space-gib/space-gib-types.mjs"; import { AUTO_GENERATED_VERSION } from "./AUTO-GENERATED-version.mjs"; import { registerDeprecatedFunctionNamesAndFunctionInfos_Web } from "./api/function-infos.web.mjs"; import { getSpaceGibShellSvc } from "./ui/shell/space-gib-shell-service.mjs"; // Early check: if we are in an OAuth callback popup redirect, notify parent window and close immediately. const urlParams = new URLSearchParams(window.location.search); if (urlParams.has('code') && urlParams.has('state') && window.opener) { const code = urlParams.get('code'); const state = urlParams.get('state'); window.opener.postMessage({ type: 'sso-oauth-callback', code, state }, window.location.origin); window.close(); } console.log(`[space-gib bootstrap] version: ${AUTO_GENERATED_VERSION}`); const clientProfiles = [ process.env.KEYSTONE_PROFILE_SOVEREIGN_PRIMARY, process.env.KEYSTONE_PROFILE_SOVEREIGN_SYNC, process.env.KEYSTONE_PROFILE_CUSTODIAN_SYNC, ].filter(Boolean) as string[]; const isProdEnv = process.env.NODE_ENV === 'production'; const hasDevProfile = clientProfiles.some(p => p.endsWith('.dev')); const hasStagingProfile = clientProfiles.some(p => p.endsWith('.staging')); if (isProdEnv && (hasDevProfile || hasStagingProfile)) { throw new Error(`Security Violation: Non-production keystone profiles are prohibited when NODE_ENV=production. Active client profiles: ${clientProfiles.join(', ')}. (E: 7a8b9c0d1e2f3456789abcdef0123456)`); } if (hasDevProfile) { console.warn(`%c⚠️ WARNING: DEVELOPMENT KEYSTONE PROFILE ACTIVE (.dev)!\nGENERATED KEYSTONES USE LOW-SECURITY DEV PARAMETERS FOR RAPID TESTING.\nFOR LOCAL TESTING ONLY — DO NOT USE FOR REAL SECRETS OR PRODUCTION DATA!`, 'background: #990000; color: #ffffff; font-size: 14px; font-weight: bold; padding: 8px; border-radius: 4px;'); } else if (hasStagingProfile) { console.info(`%cℹ️ STAGING KEYSTONE PROFILE ACTIVE (.staging)`, 'background: #005599; color: #ffffff; font-size: 13px; font-weight: bold; padding: 6px; border-radius: 4px;'); } // --------------------------------------------------------------------------- // Main entry point // --------------------------------------------------------------------------- export async function bootstrapSpaceGibApp() { await bootstrapIbGibApp({ config: APP_CONFIG, getGlobalThis: getIbGibGlobalThis_SpaceGib, AppClass: SpaceGibApp_V1, defaultAppData: DEFAULT_SPACE_GIB_APP_DATA_V1, paramInfos: PARAM_INFOS, registerAgentFunctionInfos: registerDeprecatedFunctionNamesAndFunctionInfos_Web, localSpaceNamePrefix: 'space_gib_', onReady: async (app) => { if (GLOBAL_LOG_A_LOT) { console.log(`[bootstrapSpaceGibApp] Engine ready. app: ${app?.ib}`); } // Hand over control to the shell await getSpaceGibShellSvc().onEngineReady(); }, }); }