@genex-ai/embed-sdk 0.4.0 → 0.4.1
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.
|
@@ -138,6 +138,7 @@ async function ensurePlayer() {
|
|
|
138
138
|
if (state === "pending") await waitForPlayer();
|
|
139
139
|
if (state === "blocked") throw new Error("genex embed auth: blocked");
|
|
140
140
|
}
|
|
141
|
+
var lastWorldVersion;
|
|
141
142
|
function stateFetch(path, init = {}) {
|
|
142
143
|
const headers = { Authorization: `Bearer ${embedToken}` };
|
|
143
144
|
if (init.body !== void 0) headers["Content-Type"] = "application/json";
|
|
@@ -192,18 +193,22 @@ async function loadWorldState() {
|
|
|
192
193
|
const res = await stateFetch("/state");
|
|
193
194
|
if (!res.ok) throw new Error(`genex load world state failed (${res.status})`);
|
|
194
195
|
const body = await res.json();
|
|
196
|
+
lastWorldVersion = body.version;
|
|
195
197
|
return { data: body.data, version: body.version };
|
|
196
198
|
}
|
|
197
199
|
async function saveWorldState(data, opts) {
|
|
198
200
|
await ensurePlayer();
|
|
199
201
|
if (state === "guest") return { saved: false, guest: true };
|
|
200
|
-
|
|
202
|
+
const guard = opts && "ifVersion" in opts ? opts.ifVersion : lastWorldVersion;
|
|
203
|
+
const result = await decodeSave(
|
|
201
204
|
await stateFetch("/state", {
|
|
202
205
|
method: "PUT",
|
|
203
206
|
body: JSON.stringify(data),
|
|
204
|
-
ifVersion:
|
|
207
|
+
ifVersion: guard == null ? void 0 : guard
|
|
205
208
|
})
|
|
206
209
|
);
|
|
210
|
+
if (result.version !== void 0) lastWorldVersion = result.version;
|
|
211
|
+
return result;
|
|
207
212
|
}
|
|
208
213
|
async function submitScore(score, opts) {
|
|
209
214
|
const board = opts?.board ?? "main";
|
package/dist/index.d.ts
CHANGED
|
@@ -171,13 +171,16 @@ declare function loadWorldState(): Promise<WorldStateResult>;
|
|
|
171
171
|
/**
|
|
172
172
|
* Save the game's SHARED world slot (any JSON ≤ 1MB, any signed-in player may
|
|
173
173
|
* write — let ONE authority do it, e.g. the multiplayer host, and debounce).
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
174
|
+
* If-Match is sent BY DEFAULT (from the last version this SDK loaded/saved), so a
|
|
175
|
+
* shared write can't silently clobber a newer one — a lost race resolves
|
|
176
|
+
* { conflict: true, version }: reload, merge, retry. Pass { ifVersion: n } to
|
|
177
|
+
* guard against a specific version, or { ifVersion: null } to force an
|
|
178
|
+
* unconditional overwrite (the old last-write-wins behaviour). Guests:
|
|
179
|
+
* { saved: false, guest: true } — world saves are NEVER queued (flushing a stale
|
|
180
|
+
* world later would clobber the live one; the eventual account host keeps saving).
|
|
178
181
|
*/
|
|
179
182
|
declare function saveWorldState(data: unknown, opts?: {
|
|
180
|
-
ifVersion?: number;
|
|
183
|
+
ifVersion?: number | null;
|
|
181
184
|
}): Promise<SaveStateResult>;
|
|
182
185
|
/**
|
|
183
186
|
* Submit a score (soft-trust leaderboards: identity is verified server-side,
|
package/dist/index.js
CHANGED
package/dist/sentry.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@genex-ai/embed-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Player identity + durable game state for genex games — signed-in or guest play, per-player save slots, shared world state, and soft-trust leaderboards.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|