@palbase/web 2.0.1 → 4.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-DwOtlXPP.d.cts} +13 -103
  3. package/dist/{analytics-facade-G0il4NrT.d.ts → analytics-facade-Nk6J9Ncm.d.ts} +13 -103
  4. package/dist/{chunk-VJXFABBW.js → chunk-6VGKMNXO.js} +11 -11
  5. package/dist/chunk-6VGKMNXO.js.map +1 -0
  6. package/dist/{chunk-AIPUO4QX.js → chunk-NP4NIY7A.js} +52 -48
  7. package/dist/chunk-NP4NIY7A.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 +25 -22
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +3 -4
  17. package/dist/index.d.ts +3 -4
  18. package/dist/index.js +2 -2
  19. package/dist/internal.cjs +55 -44
  20. package/dist/internal.cjs.map +1 -1
  21. package/dist/internal.d.cts +4 -16
  22. package/dist/internal.d.ts +4 -16
  23. package/dist/internal.js +2 -2
  24. package/dist/next/client.cjs +72 -58
  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 +75 -59
  31. package/dist/next/index.cjs.map +1 -1
  32. package/dist/next/index.d.cts +10 -11
  33. package/dist/next/index.d.ts +10 -11
  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-C9v5dEO6.d.cts} +1 -1
  37. package/dist/{pb-nPBhqhJr.d.ts → pb-FG_nV7NR.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 -2
  41. package/dist/react/index.d.ts +1 -2
  42. package/dist/react/index.js +2 -2
  43. package/package.json +3 -3
  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
package/dist/index.d.cts CHANGED
@@ -1,9 +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-ChlBRcLZ.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-DwOtlXPP.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-B_6o5p79.cjs';
3
+ export { C as CallOptions, P as PB, U as UploadOptions, a as UploadProgress, p as pb } from './pb-C9v5dEO6.cjs';
4
4
  export { P as PersistedSession, S as SessionStorageAdapter, l as localStorageSessionStorage, m as memorySessionStorage } from './storage-BPaeSG8K.cjs';
5
5
  export { F as FlagValue } from './pooled-flags-4GtDtsiu.js';
6
- import 'livekit-client';
7
6
 
8
7
  /* tslint:disable */
9
8
  /* eslint-disable */
@@ -207,6 +206,6 @@ interface MlsGlue {
207
206
  */
208
207
  declare function initMls(): Promise<MlsGlue>;
209
208
 
210
- declare const VERSION = "2.0.1";
209
+ declare const VERSION = "4.0.0";
211
210
 
212
211
  export { VERSION, initMls };
package/dist/index.d.ts CHANGED
@@ -1,9 +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-G0il4NrT.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-Nk6J9Ncm.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-nPBhqhJr.js';
3
+ export { C as CallOptions, P as PB, U as UploadOptions, a as UploadProgress, p as pb } from './pb-FG_nV7NR.js';
4
4
  export { P as PersistedSession, S as SessionStorageAdapter, l as localStorageSessionStorage, m as memorySessionStorage } from './storage-BPaeSG8K.js';
5
5
  export { F as FlagValue } from './pooled-flags-4GtDtsiu.js';
6
- import 'livekit-client';
7
6
 
8
7
  /* tslint:disable */
9
8
  /* eslint-disable */
@@ -207,6 +206,6 @@ interface MlsGlue {
207
206
  */
208
207
  declare function initMls(): Promise<MlsGlue>;
209
208
 
210
- declare const VERSION = "2.0.1";
209
+ declare const VERSION = "4.0.0";
211
210
 
212
211
  export { VERSION, initMls };
package/dist/index.js CHANGED
@@ -13,8 +13,8 @@ import {
13
13
  localStorageSessionStorage,
14
14
  memorySessionStorage,
15
15
  pb
16
- } from "./chunk-AIPUO4QX.js";
17
- import "./chunk-PZ5AY32C.js";
16
+ } from "./chunk-NP4NIY7A.js";
17
+ import "./chunk-S7NAY3MW.js";
18
18
  export {
19
19
  BackendError,
20
20
  PalbeAnalytics,
package/dist/internal.cjs CHANGED
@@ -45,18 +45,9 @@ var PalbaseError = class extends Error {
45
45
  }
46
46
  };
47
47
  var PALBASE_DEFAULT_HOST = "api.palbase.studio";
48
- var REF_LEN = 8;
49
- var BASE62_RE = /^[0-9A-Za-z]+$/;
50
- function parseProjectRef(apiKey) {
51
- if (apiKey.length < 13) return null;
52
- if (!apiKey.startsWith("pb_")) return null;
53
- if (apiKey[11] !== "_") return null;
54
- const ref = apiKey.slice(3, 11);
55
- if (ref.length !== REF_LEN) return null;
56
- if (!BASE62_RE.test(ref)) return null;
57
- const scope = apiKey[12];
58
- if (scope !== "c") return null;
59
- return ref;
48
+ var API_KEY_RE = /^pb_([a-z0-9]+)_c[A-Za-z0-9]{20}$/;
49
+ function parseEnvironmentRef(apiKey) {
50
+ return API_KEY_RE.exec(apiKey)?.[1] ?? null;
60
51
  }
61
52
  var MAX_RETRIES = 3;
62
53
  var INITIAL_BACKOFF_MS = 200;
@@ -86,8 +77,7 @@ var HttpClient = class _HttpClient {
86
77
  * with the parent at runtime — later changes on the parent propagate to
87
78
  * the scope and vice versa.
88
79
  *
89
- * Typical use: tagging admin calls with `x-palbase-project: <ref>` so the
90
- * gateway can route them to the correct project's data plane.
80
+ * Typical use: adding an Environment-routing header for an admin call.
91
81
  */
92
82
  withHeaders(extra) {
93
83
  const mergedHeaders = { ...this.options?.headers ?? {}, ...extra };
@@ -128,10 +118,10 @@ var HttpClient = class _HttpClient {
128
118
  if (this.options?.url) {
129
119
  return this.options.url;
130
120
  }
131
- if (this.apiKey && parseProjectRef(this.apiKey) === null) {
121
+ if (this.apiKey && parseEnvironmentRef(this.apiKey) === null) {
132
122
  throw new PalbaseError(
133
123
  "invalid_api_key",
134
- 'Invalid API key format. Expected pb_{ref}_{scope}{random}. For dev/staging pass `url: "https://api.dev.palbase.studio"` via options.',
124
+ 'Invalid API key format. Expected pb_{environment_ref}_c{20_base62_chars}. For dev/staging pass `url: "https://api.dev.palbase.studio"` via options.',
135
125
  0
136
126
  );
137
127
  }
@@ -144,10 +134,6 @@ var HttpClient = class _HttpClient {
144
134
  const effectiveKey = this.apiKey;
145
135
  if (effectiveKey) {
146
136
  headers["apikey"] = effectiveKey;
147
- const ref = parseProjectRef(effectiveKey);
148
- if (ref) {
149
- headers["X-Project-Ref"] = ref;
150
- }
151
137
  }
152
138
  const token = this.tokenManager?.getAccessToken();
153
139
  if (token) {
@@ -1153,13 +1139,6 @@ var AuthClient = class {
1153
1139
  }
1154
1140
  };
1155
1141
 
1156
- // src/api-key.ts
1157
- var API_KEY_RE = /^pb_([^_]+)_[cs][A-Za-z0-9]{20}$/;
1158
- function endpointRefFromApiKey(apiKey) {
1159
- const m = API_KEY_RE.exec(apiKey);
1160
- return m ? m[1] ?? "" : "";
1161
- }
1162
-
1163
1142
  // src/analytics-facade.ts
1164
1143
  var EVENT_NAME_RE = /^[a-zA-Z$][a-zA-Z0-9_.:$-]{0,63}$/;
1165
1144
  var FLUSH_AT = 20;
@@ -1217,7 +1196,7 @@ var AnalyticsState = class {
1217
1196
  idKey;
1218
1197
  optOutKey;
1219
1198
  constructor(rt) {
1220
- const ref = endpointRefFromApiKey(rt.config.apiKey);
1199
+ const ref = rt.config.environmentRef;
1221
1200
  this.idKey = ref ? `palbe.analytics.id.${ref}` : "palbe.analytics.id";
1222
1201
  this.optOutKey = ref ? `palbe.analytics.optout.${ref}` : "palbe.analytics.optout";
1223
1202
  rt.auth.onAuthEvent((event) => {
@@ -1431,6 +1410,13 @@ var PalbeAnalytics = class {
1431
1410
  }
1432
1411
  };
1433
1412
 
1413
+ // src/api-key.ts
1414
+ var PUBLISHABLE_API_KEY_RE = /^pb_([a-z0-9]+)_c[A-Za-z0-9]{20}$/;
1415
+ function environmentRefFromPublishableApiKey(apiKey) {
1416
+ const match = PUBLISHABLE_API_KEY_RE.exec(apiKey);
1417
+ return match ? match[1] ?? "" : "";
1418
+ }
1419
+
1434
1420
  // src/auth-wire.ts
1435
1421
  function asWireAuthResult(raw) {
1436
1422
  if (typeof raw !== "object" || raw === null) return null;
@@ -1778,19 +1764,29 @@ var PalbeAuth = class {
1778
1764
 
1779
1765
  // src/calls/facade.ts
1780
1766
  var import_livekit_client = require("livekit-client");
1781
- var Call = class {
1767
+ var Call = class _Call {
1782
1768
  id;
1783
1769
  _state = "connecting";
1784
1770
  _participants = /* @__PURE__ */ new Map();
1785
1771
  _listeners = /* @__PURE__ */ new Set();
1786
1772
  _room;
1787
1773
  _keyProvider;
1788
- /** @internal obtain via PalbeCalls.start() / .accept() */
1774
+ // PRIVATE constructor + `@internal` factory: the media-engine types (`Room`,
1775
+ // `ExternalE2EEKeyProvider`) appear ONLY on a private constructor and an
1776
+ // `@internal` static factory, both of which `stripInternal` (set in this
1777
+ // package's tsconfig) removes from the emitted public `.d.ts`. So no engine type
1778
+ // ever reaches the public API surface — the same "no engine type in the public
1779
+ // interface" contract the iOS SDK enforces. Consumers obtain a `Call` only
1780
+ // through `pb.calls.start()` / `.accept()`.
1789
1781
  constructor(callId, room, keyProvider) {
1790
1782
  this.id = callId;
1791
1783
  this._room = room;
1792
1784
  this._keyProvider = keyProvider;
1793
- this._wireRoomEvents();
1785
+ this._wireMediaEvents();
1786
+ }
1787
+ /** @internal — facade-only factory; stripped from the public `.d.ts`. */
1788
+ static _create(callId, room, keyProvider) {
1789
+ return new _Call(callId, room, keyProvider);
1794
1790
  }
1795
1791
  // ─── State ──────────────────────────────────────────────────────────────
1796
1792
  get state() {
@@ -1800,9 +1796,9 @@ var Call = class {
1800
1796
  get participants() {
1801
1797
  return Array.from(this._participants.values());
1802
1798
  }
1803
- get localParticipant() {
1804
- return this._room.localParticipant;
1805
- }
1799
+ // (No `localParticipant` accessor: it would return a raw media-engine participant
1800
+ // object and leak the engine type onto the public API. Local mic/camera control is
1801
+ // exposed engine-agnostically via `mute()` / `setCamera()` below.)
1806
1802
  // ─── Subscribe ──────────────────────────────────────────────────────────
1807
1803
  /**
1808
1804
  * Subscribe to call changes (state + participant updates).
@@ -1826,7 +1822,7 @@ var Call = class {
1826
1822
  /**
1827
1823
  * Set a raw frame encryption key (ArrayBuffer) for this call.
1828
1824
  * Design seam for SP-1.x web-MLS: call this with the MLS exporter secret
1829
- * to enable frame-level E2EE via ExternalE2EEKeyProvider.
1825
+ * to enable frame-level E2EE via the media engine's external key provider.
1830
1826
  *
1831
1827
  * NOTE: The room must have been opened with `e2ee` options for this to take
1832
1828
  * effect. Currently calls connect WITHOUT e2ee — see module docstring.
@@ -1836,7 +1832,7 @@ var Call = class {
1836
1832
  async setMediaKey(key) {
1837
1833
  await this._keyProvider.setKey(key);
1838
1834
  }
1839
- /** Leave the call and disconnect from the LiveKit room. */
1835
+ /** Leave the call and disconnect from the media room. */
1840
1836
  async leave() {
1841
1837
  await this._room.disconnect();
1842
1838
  this._setState("ended");
@@ -1878,7 +1874,7 @@ var Call = class {
1878
1874
  }
1879
1875
  this._emit();
1880
1876
  }
1881
- _wireRoomEvents() {
1877
+ _wireMediaEvents() {
1882
1878
  this._room.on(import_livekit_client.RoomEvent.Connected, () => {
1883
1879
  this._setState("active");
1884
1880
  }).on(
@@ -1919,9 +1915,9 @@ var PalbeCalls = class {
1919
1915
  *
1920
1916
  * @param groupId - Messaging group display-id (`grp_<uuidv7>`)
1921
1917
  * @param media - Which media tracks to publish (default: audio + video)
1922
- * @returns A `Call` in `connecting` state; transitions to `active` once LiveKit connects.
1918
+ * @returns A `Call` in `connecting` state; transitions to `active` once the media room connects.
1923
1919
  *
1924
- * @throws BackendError('network', { code: 'call_service_unavailable' }) if LiveKit SFU is down (503)
1920
+ * @throws BackendError('network', { code: 'call_service_unavailable' }) if the SFU is down (503)
1925
1921
  * @throws BackendError('forbidden', { code: 'not_group_member' }) if the caller is not a member (403)
1926
1922
  * @throws BackendError('conflict', { code: 'call_room_full' }) if the room is full (409)
1927
1923
  */
@@ -1978,7 +1974,7 @@ var PalbeCalls = class {
1978
1974
  adaptiveStream: true,
1979
1975
  dynacast: true
1980
1976
  });
1981
- const call = new Call(callId, room, keyProvider);
1977
+ const call = Call._create(callId, room, keyProvider);
1982
1978
  await room.connect(edgeUrl, token);
1983
1979
  if (media.includes("audio")) {
1984
1980
  await room.localParticipant.setMicrophoneEnabled(true);
@@ -2571,7 +2567,7 @@ var PalbeFlags = class {
2571
2567
  constructor(rt) {
2572
2568
  this.transport = new FlagsClient(rt.http);
2573
2569
  const browser = typeof document !== "undefined";
2574
- const ref = endpointRefFromApiKey(rt.config.apiKey);
2570
+ const ref = rt.config.environmentRef;
2575
2571
  const options = {
2576
2572
  auth: palbeAuthAdapter(rt.auth),
2577
2573
  ...ref ? { storageKey: `palbe.flags.${ref}` } : {},
@@ -8311,7 +8307,7 @@ var AnonTokenProvider = class {
8311
8307
  }
8312
8308
  /**
8313
8309
  * Raw fetch, deliberately NOT through HttpClient/palbeRequest: the mint
8314
- * must carry the project apikey and NEVER a Bearer (iOS keeps
8310
+ * must carry the Environment API key and NEVER a Bearer (iOS keeps
8315
8311
  * `/auth/anonymous` on the unauthenticated-path list), and HttpClient's
8316
8312
  * pre-flight would try to refresh a stale session before an anon mint —
8317
8313
  * exactly the entanglement this provider exists to avoid.
@@ -8968,10 +8964,25 @@ function defaultSessionStorage(key) {
8968
8964
  }
8969
8965
 
8970
8966
  // src/version.ts
8971
- var VERSION = "2.0.1";
8967
+ var VERSION = "4.0.0";
8972
8968
 
8973
8969
  // src/runtime.ts
8974
8970
  function buildRuntime(config) {
8971
+ const keyEnvironmentRef = environmentRefFromPublishableApiKey(config.apiKey);
8972
+ if (keyEnvironmentRef === "") {
8973
+ throw new Error("PalbeConfig.apiKey does not contain a valid publishable Environment identity");
8974
+ } else if (config.environmentRef !== keyEnvironmentRef) {
8975
+ throw new Error("PalbeConfig.environmentRef must match the Environment identity in apiKey");
8976
+ }
8977
+ let runtimeURL;
8978
+ try {
8979
+ runtimeURL = new URL(config.url);
8980
+ } catch {
8981
+ throw new Error("PalbeConfig.url must be a valid URL");
8982
+ }
8983
+ if (runtimeURL.hostname.endsWith(".palbase.studio") && runtimeURL.hostname.split(".")[0] !== config.environmentRef) {
8984
+ throw new Error("PalbeConfig.url must match environmentRef for palbase.studio");
8985
+ }
8975
8986
  const http = new HttpClient(config.apiKey, {
8976
8987
  url: config.url,
8977
8988
  headers: { "X-Client-Info": `palbe-web/${VERSION}`, ...config.headers }
@@ -8980,7 +8991,7 @@ function buildRuntime(config) {
8980
8991
  const tokenManager = new TokenManager();
8981
8992
  http.tokenManager = tokenManager;
8982
8993
  const authClient = new AuthClient(http, tokenManager);
8983
- const ref = endpointRefFromApiKey(config.apiKey);
8994
+ const ref = config.environmentRef;
8984
8995
  const storage = config.storage ?? defaultSessionStorage(ref ? `palbe.session.${ref}` : void 0);
8985
8996
  const persisted = storage.load();
8986
8997
  if (persisted) {