initiative-api

module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: MIT

README

initiative-api

License Issues PRs Coverage

Go API behind Initiative!, the SweetRPG initiative tracker. All tracker rules live here; clients are presentation only (PADR-0033, proposed). Design and task list: openspec/changes/initiative-api in sweetrpg/platform.

Status: skeleton. Config validation, logging, tracing, and /status/* are in place; auth, data layer, and domain routes are not.

Running

cp .env.example .env
make run
Variable Default Notes
BIND_ADDRESS :8000 host:port
ENV dev
LOG_LEVEL WARN DEBUG, INFO, WARN, ERROR
OTEL_EXPORTER_OTLP_ENDPOINT unset absolute URL of the trace collector
AUTH_API_URL required auth-api base URL; tokens are verified via /authz/check
USERS_API_URL required users-api base URL; resolves the caller to users._id
ENTITLEMENTS_API_URL required entitlements-api base URL; the caller's bearer is forwarded on checks
ALLOWED_ORIGINS unset comma-separated; unset disables CORS, * is rejected

Invalid values stop the process at startup with every problem listed.

Endpoints

  • GET /status/ping: shallow liveness and readiness probe.
  • GET /status/health: dependency check (no dependencies yet).
  • GET /themes, GET /themes/packaged, GET /themes/{id}, POST /themes, PATCH /themes/{id} (body carries revision), DELETE /themes/{id}?revision=N. Custom themes take the lowest free slot below initiative.theme_slots; packaged themes (pkg- IDs) are read-only. Errors are {code, message, correlation_id, key?, limit?}.
  • PUT /entitlements/active/{themes|rosters|encounters|credentials} (body ids): choose which items stay active when a limit is below the number owned. Over-limit items go inactive (inactive_at), never deleted: readable and deletable, not editable (403 item_inactive), and an inactive credential stops authenticating. Limits are re-read on the owner's own requests (at most every 30 s).
  • Without the initiative.game_systems_extra flag, encounters using a game system other than No System are locked (locked_at): readable and deletable, not editable or runnable (403 entitlement_required), and unlocked unchanged when the flag returns. Creating or switching to a gated system without the flag gets the same error.
  • POST /credentials (body label, scopes; the secret is returned once), GET /credentials, POST /credentials/{id}/revoke. Integrations send the secret as Authorization: Bearer ic_...; it acts as its owner with the user role, read allows GET and write allows other methods. Credentials cannot reach /credentials, /entitlements or /themes. A deny or role removal in auth-api ends the owner's credentials (PADR-0039): the service consumes the AUTH_EVENTS stream (NATS_URL, optional NATS_DURABLE_NAME, NATS_CREDS or NATS_USER/NATS_PASSWORD). Credentials answer 503 credentials_unavailable until the consumer has caught up, and stay off if NATS_URL is unset or the consumer fell behind the stream's retention. POST /admin/credentials/reopen (admin bearer only) clears that close and logs an audit entry; the gate records the actor.
  • GET /combatants?ref_key=&ref_value=: the caller's combatants whose external_refs match.

Every response carries X-Correlation-ID (the caller's value, or a generated one), also written to the access log as correlation_id.

Checks

make lint test

Directories

Path Synopsis
cmd
initiative-api command
Command initiative-api serves the Initiative! API.
Command initiative-api serves the Initiative! API.
seed command
Command seed applies the checked-in game-system definitions to the configured database.
Command seed applies the checked-in game-system definitions to the configured database.
Package config loads and validates the service configuration from the environment.
Package config loads and validates the service configuration from the environment.
Package constants holds service-wide names and environment variable keys.
Package constants holds service-wide names and environment variable keys.
Package data is initiative-api's data layer.
Package data is initiative-api's data layer.
Package domain holds initiative-api's rules over the owner-scoped data layer: rosters and characters, and moving cast between rosters and encounters.
Package domain holds initiative-api's rules over the owner-scoped data layer: rosters and characters, and moving cast between rosters and encounters.
Package entitlements is the client for entitlements-api's check routes (docs/entitlements-check-contract.md in the platform repo, PADR-0034).
Package entitlements is the client for entitlements-api's check routes (docs/entitlements-check-contract.md in the platform repo, PADR-0034).
Package events consumes auth-api's change events from the platform bus (PADR-0039): a deny or a role removal ends the subject's integration credentials.
Package events consumes auth-api's change events from the platform bus (PADR-0039): a deny or a role removal ends the subject's integration credentials.
Package seed loads the versioned game-system definitions checked into this repo.
Package seed loads the versioned game-system definitions checked into this repo.
Package server wires the HTTP routes and middleware.
Package server wires the HTTP routes and middleware.
Package store is the narrow MongoDB surface the data layer needs.
Package store is the narrow MongoDB surface the data layer needs.
fake
Package fake is an in-memory store.Collection for tests.
Package fake is an in-memory store.Collection for tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL