@palbase/web 7.3.0 → 7.3.2
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-HKZVA3I3.js} +67 -5
- package/dist/chunk-HKZVA3I3.js.map +1 -0
- package/dist/{chunk-ZC6Q3GPX.js → chunk-OZLTH7YB.js} +2 -2
- package/dist/{chunk-YBURINUN.js → chunk-TQAQR3OP.js} +5 -44
- package/dist/chunk-TQAQR3OP.js.map +1 -0
- package/dist/index.cjs +49 -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 +65 -46
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.js +2 -2
- package/dist/next/client.cjs +65 -46
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.js +2 -2
- package/dist/next/index.cjs +65 -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 +49 -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-OZLTH7YB.js.map} +0 -0
package/dist/next/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
importNextServer
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-OZLTH7YB.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-
|
|
17
|
+
} from "../chunk-TQAQR3OP.js";
|
|
18
18
|
import {
|
|
19
19
|
BackendError
|
|
20
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-HKZVA3I3.js";
|
|
21
21
|
import {
|
|
22
22
|
environmentRefFromApiKey,
|
|
23
23
|
environmentRefFromPublishableApiKey
|
package/dist/next/proxy.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
importNextServer
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-OZLTH7YB.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-
|
|
12
|
+
} from "../chunk-HKZVA3I3.js";
|
|
13
13
|
import {
|
|
14
14
|
environmentRefFromPublishableApiKey
|
|
15
15
|
} from "../chunk-CFDU23TB.js";
|
package/dist/react/index.cjs
CHANGED
|
@@ -49,6 +49,54 @@ 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
|
+
var MAX_POW_DIFFICULTY = 24;
|
|
78
|
+
function powBudget(difficulty) {
|
|
79
|
+
return 8 * 2 ** difficulty;
|
|
80
|
+
}
|
|
81
|
+
async function solvePowChallenge(challenge, maxIterations = powBudget(challenge.difficulty)) {
|
|
82
|
+
if (challenge.difficulty > MAX_POW_DIFFICULTY) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`proof-of-work: refusing difficulty ${challenge.difficulty}; this client attempts at most ${MAX_POW_DIFFICULTY}, which is the highest a Palbase stack issues`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
for (let nonce = 0; nonce < maxIterations; nonce++) {
|
|
88
|
+
const digest = await crypto.subtle.digest("SHA-256", encoder.encode(challenge.prefix + nonce));
|
|
89
|
+
if (leadingZeroBits(new Uint8Array(digest)) >= challenge.difficulty) {
|
|
90
|
+
return {
|
|
91
|
+
[POW_CHALLENGE_ID_HEADER]: challenge.id,
|
|
92
|
+
[POW_NONCE_HEADER]: String(nonce)
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
throw new Error(
|
|
97
|
+
`proof-of-work: no nonce found for difficulty ${challenge.difficulty} within ${maxIterations} attempts`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
52
100
|
|
|
53
101
|
// src/errors.ts
|
|
54
102
|
var BackendError = class _BackendError extends Error {
|
|
@@ -169,47 +217,6 @@ function redactUrl(rawUrl) {
|
|
|
169
217
|
return path.split("/").map((seg) => isSensitiveSegment(seg) ? ":id" : seg).join("/");
|
|
170
218
|
}
|
|
171
219
|
|
|
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
220
|
// src/request.ts
|
|
214
221
|
var MUTATING = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
215
222
|
var PERF_EXCLUDED_PREFIX = "/v1/analytics/";
|
|
@@ -404,7 +411,7 @@ function applyBrowserOriginHeader(headers) {
|
|
|
404
411
|
}
|
|
405
412
|
|
|
406
413
|
// src/version.ts
|
|
407
|
-
var VERSION = "7.3.
|
|
414
|
+
var VERSION = "7.3.2";
|
|
408
415
|
|
|
409
416
|
// src/call.ts
|
|
410
417
|
async function callEndpoint(resolveRt, name, input, options) {
|