@palbase/web 1.10.0 → 2.0.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/index.d.cts CHANGED
@@ -1,8 +1,8 @@
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 UnreadView, V as Unsubscribe } from './analytics-facade-B7vujhPJ.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 UnreadView, V as Unsubscribe } from './analytics-facade-ChlBRcLZ.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-6965XULp.cjs';
3
+ export { C as CallOptions, P as PB, U as UploadOptions, a as UploadProgress, p as pb } from './pb-B_6o5p79.cjs';
4
4
  export { P as PersistedSession, S as SessionStorageAdapter, l as localStorageSessionStorage, m as memorySessionStorage } from './storage-BPaeSG8K.cjs';
5
- export { F as FlagValue } from './pooled-flags-Bwq4usn0.js';
5
+ export { F as FlagValue } from './pooled-flags-4GtDtsiu.js';
6
6
  import 'livekit-client';
7
7
 
8
8
  /* tslint:disable */
@@ -207,6 +207,6 @@ interface MlsGlue {
207
207
  */
208
208
  declare function initMls(): Promise<MlsGlue>;
209
209
 
210
- declare const VERSION = "1.10.0";
210
+ declare const VERSION = "2.0.1";
211
211
 
212
212
  export { VERSION, initMls };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
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 UnreadView, V as Unsubscribe } from './analytics-facade-CHh5EGC2.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 UnreadView, V as Unsubscribe } from './analytics-facade-G0il4NrT.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-ChNq987M.js';
3
+ export { C as CallOptions, P as PB, U as UploadOptions, a as UploadProgress, p as pb } from './pb-nPBhqhJr.js';
4
4
  export { P as PersistedSession, S as SessionStorageAdapter, l as localStorageSessionStorage, m as memorySessionStorage } from './storage-BPaeSG8K.js';
5
- export { F as FlagValue } from './pooled-flags-Bwq4usn0.js';
5
+ export { F as FlagValue } from './pooled-flags-4GtDtsiu.js';
6
6
  import 'livekit-client';
7
7
 
8
8
  /* tslint:disable */
@@ -207,6 +207,6 @@ interface MlsGlue {
207
207
  */
208
208
  declare function initMls(): Promise<MlsGlue>;
209
209
 
210
- declare const VERSION = "1.10.0";
210
+ declare const VERSION = "2.0.1";
211
211
 
212
212
  export { VERSION, initMls };
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  localStorageSessionStorage,
14
14
  memorySessionStorage,
15
15
  pb
16
- } from "./chunk-4ZJHHXD3.js";
16
+ } from "./chunk-AIPUO4QX.js";
17
17
  import "./chunk-PZ5AY32C.js";
18
18
  export {
19
19
  BackendError,
package/dist/internal.cjs CHANGED
@@ -448,12 +448,6 @@ async function palbeRequest(rt, method, path, spec = {}) {
448
448
  if (MUTATING.has(method) && !callerHasKey) {
449
449
  headers["Idempotency-Key"] = crypto.randomUUID();
450
450
  }
451
- if (rt.appIdentifier !== "") {
452
- const callerHasBundle = Object.keys(headers).some(
453
- (k) => k.toLowerCase() === "x-palbase-bundle"
454
- );
455
- if (!callerHasBundle) headers["X-Palbase-Bundle"] = rt.appIdentifier;
456
- }
457
451
  const attempt = async () => {
458
452
  try {
459
453
  return await rt.http.request(method, path, {
@@ -1437,23 +1431,6 @@ var PalbeAnalytics = class {
1437
1431
  }
1438
1432
  };
1439
1433
 
1440
- // src/app-config.ts
1441
- function loadAppConfig(raw) {
1442
- if (typeof raw !== "object" || raw === null) {
1443
- throw new Error("app_config_invalid: expected a JSON object");
1444
- }
1445
- const r = raw;
1446
- const str = (k) => typeof r[k] === "string" ? r[k] : "";
1447
- return { appId: str("app_id"), identifier: str("identifier"), envPreset: str("env_preset") };
1448
- }
1449
- function assertOriginMatches(cfg, runtimeOrigin) {
1450
- if (cfg.identifier === "") return;
1451
- if (runtimeOrigin === "") return;
1452
- if (runtimeOrigin !== cfg.identifier) {
1453
- throw new Error(`app_config_mismatch: expected origin ${cfg.identifier}, got ${runtimeOrigin}`);
1454
- }
1455
- }
1456
-
1457
1434
  // src/auth-wire.ts
1458
1435
  function asWireAuthResult(raw) {
1459
1436
  if (typeof raw !== "object" || raw === null) return null;
@@ -2015,6 +1992,19 @@ var PalbeCalls = class {
2015
1992
 
2016
1993
  // ../modules/flags/dist/index.js
2017
1994
  var FLAG_NAME_RE = /^[a-zA-Z0-9_-]+$/;
1995
+ function flagEnabled(value) {
1996
+ if (typeof value === "boolean") return value;
1997
+ return value != null && value !== 0 && value !== "";
1998
+ }
1999
+ function flagVariant(value) {
2000
+ return typeof value === "string" ? { name: value } : null;
2001
+ }
2002
+ function mapResponse(res, fn) {
2003
+ if (res.error || res.data == null) {
2004
+ return { ...res, data: null };
2005
+ }
2006
+ return { ...res, data: fn(res.data) };
2007
+ }
2018
2008
  var FlagsClient = class {
2019
2009
  httpClient;
2020
2010
  getCurrentUserId;
@@ -2034,10 +2024,11 @@ var FlagsClient = class {
2034
2024
  `Invalid flag name: "${flagName}". Flag names must match ${FLAG_NAME_RE.source}`
2035
2025
  );
2036
2026
  }
2037
- const params = this.buildContextParams(context);
2038
- const query = params.toString();
2039
- const path = `/v1/flags/${flagName}/enabled${query ? `?${query}` : ""}`;
2040
- return this.httpClient.request("GET", path);
2027
+ const res = await this.httpClient.request(
2028
+ "GET",
2029
+ this.mergedPath(context)
2030
+ );
2031
+ return mapResponse(res, (snap) => flagEnabled(snap.values?.[flagName]));
2041
2032
  }
2042
2033
  async getVariant(flagName, context) {
2043
2034
  if (!FLAG_NAME_RE.test(flagName)) {
@@ -2045,16 +2036,29 @@ var FlagsClient = class {
2045
2036
  `Invalid flag name: "${flagName}". Flag names must match ${FLAG_NAME_RE.source}`
2046
2037
  );
2047
2038
  }
2048
- const params = this.buildContextParams(context);
2049
- const query = params.toString();
2050
- const path = `/v1/flags/${flagName}/variant${query ? `?${query}` : ""}`;
2051
- return this.httpClient.request("GET", path);
2039
+ const res = await this.httpClient.request(
2040
+ "GET",
2041
+ this.mergedPath(context)
2042
+ );
2043
+ if (res.error || res.data == null) {
2044
+ return { ...res, data: null };
2045
+ }
2046
+ return { ...res, data: flagVariant(res.data.values?.[flagName]) };
2052
2047
  }
2053
2048
  async getAll(context) {
2054
- const params = this.buildContextParams(context);
2055
- const query = params.toString();
2056
- const path = `/v1/flags${query ? `?${query}` : ""}`;
2057
- return this.httpClient.request("GET", path);
2049
+ const res = await this.httpClient.request(
2050
+ "GET",
2051
+ this.mergedPath(context)
2052
+ );
2053
+ return mapResponse(res, (snap) => {
2054
+ const values = snap.values ?? {};
2055
+ return Object.keys(values).map((name) => {
2056
+ const value = values[name];
2057
+ const flag = { name, enabled: flagEnabled(value) };
2058
+ if (typeof value === "string") flag.variant = { name: value };
2059
+ return flag;
2060
+ });
2061
+ });
2058
2062
  }
2059
2063
  /**
2060
2064
  * Cold-start read: the full merged flag set for the current auth identity.
@@ -2153,15 +2157,16 @@ var FlagsClient = class {
2153
2157
  }
2154
2158
  };
2155
2159
  }
2156
- buildContextParams(context) {
2157
- const params = new URLSearchParams();
2158
- if (context?.userId) {
2159
- params.set("userId", context.userId);
2160
- }
2161
- if (context?.properties) {
2162
- params.set("properties", JSON.stringify(context.properties));
2163
- }
2164
- return params;
2160
+ /**
2161
+ * Resolve the merged-read path for a context. With `context.userId` present the
2162
+ * read targets that specific user's merged view (`/v1/user-flags/users/{id}`, a
2163
+ * privileged cross-user read); otherwise the current auth user's view
2164
+ * (`/v1/user-flags`). `context.properties` has no server-side targeting support
2165
+ * in the user-flags module and is ignored.
2166
+ */
2167
+ mergedPath(context) {
2168
+ const uid = context?.userId;
2169
+ return uid ? `/v1/user-flags/users/${encodeURIComponent(uid)}` : "/v1/user-flags";
2165
2170
  }
2166
2171
  };
2167
2172
  var DEFAULT_POLL_MS = 3e4;
@@ -2623,7 +2628,7 @@ var PalbeFlags = class {
2623
2628
  *
2624
2629
  * DEVIATION from iOS sync-cache parity: the platform does not propagate
2625
2630
  * variant metadata into the user-flags snapshot/delta cache, so this is an
2626
- * ASYNC transport read (`GET /v1/flags/{key}/variant`), not a cache lookup.
2631
+ * ASYNC transport read (derived from `GET /v1/user-flags`), not a cache lookup.
2627
2632
  */
2628
2633
  async getVariant(key) {
2629
2634
  let res;
@@ -8263,6 +8268,14 @@ function observeWebVitals(record) {
8263
8268
  };
8264
8269
  }
8265
8270
 
8271
+ // src/runtime-metadata.ts
8272
+ var APP_METADATA_HEADER = "X-Palbase-Bundle";
8273
+ function applyBrowserOriginHeader(headers) {
8274
+ if (Object.keys(headers).some((key) => key.toLowerCase() === "x-palbase-bundle")) return;
8275
+ const origin = typeof window !== "undefined" && typeof window.location !== "undefined" ? window.location.origin : "";
8276
+ if (origin !== "") headers[APP_METADATA_HEADER] = origin;
8277
+ }
8278
+
8266
8279
  // src/realtime/anon-token.ts
8267
8280
  var REFRESH_SKEW_MS = 6e4;
8268
8281
  var AnonTokenProvider = class {
@@ -8305,11 +8318,16 @@ var AnonTokenProvider = class {
8305
8318
  */
8306
8319
  async mint() {
8307
8320
  const base = this.rt.config.url.replace(/\/+$/, "");
8321
+ const headers = {
8322
+ apikey: this.rt.config.apiKey,
8323
+ ...this.rt.config.headers
8324
+ };
8325
+ applyBrowserOriginHeader(headers);
8308
8326
  let response;
8309
8327
  try {
8310
8328
  response = await fetch(`${base}/auth/anonymous`, {
8311
8329
  method: "POST",
8312
- headers: { apikey: this.rt.config.apiKey }
8330
+ headers
8313
8331
  });
8314
8332
  } catch (e) {
8315
8333
  throw new BackendError("network", {
@@ -8950,17 +8968,15 @@ function defaultSessionStorage(key) {
8950
8968
  }
8951
8969
 
8952
8970
  // src/version.ts
8953
- var VERSION = "1.10.0";
8971
+ var VERSION = "2.0.1";
8954
8972
 
8955
8973
  // src/runtime.ts
8956
8974
  function buildRuntime(config) {
8957
- const appIdentifier = config.identifier ?? "";
8958
- const runtimeOrigin = typeof window !== "undefined" && typeof window.location !== "undefined" ? window.location.origin : "";
8959
- assertOriginMatches(loadAppConfig({ identifier: appIdentifier }), runtimeOrigin);
8960
8975
  const http = new HttpClient(config.apiKey, {
8961
8976
  url: config.url,
8962
8977
  headers: { "X-Client-Info": `palbe-web/${VERSION}`, ...config.headers }
8963
8978
  });
8979
+ http.addInterceptor(({ headers }) => applyBrowserOriginHeader(headers));
8964
8980
  const tokenManager = new TokenManager();
8965
8981
  http.tokenManager = tokenManager;
8966
8982
  const authClient = new AuthClient(http, tokenManager);
@@ -9009,7 +9025,6 @@ function buildRuntime(config) {
9009
9025
  let perf;
9010
9026
  const rt = {
9011
9027
  config,
9012
- appIdentifier,
9013
9028
  http,
9014
9029
  tokenManager,
9015
9030
  authClient,
@@ -9168,7 +9183,9 @@ async function buildHeaders(rt, extra) {
9168
9183
  if (token) headers.Authorization = `Bearer ${token}`;
9169
9184
  const callerHasKey = Object.keys(extra ?? {}).some((k) => k.toLowerCase() === "idempotency-key");
9170
9185
  if (!callerHasKey) headers["Idempotency-Key"] = crypto.randomUUID();
9171
- return { ...headers, ...extra };
9186
+ const merged = { ...headers, ...extra };
9187
+ applyBrowserOriginHeader(merged);
9188
+ return merged;
9172
9189
  }
9173
9190
  function buildForm(options) {
9174
9191
  const form = new FormData();