@palbase/web 7.2.1 → 7.3.0

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.
Files changed (38) hide show
  1. package/dist/{analytics-facade-DLfnVVwL.d.ts → analytics-facade-BER0EyYT.d.ts} +8 -3
  2. package/dist/{analytics-facade-jyXv7Cu4.d.cts → analytics-facade-CQXCQSoF.d.cts} +8 -3
  3. package/dist/{chunk-GITHW5JK.js → chunk-YBURINUN.js} +60 -14
  4. package/dist/chunk-YBURINUN.js.map +1 -0
  5. package/dist/gen/cli.cjs +15 -24
  6. package/dist/gen/cli.cjs.map +1 -1
  7. package/dist/gen/cli.js +15 -24
  8. package/dist/gen/cli.js.map +1 -1
  9. package/dist/index.cjs +51 -4
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +3 -3
  12. package/dist/index.d.ts +3 -3
  13. package/dist/index.js +1 -1
  14. package/dist/internal.cjs +59 -13
  15. package/dist/internal.cjs.map +1 -1
  16. package/dist/internal.d.cts +3 -3
  17. package/dist/internal.d.ts +3 -3
  18. package/dist/internal.js +1 -1
  19. package/dist/next/client.cjs +67 -21
  20. package/dist/next/client.cjs.map +1 -1
  21. package/dist/next/client.js +5 -3
  22. package/dist/next/client.js.map +1 -1
  23. package/dist/next/index.cjs +73 -27
  24. package/dist/next/index.cjs.map +1 -1
  25. package/dist/next/index.d.cts +2 -22
  26. package/dist/next/index.d.ts +2 -22
  27. package/dist/next/index.js +5 -4
  28. package/dist/next/index.js.map +1 -1
  29. package/dist/{pb-DdzpEkPY.d.ts → pb-BRlmBIAm.d.ts} +1 -1
  30. package/dist/{pb-CfYQGEn0.d.cts → pb-WAQvwCfM.d.cts} +1 -1
  31. package/dist/react/index.cjs +50 -3
  32. package/dist/react/index.cjs.map +1 -1
  33. package/dist/react/index.d.cts +1 -1
  34. package/dist/react/index.d.ts +1 -1
  35. package/dist/react/index.js +1 -1
  36. package/package.json +13 -13
  37. package/LICENSE +0 -21
  38. package/dist/chunk-GITHW5JK.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -181,6 +181,47 @@ function redactUrl(rawUrl) {
181
181
  return path.split("/").map((seg2) => isSensitiveSegment(seg2) ? ":id" : seg2).join("/");
182
182
  }
183
183
 
184
+ // src/pow.ts
185
+ var POW_CHALLENGE_ID_HEADER = "X-PoW-Challenge-ID";
186
+ var POW_NONCE_HEADER = "X-PoW-Nonce";
187
+ function asPowChallenge(details) {
188
+ if (typeof details !== "object" || details === null) return null;
189
+ const env = details;
190
+ if (env.error !== "pow_required") return null;
191
+ const c = env.challenge;
192
+ if (typeof c !== "object" || c === null) return null;
193
+ const { id, prefix, difficulty } = c;
194
+ if (typeof id !== "string" || typeof prefix !== "string") return null;
195
+ if (typeof difficulty !== "number" || !Number.isInteger(difficulty) || difficulty < 0) return null;
196
+ return { id, prefix, difficulty };
197
+ }
198
+ var encoder = new TextEncoder();
199
+ function leadingZeroBits(hash) {
200
+ let bits = 0;
201
+ for (const byte of hash) {
202
+ if (byte === 0) {
203
+ bits += 8;
204
+ continue;
205
+ }
206
+ return bits + Math.clz32(byte) - 24;
207
+ }
208
+ return bits;
209
+ }
210
+ async function solvePowChallenge(challenge, maxIterations = 1 << 24) {
211
+ for (let nonce = 0; nonce < maxIterations; nonce++) {
212
+ const digest = await crypto.subtle.digest("SHA-256", encoder.encode(challenge.prefix + nonce));
213
+ if (leadingZeroBits(new Uint8Array(digest)) >= challenge.difficulty) {
214
+ return {
215
+ [POW_CHALLENGE_ID_HEADER]: challenge.id,
216
+ [POW_NONCE_HEADER]: String(nonce)
217
+ };
218
+ }
219
+ }
220
+ throw new Error(
221
+ `proof-of-work: no nonce found for difficulty ${challenge.difficulty} within ${maxIterations} attempts`
222
+ );
223
+ }
224
+
184
225
  // src/request.ts
185
226
  var MUTATING = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
186
227
  var PERF_EXCLUDED_PREFIX = "/v1/analytics/";
@@ -204,11 +245,11 @@ async function palbeRequest(rt, method, path, spec = {}) {
204
245
  if (MUTATING.has(method) && !callerHasKey) {
205
246
  headers["Idempotency-Key"] = crypto.randomUUID();
206
247
  }
207
- const attempt = async () => {
248
+ const attempt = async (extra) => {
208
249
  try {
209
250
  return await rt.http.request(method, path, {
210
251
  body: spec.body,
211
- headers,
252
+ headers: extra ? { ...headers, ...extra } : headers,
212
253
  signal: spec.signal
213
254
  });
214
255
  } catch (e) {
@@ -243,6 +284,12 @@ async function palbeRequest(rt, method, path, spec = {}) {
243
284
  }
244
285
  res = await attempt();
245
286
  }
287
+ if (res.error?.status === 403 && res.error.code === "pow_required") {
288
+ const challenge = asPowChallenge(res.error.details);
289
+ if (challenge) {
290
+ res = await attempt(await solvePowChallenge(challenge));
291
+ }
292
+ }
246
293
  } catch (e) {
247
294
  if (!isAbort(e)) record(asPalbaseError(e)?.status ?? 0);
248
295
  throw e;
@@ -1856,7 +1903,7 @@ var PalbeFlags = class {
1856
1903
  constructor(rt) {
1857
1904
  this.transport = new FlagsClient(rt.http);
1858
1905
  const browser = typeof document !== "undefined";
1859
- const ref = rt.config.environmentRef;
1906
+ const ref = rt.projectRef;
1860
1907
  const options = {
1861
1908
  auth: palbeAuthAdapter(rt.auth),
1862
1909
  ...ref ? { storageKey: `palbe.flags.${ref}` } : {},
@@ -7911,7 +7958,7 @@ function localStorageSessionStorage(key = DEFAULT_KEY) {
7911
7958
  }
7912
7959
 
7913
7960
  // src/version.ts
7914
- var VERSION = "7.2.1";
7961
+ var VERSION = "7.3.0";
7915
7962
 
7916
7963
  // src/internal.ts
7917
7964
  function getRuntime() {