@palbase/web 7.2.2 → 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.
Files changed (44) 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-ACCJV6FV.js → chunk-53TN7KYR.js} +58 -5
  4. package/dist/chunk-53TN7KYR.js.map +1 -0
  5. package/dist/{chunk-ZC6Q3GPX.js → chunk-CBN3PWNL.js} +2 -2
  6. package/dist/{chunk-IREKQSHT.js → chunk-RRHJV6YD.js} +22 -15
  7. package/dist/chunk-RRHJV6YD.js.map +1 -0
  8. package/dist/gen/cli.cjs +6 -12
  9. package/dist/gen/cli.cjs.map +1 -1
  10. package/dist/gen/cli.js +6 -12
  11. package/dist/gen/cli.js.map +1 -1
  12. package/dist/index.cjs +49 -4
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +3 -3
  15. package/dist/index.d.ts +3 -3
  16. package/dist/index.js +2 -2
  17. package/dist/internal.cjs +73 -17
  18. package/dist/internal.cjs.map +1 -1
  19. package/dist/internal.d.cts +3 -3
  20. package/dist/internal.d.ts +3 -3
  21. package/dist/internal.js +2 -2
  22. package/dist/next/client.cjs +81 -25
  23. package/dist/next/client.cjs.map +1 -1
  24. package/dist/next/client.js +6 -4
  25. package/dist/next/client.js.map +1 -1
  26. package/dist/next/index.cjs +87 -31
  27. package/dist/next/index.cjs.map +1 -1
  28. package/dist/next/index.d.cts +2 -22
  29. package/dist/next/index.d.ts +2 -22
  30. package/dist/next/index.js +7 -6
  31. package/dist/next/index.js.map +1 -1
  32. package/dist/next/proxy.js +2 -2
  33. package/dist/{pb-DdzpEkPY.d.ts → pb-BRlmBIAm.d.ts} +1 -1
  34. package/dist/{pb-CfYQGEn0.d.cts → pb-WAQvwCfM.d.cts} +1 -1
  35. package/dist/react/index.cjs +48 -3
  36. package/dist/react/index.cjs.map +1 -1
  37. package/dist/react/index.d.cts +1 -1
  38. package/dist/react/index.d.ts +1 -1
  39. package/dist/react/index.js +2 -2
  40. package/package.json +13 -13
  41. package/LICENSE +0 -21
  42. package/dist/chunk-ACCJV6FV.js.map +0 -1
  43. package/dist/chunk-IREKQSHT.js.map +0 -1
  44. /package/dist/{chunk-ZC6Q3GPX.js.map → chunk-CBN3PWNL.js.map} +0 -0
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.1";
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.1";
210
210
 
211
211
  export { VERSION, initMls };
package/dist/index.js CHANGED
@@ -11,11 +11,11 @@ import {
11
11
  localStorageSessionStorage,
12
12
  memorySessionStorage,
13
13
  pb
14
- } from "./chunk-IREKQSHT.js";
14
+ } from "./chunk-RRHJV6YD.js";
15
15
  import {
16
16
  BackendError,
17
17
  isBackendError
18
- } from "./chunk-ACCJV6FV.js";
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,
@@ -479,11 +530,11 @@ async function palbeRequest(rt, method, path, spec = {}) {
479
530
  if (MUTATING.has(method) && !callerHasKey) {
480
531
  headers["Idempotency-Key"] = crypto.randomUUID();
481
532
  }
482
- const attempt = async () => {
533
+ const attempt = async (extra) => {
483
534
  try {
484
535
  return await rt.http.request(method, path, {
485
536
  body: spec.body,
486
- headers,
537
+ headers: extra ? { ...headers, ...extra } : headers,
487
538
  signal: spec.signal
488
539
  });
489
540
  } catch (e) {
@@ -518,6 +569,12 @@ async function palbeRequest(rt, method, path, spec = {}) {
518
569
  }
519
570
  res = await attempt();
520
571
  }
572
+ if (res.error?.status === 403 && res.error.code === "pow_required") {
573
+ const challenge = asPowChallenge(res.error.details);
574
+ if (challenge) {
575
+ res = await attempt(await solvePowChallenge(challenge));
576
+ }
577
+ }
521
578
  } catch (e) {
522
579
  if (!isAbort(e)) record(asPalbaseError(e)?.status ?? 0);
523
580
  throw e;
@@ -1258,7 +1315,7 @@ var AnalyticsState = class {
1258
1315
  idKey;
1259
1316
  optOutKey;
1260
1317
  constructor(rt) {
1261
- const ref = rt.config.environmentRef;
1318
+ const ref = rt.projectRef;
1262
1319
  this.idKey = ref ? `palbe.analytics.id.${ref}` : "palbe.analytics.id";
1263
1320
  this.optOutKey = ref ? `palbe.analytics.optout.${ref}` : "palbe.analytics.optout";
1264
1321
  rt.auth.onAuthEvent((event) => {
@@ -2899,7 +2956,7 @@ var PalbeFlags = class {
2899
2956
  constructor(rt) {
2900
2957
  this.transport = new FlagsClient(rt.http);
2901
2958
  const browser = typeof document !== "undefined";
2902
- const ref = rt.config.environmentRef;
2959
+ const ref = rt.projectRef;
2903
2960
  const options = {
2904
2961
  auth: palbeAuthAdapter(rt.auth),
2905
2962
  ...ref ? { storageKey: `palbe.flags.${ref}` } : {},
@@ -9298,15 +9355,13 @@ function defaultSessionStorage(key) {
9298
9355
  }
9299
9356
 
9300
9357
  // src/version.ts
9301
- var VERSION = "7.2.2";
9358
+ var VERSION = "7.3.1";
9302
9359
 
9303
9360
  // src/runtime.ts
9304
9361
  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");
9362
+ const projectRef = environmentRefFromPublishableApiKey(config.apiKey);
9363
+ if (projectRef === "") {
9364
+ throw new Error("PalbeConfig.apiKey does not contain a valid publishable project identity");
9310
9365
  }
9311
9366
  let runtimeURL;
9312
9367
  try {
@@ -9314,8 +9369,8 @@ function buildRuntime(config) {
9314
9369
  } catch {
9315
9370
  throw new Error("PalbeConfig.url must be a valid URL");
9316
9371
  }
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");
9372
+ if (runtimeURL.hostname.endsWith(".palbase.studio") && runtimeURL.hostname.split(".")[0] !== projectRef) {
9373
+ throw new Error("PalbeConfig.url must match the project identity in apiKey for palbase.studio");
9319
9374
  }
9320
9375
  const http = new HttpClient(config.apiKey, {
9321
9376
  url: config.url,
@@ -9325,7 +9380,7 @@ function buildRuntime(config) {
9325
9380
  const tokenManager = new TokenManager();
9326
9381
  http.tokenManager = tokenManager;
9327
9382
  const authClient = new AuthClient(http, tokenManager);
9328
- const ref = config.environmentRef;
9383
+ const ref = projectRef;
9329
9384
  const storage = config.storage ?? defaultSessionStorage(ref ? `palbe.session.${ref}` : void 0);
9330
9385
  const persisted = storage.load();
9331
9386
  if (persisted) {
@@ -9370,6 +9425,7 @@ function buildRuntime(config) {
9370
9425
  let perf;
9371
9426
  const rt = {
9372
9427
  config,
9428
+ projectRef,
9373
9429
  http,
9374
9430
  tokenManager,
9375
9431
  authClient,