scorezilla 0.3.0 → 0.4.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/API.md +21 -11
- package/CHANGELOG.md +37 -0
- package/dist/{errors-CWTmormh.d.cts → errors-BhPRMQiV.d.cts} +24 -3
- package/dist/{errors-CWTmormh.d.ts → errors-BhPRMQiV.d.ts} +24 -3
- package/dist/identity.cjs.map +1 -1
- package/dist/identity.js.map +1 -1
- package/dist/index.cjs +37 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -13
- package/dist/index.d.ts +10 -13
- package/dist/index.js +37 -17
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +32 -13
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +5 -3
- package/dist/server.d.ts +5 -3
- package/dist/server.js +32 -13
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
package/dist/server.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { F as FetchImpl, g as SecretKeyConfig, A as ApiSuccess, a as SubmitScoreResponse, L as LeaderboardResponse, P as PlayerRankResponse, W as WindowAroundResponse } from './errors-
|
|
2
|
-
export { R as RankedEntry, e as ScorezillaError, f as ScorezillaErrorCode } from './errors-
|
|
1
|
+
import { F as FetchImpl, g as SecretKeyConfig, A as ApiSuccess, a as SubmitScoreResponse, L as LeaderboardResponse, P as PlayerRankResponse, W as WindowAroundResponse } from './errors-BhPRMQiV.cjs';
|
|
2
|
+
export { R as RankedEntry, e as ScorezillaError, f as ScorezillaErrorCode } from './errors-BhPRMQiV.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Built-in request verifiers for {@link createScoreSubmitHandler} (#211).
|
|
@@ -321,7 +321,9 @@ declare class Scorezilla {
|
|
|
321
321
|
submitScore(input: SubmitScoreInput): Promise<ApiSuccess<SubmitScoreResponse>>;
|
|
322
322
|
/** Fetch the top-N entries on a board. */
|
|
323
323
|
getLeaderboard(input: GetLeaderboardInput): Promise<ApiSuccess<LeaderboardResponse>>;
|
|
324
|
-
/** Look up a single player's rank on a board.
|
|
324
|
+
/** Look up a single player's rank on a board. "No entry yet" returns
|
|
325
|
+
* `{ ranked: false }` (narrow on `ranked`); `not_found` is thrown only for
|
|
326
|
+
* a missing board. */
|
|
325
327
|
getPlayerRank(input: GetPlayerRankInput): Promise<ApiSuccess<PlayerRankResponse>>;
|
|
326
328
|
/** Fetch the slice of entries surrounding a player. */
|
|
327
329
|
getWindowAround(input: GetWindowAroundInput): Promise<ApiSuccess<WindowAroundResponse>>;
|
package/dist/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { F as FetchImpl, g as SecretKeyConfig, A as ApiSuccess, a as SubmitScoreResponse, L as LeaderboardResponse, P as PlayerRankResponse, W as WindowAroundResponse } from './errors-
|
|
2
|
-
export { R as RankedEntry, e as ScorezillaError, f as ScorezillaErrorCode } from './errors-
|
|
1
|
+
import { F as FetchImpl, g as SecretKeyConfig, A as ApiSuccess, a as SubmitScoreResponse, L as LeaderboardResponse, P as PlayerRankResponse, W as WindowAroundResponse } from './errors-BhPRMQiV.js';
|
|
2
|
+
export { R as RankedEntry, e as ScorezillaError, f as ScorezillaErrorCode } from './errors-BhPRMQiV.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Built-in request verifiers for {@link createScoreSubmitHandler} (#211).
|
|
@@ -321,7 +321,9 @@ declare class Scorezilla {
|
|
|
321
321
|
submitScore(input: SubmitScoreInput): Promise<ApiSuccess<SubmitScoreResponse>>;
|
|
322
322
|
/** Fetch the top-N entries on a board. */
|
|
323
323
|
getLeaderboard(input: GetLeaderboardInput): Promise<ApiSuccess<LeaderboardResponse>>;
|
|
324
|
-
/** Look up a single player's rank on a board.
|
|
324
|
+
/** Look up a single player's rank on a board. "No entry yet" returns
|
|
325
|
+
* `{ ranked: false }` (narrow on `ranked`); `not_found` is thrown only for
|
|
326
|
+
* a missing board. */
|
|
325
327
|
getPlayerRank(input: GetPlayerRankInput): Promise<ApiSuccess<PlayerRankResponse>>;
|
|
326
328
|
/** Fetch the slice of entries surrounding a player. */
|
|
327
329
|
getWindowAround(input: GetWindowAroundInput): Promise<ApiSuccess<WindowAroundResponse>>;
|
package/dist/server.js
CHANGED
|
@@ -22,6 +22,29 @@ function validateSecretKey(cfg) {
|
|
|
22
22
|
return { keyId: match[1], secret: sk };
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
// src/uuid.ts
|
|
26
|
+
function uuidV4FromBytes(bytes) {
|
|
27
|
+
bytes[6] = (bytes[6] ?? 0) & 15 | 64;
|
|
28
|
+
bytes[8] = (bytes[8] ?? 0) & 63 | 128;
|
|
29
|
+
let hex = "";
|
|
30
|
+
for (const b of bytes) {
|
|
31
|
+
hex += b.toString(16).padStart(2, "0");
|
|
32
|
+
}
|
|
33
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
34
|
+
}
|
|
35
|
+
function randomUUID() {
|
|
36
|
+
const c = globalThis.crypto;
|
|
37
|
+
if (c && typeof c.randomUUID === "function") {
|
|
38
|
+
return c.randomUUID();
|
|
39
|
+
}
|
|
40
|
+
if (c && typeof c.getRandomValues === "function") {
|
|
41
|
+
return uuidV4FromBytes(c.getRandomValues(new Uint8Array(16)));
|
|
42
|
+
}
|
|
43
|
+
throw new Error(
|
|
44
|
+
"scorezilla: no Web Crypto RNG available (neither crypto.randomUUID nor crypto.getRandomValues). The SDK requires Node \u2265 20 or a modern browser."
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
25
48
|
// src/hmac.ts
|
|
26
49
|
var enc = new TextEncoder();
|
|
27
50
|
var HMAC_AUTH_SCHEME = "Scorezilla-HMAC-SHA256";
|
|
@@ -84,13 +107,7 @@ async function buildHmacAuthHeader(args) {
|
|
|
84
107
|
return `${HMAC_AUTH_SCHEME} keyId=${args.keyId}, ts=${ts}, nonce=${nonce}, signature=${signature}${vParam}`;
|
|
85
108
|
}
|
|
86
109
|
function generateNonce() {
|
|
87
|
-
|
|
88
|
-
if (!c || typeof c.randomUUID !== "function") {
|
|
89
|
-
throw new Error(
|
|
90
|
-
"scorezilla: globalThis.crypto.randomUUID is unavailable. The HMAC server adapter requires Node \u2265 20 or a modern runtime."
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
return c.randomUUID();
|
|
110
|
+
return randomUUID();
|
|
94
111
|
}
|
|
95
112
|
function base64UrlEncode(bytes) {
|
|
96
113
|
let bin = "";
|
|
@@ -358,14 +375,14 @@ function shouldRetryError(err) {
|
|
|
358
375
|
return false;
|
|
359
376
|
}
|
|
360
377
|
function generateIdempotencyKey() {
|
|
361
|
-
|
|
362
|
-
|
|
378
|
+
try {
|
|
379
|
+
return randomUUID();
|
|
380
|
+
} catch {
|
|
363
381
|
throw new ScorezillaError(
|
|
364
|
-
"scorezilla:
|
|
382
|
+
"scorezilla: no Web Crypto RNG available (neither crypto.randomUUID nor crypto.getRandomValues). The SDK requires Node \u2265 20 or a modern browser.",
|
|
365
383
|
{ status: 0, code: "internal_error" }
|
|
366
384
|
);
|
|
367
385
|
}
|
|
368
|
-
return c.randomUUID();
|
|
369
386
|
}
|
|
370
387
|
function sleep(ms, signal) {
|
|
371
388
|
return new Promise((resolve, reject) => {
|
|
@@ -840,7 +857,7 @@ var Scorezilla = class _Scorezilla {
|
|
|
840
857
|
* Mirrors the static on the public-key client so consumers can log
|
|
841
858
|
* the running SDK build the same way regardless of which surface
|
|
842
859
|
* they imported. */
|
|
843
|
-
static version = "0.
|
|
860
|
+
static version = "0.4.0";
|
|
844
861
|
#keyId;
|
|
845
862
|
#secret;
|
|
846
863
|
#baseUrl;
|
|
@@ -915,7 +932,9 @@ var Scorezilla = class _Scorezilla {
|
|
|
915
932
|
signal: input.signal
|
|
916
933
|
});
|
|
917
934
|
}
|
|
918
|
-
/** Look up a single player's rank on a board.
|
|
935
|
+
/** Look up a single player's rank on a board. "No entry yet" returns
|
|
936
|
+
* `{ ranked: false }` (narrow on `ranked`); `not_found` is thrown only for
|
|
937
|
+
* a missing board. */
|
|
919
938
|
async getPlayerRank(input) {
|
|
920
939
|
return this.#request({
|
|
921
940
|
path: getPlayerRankPath(input.boardId, input.playerId),
|