@palbase/web 7.3.0 → 7.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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  importNextServer
3
- } from "../chunk-ZC6Q3GPX.js";
3
+ } from "../chunk-CBN3PWNL.js";
4
4
  import {
5
5
  SESSION_COOKIE_ATTRS,
6
6
  clearedSessionCookieNames,
@@ -14,10 +14,10 @@ import {
14
14
  buildRuntime,
15
15
  createBoundClient,
16
16
  getRuntime
17
- } from "../chunk-YBURINUN.js";
17
+ } from "../chunk-RRHJV6YD.js";
18
18
  import {
19
19
  BackendError
20
- } from "../chunk-ACCJV6FV.js";
20
+ } from "../chunk-53TN7KYR.js";
21
21
  import {
22
22
  environmentRefFromApiKey,
23
23
  environmentRefFromPublishableApiKey
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  importNextServer
3
- } from "../chunk-ZC6Q3GPX.js";
3
+ } from "../chunk-CBN3PWNL.js";
4
4
  import {
5
5
  SESSION_COOKIE_ATTRS,
6
6
  clearedSessionCookieNames,
@@ -9,7 +9,7 @@ import {
9
9
  } from "../chunk-6VGKMNXO.js";
10
10
  import {
11
11
  BackendError
12
- } from "../chunk-ACCJV6FV.js";
12
+ } from "../chunk-53TN7KYR.js";
13
13
  import {
14
14
  environmentRefFromPublishableApiKey
15
15
  } from "../chunk-CFDU23TB.js";
@@ -49,6 +49,45 @@ var PalbaseError = class extends Error {
49
49
  this.details = details;
50
50
  }
51
51
  };
52
+ var POW_CHALLENGE_ID_HEADER = "X-PoW-Challenge-ID";
53
+ var POW_NONCE_HEADER = "X-PoW-Nonce";
54
+ function asPowChallenge(details) {
55
+ if (typeof details !== "object" || details === null) return null;
56
+ const env = details;
57
+ if (env.error !== "pow_required") return null;
58
+ const c = env.challenge;
59
+ if (typeof c !== "object" || c === null) return null;
60
+ const { id, prefix, difficulty } = c;
61
+ if (typeof id !== "string" || typeof prefix !== "string") return null;
62
+ if (typeof difficulty !== "number" || !Number.isInteger(difficulty) || difficulty < 0) return null;
63
+ return { id, prefix, difficulty };
64
+ }
65
+ var encoder = new TextEncoder();
66
+ function leadingZeroBits(hash) {
67
+ let bits = 0;
68
+ for (const byte of hash) {
69
+ if (byte === 0) {
70
+ bits += 8;
71
+ continue;
72
+ }
73
+ return bits + Math.clz32(byte) - 24;
74
+ }
75
+ return bits;
76
+ }
77
+ async function solvePowChallenge(challenge, maxIterations = 1 << 24) {
78
+ for (let nonce = 0; nonce < maxIterations; nonce++) {
79
+ const digest = await crypto.subtle.digest("SHA-256", encoder.encode(challenge.prefix + nonce));
80
+ if (leadingZeroBits(new Uint8Array(digest)) >= challenge.difficulty) {
81
+ return {
82
+ [POW_CHALLENGE_ID_HEADER]: challenge.id,
83
+ [POW_NONCE_HEADER]: String(nonce)
84
+ };
85
+ }
86
+ }
87
+ throw new Error(
88
+ `proof-of-work: no nonce found for difficulty ${challenge.difficulty} within ${maxIterations} attempts`
89
+ );
90
+ }
52
91
 
53
92
  // src/errors.ts
54
93
  var BackendError = class _BackendError extends Error {
@@ -169,47 +208,6 @@ function redactUrl(rawUrl) {
169
208
  return path.split("/").map((seg) => isSensitiveSegment(seg) ? ":id" : seg).join("/");
170
209
  }
171
210
 
172
- // src/pow.ts
173
- var POW_CHALLENGE_ID_HEADER = "X-PoW-Challenge-ID";
174
- var POW_NONCE_HEADER = "X-PoW-Nonce";
175
- function asPowChallenge(details) {
176
- if (typeof details !== "object" || details === null) return null;
177
- const env = details;
178
- if (env.error !== "pow_required") return null;
179
- const c = env.challenge;
180
- if (typeof c !== "object" || c === null) return null;
181
- const { id, prefix, difficulty } = c;
182
- if (typeof id !== "string" || typeof prefix !== "string") return null;
183
- if (typeof difficulty !== "number" || !Number.isInteger(difficulty) || difficulty < 0) return null;
184
- return { id, prefix, difficulty };
185
- }
186
- var encoder = new TextEncoder();
187
- function leadingZeroBits(hash) {
188
- let bits = 0;
189
- for (const byte of hash) {
190
- if (byte === 0) {
191
- bits += 8;
192
- continue;
193
- }
194
- return bits + Math.clz32(byte) - 24;
195
- }
196
- return bits;
197
- }
198
- async function solvePowChallenge(challenge, maxIterations = 1 << 24) {
199
- for (let nonce = 0; nonce < maxIterations; nonce++) {
200
- const digest = await crypto.subtle.digest("SHA-256", encoder.encode(challenge.prefix + nonce));
201
- if (leadingZeroBits(new Uint8Array(digest)) >= challenge.difficulty) {
202
- return {
203
- [POW_CHALLENGE_ID_HEADER]: challenge.id,
204
- [POW_NONCE_HEADER]: String(nonce)
205
- };
206
- }
207
- }
208
- throw new Error(
209
- `proof-of-work: no nonce found for difficulty ${challenge.difficulty} within ${maxIterations} attempts`
210
- );
211
- }
212
-
213
211
  // src/request.ts
214
212
  var MUTATING = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
215
213
  var PERF_EXCLUDED_PREFIX = "/v1/analytics/";
@@ -404,7 +402,7 @@ function applyBrowserOriginHeader(headers) {
404
402
  }
405
403
 
406
404
  // src/version.ts
407
- var VERSION = "7.3.0";
405
+ var VERSION = "7.3.1";
408
406
 
409
407
  // src/call.ts
410
408
  async function callEndpoint(resolveRt, name, input, options) {