@gamebeast/sdk-contract
The HTTP contract between core-backend and the Gamebeast SDKs: Zod schemas and inferred types for every /sdk/* request and response an SDK uses, and the alias slugging both sides normalize names with.
core-backend declares its SDK routes with these schemas (via workspace:*), and the JavaScript SDKs in GamebeastGG/gamebeast-js (@gamebeast/js, @gamebeast/node, and their shared @gamebeast/core) depend on the published version. That gives one definition for each shape: change it here and the backend, its OpenAPI document, and the SDKs all follow. The Roblox, Unity, Unreal (GamebeastGG/gamebeast-unreal) and Godot (GamebeastGG/gamebeast-godot) SDKs don't depend on this package, but parse the same responses, so a change here affects them too.
This is the only package in the monorepo published to npm. Everything in it is public API. For which SDK calls which route, and the full checklist for changing one, see core-backend's src/sdk/AGENTS.md.
What's in it
| Module |
Contents |
v2/configurations |
GET /sdk/v2/configurations, POST /sdk/v2/configurations/evaluate responses; EvaluateConfigurationV2Body |
v2/bootstrap |
/sdk/v2/bootstrap and /sdk/v2/status snapshots |
v2/experiments |
Experiment descriptor, /experiments/active, single and bulk assignment responses; BulkAssignV2Body |
v2/headers |
v2 request headers |
v1/markers |
POST /sdk/v1/markers: the per-marker schema (none/javascript/unity/unreal/godot/discord platforms), body, responses |
v1/cohorts |
POST /sdk/v1/cohorts/membership body and response |
v1/headers |
v1 request headers (isstudio) |
errors |
v2 error envelope and codes; marker-ingestion error codes |
context |
Targeting-context value schemas and the properties-only context type SDKs send |
core (./core) |
toAliasSlug and every request limit (context sizes, id lengths, bulk batch size). No Zod: see below |
Two request bodies are only types here, EvaluateConfigurationV2Body and BulkAssignV2Body. Their backend schemas embed the full targeting context, which is built from the targeting-field registry in @gamebeast/experiments, and that package isn't published. core-backend's sdkContract.compat.test.ts fails to compile if those schemas stop accepting the contract types.
Usage
import {
SdkConfigurationV2ResponseSchema,
type SdkConfigurationV2Response,
} from "@gamebeast/sdk-contract";
import { CONTEXT_MAX_PROPERTIES, toAliasSlug } from "@gamebeast/sdk-contract/core";
const parsed = SdkConfigurationV2ResponseSchema.safeParse(await response.json());
zod (^4.6) is a dependency. Browser code should import values only from @gamebeast/sdk-contract/core and use import type for everything else, so the schemas (and classic Zod, about 90 KB gzipped) stay out of the bundle. Importing a constant from the package root would keep the module it's defined in, Zod included. src/core.test.ts fails if core/ ever imports Zod.
Changing the contract
Already-shipped SDKs parse responses with whatever version they were built against, so version changes by what an old SDK can still read:
- Patch: docs, or a fix that doesn't change what parses.
- Minor: additive. A new optional response field, a new endpoint schema, a request field the backend treats as optional. Old SDKs drop unknown keys, so new fields are safe.
- Major: anything an old SDK would reject or misread. Removing or renaming a field, narrowing a type, making a field nullable, adding an enum value to a response field, or making a request field required.
The backend change has to stay compatible with SDKs already in the field regardless of the version number. A major version only tells SDK authors to update; it doesn't stop old installs from calling the API.
Any change to a non-test file in src/ needs a version bump in the same PR. The SDK contract version check (sdk-contract-version.yml) fails the PR otherwise, because an unbumped change is never published and the SDKs would never see it. For a src/ change that genuinely shouldn't release (a comment, say), add the sdk-contract:no-release label.
Releasing
- Change the schemas, then bump
version in this package's package.json in the same PR.
- On merge to
main, publish-sdk-contract.yml builds, tests, and publishes the version if it isn't on npm yet, through npm trusted publishing. A merge that doesn't bump the version publishes nothing. To retry a failed publish, rerun the workflow (it also has a manual workflow_dispatch trigger).
- Bump
@gamebeast/sdk-contract in gamebeast-js and release the SDKs (its README covers that).
Locally: moon run sdk-contract:build sdk-contract:test. To check the publish tarball, run pnpm pack and inspect it. publishConfig repoints types/exports from src/ to dist/.
npm setup
Publishing needs no token: npm trusts this repo's workflow directly (OIDC). The package's trusted publisher on npmjs.com (package Settings → Trusted publishing) is:
| Field |
Value |
| Provider |
GitHub Actions |
| Repository |
GamebeastGG/service-monorepo |
| Workflow |
publish-sdk-contract.yml |
| Environment |
npm-publish |
| Permissions |
publish |
Check it with npm trust list @gamebeast/sdk-contract. Renaming the workflow file or the environment breaks publishing until the entry is updated. Things that have tripped this up:
-
403 OIDC permission denied for this action: the entry only has stage publish. Revoke it (npm trust revoke @gamebeast/sdk-contract --id=<id>) and recreate it with npm trust github @gamebeast/sdk-contract --file publish-sdk-contract.yml --repo GamebeastGG/service-monorepo --env npm-publish --allow-publish.
-
404 Not Found - PUT: trusted publishing can't create a package, only publish new versions of an existing one. A brand-new package needs one manual publish first (a placeholder version is enough), then the trusted publisher.
-
The job fails after "already on npm; nothing to publish": a cache: setting on setup-node. Its post-step fails when nothing was installed, so the workflow doesn't cache.
-
422 Unprocessable Entity ... Unsupported GitHub Actions source repository visibility: "internal": npm only accepts provenance attestations from public repositories, and this repo is internal. The workflow publishes with --provenance=false, and publishConfig must not set provenance.
Versions of this package have no provenance attestation, because the repo isn't public. The first version, 1.0.0, was published by hand from a maintainer's machine; later versions come from this workflow. 0.0.0-stage is the placeholder that created the package on npm; don't depend on it.