@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.
@@ -1,6 +1,6 @@
1
1
  import { Room, ExternalE2EEKeyProvider } from 'livekit-client';
2
2
  import { S as SessionStorageAdapter } from './storage-BPaeSG8K.cjs';
3
- import { F } from './pooled-flags-Bwq4usn0.js';
3
+ import { F } from './pooled-flags-4GtDtsiu.js';
4
4
 
5
5
  declare class PalbaseError$1 extends Error {
6
6
  readonly code: string;
@@ -622,8 +622,17 @@ interface PalbeConfig {
622
622
  apiKey: string;
623
623
  /** Registered app identity persisted by `palbase web link`. */
624
624
  appId: string;
625
- /** Informational — url+apiKey are already branch-specific (endpointRef embeds the branch slug); gen bakes all three consistently. */
626
- branch?: string;
625
+ /**
626
+ * The ENVIRONMENT this config targets — informational only.
627
+ *
628
+ * `url` and `apiKey` ALREADY identify the environment (the ref is the host
629
+ * label and is embedded in the key), so nothing at runtime reads this: it is
630
+ * here so a developer looking at the generated file can see WHICH runtime it
631
+ * points at. It replaces the old `branch` field — the Palbase branch is gone
632
+ * as a resource, and a second, drift-prone name for the same runtime is
633
+ * exactly how a build ends up talking to production from a staging checkout.
634
+ */
635
+ environmentRef?: string;
627
636
  oauth?: PalbeOAuthConfig;
628
637
  /** Refresh-token persistence. Default: endpoint-scoped localStorage in browsers, memory elsewhere. */
629
638
  storage?: SessionStorageAdapter;
@@ -679,7 +688,7 @@ declare class PalbeFlags {
679
688
  *
680
689
  * DEVIATION from iOS sync-cache parity: the platform does not propagate
681
690
  * variant metadata into the user-flags snapshot/delta cache, so this is an
682
- * ASYNC transport read (`GET /v1/flags/{key}/variant`), not a cache lookup.
691
+ * ASYNC transport read (derived from `GET /v1/user-flags`), not a cache lookup.
683
692
  */
684
693
  getVariant(key: string): Promise<string | null>;
685
694
  /** Subscribe to any change in the cached flag set. */
@@ -1,6 +1,6 @@
1
1
  import { Room, ExternalE2EEKeyProvider } from 'livekit-client';
2
2
  import { S as SessionStorageAdapter } from './storage-BPaeSG8K.js';
3
- import { F } from './pooled-flags-Bwq4usn0.js';
3
+ import { F } from './pooled-flags-4GtDtsiu.js';
4
4
 
5
5
  declare class PalbaseError$1 extends Error {
6
6
  readonly code: string;
@@ -622,8 +622,17 @@ interface PalbeConfig {
622
622
  apiKey: string;
623
623
  /** Registered app identity persisted by `palbase web link`. */
624
624
  appId: string;
625
- /** Informational — url+apiKey are already branch-specific (endpointRef embeds the branch slug); gen bakes all three consistently. */
626
- branch?: string;
625
+ /**
626
+ * The ENVIRONMENT this config targets — informational only.
627
+ *
628
+ * `url` and `apiKey` ALREADY identify the environment (the ref is the host
629
+ * label and is embedded in the key), so nothing at runtime reads this: it is
630
+ * here so a developer looking at the generated file can see WHICH runtime it
631
+ * points at. It replaces the old `branch` field — the Palbase branch is gone
632
+ * as a resource, and a second, drift-prone name for the same runtime is
633
+ * exactly how a build ends up talking to production from a staging checkout.
634
+ */
635
+ environmentRef?: string;
627
636
  oauth?: PalbeOAuthConfig;
628
637
  /** Refresh-token persistence. Default: endpoint-scoped localStorage in browsers, memory elsewhere. */
629
638
  storage?: SessionStorageAdapter;
@@ -679,7 +688,7 @@ declare class PalbeFlags {
679
688
  *
680
689
  * DEVIATION from iOS sync-cache parity: the platform does not propagate
681
690
  * variant metadata into the user-flags snapshot/delta cache, so this is an
682
- * ASYNC transport read (`GET /v1/flags/{key}/variant`), not a cache lookup.
691
+ * ASYNC transport read (derived from `GET /v1/user-flags`), not a cache lookup.
683
692
  */
684
693
  getVariant(key: string): Promise<string | null>;
685
694
  /** Subscribe to any change in the cached flag set. */
@@ -1969,6 +1969,19 @@ var PalbeCalls = class {
1969
1969
 
1970
1970
  // ../modules/flags/dist/index.js
1971
1971
  var FLAG_NAME_RE = /^[a-zA-Z0-9_-]+$/;
1972
+ function flagEnabled(value) {
1973
+ if (typeof value === "boolean") return value;
1974
+ return value != null && value !== 0 && value !== "";
1975
+ }
1976
+ function flagVariant(value) {
1977
+ return typeof value === "string" ? { name: value } : null;
1978
+ }
1979
+ function mapResponse(res, fn) {
1980
+ if (res.error || res.data == null) {
1981
+ return { ...res, data: null };
1982
+ }
1983
+ return { ...res, data: fn(res.data) };
1984
+ }
1972
1985
  var FlagsClient = class {
1973
1986
  httpClient;
1974
1987
  getCurrentUserId;
@@ -1988,10 +2001,11 @@ var FlagsClient = class {
1988
2001
  `Invalid flag name: "${flagName}". Flag names must match ${FLAG_NAME_RE.source}`
1989
2002
  );
1990
2003
  }
1991
- const params = this.buildContextParams(context);
1992
- const query = params.toString();
1993
- const path = `/v1/flags/${flagName}/enabled${query ? `?${query}` : ""}`;
1994
- return this.httpClient.request("GET", path);
2004
+ const res = await this.httpClient.request(
2005
+ "GET",
2006
+ this.mergedPath(context)
2007
+ );
2008
+ return mapResponse(res, (snap) => flagEnabled(snap.values?.[flagName]));
1995
2009
  }
1996
2010
  async getVariant(flagName, context) {
1997
2011
  if (!FLAG_NAME_RE.test(flagName)) {
@@ -1999,16 +2013,29 @@ var FlagsClient = class {
1999
2013
  `Invalid flag name: "${flagName}". Flag names must match ${FLAG_NAME_RE.source}`
2000
2014
  );
2001
2015
  }
2002
- const params = this.buildContextParams(context);
2003
- const query = params.toString();
2004
- const path = `/v1/flags/${flagName}/variant${query ? `?${query}` : ""}`;
2005
- return this.httpClient.request("GET", path);
2016
+ const res = await this.httpClient.request(
2017
+ "GET",
2018
+ this.mergedPath(context)
2019
+ );
2020
+ if (res.error || res.data == null) {
2021
+ return { ...res, data: null };
2022
+ }
2023
+ return { ...res, data: flagVariant(res.data.values?.[flagName]) };
2006
2024
  }
2007
2025
  async getAll(context) {
2008
- const params = this.buildContextParams(context);
2009
- const query = params.toString();
2010
- const path = `/v1/flags${query ? `?${query}` : ""}`;
2011
- return this.httpClient.request("GET", path);
2026
+ const res = await this.httpClient.request(
2027
+ "GET",
2028
+ this.mergedPath(context)
2029
+ );
2030
+ return mapResponse(res, (snap) => {
2031
+ const values = snap.values ?? {};
2032
+ return Object.keys(values).map((name) => {
2033
+ const value = values[name];
2034
+ const flag = { name, enabled: flagEnabled(value) };
2035
+ if (typeof value === "string") flag.variant = { name: value };
2036
+ return flag;
2037
+ });
2038
+ });
2012
2039
  }
2013
2040
  /**
2014
2041
  * Cold-start read: the full merged flag set for the current auth identity.
@@ -2107,15 +2134,16 @@ var FlagsClient = class {
2107
2134
  }
2108
2135
  };
2109
2136
  }
2110
- buildContextParams(context) {
2111
- const params = new URLSearchParams();
2112
- if (context?.userId) {
2113
- params.set("userId", context.userId);
2114
- }
2115
- if (context?.properties) {
2116
- params.set("properties", JSON.stringify(context.properties));
2117
- }
2118
- return params;
2137
+ /**
2138
+ * Resolve the merged-read path for a context. With `context.userId` present the
2139
+ * read targets that specific user's merged view (`/v1/user-flags/users/{id}`, a
2140
+ * privileged cross-user read); otherwise the current auth user's view
2141
+ * (`/v1/user-flags`). `context.properties` has no server-side targeting support
2142
+ * in the user-flags module and is ignored.
2143
+ */
2144
+ mergedPath(context) {
2145
+ const uid = context?.userId;
2146
+ return uid ? `/v1/user-flags/users/${encodeURIComponent(uid)}` : "/v1/user-flags";
2119
2147
  }
2120
2148
  };
2121
2149
  var DEFAULT_POLL_MS = 3e4;
@@ -2577,7 +2605,7 @@ var PalbeFlags = class {
2577
2605
  *
2578
2606
  * DEVIATION from iOS sync-cache parity: the platform does not propagate
2579
2607
  * variant metadata into the user-flags snapshot/delta cache, so this is an
2580
- * ASYNC transport read (`GET /v1/flags/{key}/variant`), not a cache lookup.
2608
+ * ASYNC transport read (derived from `GET /v1/user-flags`), not a cache lookup.
2581
2609
  */
2582
2610
  async getVariant(key) {
2583
2611
  let res;
@@ -8916,7 +8944,7 @@ function defaultSessionStorage(key) {
8916
8944
  }
8917
8945
 
8918
8946
  // src/version.ts
8919
- var VERSION = "2.0.0";
8947
+ var VERSION = "2.0.1";
8920
8948
 
8921
8949
  // src/runtime.ts
8922
8950
  function buildRuntime(config) {
@@ -9329,4 +9357,4 @@ export {
9329
9357
  pb,
9330
9358
  createBoundClient
9331
9359
  };
9332
- //# sourceMappingURL=chunk-V6VTX65P.js.map
9360
+ //# sourceMappingURL=chunk-AIPUO4QX.js.map