@palbase/web 2.0.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.
@@ -7,7 +7,7 @@ import {
7
7
  __configure,
8
8
  endpointRefFromApiKey,
9
9
  getRuntime
10
- } from "../chunk-V6VTX65P.js";
10
+ } from "../chunk-AIPUO4QX.js";
11
11
  import "../chunk-PZ5AY32C.js";
12
12
 
13
13
  // src/next/client.ts
@@ -2007,6 +2007,19 @@ var PalbeCalls = class {
2007
2007
 
2008
2008
  // ../modules/flags/dist/index.js
2009
2009
  var FLAG_NAME_RE = /^[a-zA-Z0-9_-]+$/;
2010
+ function flagEnabled(value) {
2011
+ if (typeof value === "boolean") return value;
2012
+ return value != null && value !== 0 && value !== "";
2013
+ }
2014
+ function flagVariant(value) {
2015
+ return typeof value === "string" ? { name: value } : null;
2016
+ }
2017
+ function mapResponse(res, fn) {
2018
+ if (res.error || res.data == null) {
2019
+ return { ...res, data: null };
2020
+ }
2021
+ return { ...res, data: fn(res.data) };
2022
+ }
2010
2023
  var FlagsClient = class {
2011
2024
  httpClient;
2012
2025
  getCurrentUserId;
@@ -2026,10 +2039,11 @@ var FlagsClient = class {
2026
2039
  `Invalid flag name: "${flagName}". Flag names must match ${FLAG_NAME_RE.source}`
2027
2040
  );
2028
2041
  }
2029
- const params = this.buildContextParams(context);
2030
- const query = params.toString();
2031
- const path = `/v1/flags/${flagName}/enabled${query ? `?${query}` : ""}`;
2032
- return this.httpClient.request("GET", path);
2042
+ const res = await this.httpClient.request(
2043
+ "GET",
2044
+ this.mergedPath(context)
2045
+ );
2046
+ return mapResponse(res, (snap) => flagEnabled(snap.values?.[flagName]));
2033
2047
  }
2034
2048
  async getVariant(flagName, context) {
2035
2049
  if (!FLAG_NAME_RE.test(flagName)) {
@@ -2037,16 +2051,29 @@ var FlagsClient = class {
2037
2051
  `Invalid flag name: "${flagName}". Flag names must match ${FLAG_NAME_RE.source}`
2038
2052
  );
2039
2053
  }
2040
- const params = this.buildContextParams(context);
2041
- const query = params.toString();
2042
- const path = `/v1/flags/${flagName}/variant${query ? `?${query}` : ""}`;
2043
- return this.httpClient.request("GET", path);
2054
+ const res = await this.httpClient.request(
2055
+ "GET",
2056
+ this.mergedPath(context)
2057
+ );
2058
+ if (res.error || res.data == null) {
2059
+ return { ...res, data: null };
2060
+ }
2061
+ return { ...res, data: flagVariant(res.data.values?.[flagName]) };
2044
2062
  }
2045
2063
  async getAll(context) {
2046
- const params = this.buildContextParams(context);
2047
- const query = params.toString();
2048
- const path = `/v1/flags${query ? `?${query}` : ""}`;
2049
- return this.httpClient.request("GET", path);
2064
+ const res = await this.httpClient.request(
2065
+ "GET",
2066
+ this.mergedPath(context)
2067
+ );
2068
+ return mapResponse(res, (snap) => {
2069
+ const values = snap.values ?? {};
2070
+ return Object.keys(values).map((name) => {
2071
+ const value = values[name];
2072
+ const flag = { name, enabled: flagEnabled(value) };
2073
+ if (typeof value === "string") flag.variant = { name: value };
2074
+ return flag;
2075
+ });
2076
+ });
2050
2077
  }
2051
2078
  /**
2052
2079
  * Cold-start read: the full merged flag set for the current auth identity.
@@ -2145,15 +2172,16 @@ var FlagsClient = class {
2145
2172
  }
2146
2173
  };
2147
2174
  }
2148
- buildContextParams(context) {
2149
- const params = new URLSearchParams();
2150
- if (context?.userId) {
2151
- params.set("userId", context.userId);
2152
- }
2153
- if (context?.properties) {
2154
- params.set("properties", JSON.stringify(context.properties));
2155
- }
2156
- return params;
2175
+ /**
2176
+ * Resolve the merged-read path for a context. With `context.userId` present the
2177
+ * read targets that specific user's merged view (`/v1/user-flags/users/{id}`, a
2178
+ * privileged cross-user read); otherwise the current auth user's view
2179
+ * (`/v1/user-flags`). `context.properties` has no server-side targeting support
2180
+ * in the user-flags module and is ignored.
2181
+ */
2182
+ mergedPath(context) {
2183
+ const uid = context?.userId;
2184
+ return uid ? `/v1/user-flags/users/${encodeURIComponent(uid)}` : "/v1/user-flags";
2157
2185
  }
2158
2186
  };
2159
2187
  var DEFAULT_POLL_MS = 3e4;
@@ -2615,7 +2643,7 @@ var PalbeFlags = class {
2615
2643
  *
2616
2644
  * DEVIATION from iOS sync-cache parity: the platform does not propagate
2617
2645
  * variant metadata into the user-flags snapshot/delta cache, so this is an
2618
- * ASYNC transport read (`GET /v1/flags/{key}/variant`), not a cache lookup.
2646
+ * ASYNC transport read (derived from `GET /v1/user-flags`), not a cache lookup.
2619
2647
  */
2620
2648
  async getVariant(key) {
2621
2649
  let res;
@@ -8955,7 +8983,7 @@ function defaultSessionStorage(key) {
8955
8983
  }
8956
8984
 
8957
8985
  // src/version.ts
8958
- var VERSION = "2.0.0";
8986
+ var VERSION = "2.0.1";
8959
8987
 
8960
8988
  // src/runtime.ts
8961
8989
  function buildRuntime(config) {