seitime-bridge/scripts/settings.js
Vassili Minaev bc3aa10ab2 Initial scaffolding: settings + manifest push
Foundry v12 ESM module that pushes the world's PC actor manifest to a
companion Frappe app via webhook.

Structure:
- scripts/main.js: registers settings on init, exposes API on ready,
  wires createActor/deleteActor/periodic hooks. All push operations
  gated to game.users.activeGM to avoid duplicate pushes from co-GMs.
- scripts/settings.js: Frappe URL, shared secret, world ID, periodic
  interval. Secret uses `secret: true` for masked input but is still
  readable by all connected clients (documented in setting hint).
- scripts/api.js: bridgeFetch helper with X-Bridge-Secret/-World
  headers, pushManifest, testConnection.
- scripts/constants.js: MODULE_ID.

Public API exposed at globalThis.seitimeBridge:
  seitimeBridge.testConnection()  // round-trip empty manifest
  seitimeBridge.pushManifest()    // push current world manifest

dnd5e is declared as a related system in module.json.
Snapshot push and End Session macro come in subsequent commits.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-10 02:26:53 -06:00

52 lines
1.8 KiB
JavaScript

/**
* Module settings registration.
*
* Note on `sharedSecret`: Foundry stores world-scope settings in a place
* readable by all connected clients, not just GMs. A player with browser
* console access can read the value. This is acceptable here because the
* secret only authorizes pushing dnd5e actor data — which players already
* have access to through normal play — and the Frappe side enforces all
* other authorization. Rotate the secret if you stop trusting a player.
*/
import { MODULE_ID } from "./constants.js";
export function registerSettings() {
game.settings.register(MODULE_ID, "frappeBaseUrl", {
name: "Frappe Base URL",
hint: "Base URL of your Seitime Frappe site, e.g. https://seitime.vassi.li (no trailing slash).",
scope: "world",
config: true,
type: String,
default: "",
});
game.settings.register(MODULE_ID, "sharedSecret", {
name: "Shared Secret",
hint: "Bridge secret — must match Foundry Settings → Shared Secret on the Frappe side. Readable by any connected client; rotate if compromised.",
scope: "world",
config: true,
type: String,
default: "",
secret: true,
});
game.settings.register(MODULE_ID, "worldId", {
name: "World ID",
hint: "Identifier sent in the X-Bridge-World header. If you've configured Allowed World IDs on the Frappe side, this must be one of them. Leave blank to use the current Foundry world's id.",
scope: "world",
config: true,
type: String,
default: "",
});
game.settings.register(MODULE_ID, "manifestSyncIntervalMinutes", {
name: "Manifest Sync Interval (minutes)",
hint: "How often to push the actor manifest while the world is open. 0 disables periodic sync; on/create/delete pushes still fire.",
scope: "world",
config: true,
type: Number,
default: 15,
range: { min: 0, max: 120, step: 1 },
});
}