# Versioning and migration notes

**Purpose:** this page explains how SDK versions are numbered, what never changes inside the `v1` line, and what to check when you move between releases. Here "version" always means a version of the SDK; the files you upload for a game are called a build.

## The script URL is the contract

```text
https://sdk.zokogames.com/zokogames-sdk-v1.js
```

That URL is the **latest** alias of the 1.x line: it is cached for about an hour at most and always points at the newest 1.x release. To lock a build to one release, use the immutable, versioned URL instead:

```text
https://sdk.zokogames.com/1.7.0/zokogames-sdk-v1.js
```

A versioned file never changes once published. Pinning means you do not receive fixes until you change the number, so most games should use the latest alias.

The `v1` in the file name is the major version. Inside a major version the SDK stays **backwards compatible**: methods, argument shapes, return values and error codes you already use keep working. The current release is **1.7.0** and the exact number is exported as `SDK_VERSION` by the module build and set as `window.ZokoGames.SDK_VERSION` by the script tag (the SDK also sends the number to the portal during the handshake).

What may change inside `v1` without notice:

- New methods, new optional arguments and new fields on returned objects.
- New error codes. Always keep a default branch in `switch (e.code)` that takes the safe path.
- Calls the portal accepts but barely uses today (`reportGameCompletedPercentage` and `setGameContext` have only small effects, see [game](https://docs.zokogames.com/sdk/game#completion)) start doing more.
- Bug fixes and stricter validation of arguments that were already documented as invalid.

What requires a new major version (`v2`) and a long overlap:

- Removing or renaming a method, argument or documented error code.
- Changing the meaning of an existing return value.
- Changing the wire protocol in a way old SDK builds cannot answer.

The portal checks the protocol version during `init()`. A game built against `v1` keeps working while `v1` is served.

## Do not self-host an old copy

Load the script from the URL above rather than copying it into your build, so fixes reach your players. If you must bundle a copy (an offline build), keep the `ZokoGames` global name so the upload validator still recognises the SDK, and update the copy whenever the [changelog](https://docs.zokogames.com/business/changelog) lists a release.

## Migration notes

The newest release is listed first, and the docs changelog (Business, then Changelog) lists every release.

### 1.7.0

Additive: game code written for 1.6.4 needs no change, and no name, global, error code or return value changes. New: `SDK.analytics.track(name, params?)` (custom events, fire-and-forget), `SDK.data.mirrorIndexedDB(options?)` (cloud saves for Unity, Godot and GameMaker, which save into IndexedDB; await it before the engine starts), `SDK.game.room.addLeftListener` / `removeLeftListener` (the portal ended your room membership: `left`, `kicked`, `closed` or `disconnected`) and an optional second argument `{ portalOnly: true }` on `showInviteButton` / `hideInviteButton` (the portal's invite button without a room). A portal older than 1.7.0 drops the new calls; check for them before use if you pin an older script. The script grew from about 57.7 KB to about 71 KB minified.

### 1.6.4

Additive: game code written for 1.6.3 needs no change, and no name, global, error code or return value changes. `SDK.user.submitScore` accepts an optional `delayed: { encryptedScore, earnedAt }`: a second copy of the score, sealed at the end of the run with `earnedAt = Date.now()`, that the portal keeps on the device for a signed-in player (boards with an encryption key only, never in kids mode, never for guests) and sends when they are back online, within 72 hours. It counts for the all-time board only, not the weekly board. There is no new message kind; a malformed `delayed` is dropped and the normal score still goes through, and a portal older than 1.6.4 ignores it. Neither the SDK nor local mode checks `earnedAt` or the token. Local mode changed in two ways you will see when you test: it refuses a midgame ad with `adCooldown` until the game has called `gameplayStart()` (or 30 seconds of visible page time have passed; rewarded ads are not gated), and it shows "Score saved offline" for an offline signed-in `submitScore` with `delayed`. Three small additions: every `add<Thing>Listener` method now returns a function that removes that listener, `window.ZokoGames.SDK_VERSION` holds the version string, and `SdkError.code` autocompletes the known codes in editors (any other string stays valid). The engine plugins need no update and do not pass `delayed`. Pinned: `https://sdk.zokogames.com/1.7.0/zokogames-sdk-v1.js`.

### 1.6.3

Messages only: game code written for 1.6.2 needs no change, and no name, global, type, error code, return value or timing changes. The `sdkDisabled` message says why the SDK is disabled and links the local testing page; the one-time "Disabled" console line adds a hint to use `?useLocalSdk=true` when local mode is the way out. `invalidArgument` messages say what was received, and the banner `invalidSize` message lists the allowed sizes. New one-time console warnings that never throw: callbacks passed to `ad.requestAd` that can never run, a non-object passed to `user.getUserToken`, and a misspelled local scenario switch value. Local mode logs each `user.submitScore` call. If your code compares the text of an error `message`, compare the `code` instead: codes are stable, messages are not. One fix: `ad.requestAd` now resolves when the callbacks object cannot be read (for example a revoked `Proxy`); before, such a request stayed pending for ever. Pinned: `https://sdk.zokogames.com/1.6.3/zokogames-sdk-v1.js`.

### 1.6.2

Additive: game code written for 1.6.1 needs no change, and no name, global or message format changes. `SDK.game.gameId` is a new read-only string with the portal's id for your game (`"local-game"` in local mode); like the other game properties it throws `sdkNotInitialized` before `init()` resolves and `sdkDisabled` when the environment is `disabled`. The SDK writes one-time console notices (once per page each): an info line saying why the environment is `disabled`, an info line the first time a member is used before `init()` resolved, and a warning the first time a cloud save fails to sync (the save is kept locally and retried). A parent page on a host with a reserved label at any depth, such as `x.g-<slug>.zokogames.com`, no longer counts as the portal. Two fixes: an ad request that already ended (timeout, error or finished) ignores later host events, so a late `adStarted` no longer keeps banners refused with `videoAdPlaying`; and `showAuthPrompt()` asks the portal who is signed in (one extra `user.getUser` call) instead of trusting the cached player, so it opens the sign-in dialog after a sign-out in the portal instead of rejecting with `userAlreadySignedIn`. The engine plugins need no update and do not wrap `gameId` yet. Pinned: `https://sdk.zokogames.com/1.6.2/zokogames-sdk-v1.js`.

### 1.6.1

Security hardening: game code written for 1.6.0 needs no change, and no name, global or message format changes. The SDK accepts the handshake answer only from a ZokoGames page (`https` on `zokogames.com` or a subdomain, except the game hosts `g-<slug>` and the preview runner), from a local host when the game itself also runs on a local host, or from the game's own origin. Any other answer counts as no answer (`local` when local mode applies, otherwise `disabled`), so a site that frames your game can no longer pose as the portal. One trailing dot on a host name is ignored. `SDK.ad.requestAd(type, null)` no longer throws, and the descriptions of the banner error codes `missingId` and `notCreated`, which had been swapped, are correct now. The engine plugins need no update. Pinned: `https://sdk.zokogames.com/1.6.1/zokogames-sdk-v1.js`.

### 1.6.0

Additive: game code written for 1.5 needs no change. The room host can call `SDK.game.updateRoom({ isPublic: true })` so friends can join the room from their friends list; rooms are private by default, a guest's value is ignored, and in kids mode rooms always stay private. A value that is not a boolean rejects with `invalidArgument`; an older portal ignores the field. The engine wrappers move to 1.6.0 as well (Construct 3 action **Set room public**, Unity `ZokoRoomUpdate.IsPublic`). See [multiplayer rooms](https://docs.zokogames.com/guides/multiplayer-rooms). Pinned: `https://sdk.zokogames.com/1.6.0/zokogames-sdk-v1.js`.

### 1.5.1

Additive, and only for testing: nothing changes outside local mode, and game code written for 1.5.0 needs no change. Local mode now fires `settingsChange`, `joinRoom` and `offlineChange` when the page dispatches the `zokogames:local-settings`, `zokogames:local-join-room` and `zokogames:local-offline` window events, so you can test those listeners without the portal (see [simulating portal events](https://docs.zokogames.com/getting-started/local-testing#simulating-portal-events)). The engine wrappers stay at 1.5.0. Pinned: `https://sdk.zokogames.com/1.5.1/zokogames-sdk-v1.js`.

### 1.5.0

Additive: nothing breaks and game code written for 1.4 needs no change. `SDK.game.settings.kidsMode` (an optional boolean) is now typed and is also in the settings listener's payload; where it is `undefined` (an older portal), fall back to `disableChat`. Local mode reads `?kidsMode=true`, and the [Preview tool](https://www.zokogames.com/preview) can send a kids-mode settings change. The type declarations add `LeaderboardEntry`, one row of the [leaderboard](https://docs.zokogames.com/sdk/leaderboards) JSON endpoints with `isYou` and the opaque per-game `userId`: a type only, the SDK has no leaderboard read call. The engine wrappers 1.5.0 expose `kidsMode` as well (see each [engine page](https://docs.zokogames.com/engines/overview)). See [kids mode](https://docs.zokogames.com/sdk/game#kids-mode). Pinned: `https://sdk.zokogames.com/1.5.0/zokogames-sdk-v1.js`.

### 1.4.1 (fix)

Nothing breaks and no action is needed: 1.4.1 only fixes robustness problems, and every name, argument and error code stays the same. What you may notice:

- **Start-up in the portal:** when the page that embeds your game is the portal (zokogames.com), the SDK now waits up to 15 s for the portal to answer `init()` instead of giving up after 1.5 s, so a slow connection no longer leaves the game `disabled` for the whole session. On any other page the wait stays 1.5 s.
- **Calls you do not await:** `gameplayStart`, `gameplayStop`, `happytime`, `loadingStart`, `loadingStop` and `leftRoom` resolve with a console warning when the portal does not answer in time, so they no longer cause an unhandled promise rejection. They still reject with `sdkNotInitialized` or `sdkDisabled`.
- **Cloud saves:** `data.setItem` is faster on large saves (the 1 MB limit is unchanged). A failed sync is retried on its own after 2 s, 4 s and so on, at most 60 s apart. Values in a save that are not strings are read back as strings, as in `localStorage`, and `mirrorLocalStorage` handles a key named `__proto__`.
- **Player tokens:** `getUserToken` keeps one token per `signingKeyType`, so a request for `IN_GAME_AUTH_LEGACY` never receives the default token, and a sign-in during a request no longer keeps the previous player's token.
- **Stricter arguments:** an argument that cannot be copied to the portal (a function, a DOM node) rejects with `invalidArgument` instead of `other`; `setGameContext` refuses `NaN` and `Infinity` with `invalidArgument`; `banner.requestBanner` refuses sizes given as strings (`"300"`) with `invalidSize`; `getInviteParam("constructor")` returns `null`.
- **Reloads:** a late portal answer meant for the previous page load can no longer settle a call made after the game frame reloads.
- **Compatibility shim:** an `adError` callback that throws, or a callback that is not a function, no longer rejects the promise `requestAd` returns.

The script grows by about 2 KB (51.7 KB, 18.3 KB gzip), and the module build declares `"sideEffects": false`. Pinned: `https://sdk.zokogames.com/1.4.1/zokogames-sdk-v1.js`.

### 1.3 to 1.4

Nothing breaks. New: `SDK.game.reportChat(...)` (report a chat message), `SDK.game.onScreenshotRequest(handler)` (an image for the feedback form) and `SDK.data.mirrorLocalStorage(options)` (opt-in cloud save for games that use `localStorage`); see [reporting chat](https://docs.zokogames.com/sdk/game#reporting-chat), [feedback screenshot](https://docs.zokogames.com/sdk/game#feedback-screenshot) and [mirroring localStorage](https://docs.zokogames.com/sdk/data#mirroring-localstorage-ported-games). All three need SDK 1.4.0. On a portal that does not know `reportChat` the call rejects with `unexpectedError`; without a screenshot handler the portal simply gets no image from older SDKs. The script grows by about 9 KB. Game code written for 1.3 needs no change.

### 1.2 to 1.3

Nothing breaks. New: `SDK.game.room`, a data channel for the players of one room (see [room data channel](https://docs.zokogames.com/sdk/game#room-data-channel)), with the error codes `notInRoom`, `notHost`, `payloadTooLarge`, `stateTooLarge`, `unknownMember` and `roomUnavailable` (grouped as `ERROR_CODES.room`, with the type `RoomErrorCode`; `rateLimited` is also reported there). It needs SDK 1.3.0 on a portal that has the channel; on an older portal `room.send` fails with `unexpectedError`, so check for the error and fall back to your own server if you must support both. Game code written for 1.2 needs no change.

### 1.1 to 1.2

Nothing breaks. New: `SDK.game.isOffline`, `addOfflineListener` and `removeOfflineListener`, described under [offline state](https://docs.zokogames.com/sdk/game#offline-state), and `SDK.achievements` (`unlock`, `list`, `onUnlock`; see [achievements](https://docs.zokogames.com/sdk/achievements)). On a portal that does not know the achievement calls, `unlock` resolves `{ ok: false, reason: "error" }`. On a portal that does not send the flag, `isOffline` stays `false`. In local mode it mirrors `navigator.onLine` and `?offline=true` pins it. Game code written for 1.1 needs no change.

### 1.1.1 (fix)

The 30 second banner refresh floor and the per-session refresh cap now also hold when you clear a banner and request the same container again (the [banner limits](https://docs.zokogames.com/sdk/banners#limits)). Local mode reads `instantJoin=true` and every other query parameter of the page address as invite parameters.

### 1.0 to 1.1

Nothing breaks: 1.1 only adds. Upgrade by using the latest URL (or by changing the number in a pinned URL). The one name to act on:

- **`store.getPurchaseToken()` is the name to use for the purchase token; `user.getXsollaUserToken()` is a deprecated alias for it.** Both names arrived together in 1.1.0; 1.0 had no purchase token call. Both return `Promise<string>`, a signed token your server verifies, and both fail with `userNotAuthenticated` for guests. The old name still works, so existing code keeps running, but new code and edits should call the new name:

```js
// 1.1.0: deprecated alias, kept for ported code
const legacyToken = await SDK.user.getXsollaUserToken();
// 1.1.0: the name to use
const token = await SDK.store.getPurchaseToken();
```

  Check `SDK.store.isAvailable` before relying on purchases. See [in-game purchases](https://docs.zokogames.com/sdk/purchases) for what to do with the token.
- **New in 1.1:** the `SDK.store` module (`isAvailable`, `getCatalogItems`, `getPlayerInventory`, `buyItem`, `consumeItem`, `setSandbox`, `getPurchaseToken`) with its [error codes](https://docs.zokogames.com/sdk/introduction#errors); `SDK.game.loadingProgress(0..100)`; `ad_response` for local-mode ad failures; the exported `ERROR_CODES` table.
- **Changed behaviour:** `getUserToken({ signingKeyType })` now sends the key type to the portal and caches one token per key type (every token is still signed RS256 by the same key set). `submitScore` accepts an empty `encryptedScore` for boards that have no encryption key.
- **Deprecated, still working:** `game.showInviteButton(params)` and `game.hideInviteButton()` (use `updateRoom({ isJoinable, inviteParams })`), `game.isInstantJoin` (use `isInstantMultiplayer`), `user.getXsollaUserToken()`.

### 1.0.0 (first release)

There is nothing to migrate from earlier ZokoGames versions. If you come from another portal's SDK, use the [migration guide](https://docs.zokogames.com/guides/migrating). The points that bite most often:

- Errors are plain `{ code, message }` objects, not `Error` instances. Use `e.code`, not `e instanceof Error`.
- `init()` never rejects. Check `SDK.environment` instead of catching.
- `SDK.data` methods are synchronous and throw, they do not return promises.
- `getUserToken` accepts `signingKeyType` for ported code but signs every token the same way (RS256, one key set). From 1.1 the argument is passed to the portal and cached per key type.
- `__dangerousUserId` is for display only. Identify players on your server through the verified token.
- 1.0 has no client store or purchase API; it arrived in 1.1. See [in-game purchases](https://docs.zokogames.com/sdk/purchases).

### Compatibility shim

`zokogames-compat-v1.js` is an optional script for porting a game written against another portal's SDK shape. Download it from `https://www.zokogames.com/sdk/zokogames-compat-v1.js`, put it in your build zip and load it after the ZokoGames SDK and set `data-global` to the global your game already reads. It translates the old names and error spellings to the ones on this page. New games should call `SDK` directly. See the [migration guide](https://docs.zokogames.com/guides/migrating).

### Engine wrappers

Wrappers share one browser bridge with the JavaScript SDK. When you update a wrapper, re-export your web build and re-test in the [Preview tool](https://www.zokogames.com/preview). Wrapper-specific changes are listed on each engine page and in the changelog.

## In local mode, and for guests, offline, ad-blocked and ad-free players

The version does not change these behaviours, which are listed on each module page. The only version-specific rules are that `isOffline` needs SDK 1.2.0 on a portal that sends the flag that `game.room` needs SDK 1.3.0, and that `reportChat`, `onScreenshotRequest` and `mirrorLocalStorage` need SDK 1.4.0.

## Checking the version at run time

The version is not a property of `SDK`. Read it from the module build, which is not published on npm at present (`import { SDK_VERSION } from "@zoko/sdk"`) or from the pinned script URL you load; the script-tag global exposes only `ZokoGames.SDK`.

## How to upgrade safely

1. Read the [changelog](https://docs.zokogames.com/business/changelog) for the release.
2. Run the game with `?sdk_debug=true` and look for new warnings.
3. Check error handling still takes the safe path for unknown codes.
4. Test in local mode, then in the Preview tool, then in a build preview from the console.
5. Ship the update. See [updating a live game](https://docs.zokogames.com/getting-started/updating-a-game).

## Next steps

- [Changelog](https://docs.zokogames.com/business/changelog)
- [Migrating from another portal's SDK](https://docs.zokogames.com/guides/migrating)
