@palbase/web 7.2.2 → 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-IREKQSHT.js → chunk-YBURINUN.js} +60 -14
  4. package/dist/chunk-YBURINUN.js.map +1 -0
  5. package/dist/gen/cli.cjs +6 -12
  6. package/dist/gen/cli.cjs.map +1 -1
  7. package/dist/gen/cli.js +6 -12
  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-IREKQSHT.js.map +0 -1
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- export { f as AnalyticsProperties, g as AuthChangeEvent, h as AuthState, i as AuthSuccess, A as AuthUser, j as Call, k as CallChangeCallback, l as CallParticipant, m as CallState, C as Chat, n as ChatBackend, o as ChatDraft, p as ChatKind, b as ChatMember, c as ChatMessage, q as ChatMessageKind, r as ChatRole, s as ChatState, t as CommsPrefs, F as FlagsView, M as MagicLinkResult, u as MentionRange, v as MessageDirection, N as NotifyScope, O as OAuthExchangeResult, w as PalbeAnalytics, x as PalbeAuth, y as PalbeCalls, P as PalbeConfig, z as PalbeFlags, B as PalbeMessaging, D as PalbeOAuthConfig, E as PalbeRealtime, G as PresenceState, H as RealtimeChannel, R as RealtimeConnectionState, I as RealtimeHandler, a as RealtimePayload, J as RealtimeStatus, K as RealtimeStatusSnapshot, L as RealtimeSubscription, Q as ResolvedMention, S as ResolvedReply, T as SentReceipt, U as SignInMethods, V as UnreadView, W as Unsubscribe } from './analytics-facade-jyXv7Cu4.cjs';
1
+ export { f as AnalyticsProperties, g as AuthChangeEvent, h as AuthState, i as AuthSuccess, A as AuthUser, j as Call, k as CallChangeCallback, l as CallParticipant, m as CallState, C as Chat, n as ChatBackend, o as ChatDraft, p as ChatKind, b as ChatMember, c as ChatMessage, q as ChatMessageKind, r as ChatRole, s as ChatState, t as CommsPrefs, F as FlagsView, M as MagicLinkResult, u as MentionRange, v as MessageDirection, N as NotifyScope, O as OAuthExchangeResult, w as PalbeAnalytics, x as PalbeAuth, y as PalbeCalls, P as PalbeConfig, z as PalbeFlags, B as PalbeMessaging, D as PalbeOAuthConfig, E as PalbeRealtime, G as PresenceState, H as RealtimeChannel, R as RealtimeConnectionState, I as RealtimeHandler, a as RealtimePayload, J as RealtimeStatus, K as RealtimeStatusSnapshot, L as RealtimeSubscription, Q as ResolvedMention, S as ResolvedReply, T as SentReceipt, U as SignInMethods, V as UnreadView, W as Unsubscribe } from './analytics-facade-CQXCQSoF.cjs';
2
2
  export { B as BackendError, a as BackendErrorKind, F as FieldError, i as isBackendError } from './errors-fDoNdTrJ.cjs';
3
- export { C as CallOptions, P as PB, U as UploadOptions, a as UploadProgress, p as pb } from './pb-CfYQGEn0.cjs';
3
+ export { C as CallOptions, P as PB, U as UploadOptions, a as UploadProgress, p as pb } from './pb-WAQvwCfM.cjs';
4
4
  export { P as PersistedSession, S as SessionStorageAdapter, l as localStorageSessionStorage, m as memorySessionStorage } from './storage-BPaeSG8K.cjs';
5
5
  export { F as FlagValue } from './pooled-flags-4GtDtsiu.js';
6
6
 
@@ -206,6 +206,6 @@ interface MlsGlue {
206
206
  */
207
207
  declare function initMls(): Promise<MlsGlue>;
208
208
 
209
- declare const VERSION = "7.2.2";
209
+ declare const VERSION = "7.3.0";
210
210
 
211
211
  export { VERSION, initMls };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { f as AnalyticsProperties, g as AuthChangeEvent, h as AuthState, i as AuthSuccess, A as AuthUser, j as Call, k as CallChangeCallback, l as CallParticipant, m as CallState, C as Chat, n as ChatBackend, o as ChatDraft, p as ChatKind, b as ChatMember, c as ChatMessage, q as ChatMessageKind, r as ChatRole, s as ChatState, t as CommsPrefs, F as FlagsView, M as MagicLinkResult, u as MentionRange, v as MessageDirection, N as NotifyScope, O as OAuthExchangeResult, w as PalbeAnalytics, x as PalbeAuth, y as PalbeCalls, P as PalbeConfig, z as PalbeFlags, B as PalbeMessaging, D as PalbeOAuthConfig, E as PalbeRealtime, G as PresenceState, H as RealtimeChannel, R as RealtimeConnectionState, I as RealtimeHandler, a as RealtimePayload, J as RealtimeStatus, K as RealtimeStatusSnapshot, L as RealtimeSubscription, Q as ResolvedMention, S as ResolvedReply, T as SentReceipt, U as SignInMethods, V as UnreadView, W as Unsubscribe } from './analytics-facade-DLfnVVwL.js';
1
+ export { f as AnalyticsProperties, g as AuthChangeEvent, h as AuthState, i as AuthSuccess, A as AuthUser, j as Call, k as CallChangeCallback, l as CallParticipant, m as CallState, C as Chat, n as ChatBackend, o as ChatDraft, p as ChatKind, b as ChatMember, c as ChatMessage, q as ChatMessageKind, r as ChatRole, s as ChatState, t as CommsPrefs, F as FlagsView, M as MagicLinkResult, u as MentionRange, v as MessageDirection, N as NotifyScope, O as OAuthExchangeResult, w as PalbeAnalytics, x as PalbeAuth, y as PalbeCalls, P as PalbeConfig, z as PalbeFlags, B as PalbeMessaging, D as PalbeOAuthConfig, E as PalbeRealtime, G as PresenceState, H as RealtimeChannel, R as RealtimeConnectionState, I as RealtimeHandler, a as RealtimePayload, J as RealtimeStatus, K as RealtimeStatusSnapshot, L as RealtimeSubscription, Q as ResolvedMention, S as ResolvedReply, T as SentReceipt, U as SignInMethods, V as UnreadView, W as Unsubscribe } from './analytics-facade-BER0EyYT.js';
2
2
  export { B as BackendError, a as BackendErrorKind, F as FieldError, i as isBackendError } from './errors-fDoNdTrJ.js';
3
- export { C as CallOptions, P as PB, U as UploadOptions, a as UploadProgress, p as pb } from './pb-DdzpEkPY.js';
3
+ export { C as CallOptions, P as PB, U as UploadOptions, a as UploadProgress, p as pb } from './pb-BRlmBIAm.js';
4
4
  export { P as PersistedSession, S as SessionStorageAdapter, l as localStorageSessionStorage, m as memorySessionStorage } from './storage-BPaeSG8K.js';
5
5
  export { F as FlagValue } from './pooled-flags-4GtDtsiu.js';
6
6
 
@@ -206,6 +206,6 @@ interface MlsGlue {
206
206
  */
207
207
  declare function initMls(): Promise<MlsGlue>;
208
208
 
209
- declare const VERSION = "7.2.2";
209
+ declare const VERSION = "7.3.0";
210
210
 
211
211
  export { VERSION, initMls };
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  localStorageSessionStorage,
12
12
  memorySessionStorage,
13
13
  pb
14
- } from "./chunk-IREKQSHT.js";
14
+ } from "./chunk-YBURINUN.js";
15
15
  import {
16
16
  BackendError,
17
17
  isBackendError
package/dist/internal.cjs CHANGED
@@ -456,6 +456,47 @@ function redactUrl(rawUrl) {
456
456
  return path.split("/").map((seg2) => isSensitiveSegment(seg2) ? ":id" : seg2).join("/");
457
457
  }
458
458
 
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
+
459
500
  // src/request.ts
460
501
  var MUTATING = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
461
502
  var PERF_EXCLUDED_PREFIX = "/v1/analytics/";
@@ -479,11 +520,11 @@ async function palbeRequest(rt, method, path, spec = {}) {
479
520
  if (MUTATING.has(method) && !callerHasKey) {
480
521
  headers["Idempotency-Key"] = crypto.randomUUID();
481
522
  }
482
- const attempt = async () => {
523
+ const attempt = async (extra) => {
483
524
  try {
484
525
  return await rt.http.request(method, path, {
485
526
  body: spec.body,
486
- headers,
527
+ headers: extra ? { ...headers, ...extra } : headers,
487
528
  signal: spec.signal
488
529
  });
489
530
  } catch (e) {
@@ -518,6 +559,12 @@ async function palbeRequest(rt, method, path, spec = {}) {
518
559
  }
519
560
  res = await attempt();
520
561
  }
562
+ if (res.error?.status === 403 && res.error.code === "pow_required") {
563
+ const challenge = asPowChallenge(res.error.details);
564
+ if (challenge) {
565
+ res = await attempt(await solvePowChallenge(challenge));
566
+ }
567
+ }
521
568
  } catch (e) {
522
569
  if (!isAbort(e)) record(asPalbaseError(e)?.status ?? 0);
523
570
  throw e;
@@ -1258,7 +1305,7 @@ var AnalyticsState = class {
1258
1305
  idKey;
1259
1306
  optOutKey;
1260
1307
  constructor(rt) {
1261
- const ref = rt.config.environmentRef;
1308
+ const ref = rt.projectRef;
1262
1309
  this.idKey = ref ? `palbe.analytics.id.${ref}` : "palbe.analytics.id";
1263
1310
  this.optOutKey = ref ? `palbe.analytics.optout.${ref}` : "palbe.analytics.optout";
1264
1311
  rt.auth.onAuthEvent((event) => {
@@ -2899,7 +2946,7 @@ var PalbeFlags = class {
2899
2946
  constructor(rt) {
2900
2947
  this.transport = new FlagsClient(rt.http);
2901
2948
  const browser = typeof document !== "undefined";
2902
- const ref = rt.config.environmentRef;
2949
+ const ref = rt.projectRef;
2903
2950
  const options = {
2904
2951
  auth: palbeAuthAdapter(rt.auth),
2905
2952
  ...ref ? { storageKey: `palbe.flags.${ref}` } : {},
@@ -9298,15 +9345,13 @@ function defaultSessionStorage(key) {
9298
9345
  }
9299
9346
 
9300
9347
  // src/version.ts
9301
- var VERSION = "7.2.2";
9348
+ var VERSION = "7.3.0";
9302
9349
 
9303
9350
  // src/runtime.ts
9304
9351
  function buildRuntime(config) {
9305
- const keyEnvironmentRef = environmentRefFromPublishableApiKey(config.apiKey);
9306
- if (keyEnvironmentRef === "") {
9307
- throw new Error("PalbeConfig.apiKey does not contain a valid publishable Environment identity");
9308
- } else if (config.environmentRef !== keyEnvironmentRef) {
9309
- throw new Error("PalbeConfig.environmentRef must match the Environment identity in apiKey");
9352
+ const projectRef = environmentRefFromPublishableApiKey(config.apiKey);
9353
+ if (projectRef === "") {
9354
+ throw new Error("PalbeConfig.apiKey does not contain a valid publishable project identity");
9310
9355
  }
9311
9356
  let runtimeURL;
9312
9357
  try {
@@ -9314,8 +9359,8 @@ function buildRuntime(config) {
9314
9359
  } catch {
9315
9360
  throw new Error("PalbeConfig.url must be a valid URL");
9316
9361
  }
9317
- if (runtimeURL.hostname.endsWith(".palbase.studio") && runtimeURL.hostname.split(".")[0] !== config.environmentRef) {
9318
- throw new Error("PalbeConfig.url must match environmentRef for palbase.studio");
9362
+ if (runtimeURL.hostname.endsWith(".palbase.studio") && runtimeURL.hostname.split(".")[0] !== projectRef) {
9363
+ throw new Error("PalbeConfig.url must match the project identity in apiKey for palbase.studio");
9319
9364
  }
9320
9365
  const http = new HttpClient(config.apiKey, {
9321
9366
  url: config.url,
@@ -9325,7 +9370,7 @@ function buildRuntime(config) {
9325
9370
  const tokenManager = new TokenManager();
9326
9371
  http.tokenManager = tokenManager;
9327
9372
  const authClient = new AuthClient(http, tokenManager);
9328
- const ref = config.environmentRef;
9373
+ const ref = projectRef;
9329
9374
  const storage = config.storage ?? defaultSessionStorage(ref ? `palbe.session.${ref}` : void 0);
9330
9375
  const persisted = storage.load();
9331
9376
  if (persisted) {
@@ -9370,6 +9415,7 @@ function buildRuntime(config) {
9370
9415
  let perf;
9371
9416
  const rt = {
9372
9417
  config,
9418
+ projectRef,
9373
9419
  http,
9374
9420
  tokenManager,
9375
9421
  authClient,