@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.
- package/dist/{chunk-ACCJV6FV.js → chunk-53TN7KYR.js} +58 -5
- package/dist/chunk-53TN7KYR.js.map +1 -0
- package/dist/{chunk-ZC6Q3GPX.js → chunk-CBN3PWNL.js} +2 -2
- package/dist/{chunk-YBURINUN.js → chunk-RRHJV6YD.js} +5 -44
- package/dist/chunk-RRHJV6YD.js.map +1 -0
- package/dist/index.cjs +40 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/internal.cjs +56 -46
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.js +2 -2
- package/dist/next/client.cjs +56 -46
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.js +2 -2
- package/dist/next/index.cjs +56 -46
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.js +3 -3
- package/dist/next/proxy.js +2 -2
- package/dist/react/index.cjs +40 -42
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-ACCJV6FV.js.map +0 -1
- package/dist/chunk-YBURINUN.js.map +0 -1
- /package/dist/{chunk-ZC6Q3GPX.js.map → chunk-CBN3PWNL.js.map} +0 -0
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -11,11 +11,11 @@ import {
|
|
|
11
11
|
localStorageSessionStorage,
|
|
12
12
|
memorySessionStorage,
|
|
13
13
|
pb
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-RRHJV6YD.js";
|
|
15
15
|
import {
|
|
16
16
|
BackendError,
|
|
17
17
|
isBackendError
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-53TN7KYR.js";
|
|
19
19
|
import "./chunk-CFDU23TB.js";
|
|
20
20
|
import "./chunk-PZ5AY32C.js";
|
|
21
21
|
export {
|
package/dist/internal.cjs
CHANGED
|
@@ -54,6 +54,45 @@ var PalbaseError = class extends Error {
|
|
|
54
54
|
this.details = details;
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
|
+
var POW_CHALLENGE_ID_HEADER = "X-PoW-Challenge-ID";
|
|
58
|
+
var POW_NONCE_HEADER = "X-PoW-Nonce";
|
|
59
|
+
function asPowChallenge(details) {
|
|
60
|
+
if (typeof details !== "object" || details === null) return null;
|
|
61
|
+
const env = details;
|
|
62
|
+
if (env.error !== "pow_required") return null;
|
|
63
|
+
const c = env.challenge;
|
|
64
|
+
if (typeof c !== "object" || c === null) return null;
|
|
65
|
+
const { id, prefix, difficulty } = c;
|
|
66
|
+
if (typeof id !== "string" || typeof prefix !== "string") return null;
|
|
67
|
+
if (typeof difficulty !== "number" || !Number.isInteger(difficulty) || difficulty < 0) return null;
|
|
68
|
+
return { id, prefix, difficulty };
|
|
69
|
+
}
|
|
70
|
+
var encoder = new TextEncoder();
|
|
71
|
+
function leadingZeroBits(hash) {
|
|
72
|
+
let bits = 0;
|
|
73
|
+
for (const byte of hash) {
|
|
74
|
+
if (byte === 0) {
|
|
75
|
+
bits += 8;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
return bits + Math.clz32(byte) - 24;
|
|
79
|
+
}
|
|
80
|
+
return bits;
|
|
81
|
+
}
|
|
82
|
+
async function solvePowChallenge(challenge, maxIterations = 1 << 24) {
|
|
83
|
+
for (let nonce = 0; nonce < maxIterations; nonce++) {
|
|
84
|
+
const digest = await crypto.subtle.digest("SHA-256", encoder.encode(challenge.prefix + nonce));
|
|
85
|
+
if (leadingZeroBits(new Uint8Array(digest)) >= challenge.difficulty) {
|
|
86
|
+
return {
|
|
87
|
+
[POW_CHALLENGE_ID_HEADER]: challenge.id,
|
|
88
|
+
[POW_NONCE_HEADER]: String(nonce)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
throw new Error(
|
|
93
|
+
`proof-of-work: no nonce found for difficulty ${challenge.difficulty} within ${maxIterations} attempts`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
57
96
|
function detectPlatform() {
|
|
58
97
|
if (typeof Deno !== "undefined") {
|
|
59
98
|
return "deno";
|
|
@@ -190,9 +229,9 @@ var HttpClient = class _HttpClient {
|
|
|
190
229
|
}
|
|
191
230
|
return headers;
|
|
192
231
|
}
|
|
193
|
-
async executeWithRetry(method, path, options, attempt) {
|
|
232
|
+
async executeWithRetry(method, path, options, attempt, earned) {
|
|
194
233
|
const url = `${this.getBaseUrl()}${path}`;
|
|
195
|
-
const headers = this.buildHeaders(options);
|
|
234
|
+
const headers = { ...this.buildHeaders(options), ...earned };
|
|
196
235
|
for (const interceptor of this.interceptors) {
|
|
197
236
|
await interceptor({ headers, method, path });
|
|
198
237
|
}
|
|
@@ -211,7 +250,7 @@ var HttpClient = class _HttpClient {
|
|
|
211
250
|
if (attempt < MAX_RETRIES - 1) {
|
|
212
251
|
const backoff = INITIAL_BACKOFF_MS * 2 ** attempt;
|
|
213
252
|
await this.delay(backoff);
|
|
214
|
-
return this.executeWithRetry(method, path, options, attempt + 1);
|
|
253
|
+
return this.executeWithRetry(method, path, options, attempt + 1, earned);
|
|
215
254
|
}
|
|
216
255
|
throw new PalbaseError(
|
|
217
256
|
"network_error",
|
|
@@ -225,7 +264,7 @@ var HttpClient = class _HttpClient {
|
|
|
225
264
|
const parsed = retryAfter ? Number.parseInt(retryAfter, 10) : Number.NaN;
|
|
226
265
|
const delayMs = Number.isNaN(parsed) ? INITIAL_BACKOFF_MS * 2 ** attempt : Math.min(parsed * 1e3, MAX_RETRY_DELAY_MS);
|
|
227
266
|
await this.delay(delayMs);
|
|
228
|
-
return this.executeWithRetry(method, path, options, attempt + 1);
|
|
267
|
+
return this.executeWithRetry(method, path, options, attempt + 1, earned);
|
|
229
268
|
}
|
|
230
269
|
}
|
|
231
270
|
let data = null;
|
|
@@ -239,6 +278,18 @@ var HttpClient = class _HttpClient {
|
|
|
239
278
|
errorBody = body;
|
|
240
279
|
}
|
|
241
280
|
}
|
|
281
|
+
if (response.status === 403 && !earned) {
|
|
282
|
+
const challenge = asPowChallenge(errorBody);
|
|
283
|
+
if (challenge) {
|
|
284
|
+
return this.executeWithRetry(
|
|
285
|
+
method,
|
|
286
|
+
path,
|
|
287
|
+
options,
|
|
288
|
+
attempt,
|
|
289
|
+
await solvePowChallenge(challenge)
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
242
293
|
if (!response.ok) {
|
|
243
294
|
return {
|
|
244
295
|
data: null,
|
|
@@ -456,47 +507,6 @@ function redactUrl(rawUrl) {
|
|
|
456
507
|
return path.split("/").map((seg2) => isSensitiveSegment(seg2) ? ":id" : seg2).join("/");
|
|
457
508
|
}
|
|
458
509
|
|
|
459
|
-
// src/pow.ts
|
|
460
|
-
var POW_CHALLENGE_ID_HEADER = "X-PoW-Challenge-ID";
|
|
461
|
-
var POW_NONCE_HEADER = "X-PoW-Nonce";
|
|
462
|
-
function asPowChallenge(details) {
|
|
463
|
-
if (typeof details !== "object" || details === null) return null;
|
|
464
|
-
const env = details;
|
|
465
|
-
if (env.error !== "pow_required") return null;
|
|
466
|
-
const c = env.challenge;
|
|
467
|
-
if (typeof c !== "object" || c === null) return null;
|
|
468
|
-
const { id, prefix, difficulty } = c;
|
|
469
|
-
if (typeof id !== "string" || typeof prefix !== "string") return null;
|
|
470
|
-
if (typeof difficulty !== "number" || !Number.isInteger(difficulty) || difficulty < 0) return null;
|
|
471
|
-
return { id, prefix, difficulty };
|
|
472
|
-
}
|
|
473
|
-
var encoder = new TextEncoder();
|
|
474
|
-
function leadingZeroBits(hash) {
|
|
475
|
-
let bits = 0;
|
|
476
|
-
for (const byte of hash) {
|
|
477
|
-
if (byte === 0) {
|
|
478
|
-
bits += 8;
|
|
479
|
-
continue;
|
|
480
|
-
}
|
|
481
|
-
return bits + Math.clz32(byte) - 24;
|
|
482
|
-
}
|
|
483
|
-
return bits;
|
|
484
|
-
}
|
|
485
|
-
async function solvePowChallenge(challenge, maxIterations = 1 << 24) {
|
|
486
|
-
for (let nonce = 0; nonce < maxIterations; nonce++) {
|
|
487
|
-
const digest = await crypto.subtle.digest("SHA-256", encoder.encode(challenge.prefix + nonce));
|
|
488
|
-
if (leadingZeroBits(new Uint8Array(digest)) >= challenge.difficulty) {
|
|
489
|
-
return {
|
|
490
|
-
[POW_CHALLENGE_ID_HEADER]: challenge.id,
|
|
491
|
-
[POW_NONCE_HEADER]: String(nonce)
|
|
492
|
-
};
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
throw new Error(
|
|
496
|
-
`proof-of-work: no nonce found for difficulty ${challenge.difficulty} within ${maxIterations} attempts`
|
|
497
|
-
);
|
|
498
|
-
}
|
|
499
|
-
|
|
500
510
|
// src/request.ts
|
|
501
511
|
var MUTATING = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
502
512
|
var PERF_EXCLUDED_PREFIX = "/v1/analytics/";
|
|
@@ -9345,7 +9355,7 @@ function defaultSessionStorage(key) {
|
|
|
9345
9355
|
}
|
|
9346
9356
|
|
|
9347
9357
|
// src/version.ts
|
|
9348
|
-
var VERSION = "7.3.
|
|
9358
|
+
var VERSION = "7.3.1";
|
|
9349
9359
|
|
|
9350
9360
|
// src/runtime.ts
|
|
9351
9361
|
function buildRuntime(config) {
|