@indiegems/gem-web-sdk 7.5.0 → 7.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +886 -0
- package/README.md +1 -0
- package/dist/function.d.ts +978 -0
- package/dist/game.d.ts +4 -1
- package/dist/gem-web-sdk.bridge.js +1 -1
- package/dist/gem-web-sdk.esm.js +1 -1
- package/dist/gem-web-sdk.function.js +3 -0
- package/dist/gem-web-sdk.game.js +2 -2
- package/dist/gem-web-sdk.min.js +2 -2
- package/dist/gem-web-sdk.sdk.js +2 -2
- package/dist/gem-web-sdk.server.js +1 -1
- package/dist/sdk.d.ts +4 -1
- package/docs/analytics.md +2 -3
- package/docs/api/api-reference-game.md +60 -33
- package/docs/api/api-reference-server.md +1 -1
- package/docs/api/reference.json +29 -12
- package/docs/changelog.md +886 -0
- package/docs/getting-started.md +8 -6
- package/docs/manifest.json +18 -8
- package/docs/server-bundles.md +2 -2
- package/docs/serverless-functions-js.md +139 -0
- package/docs/what-a-game-must-do.md +39 -26
- package/package.json +7 -2
- package/schema/bridge.v1.json +1 -1
package/docs/api/reference.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"schema_version": 1,
|
|
3
3
|
"source": {
|
|
4
4
|
"repo": "IndieGems/gem-web-sdk",
|
|
5
|
-
"version": "7.
|
|
5
|
+
"version": "7.6.0"
|
|
6
6
|
},
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -5836,7 +5836,7 @@
|
|
|
5836
5836
|
"url": "https://gemarcade.com/developer/api/game#framestate",
|
|
5837
5837
|
"signature": "type FrameState = \"waiting\" | \"connected\" | \"refused\" | \"closed\"",
|
|
5838
5838
|
"documented": true,
|
|
5839
|
-
"summary": "Where the bridge to the arcade stands.\n\n`waiting` is the state a game boots in and
|
|
5839
|
+
"summary": "Where the bridge to the arcade stands.\n\n`waiting` is the state a game boots in: framed, and its parent has not\nanswered yet. `connected` is the only state in which the arcade is\nlistening. `refused` is final: the page that framed this game is not one it\naccepts (its origin is not in `allowedEmbedders`), or it speaks no protocol\nversion in common. `closed` means a connection existed and ended.\n\nReceived by `onStateChange` and resolved by `awaitBridge`, both of which are\ndocumented — so without a name for this union a game could observe the value\nand not be able to declare a variable holding it.",
|
|
5840
5840
|
"deprecated": null,
|
|
5841
5841
|
"params": [],
|
|
5842
5842
|
"returns": null,
|
|
@@ -5876,7 +5876,7 @@
|
|
|
5876
5876
|
"url": "https://gemarcade.com/developer/api/game#gemframe-currentstate",
|
|
5877
5877
|
"signature": "get currentState(): FrameState",
|
|
5878
5878
|
"documented": true,
|
|
5879
|
-
"summary": "Where the bridge is right now, without waiting.\n\n- `waiting` — the arcade has not connected yet. Normal at startup.\n- `connected` — the bridge is up and everything works.\n- `refused` — the
|
|
5879
|
+
"summary": "Where the bridge is right now, without waiting.\n\n- `waiting` — the arcade has not connected yet. Normal at startup.\n- `connected` — the bridge is up and everything works.\n- `refused` — final: the page that framed the game is not one it accepts,\n or no protocol version is shared.\n- `closed` — the session has ended.\n\nA snapshot, so it can change immediately after you read it. To wait for the\nquestion to be settled once, use [GemFrame.settled](https://gemarcade.com/developer/api/game#gemframe-settled).\n\nA page that frames the game and never answers leaves it `waiting`, which\nis the case worth handling: boot anyway, and say there is no session.",
|
|
5880
5880
|
"deprecated": null,
|
|
5881
5881
|
"params": [],
|
|
5882
5882
|
"returns": null,
|
|
@@ -5934,7 +5934,7 @@
|
|
|
5934
5934
|
"url": "https://gemarcade.com/developer/api/game#gemframe-settled",
|
|
5935
5935
|
"signature": "settled(timeoutMs?: number): Promise<FrameState>",
|
|
5936
5936
|
"documented": true,
|
|
5937
|
-
"summary": "Wait until it is known whether there is a bridge, then carry on either way.\n\nResolves as soon as the connection is settled — connected, refused or\nclosed — or when the timeout runs out, with whichever state it is in.\n\nTHE GATE TO AWAIT BEFORE LOADING A HEAVY BUNDLE. The connection offer is\ndelivered to your game rather than polled, so if your main thread is busy\nparsing several megabytes of JavaScript, the offer waits behind that work —\nand by the time it arrives the connection it carried may already be gone.\nAwaiting this first keeps the thread free long enough to accept.\n\nTHE WAIT IS BOUNDED ON PURPOSE, because
|
|
5937
|
+
"summary": "Wait until it is known whether there is a bridge, then carry on either way.\n\nResolves as soon as the connection is settled — connected, refused or\nclosed — or when the timeout runs out, with whichever state it is in.\n\nTHE GATE TO AWAIT BEFORE LOADING A HEAVY BUNDLE. The connection offer is\ndelivered to your game rather than polled, so if your main thread is busy\nparsing several megabytes of JavaScript, the offer waits behind that work —\nand by the time it arrives the connection it carried may already be gone.\nAwaiting this first keeps the thread free long enough to accept.\n\nTHE WAIT IS BOUNDED ON PURPOSE, because the page framing your game may\nnever answer, and your game must still start and say so. Proceed on either\noutcome and read the resolved state to know which kind of boot this is.\n\n```js\nconst state = await gem.frame.settled();\nconst game = await import('./game-engine.js');\ngame.start({ online: state === 'connected' });\n```",
|
|
5938
5938
|
"deprecated": null,
|
|
5939
5939
|
"params": [
|
|
5940
5940
|
{
|
|
@@ -8171,7 +8171,7 @@
|
|
|
8171
8171
|
"url": "https://gemarcade.com/developer/api/game#gemviewport-reserved",
|
|
8172
8172
|
"signature": "readonly reserved: readonly GemReservedArea[]",
|
|
8173
8173
|
"documented": true,
|
|
8174
|
-
"summary": "Rectangles of your frame the arcade's own controls cover — its Back tab in\nthe top-left corner, and the wallets
|
|
8174
|
+
"summary": "Rectangles of your frame the arcade's own controls cover — its Back tab in\nthe top-left corner, and the wallets in the top-right while they are shown (see\n`setWalletVisible`). Keep essential UI and touch targets out of them. Empty\nwhen the arcade covers nothing.\n\nA stylesheet reads the per-corner custom properties the SDK stamps from\nthese instead — `--gem-reserved-tl-height` and friends.",
|
|
8175
8175
|
"deprecated": null,
|
|
8176
8176
|
"params": [],
|
|
8177
8177
|
"returns": null,
|
|
@@ -8495,7 +8495,7 @@
|
|
|
8495
8495
|
"url": "https://gemarcade.com/developer/api/game#gem-awaitidentity",
|
|
8496
8496
|
"signature": "awaitIdentity(timeoutMs?: number): Promise<GemIdentity>",
|
|
8497
8497
|
"documented": true,
|
|
8498
|
-
"summary": "The player's identity, waiting for sign-in if it has not finished.\n\nAwait this when you need the ids themselves. Rooms are scoped to your game,\nand your game's id comes from sign-in — but a room call made before it\nlands performs this same wait on your behalf, so awaiting it first is a\nchoice rather than a requirement. In a real session the wait is normally a\nsingle round trip to the page hosting your game.\n\nRejects rather than resolving `null` if the wait runs out: a session that\ncannot sign in cannot do anything else either, and a `null` you might not\ncheck is how a game carries on into a failure it could have reported.",
|
|
8498
|
+
"summary": "The player's identity, waiting for sign-in if it has not finished.\n\nAwait this when you need the ids themselves. Rooms are scoped to your game,\nand your game's id comes from sign-in — but a room call made before it\nlands performs this same wait on your behalf, so awaiting it first is a\nchoice rather than a requirement. In a real session the wait is normally a\nsingle round trip to the page hosting your game.\n\nRejects rather than resolving `null` if the wait runs out: a session that\ncannot sign in cannot do anything else either, and a `null` you might not\ncheck is how a game carries on into a failure it could have reported. It\nrejects at once, without waiting, when the page that framed the game was\nrefused: no token can arrive from it.",
|
|
8499
8499
|
"deprecated": null,
|
|
8500
8500
|
"params": [
|
|
8501
8501
|
{
|
|
@@ -8519,7 +8519,7 @@
|
|
|
8519
8519
|
"url": "https://gemarcade.com/developer/api/game#gem-awaitbridge",
|
|
8520
8520
|
"signature": "awaitBridge(timeoutMs?: number): Promise<FrameState | null>",
|
|
8521
8521
|
"documented": true,
|
|
8522
|
-
"summary": "Waits for the connection to the arcade to settle, one way or the other.\n\nResolves with the state it settled into — connected, refused or closed — or\nwith whatever it had reached by `timeoutMs`, which defaults to 10 seconds.\n\
|
|
8522
|
+
"summary": "Waits for the connection to the arcade to settle, one way or the other.\n\nResolves with the state it settled into — connected, refused or closed — or\nwith whatever it had reached by `timeoutMs`, which defaults to 10 seconds.\n\nA game is always framed (`createGem` throws [GemUnframedError](https://gemarcade.com/developer/api/game#gemunframederror)\notherwise), so this normally resolves `connected` within a moment. It\nresolves `refused` at once when the page that framed the game is not one it\naccepts, and `waiting` only when the page framing it never answers.\n\n**Await this in your boot entry before importing your main bundle.** The\narcade hands your game its connection as a one-off delivery rather than\nsomething you can ask for later, so if the browser's main thread is busy\nparsing several megabytes of JavaScript when it arrives, your game can miss\nit. Awaiting this keeps the thread free through that window; the moment it\nresolves, load everything.\n\nCarry on whatever it resolves to. `connected` means a Gem host is\nlistening — the Arcade, the Editor or the dev host on your machine;\nanything else means no session, which your game has to survive with a\nmessage rather than a hang.",
|
|
8523
8523
|
"deprecated": null,
|
|
8524
8524
|
"params": [
|
|
8525
8525
|
{
|
|
@@ -8543,7 +8543,7 @@
|
|
|
8543
8543
|
"url": "https://gemarcade.com/developer/api/game#gem-player",
|
|
8544
8544
|
"signature": "readonly player: GemPlayer | null",
|
|
8545
8545
|
"documented": true,
|
|
8546
|
-
"summary": "The player's display identity — the name, handle and avatar you show them.\n\n`null` until the arcade sends it
|
|
8546
|
+
"summary": "The player's display identity — the name, handle and avatar you show them.\n\n`null` until the arcade sends it. Nothing obliges it to be sent at all, so treat its absence as normal and\nhave a fallback: a game with no display name is fine, a game that waits\nforever for one is not.\n\nThe name and handle are player-authored, so they arrive wrapped rather than\nas plain strings — assigning one to `innerHTML` will not compile. Unwrap at\nthe point you render.\n\nThis is distinct from [Gem.identity](https://gemarcade.com/developer/api/game#gem-identity), which is who the platform says\nthey are, and from [Gem.me](https://gemarcade.com/developer/api/game#gem-me), which is their data in your game.",
|
|
8547
8547
|
"deprecated": null,
|
|
8548
8548
|
"params": [],
|
|
8549
8549
|
"returns": null,
|
|
@@ -8960,7 +8960,7 @@
|
|
|
8960
8960
|
"url": "https://gemarcade.com/developer/api/game#gem-awaitcohorts",
|
|
8961
8961
|
"signature": "awaitCohorts(timeoutMs?: number): Promise<GemCohorts | null>",
|
|
8962
8962
|
"documented": true,
|
|
8963
|
-
"summary": "The experiment cohorts, waiting up to `timeoutMs` for them.\n\nResolves `null` rather than rejecting
|
|
8963
|
+
"summary": "The experiment cohorts, waiting up to `timeoutMs` for them.\n\nResolves `null` rather than rejecting once the wait is out, or at once if\nthe page that framed the game was refused. Use it at the ONE point\nyour game branches on a cohort — typically\nthe first run's opening — and give it a short budget: the answer normally\narrives within the first second, and a player kept on a splash screen for a\nvalue that changes a tutorial's wording has been made to pay for an\nexperiment they cannot see.",
|
|
8964
8964
|
"deprecated": null,
|
|
8965
8965
|
"params": [
|
|
8966
8966
|
{
|
|
@@ -9032,7 +9032,7 @@
|
|
|
9032
9032
|
"url": "https://gemarcade.com/developer/api/game#gem-setwalletvisible",
|
|
9033
9033
|
"signature": "setWalletVisible(visible: boolean, options?: WalletVisibleOptions): boolean",
|
|
9034
9034
|
"documented": true,
|
|
9035
|
-
"summary": "Show or hide the player's wallets — Gems, Tickets, the achievement score —\nthat the arcade draws over your game. **They are shown until you say\notherwise**: hide them during gameplay, show them again on your menus.\n\n```js\nlevel.onStart = () => gem.setWalletVisible(false);\nmenu.onOpen = () => gem.setWalletVisible(true);\n// A screen that sells in one currency may narrow it:\nticketStore.onOpen = () => gem.setWalletVisible(true, { only: ['ARCADE_TICKETS'] });\n```\n\n**It is screen state, not a toggle.** Each call is the whole answer and\nreplaces the last. While hidden, the arcade still pops a wallet up for a\nmoment when something happens to it — a reward you cued, a spend, a\nlanding — and your state never cancels that. Shown wallets cover part of\nyour frame
|
|
9035
|
+
"summary": "Show or hide the player's wallets — Gems, Tickets, the achievement score —\nthat the arcade draws over your game. **They are shown until you say\notherwise**: hide them during gameplay, show them again on your menus.\n\n```js\nlevel.onStart = () => gem.setWalletVisible(false);\nmenu.onOpen = () => gem.setWalletVisible(true);\n// A screen that sells in one currency may narrow it:\nticketStore.onOpen = () => gem.setWalletVisible(true, { only: ['ARCADE_TICKETS'] });\n```\n\n**It is screen state, not a toggle.** Each call is the whole answer and\nreplaces the last. While hidden, the arcade still pops a wallet up for a\nmoment when something happens to it — a reward you cued, a spend, a\nlanding — and your state never cancels that. Shown wallets cover part of\nyour frame's top-right corner, which arrives as a rectangle in\n`gem.viewport.reserved`; hiding them gives that space back. A wallet the\narcade pops up for a moment floats over your game and moves nothing.\n\n**Never draw a platform balance yourself**, and never show a pending state\nfor one: the arcade takes every figure from the platform. If this returns\n`false`, do nothing in its place.",
|
|
9036
9036
|
"deprecated": null,
|
|
9037
9037
|
"params": [
|
|
9038
9038
|
{
|
|
@@ -9103,7 +9103,7 @@
|
|
|
9103
9103
|
"url": "https://gemarcade.com/developer/api/game#gem-frame",
|
|
9104
9104
|
"signature": "readonly frame: GemFrame",
|
|
9105
9105
|
"documented": true,
|
|
9106
|
-
"summary": "Your game's connection to the arcade.\n\nALWAYS PRESENT, even when nothing is on the other end
|
|
9106
|
+
"summary": "Your game's connection to the arcade.\n\nALWAYS PRESENT, even when nothing is on the other end yet: a page that\nnever answers leaves the frame in `waiting`, and a refused one ends it in\n`refused`, which is the state to read when you want to know whether anyone\never answered. Do not write a `=== null` branch; it can never run.\n\n**This is where the loading contract lives.** Call `progress()` as your\ngame loads and `ready()` when it is playable, so the arcade can show a real\nloading state instead of a blank frame. Both are on the platform's release\nchecklist.",
|
|
9107
9107
|
"deprecated": null,
|
|
9108
9108
|
"params": [],
|
|
9109
9109
|
"returns": null,
|
|
@@ -9241,7 +9241,7 @@
|
|
|
9241
9241
|
"url": "https://gemarcade.com/developer/api/game#creategem",
|
|
9242
9242
|
"signature": "function createGem(options?: GemOptions): Gem",
|
|
9243
9243
|
"documented": true,
|
|
9244
|
-
"summary": "Connect your game to the Gem Arcade. This is the one call every game makes.\n\nIt assembles everything and connects to the arcade that framed your game. The\nsame code runs on your machine and in production without a flag — but it needs\na
|
|
9244
|
+
"summary": "Connect your game to the Gem Arcade. This is the one call every game makes.\n\nIt assembles everything and connects to the arcade that framed your game. The\nsame code runs on your machine and in production without a flag — but it needs\na frame either way. Opened at the top level it throws\n[GemUnframedError](https://gemarcade.com/developer/api/game#gemunframederror), which says how to run it: in the Arcade, the Editor,\nor the Gem dev host on your machine (`npm run dev`, signed in to `gemctl`).\n\nOne dependency, imported like anything else. The install is at\nhttps://gemarcade.com/developer/docs/getting-started#3-add-the-sdk\n\n```js\nimport { createGem } from '@indiegems/gem-web-sdk/sdk';\n\nconst gem = createGem();\n\nawait gem.awaitBridge(); // before loading your main bundle\nconst me = await gem.awaitIdentity(); // who is playing, once sign-in completes\n```\n\nNo options are needed. The Gem Arcade's website and app are always allowed to\nembed your game ([ARCADE_EMBEDDERS](https://gemarcade.com/developer/api/game#arcade_embedders)), and the arcade tells your game\nwhich build it is.\n\nA dev host on your own machine (`gemctl serve`, the Gem Editor) needs no\nentry either: it frames a locally-served game from a loopback origin whose\nport changes every run, and the SDK admits it by rule — only while the game\nitself is served from loopback, so nothing changes once you publish.\n\nPass `allowedEmbedders` only when a site of your own frames your game. It\nadds to the arcade's origins; see [GemOptions.allowedEmbedders](https://gemarcade.com/developer/api/game#gemoptions-allowedembedders).",
|
|
9245
9245
|
"deprecated": null,
|
|
9246
9246
|
"params": [
|
|
9247
9247
|
{
|
|
@@ -12980,6 +12980,23 @@
|
|
|
12980
12980
|
"defaultValue": null,
|
|
12981
12981
|
"guides": []
|
|
12982
12982
|
},
|
|
12983
|
+
{
|
|
12984
|
+
"id": "GemUnframedError",
|
|
12985
|
+
"name": "GemUnframedError",
|
|
12986
|
+
"anchor": "gemunframederror",
|
|
12987
|
+
"group": "failures",
|
|
12988
|
+
"url": "https://gemarcade.com/developer/api/game#gemunframederror",
|
|
12989
|
+
"signature": "class GemUnframedError",
|
|
12990
|
+
"documented": true,
|
|
12991
|
+
"summary": "Your game was opened without a Gem frame around it.\n\nThrown by `createGem` when the page is the top-level document: nothing\nframed it, so nothing can hand it a player, saves, config or rooms. The SDK\nneeds that frame — the Gem Arcade, the Gem Editor, or the Gem dev host on\nyour own machine — and refuses to start without one rather than running a\ngame that silently has no player.\n\nYou do not construct this. Run the game framed instead: `npm run dev`\n(`gemctl serve start . --dev`) while you edit, `gemctl serve start .` for a\nbuild, signed in to `gemctl` either way. Never open the address the dev\nserver itself prints.\n\nA unit test that constructs the SDK in a simulated DOM has to give its\nwindow a parent of its own, because a simulated top-level window is exactly\nwhat this refuses.",
|
|
12992
|
+
"deprecated": null,
|
|
12993
|
+
"params": [],
|
|
12994
|
+
"returns": null,
|
|
12995
|
+
"throws": null,
|
|
12996
|
+
"example": null,
|
|
12997
|
+
"defaultValue": null,
|
|
12998
|
+
"guides": []
|
|
12999
|
+
},
|
|
12983
13000
|
{
|
|
12984
13001
|
"id": "LeaderboardEntry.playerId",
|
|
12985
13002
|
"name": "playerId",
|