// Writes dist-manifest/app.json from app.template.json. // // Even Hub enforces a per-app network whitelist of exact origins, so the bridge // origin has to be in the packaged manifest. It is supplied at build time and is // never committed: no deployment hostname lives in this repository. import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'; import { dirname, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; const here = dirname(fileURLToPath(import.meta.url)); const raw = process.env.HERMEVEN_BRIDGE_ORIGIN ?? ''; if (!raw) { console.warn('[manifest] HERMEVEN_BRIDGE_ORIGIN is not set: skipping app.json. Set it before `npm run pack`.'); process.exit(0); } let origin; try { origin = new URL(raw).origin; } catch { console.error('[manifest] HERMEVEN_BRIDGE_ORIGIN is not a URL.'); process.exit(1); } if (origin !== raw) { console.error(`[manifest] HERMEVEN_BRIDGE_ORIGIN must be a bare origin (scheme://host[:port]), got a path or trailing slash.`); process.exit(1); } // Same rule as the app enforces at run time (src/net/bridgeClient.ts): HTTPS, or HTTP to // loopback for the simulator. A packaged app must never be allowed to send the device // credential and recordings over plain HTTP to a LAN or public host. const { protocol, hostname } = new URL(origin); const loopback = hostname === 'localhost' || hostname === '[::1]' || /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(hostname); if (protocol !== 'https:' && !(protocol === 'http:' && loopback)) { console.error('[manifest] HERMEVEN_BRIDGE_ORIGIN must be https:// (plain http is accepted only for loopback).'); process.exit(1); } if (protocol === 'http:') { console.warn('[manifest] Loopback HTTP origin: this build is for the simulator only and cannot work on a phone.'); } const template = readFileSync(resolve(here, '../app.template.json'), 'utf8'); const out = process.env.HERMEVEN_MANIFEST_OUT ?? resolve(here, '../dist-manifest/app.json'); mkdirSync(dirname(out), { recursive: true }); writeFileSync(out, template.replace('__HERMEVEN_BRIDGE_ORIGIN__', origin)); console.log(`[manifest] wrote ${out}`);