scorezilla 0.3.0 → 0.3.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.
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
- const c = globalThis.crypto;
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
- const c = globalThis.crypto;
362
- if (!c || typeof c.randomUUID !== "function") {
378
+ try {
379
+ return randomUUID();
380
+ } catch {
363
381
  throw new ScorezillaError(
364
- "scorezilla: globalThis.crypto.randomUUID is unavailable. The SDK requires Node \u2265 20 or a modern browser. Check your runtime.",
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.3.0";
860
+ static version = "0.3.1";
844
861
  #keyId;
845
862
  #secret;
846
863
  #baseUrl;