@palbase/web 2.0.1 → 3.0.0

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 (47) hide show
  1. package/README.md +11 -9
  2. package/dist/{analytics-facade-ChlBRcLZ.d.cts → analytics-facade-BOxQ8IP2.d.cts} +8 -16
  3. package/dist/{analytics-facade-G0il4NrT.d.ts → analytics-facade-yfMJ69vw.d.ts} +8 -16
  4. package/dist/{chunk-AIPUO4QX.js → chunk-3HVTEZ7N.js} +30 -36
  5. package/dist/chunk-3HVTEZ7N.js.map +1 -0
  6. package/dist/{chunk-VJXFABBW.js → chunk-6VGKMNXO.js} +11 -11
  7. package/dist/chunk-6VGKMNXO.js.map +1 -0
  8. package/dist/chunk-S7NAY3MW.js +24 -0
  9. package/dist/chunk-S7NAY3MW.js.map +1 -0
  10. package/dist/gen/cli.cjs +32 -6
  11. package/dist/gen/cli.cjs.map +1 -1
  12. package/dist/gen/cli.js +28 -7
  13. package/dist/gen/cli.js.map +1 -1
  14. package/dist/index.cjs +3 -10
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +3 -3
  17. package/dist/index.d.ts +3 -3
  18. package/dist/index.js +2 -2
  19. package/dist/internal.cjs +33 -32
  20. package/dist/internal.cjs.map +1 -1
  21. package/dist/internal.d.cts +3 -3
  22. package/dist/internal.d.ts +3 -3
  23. package/dist/internal.js +2 -2
  24. package/dist/next/client.cjs +50 -46
  25. package/dist/next/client.cjs.map +1 -1
  26. package/dist/next/client.d.cts +1 -1
  27. package/dist/next/client.d.ts +1 -1
  28. package/dist/next/client.js +12 -10
  29. package/dist/next/client.js.map +1 -1
  30. package/dist/next/index.cjs +53 -47
  31. package/dist/next/index.cjs.map +1 -1
  32. package/dist/next/index.d.cts +10 -10
  33. package/dist/next/index.d.ts +10 -10
  34. package/dist/next/index.js +14 -13
  35. package/dist/next/index.js.map +1 -1
  36. package/dist/{pb-B_6o5p79.d.cts → pb-B3h3NIPE.d.cts} +1 -1
  37. package/dist/{pb-nPBhqhJr.d.ts → pb-QRISxPd1.d.ts} +1 -1
  38. package/dist/react/index.cjs +1 -1
  39. package/dist/react/index.cjs.map +1 -1
  40. package/dist/react/index.d.cts +1 -1
  41. package/dist/react/index.d.ts +1 -1
  42. package/dist/react/index.js +2 -2
  43. package/package.json +2 -2
  44. package/dist/chunk-AIPUO4QX.js.map +0 -1
  45. package/dist/chunk-PZ5AY32C.js +0 -10
  46. package/dist/chunk-PZ5AY32C.js.map +0 -1
  47. package/dist/chunk-VJXFABBW.js.map +0 -1
@@ -1,7 +1,7 @@
1
- import { P as PalbeConfig, d as PalbeRuntime } from './analytics-facade-ChlBRcLZ.cjs';
2
- export { e as buildRuntime } from './analytics-facade-ChlBRcLZ.cjs';
1
+ import { P as PalbeConfig, d as PalbeRuntime } from './analytics-facade-BOxQ8IP2.cjs';
2
+ export { e as buildRuntime } from './analytics-facade-BOxQ8IP2.cjs';
3
3
  import { B as BackendError } from './errors-fDoNdTrJ.cjs';
4
- export { P as PB, c as createBoundClient } from './pb-B_6o5p79.cjs';
4
+ export { P as PB, c as createBoundClient } from './pb-B3h3NIPE.cjs';
5
5
  import 'livekit-client';
6
6
  import './storage-BPaeSG8K.cjs';
7
7
  import './pooled-flags-4GtDtsiu.js';
@@ -1,7 +1,7 @@
1
- import { P as PalbeConfig, d as PalbeRuntime } from './analytics-facade-G0il4NrT.js';
2
- export { e as buildRuntime } from './analytics-facade-G0il4NrT.js';
1
+ import { P as PalbeConfig, d as PalbeRuntime } from './analytics-facade-yfMJ69vw.js';
2
+ export { e as buildRuntime } from './analytics-facade-yfMJ69vw.js';
3
3
  import { B as BackendError } from './errors-fDoNdTrJ.js';
4
- export { P as PB, c as createBoundClient } from './pb-nPBhqhJr.js';
4
+ export { P as PB, c as createBoundClient } from './pb-QRISxPd1.js';
5
5
  import 'livekit-client';
6
6
  import './storage-BPaeSG8K.js';
7
7
  import './pooled-flags-4GtDtsiu.js';
package/dist/internal.js CHANGED
@@ -6,8 +6,8 @@ import {
6
6
  createBoundClient,
7
7
  getRuntime,
8
8
  onConfigured
9
- } from "./chunk-AIPUO4QX.js";
10
- import "./chunk-PZ5AY32C.js";
9
+ } from "./chunk-3HVTEZ7N.js";
10
+ import "./chunk-S7NAY3MW.js";
11
11
  export {
12
12
  __configure,
13
13
  __registerNamespaces,
@@ -40,18 +40,9 @@ var PalbaseError = class extends Error {
40
40
  }
41
41
  };
42
42
  var PALBASE_DEFAULT_HOST = "api.palbase.studio";
43
- var REF_LEN = 8;
44
- var BASE62_RE = /^[0-9A-Za-z]+$/;
45
- function parseProjectRef(apiKey) {
46
- if (apiKey.length < 13) return null;
47
- if (!apiKey.startsWith("pb_")) return null;
48
- if (apiKey[11] !== "_") return null;
49
- const ref = apiKey.slice(3, 11);
50
- if (ref.length !== REF_LEN) return null;
51
- if (!BASE62_RE.test(ref)) return null;
52
- const scope = apiKey[12];
53
- if (scope !== "c") return null;
54
- return ref;
43
+ var API_KEY_RE = /^pb_([a-z0-9]+)_c[A-Za-z0-9]{20}$/;
44
+ function parseEnvironmentRef(apiKey) {
45
+ return API_KEY_RE.exec(apiKey)?.[1] ?? null;
55
46
  }
56
47
  var MAX_RETRIES = 3;
57
48
  var INITIAL_BACKOFF_MS = 200;
@@ -81,8 +72,7 @@ var HttpClient = class _HttpClient {
81
72
  * with the parent at runtime — later changes on the parent propagate to
82
73
  * the scope and vice versa.
83
74
  *
84
- * Typical use: tagging admin calls with `x-palbase-project: <ref>` so the
85
- * gateway can route them to the correct project's data plane.
75
+ * Typical use: adding an Environment-routing header for an admin call.
86
76
  */
87
77
  withHeaders(extra) {
88
78
  const mergedHeaders = { ...this.options?.headers ?? {}, ...extra };
@@ -123,10 +113,10 @@ var HttpClient = class _HttpClient {
123
113
  if (this.options?.url) {
124
114
  return this.options.url;
125
115
  }
126
- if (this.apiKey && parseProjectRef(this.apiKey) === null) {
116
+ if (this.apiKey && parseEnvironmentRef(this.apiKey) === null) {
127
117
  throw new PalbaseError(
128
118
  "invalid_api_key",
129
- 'Invalid API key format. Expected pb_{ref}_{scope}{random}. For dev/staging pass `url: "https://api.dev.palbase.studio"` via options.',
119
+ 'Invalid API key format. Expected pb_{environment_ref}_c{20_base62_chars}. For dev/staging pass `url: "https://api.dev.palbase.studio"` via options.',
130
120
  0
131
121
  );
132
122
  }
@@ -139,10 +129,6 @@ var HttpClient = class _HttpClient {
139
129
  const effectiveKey = this.apiKey;
140
130
  if (effectiveKey) {
141
131
  headers["apikey"] = effectiveKey;
142
- const ref = parseProjectRef(effectiveKey);
143
- if (ref) {
144
- headers["X-Project-Ref"] = ref;
145
- }
146
132
  }
147
133
  const token = this.tokenManager?.getAccessToken();
148
134
  if (token) {
@@ -953,13 +939,6 @@ var AuthClient = class {
953
939
  }
954
940
  };
955
941
 
956
- // src/api-key.ts
957
- var API_KEY_RE = /^pb_([^_]+)_[cs][A-Za-z0-9]{20}$/;
958
- function endpointRefFromApiKey(apiKey) {
959
- const m = API_KEY_RE.exec(apiKey);
960
- return m ? m[1] ?? "" : "";
961
- }
962
-
963
942
  // src/analytics-facade.ts
964
943
  var EVENT_NAME_RE = /^[a-zA-Z$][a-zA-Z0-9_.:$-]{0,63}$/;
965
944
  var FLUSH_AT = 20;
@@ -1017,7 +996,7 @@ var AnalyticsState = class {
1017
996
  idKey;
1018
997
  optOutKey;
1019
998
  constructor(rt) {
1020
- const ref = endpointRefFromApiKey(rt.config.apiKey);
999
+ const ref = rt.config.environmentRef;
1021
1000
  this.idKey = ref ? `palbe.analytics.id.${ref}` : "palbe.analytics.id";
1022
1001
  this.optOutKey = ref ? `palbe.analytics.optout.${ref}` : "palbe.analytics.optout";
1023
1002
  rt.auth.onAuthEvent((event) => {
@@ -1231,6 +1210,13 @@ var PalbeAnalytics = class {
1231
1210
  }
1232
1211
  };
1233
1212
 
1213
+ // src/api-key.ts
1214
+ var PUBLISHABLE_API_KEY_RE = /^pb_([a-z0-9]+)_c[A-Za-z0-9]{20}$/;
1215
+ function environmentRefFromPublishableApiKey(apiKey) {
1216
+ const match = PUBLISHABLE_API_KEY_RE.exec(apiKey);
1217
+ return match ? match[1] ?? "" : "";
1218
+ }
1219
+
1234
1220
  // src/auth-wire.ts
1235
1221
  function asWireAuthResult(raw) {
1236
1222
  if (typeof raw !== "object" || raw === null) return null;
@@ -2371,7 +2357,7 @@ var PalbeFlags = class {
2371
2357
  constructor(rt) {
2372
2358
  this.transport = new FlagsClient(rt.http);
2373
2359
  const browser = typeof document !== "undefined";
2374
- const ref = endpointRefFromApiKey(rt.config.apiKey);
2360
+ const ref = rt.config.environmentRef;
2375
2361
  const options = {
2376
2362
  auth: palbeAuthAdapter(rt.auth),
2377
2363
  ...ref ? { storageKey: `palbe.flags.${ref}` } : {},
@@ -8111,7 +8097,7 @@ var AnonTokenProvider = class {
8111
8097
  }
8112
8098
  /**
8113
8099
  * Raw fetch, deliberately NOT through HttpClient/palbeRequest: the mint
8114
- * must carry the project apikey and NEVER a Bearer (iOS keeps
8100
+ * must carry the Environment API key and NEVER a Bearer (iOS keeps
8115
8101
  * `/auth/anonymous` on the unauthenticated-path list), and HttpClient's
8116
8102
  * pre-flight would try to refresh a stale session before an anon mint —
8117
8103
  * exactly the entanglement this provider exists to avoid.
@@ -8768,10 +8754,25 @@ function defaultSessionStorage(key) {
8768
8754
  }
8769
8755
 
8770
8756
  // src/version.ts
8771
- var VERSION = "2.0.1";
8757
+ var VERSION = "3.0.0";
8772
8758
 
8773
8759
  // src/runtime.ts
8774
8760
  function buildRuntime(config) {
8761
+ const keyEnvironmentRef = environmentRefFromPublishableApiKey(config.apiKey);
8762
+ if (keyEnvironmentRef === "") {
8763
+ throw new Error("PalbeConfig.apiKey does not contain a valid publishable Environment identity");
8764
+ } else if (config.environmentRef !== keyEnvironmentRef) {
8765
+ throw new Error("PalbeConfig.environmentRef must match the Environment identity in apiKey");
8766
+ }
8767
+ let runtimeURL;
8768
+ try {
8769
+ runtimeURL = new URL(config.url);
8770
+ } catch {
8771
+ throw new Error("PalbeConfig.url must be a valid URL");
8772
+ }
8773
+ if (runtimeURL.hostname.endsWith(".palbase.studio") && runtimeURL.hostname.split(".")[0] !== config.environmentRef) {
8774
+ throw new Error("PalbeConfig.url must match environmentRef for palbase.studio");
8775
+ }
8775
8776
  const http = new HttpClient(config.apiKey, {
8776
8777
  url: config.url,
8777
8778
  headers: { "X-Client-Info": `palbe-web/${VERSION}`, ...config.headers }
@@ -8780,7 +8781,7 @@ function buildRuntime(config) {
8780
8781
  const tokenManager = new TokenManager();
8781
8782
  http.tokenManager = tokenManager;
8782
8783
  const authClient = new AuthClient(http, tokenManager);
8783
- const ref = endpointRefFromApiKey(config.apiKey);
8784
+ const ref = config.environmentRef;
8784
8785
  const storage = config.storage ?? defaultSessionStorage(ref ? `palbe.session.${ref}` : void 0);
8785
8786
  const persisted = storage.load();
8786
8787
  if (persisted) {
@@ -8938,11 +8939,11 @@ function getRuntime() {
8938
8939
 
8939
8940
  // src/next/cookie-codec.ts
8940
8941
  var MAX_COOKIE_VALUE = 3500;
8941
- function sessionCookieName(endpointRef) {
8942
- return `palbe-session-${endpointRef}`;
8942
+ function sessionCookieName(environmentRef) {
8943
+ return `palbe-session-${environmentRef}`;
8943
8944
  }
8944
- function encodeSessionCookies(endpointRef, session) {
8945
- const name = sessionCookieName(endpointRef);
8945
+ function encodeSessionCookies(environmentRef, session) {
8946
+ const name = sessionCookieName(environmentRef);
8946
8947
  const value = encodeURIComponent(
8947
8948
  JSON.stringify({ a: session.accessToken, r: session.refreshToken, e: session.expiresAt })
8948
8949
  );
@@ -8961,8 +8962,8 @@ function encodeSessionCookies(endpointRef, session) {
8961
8962
  }
8962
8963
  return { set: chunks, clear: [`${name}.${chunks.length}`] };
8963
8964
  }
8964
- function decodeSessionCookies(get, endpointRef) {
8965
- const base = sessionCookieName(endpointRef);
8965
+ function decodeSessionCookies(get, environmentRef) {
8966
+ const base = sessionCookieName(environmentRef);
8966
8967
  let encoded = get(base);
8967
8968
  if (encoded === void 0) {
8968
8969
  let joined = "";
@@ -8996,8 +8997,8 @@ function parseStoredSession(json) {
8996
8997
  return null;
8997
8998
  }
8998
8999
  }
8999
- function clearedSessionCookieNames(endpointRef, present) {
9000
- const base = sessionCookieName(endpointRef);
9000
+ function clearedSessionCookieNames(environmentRef, present) {
9001
+ const base = sessionCookieName(environmentRef);
9001
9002
  const names = [];
9002
9003
  if (present(base)) names.push(base);
9003
9004
  for (let i = 0; ; i++) {
@@ -9024,12 +9025,12 @@ function cookieJar() {
9024
9025
  function deleteCookie(name) {
9025
9026
  document.cookie = `${name}=; ${WRITE_ATTRS}; Max-Age=0`;
9026
9027
  }
9027
- function cookieSessionStorage(endpointRef) {
9028
+ function cookieSessionStorage(environmentRef) {
9028
9029
  return {
9029
9030
  load() {
9030
9031
  if (typeof document === "undefined") return null;
9031
9032
  const jar = cookieJar();
9032
- const stored = decodeSessionCookies((name) => jar.get(name), endpointRef);
9033
+ const stored = decodeSessionCookies((name) => jar.get(name), environmentRef);
9033
9034
  if (!stored) return null;
9034
9035
  return stored.accessToken && stored.expiresAt > 0 ? {
9035
9036
  refreshToken: stored.refreshToken,
@@ -9040,10 +9041,10 @@ function cookieSessionStorage(endpointRef) {
9040
9041
  save(session) {
9041
9042
  if (typeof document === "undefined") return;
9042
9043
  const jar = cookieJar();
9043
- for (const name of clearedSessionCookieNames(endpointRef, (n) => jar.has(n))) {
9044
+ for (const name of clearedSessionCookieNames(environmentRef, (n) => jar.has(n))) {
9044
9045
  deleteCookie(name);
9045
9046
  }
9046
- const { set, clear } = encodeSessionCookies(endpointRef, {
9047
+ const { set, clear } = encodeSessionCookies(environmentRef, {
9047
9048
  accessToken: session.accessToken ?? "",
9048
9049
  refreshToken: session.refreshToken,
9049
9050
  expiresAt: session.expiresAt ?? 0
@@ -9056,7 +9057,7 @@ function cookieSessionStorage(endpointRef) {
9056
9057
  clear() {
9057
9058
  if (typeof document === "undefined") return;
9058
9059
  const jar = cookieJar();
9059
- for (const name of clearedSessionCookieNames(endpointRef, (n) => jar.has(n))) {
9060
+ for (const name of clearedSessionCookieNames(environmentRef, (n) => jar.has(n))) {
9060
9061
  deleteCookie(name);
9061
9062
  }
9062
9063
  }
@@ -9065,7 +9066,10 @@ function cookieSessionStorage(endpointRef) {
9065
9066
  function setupPalbeNext() {
9066
9067
  if (typeof document === "undefined") return;
9067
9068
  const config = getRuntime().config;
9068
- __configure({ ...config, storage: cookieSessionStorage(endpointRefFromApiKey(config.apiKey)) });
9069
+ __configure({
9070
+ ...config,
9071
+ storage: cookieSessionStorage(config.environmentRef)
9072
+ });
9069
9073
  }
9070
9074
  // Annotate the CommonJS export names for ESM import in node:
9071
9075
  0 && (module.exports = {