@betorigami/game-ui-shared
The Lit components, controllers, translations, wire types and game-module registry shared by every Origami game UI. It was moved out of @betorigami/games, which now holds the host element, the game folders and the registration of their modules.
Consuming
lit, @lit/context and big.js are peer dependencies so that one copy of each is bundled by the host. Importing the package registers every shared custom element.
import { GameComponent, RequiredContext, localeContext, getTranslation } from '@betorigami/game-ui-shared';
Elements read the game context through RequiredContext, one per slice they need (localeContext, sessionContext, limitsContext, servicesContext, skinContext, preferencesContext, layoutContext, walletContext), all provided by <origami-game-provider-wrapper>. Reading a slice outside the wrapper throws. Desktop and mobile styles go in ${desktopContainerQuery} { … } and ${mobileContainerQuery} { … } blocks, after the base rules they override; both query the game-layout container the wrapper provides. Tests give an element its slices with provideTestContexts and change them with updateTestContexts.
A game contributes itself through a GameUiModule:
import { registerGameUiModule, type GameUiModule } from '@betorigami/game-ui-shared';
registerGameUiModule(myGameUiModule);
The shared components reach a game only through that registry: the provider wrapper renders renderGame(), the info modal reads gameInfo and maxMultiplier, the bet-result modal uses extractOutcome, renderOutcome, renderBetDetails and verifierInputs, and the verifier link uses verifierQuery.
A game adds its wire types by module augmentation rather than by editing this package:
declare module '@betorigami/game-ui-shared' {
interface GameActionData {
MY_GAME?: MyGameStartAction | EndAction;
}
}
The package does not read environment variables. A host that wants a different provably-fair verifier calls setVerifierBaseUrl with that URL at startup; a host that does not leaves the built-in default in place.
Provider API client
ProviderApi is a client for provider-api, generated with hey-api from provider-api's OpenAPI spec. Every response is checked against the spec with zod/mini before the caller sees it.
import { ProviderApi } from '@betorigami/game-ui-shared';
const client = ProviderApi.createProviderApiClient({ baseUrl, authToken });
const { data, error } = await ProviderApi.postGamesDicePlay({ client, body });
createProviderApiClient adds the auth token, a fresh X-Origami-Trace id and a REQUEST_TIMEOUT_MS timeout to every request. data is set when the request succeeds and the response matches the spec. Otherwise error holds the error body, which resolveApiErrorCode turns into an ErrorCode. A response that doesn't match the spec throws. Inside this package, import from src/shared/provider-api/provider-api-client instead.
To regenerate it after provider-api's endpoints change:
- Start provider-api locally from the backend repo with
ENABLE_OPENAPI_DOCS=true, the default in its.env.template. It serves the spec athttp://localhost:3000/openapi.json. - Run
pnpm run generate:provider-apiin this package. - Commit the changes under
src/shared/provider-api/generated/.
The settings, including the excluded /internal/* routes, are in openapi-ts.config.ts. Don't edit the generated files by hand.
Pinning
@betorigami/game-calculations supplies the enums of the games that have not yet been extracted. A host must pin the same version of it as this package, or two copies of the engine end up in one bundle and enum identity breaks.