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.cjs
CHANGED
|
@@ -24,6 +24,29 @@ function validateSecretKey(cfg) {
|
|
|
24
24
|
return { keyId: match[1], secret: sk };
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
// src/uuid.ts
|
|
28
|
+
function uuidV4FromBytes(bytes) {
|
|
29
|
+
bytes[6] = (bytes[6] ?? 0) & 15 | 64;
|
|
30
|
+
bytes[8] = (bytes[8] ?? 0) & 63 | 128;
|
|
31
|
+
let hex = "";
|
|
32
|
+
for (const b of bytes) {
|
|
33
|
+
hex += b.toString(16).padStart(2, "0");
|
|
34
|
+
}
|
|
35
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
36
|
+
}
|
|
37
|
+
function randomUUID() {
|
|
38
|
+
const c = globalThis.crypto;
|
|
39
|
+
if (c && typeof c.randomUUID === "function") {
|
|
40
|
+
return c.randomUUID();
|
|
41
|
+
}
|
|
42
|
+
if (c && typeof c.getRandomValues === "function") {
|
|
43
|
+
return uuidV4FromBytes(c.getRandomValues(new Uint8Array(16)));
|
|
44
|
+
}
|
|
45
|
+
throw new Error(
|
|
46
|
+
"scorezilla: no Web Crypto RNG available (neither crypto.randomUUID nor crypto.getRandomValues). The SDK requires Node \u2265 20 or a modern browser."
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
27
50
|
// src/hmac.ts
|
|
28
51
|
var enc = new TextEncoder();
|
|
29
52
|
var HMAC_AUTH_SCHEME = "Scorezilla-HMAC-SHA256";
|
|
@@ -86,13 +109,7 @@ async function buildHmacAuthHeader(args) {
|
|
|
86
109
|
return `${HMAC_AUTH_SCHEME} keyId=${args.keyId}, ts=${ts}, nonce=${nonce}, signature=${signature}${vParam}`;
|
|
87
110
|
}
|
|
88
111
|
function generateNonce() {
|
|
89
|
-
|
|
90
|
-
if (!c || typeof c.randomUUID !== "function") {
|
|
91
|
-
throw new Error(
|
|
92
|
-
"scorezilla: globalThis.crypto.randomUUID is unavailable. The HMAC server adapter requires Node \u2265 20 or a modern runtime."
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
return c.randomUUID();
|
|
112
|
+
return randomUUID();
|
|
96
113
|
}
|
|
97
114
|
function base64UrlEncode(bytes) {
|
|
98
115
|
let bin = "";
|
|
@@ -360,14 +377,14 @@ function shouldRetryError(err) {
|
|
|
360
377
|
return false;
|
|
361
378
|
}
|
|
362
379
|
function generateIdempotencyKey() {
|
|
363
|
-
|
|
364
|
-
|
|
380
|
+
try {
|
|
381
|
+
return randomUUID();
|
|
382
|
+
} catch {
|
|
365
383
|
throw new ScorezillaError(
|
|
366
|
-
"scorezilla:
|
|
384
|
+
"scorezilla: no Web Crypto RNG available (neither crypto.randomUUID nor crypto.getRandomValues). The SDK requires Node \u2265 20 or a modern browser.",
|
|
367
385
|
{ status: 0, code: "internal_error" }
|
|
368
386
|
);
|
|
369
387
|
}
|
|
370
|
-
return c.randomUUID();
|
|
371
388
|
}
|
|
372
389
|
function sleep(ms, signal) {
|
|
373
390
|
return new Promise((resolve, reject) => {
|
|
@@ -842,7 +859,7 @@ var Scorezilla = class _Scorezilla {
|
|
|
842
859
|
* Mirrors the static on the public-key client so consumers can log
|
|
843
860
|
* the running SDK build the same way regardless of which surface
|
|
844
861
|
* they imported. */
|
|
845
|
-
static version = "0.
|
|
862
|
+
static version = "0.4.0";
|
|
846
863
|
#keyId;
|
|
847
864
|
#secret;
|
|
848
865
|
#baseUrl;
|
|
@@ -917,7 +934,9 @@ var Scorezilla = class _Scorezilla {
|
|
|
917
934
|
signal: input.signal
|
|
918
935
|
});
|
|
919
936
|
}
|
|
920
|
-
/** Look up a single player's rank on a board.
|
|
937
|
+
/** Look up a single player's rank on a board. "No entry yet" returns
|
|
938
|
+
* `{ ranked: false }` (narrow on `ranked`); `not_found` is thrown only for
|
|
939
|
+
* a missing board. */
|
|
921
940
|
async getPlayerRank(input) {
|
|
922
941
|
return this.#request({
|
|
923
942
|
path: getPlayerRankPath(input.boardId, input.playerId),
|