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.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
- const c = globalThis.crypto;
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
- const c = globalThis.crypto;
364
- if (!c || typeof c.randomUUID !== "function") {
380
+ try {
381
+ return randomUUID();
382
+ } catch {
365
383
  throw new ScorezillaError(
366
- "scorezilla: globalThis.crypto.randomUUID is unavailable. The SDK requires Node \u2265 20 or a modern browser. Check your runtime.",
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.3.0";
862
+ static version = "0.3.1";
846
863
  #keyId;
847
864
  #secret;
848
865
  #baseUrl;