@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.
@@ -1,10 +1,10 @@
1
- import { P as PalbeConfig, d as PalbeRuntime } from './analytics-facade-B7vujhPJ.cjs';
2
- export { e as buildRuntime } from './analytics-facade-B7vujhPJ.cjs';
1
+ import { P as PalbeConfig, d as PalbeRuntime } from './analytics-facade-ChlBRcLZ.cjs';
2
+ export { e as buildRuntime } from './analytics-facade-ChlBRcLZ.cjs';
3
3
  import { B as BackendError } from './errors-fDoNdTrJ.cjs';
4
- export { P as PB, c as createBoundClient } from './pb-6965XULp.cjs';
4
+ export { P as PB, c as createBoundClient } from './pb-B_6o5p79.cjs';
5
5
  import 'livekit-client';
6
6
  import './storage-BPaeSG8K.cjs';
7
- import './pooled-flags-Bwq4usn0.js';
7
+ import './pooled-flags-4GtDtsiu.js';
8
8
 
9
9
  interface EndpointDescriptor {
10
10
  method: string;
@@ -1,10 +1,10 @@
1
- import { P as PalbeConfig, d as PalbeRuntime } from './analytics-facade-CHh5EGC2.js';
2
- export { e as buildRuntime } from './analytics-facade-CHh5EGC2.js';
1
+ import { P as PalbeConfig, d as PalbeRuntime } from './analytics-facade-G0il4NrT.js';
2
+ export { e as buildRuntime } from './analytics-facade-G0il4NrT.js';
3
3
  import { B as BackendError } from './errors-fDoNdTrJ.js';
4
- export { P as PB, c as createBoundClient } from './pb-ChNq987M.js';
4
+ export { P as PB, c as createBoundClient } from './pb-nPBhqhJr.js';
5
5
  import 'livekit-client';
6
6
  import './storage-BPaeSG8K.js';
7
- import './pooled-flags-Bwq4usn0.js';
7
+ import './pooled-flags-4GtDtsiu.js';
8
8
 
9
9
  interface EndpointDescriptor {
10
10
  method: string;
package/dist/internal.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  createBoundClient,
7
7
  getRuntime,
8
8
  onConfigured
9
- } from "./chunk-4ZJHHXD3.js";
9
+ } from "./chunk-AIPUO4QX.js";
10
10
  import "./chunk-PZ5AY32C.js";
11
11
  export {
12
12
  __configure,
@@ -443,12 +443,6 @@ async function palbeRequest(rt, method, path, spec = {}) {
443
443
  if (MUTATING.has(method) && !callerHasKey) {
444
444
  headers["Idempotency-Key"] = crypto.randomUUID();
445
445
  }
446
- if (rt.appIdentifier !== "") {
447
- const callerHasBundle = Object.keys(headers).some(
448
- (k) => k.toLowerCase() === "x-palbase-bundle"
449
- );
450
- if (!callerHasBundle) headers["X-Palbase-Bundle"] = rt.appIdentifier;
451
- }
452
446
  const attempt = async () => {
453
447
  try {
454
448
  return await rt.http.request(method, path, {
@@ -1237,23 +1231,6 @@ var PalbeAnalytics = class {
1237
1231
  }
1238
1232
  };
1239
1233
 
1240
- // src/app-config.ts
1241
- function loadAppConfig(raw) {
1242
- if (typeof raw !== "object" || raw === null) {
1243
- throw new Error("app_config_invalid: expected a JSON object");
1244
- }
1245
- const r = raw;
1246
- const str = (k) => typeof r[k] === "string" ? r[k] : "";
1247
- return { appId: str("app_id"), identifier: str("identifier"), envPreset: str("env_preset") };
1248
- }
1249
- function assertOriginMatches(cfg, runtimeOrigin) {
1250
- if (cfg.identifier === "") return;
1251
- if (runtimeOrigin === "") return;
1252
- if (runtimeOrigin !== cfg.identifier) {
1253
- throw new Error(`app_config_mismatch: expected origin ${cfg.identifier}, got ${runtimeOrigin}`);
1254
- }
1255
- }
1256
-
1257
1234
  // src/auth-wire.ts
1258
1235
  function asWireAuthResult(raw) {
1259
1236
  if (typeof raw !== "object" || raw === null) return null;
@@ -1815,6 +1792,19 @@ var PalbeCalls = class {
1815
1792
 
1816
1793
  // ../modules/flags/dist/index.js
1817
1794
  var FLAG_NAME_RE = /^[a-zA-Z0-9_-]+$/;
1795
+ function flagEnabled(value) {
1796
+ if (typeof value === "boolean") return value;
1797
+ return value != null && value !== 0 && value !== "";
1798
+ }
1799
+ function flagVariant(value) {
1800
+ return typeof value === "string" ? { name: value } : null;
1801
+ }
1802
+ function mapResponse(res, fn) {
1803
+ if (res.error || res.data == null) {
1804
+ return { ...res, data: null };
1805
+ }
1806
+ return { ...res, data: fn(res.data) };
1807
+ }
1818
1808
  var FlagsClient = class {
1819
1809
  httpClient;
1820
1810
  getCurrentUserId;
@@ -1834,10 +1824,11 @@ var FlagsClient = class {
1834
1824
  `Invalid flag name: "${flagName}". Flag names must match ${FLAG_NAME_RE.source}`
1835
1825
  );
1836
1826
  }
1837
- const params = this.buildContextParams(context);
1838
- const query = params.toString();
1839
- const path = `/v1/flags/${flagName}/enabled${query ? `?${query}` : ""}`;
1840
- return this.httpClient.request("GET", path);
1827
+ const res = await this.httpClient.request(
1828
+ "GET",
1829
+ this.mergedPath(context)
1830
+ );
1831
+ return mapResponse(res, (snap) => flagEnabled(snap.values?.[flagName]));
1841
1832
  }
1842
1833
  async getVariant(flagName, context) {
1843
1834
  if (!FLAG_NAME_RE.test(flagName)) {
@@ -1845,16 +1836,29 @@ var FlagsClient = class {
1845
1836
  `Invalid flag name: "${flagName}". Flag names must match ${FLAG_NAME_RE.source}`
1846
1837
  );
1847
1838
  }
1848
- const params = this.buildContextParams(context);
1849
- const query = params.toString();
1850
- const path = `/v1/flags/${flagName}/variant${query ? `?${query}` : ""}`;
1851
- return this.httpClient.request("GET", path);
1839
+ const res = await this.httpClient.request(
1840
+ "GET",
1841
+ this.mergedPath(context)
1842
+ );
1843
+ if (res.error || res.data == null) {
1844
+ return { ...res, data: null };
1845
+ }
1846
+ return { ...res, data: flagVariant(res.data.values?.[flagName]) };
1852
1847
  }
1853
1848
  async getAll(context) {
1854
- const params = this.buildContextParams(context);
1855
- const query = params.toString();
1856
- const path = `/v1/flags${query ? `?${query}` : ""}`;
1857
- return this.httpClient.request("GET", path);
1849
+ const res = await this.httpClient.request(
1850
+ "GET",
1851
+ this.mergedPath(context)
1852
+ );
1853
+ return mapResponse(res, (snap) => {
1854
+ const values = snap.values ?? {};
1855
+ return Object.keys(values).map((name) => {
1856
+ const value = values[name];
1857
+ const flag = { name, enabled: flagEnabled(value) };
1858
+ if (typeof value === "string") flag.variant = { name: value };
1859
+ return flag;
1860
+ });
1861
+ });
1858
1862
  }
1859
1863
  /**
1860
1864
  * Cold-start read: the full merged flag set for the current auth identity.
@@ -1953,15 +1957,16 @@ var FlagsClient = class {
1953
1957
  }
1954
1958
  };
1955
1959
  }
1956
- buildContextParams(context) {
1957
- const params = new URLSearchParams();
1958
- if (context?.userId) {
1959
- params.set("userId", context.userId);
1960
- }
1961
- if (context?.properties) {
1962
- params.set("properties", JSON.stringify(context.properties));
1963
- }
1964
- return params;
1960
+ /**
1961
+ * Resolve the merged-read path for a context. With `context.userId` present the
1962
+ * read targets that specific user's merged view (`/v1/user-flags/users/{id}`, a
1963
+ * privileged cross-user read); otherwise the current auth user's view
1964
+ * (`/v1/user-flags`). `context.properties` has no server-side targeting support
1965
+ * in the user-flags module and is ignored.
1966
+ */
1967
+ mergedPath(context) {
1968
+ const uid = context?.userId;
1969
+ return uid ? `/v1/user-flags/users/${encodeURIComponent(uid)}` : "/v1/user-flags";
1965
1970
  }
1966
1971
  };
1967
1972
  var DEFAULT_POLL_MS = 3e4;
@@ -2423,7 +2428,7 @@ var PalbeFlags = class {
2423
2428
  *
2424
2429
  * DEVIATION from iOS sync-cache parity: the platform does not propagate
2425
2430
  * variant metadata into the user-flags snapshot/delta cache, so this is an
2426
- * ASYNC transport read (`GET /v1/flags/{key}/variant`), not a cache lookup.
2431
+ * ASYNC transport read (derived from `GET /v1/user-flags`), not a cache lookup.
2427
2432
  */
2428
2433
  async getVariant(key) {
2429
2434
  let res;
@@ -8063,6 +8068,14 @@ function observeWebVitals(record) {
8063
8068
  };
8064
8069
  }
8065
8070
 
8071
+ // src/runtime-metadata.ts
8072
+ var APP_METADATA_HEADER = "X-Palbase-Bundle";
8073
+ function applyBrowserOriginHeader(headers) {
8074
+ if (Object.keys(headers).some((key) => key.toLowerCase() === "x-palbase-bundle")) return;
8075
+ const origin = typeof window !== "undefined" && typeof window.location !== "undefined" ? window.location.origin : "";
8076
+ if (origin !== "") headers[APP_METADATA_HEADER] = origin;
8077
+ }
8078
+
8066
8079
  // src/realtime/anon-token.ts
8067
8080
  var REFRESH_SKEW_MS = 6e4;
8068
8081
  var AnonTokenProvider = class {
@@ -8105,11 +8118,16 @@ var AnonTokenProvider = class {
8105
8118
  */
8106
8119
  async mint() {
8107
8120
  const base = this.rt.config.url.replace(/\/+$/, "");
8121
+ const headers = {
8122
+ apikey: this.rt.config.apiKey,
8123
+ ...this.rt.config.headers
8124
+ };
8125
+ applyBrowserOriginHeader(headers);
8108
8126
  let response;
8109
8127
  try {
8110
8128
  response = await fetch(`${base}/auth/anonymous`, {
8111
8129
  method: "POST",
8112
- headers: { apikey: this.rt.config.apiKey }
8130
+ headers
8113
8131
  });
8114
8132
  } catch (e) {
8115
8133
  throw new BackendError("network", {
@@ -8750,17 +8768,15 @@ function defaultSessionStorage(key) {
8750
8768
  }
8751
8769
 
8752
8770
  // src/version.ts
8753
- var VERSION = "1.10.0";
8771
+ var VERSION = "2.0.1";
8754
8772
 
8755
8773
  // src/runtime.ts
8756
8774
  function buildRuntime(config) {
8757
- const appIdentifier = config.identifier ?? "";
8758
- const runtimeOrigin = typeof window !== "undefined" && typeof window.location !== "undefined" ? window.location.origin : "";
8759
- assertOriginMatches(loadAppConfig({ identifier: appIdentifier }), runtimeOrigin);
8760
8775
  const http = new HttpClient(config.apiKey, {
8761
8776
  url: config.url,
8762
8777
  headers: { "X-Client-Info": `palbe-web/${VERSION}`, ...config.headers }
8763
8778
  });
8779
+ http.addInterceptor(({ headers }) => applyBrowserOriginHeader(headers));
8764
8780
  const tokenManager = new TokenManager();
8765
8781
  http.tokenManager = tokenManager;
8766
8782
  const authClient = new AuthClient(http, tokenManager);
@@ -8809,7 +8825,6 @@ function buildRuntime(config) {
8809
8825
  let perf;
8810
8826
  const rt = {
8811
8827
  config,
8812
- appIdentifier,
8813
8828
  http,
8814
8829
  tokenManager,
8815
8830
  authClient,