@palbase/web 1.9.0 → 2.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 (43) hide show
  1. package/README.md +3 -2
  2. package/dist/{analytics-facade-DsvKx5A5.d.ts → analytics-facade-DMtGDGfd.d.ts} +3 -19
  3. package/dist/{analytics-facade-DFd5LB3_.d.cts → analytics-facade-ovP0pF2P.d.cts} +3 -19
  4. package/dist/chunk-PZ5AY32C.js +10 -0
  5. package/dist/chunk-PZ5AY32C.js.map +1 -0
  6. package/dist/{chunk-I3ZMB7XM.js → chunk-V6VTX65P.js} +23 -36
  7. package/dist/chunk-V6VTX65P.js.map +1 -0
  8. package/dist/gen/cli.cjs +1228 -0
  9. package/dist/gen/cli.cjs.map +1 -0
  10. package/dist/gen/cli.d.cts +1 -0
  11. package/dist/gen/cli.d.ts +1 -0
  12. package/dist/gen/cli.js +1206 -0
  13. package/dist/gen/cli.js.map +1 -0
  14. package/dist/index.cjs +18 -9
  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 -1
  19. package/dist/internal.cjs +19 -30
  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 -1
  24. package/dist/next/client.cjs +16 -29
  25. package/dist/next/client.cjs.map +1 -1
  26. package/dist/next/client.js +2 -1
  27. package/dist/next/client.js.map +1 -1
  28. package/dist/next/index.cjs +19 -30
  29. package/dist/next/index.cjs.map +1 -1
  30. package/dist/next/index.d.cts +2 -2
  31. package/dist/next/index.d.ts +2 -2
  32. package/dist/next/index.js +2 -1
  33. package/dist/next/index.js.map +1 -1
  34. package/dist/{pb-CDVMy1l1.d.ts → pb-CvpcQero.d.ts} +1 -1
  35. package/dist/{pb-D_fuhafL.d.cts → pb-DDM_mCQB.d.cts} +1 -1
  36. package/dist/react/index.cjs +12 -8
  37. package/dist/react/index.cjs.map +1 -1
  38. package/dist/react/index.d.cts +1 -1
  39. package/dist/react/index.d.ts +1 -1
  40. package/dist/react/index.js +2 -1
  41. package/dist/react/index.js.map +1 -1
  42. package/package.json +7 -3
  43. package/dist/chunk-I3ZMB7XM.js.map +0 -1
package/README.md CHANGED
@@ -34,8 +34,9 @@ wires `import './palbe.gen';` into your app entry, and adds a `predev`/`prebuild
34
34
  hook that keeps the types in sync. **Commit `palbe.gen.ts`** — it's the typed
35
35
  client your app imports, not a build artifact.
36
36
 
37
- The generated file calls `__configure(...)` with your project's URL and anon API
38
- key at module load, so importing it once at startup is all the setup there is.
37
+ The generated file calls `__configure(...)` with your project's URL, app ID, and
38
+ anon API key at module load, so importing it once at startup is all the setup
39
+ there is.
39
40
  If you forget to import it, every `pb` call throws a guided `BackendError`
40
41
  (`kind: 'notConfigured'`).
41
42
 
@@ -620,18 +620,10 @@ interface PalbeOAuthConfig {
620
620
  interface PalbeConfig {
621
621
  url: string;
622
622
  apiKey: string;
623
+ /** Registered app identity persisted by `palbase web link`. */
624
+ appId: string;
623
625
  /** Informational — url+apiKey are already branch-specific (endpointRef embeds the branch slug); gen bakes all three consistently. */
624
626
  branch?: string;
625
- /**
626
- * F2 app-registration: the registered app `identifier` from
627
- * `palbase-config.json` — for web this is the declared ORIGIN (e.g.
628
- * `https://app.example.com`). When non-empty, `configure` REFUSES to build the
629
- * runtime if `window.location.origin` does not match (SDK-REFUSES), and the
630
- * value rides on `X-Palbase-Bundle` on EVERY request so the Kong gate can match
631
- * it (the IDENTICAL header + value the iOS SDK sends). Empty/absent → legacy /
632
- * tooling: no guard, no header.
633
- */
634
- identifier?: string;
635
627
  oauth?: PalbeOAuthConfig;
636
628
  /** Refresh-token persistence. Default: endpoint-scoped localStorage in browsers, memory elsewhere. */
637
629
  storage?: SessionStorageAdapter;
@@ -1690,14 +1682,6 @@ declare class PalbeRealtime {
1690
1682
 
1691
1683
  interface PalbeRuntime {
1692
1684
  config: PalbeConfig;
1693
- /**
1694
- * F2 app-registration: the registered app `identifier` (web ORIGIN) stashed at
1695
- * configure. Rides on `X-Palbase-Bundle` on EVERY request (request.ts) so the
1696
- * Kong gate can match it. Empty string when the binding is unconfigured/tooling
1697
- * (no header is sent). Origin-match is enforced in `buildRuntime` BEFORE this
1698
- * runtime is returned — a mismatch throws there and no runtime is built.
1699
- */
1700
- appIdentifier: string;
1701
1685
  http: HttpClient$1;
1702
1686
  tokenManager: TokenManager$1;
1703
1687
  authClient: AuthClient;
@@ -1978,4 +1962,4 @@ declare class PalbeAnalytics {
1978
1962
  private post;
1979
1963
  }
1980
1964
 
1981
- export { type AnalyticsProperties as A, type PresenceState as B, Call as C, type RealtimeConnectionState as D, type RealtimeHandler as E, type FlagsView as F, type RealtimePayload as G, type RealtimeStatus as H, type RealtimeStatusSnapshot as I, type RealtimeSubscription as J, type ResolvedMention as K, type ResolvedReply as L, type MagicLinkResult as M, type NotifyScope as N, type OAuthExchangeResult as O, PalbeAnalytics as P, type Unsubscribe as Q, RealtimeChannel as R, type SentReceipt as S, type PalbeRuntime as T, type UnreadView as U, buildRuntime as V, PalbePerf as W, type AuthChangeEvent as a, type AuthState as b, type AuthSuccess as c, type AuthUser as d, type CallChangeCallback as e, type CallParticipant as f, type CallState as g, Chat as h, type ChatBackend as i, type ChatDraft as j, type ChatKind as k, type ChatMember as l, type ChatMessage as m, type ChatMessageKind as n, type ChatRole as o, type ChatState as p, type CommsPrefs as q, type MentionRange as r, type MessageDirection as s, PalbeAuth as t, PalbeCalls as u, type PalbeConfig as v, PalbeFlags as w, PalbeMessaging as x, type PalbeOAuthConfig as y, PalbeRealtime as z };
1965
+ export { type AuthUser as A, PalbeMessaging as B, Chat as C, type PalbeOAuthConfig as D, PalbeRealtime as E, type FlagsView as F, type PresenceState as G, RealtimeChannel as H, type RealtimeHandler as I, type RealtimeStatus as J, type RealtimeStatusSnapshot as K, type RealtimeSubscription as L, type MagicLinkResult as M, type NotifyScope as N, type OAuthExchangeResult as O, type PalbeConfig as P, type ResolvedMention as Q, type RealtimeConnectionState as R, type ResolvedReply as S, type SentReceipt as T, type UnreadView as U, type Unsubscribe as V, PalbePerf as W, type RealtimePayload as a, type ChatMember as b, type ChatMessage as c, type PalbeRuntime as d, buildRuntime as e, type AnalyticsProperties as f, type AuthChangeEvent as g, type AuthState as h, type AuthSuccess as i, Call as j, type CallChangeCallback as k, type CallParticipant as l, type CallState as m, type ChatBackend as n, type ChatDraft as o, type ChatKind as p, type ChatMessageKind as q, type ChatRole as r, type ChatState as s, type CommsPrefs as t, type MentionRange as u, type MessageDirection as v, PalbeAnalytics as w, PalbeAuth as x, PalbeCalls as y, PalbeFlags as z };
@@ -620,18 +620,10 @@ interface PalbeOAuthConfig {
620
620
  interface PalbeConfig {
621
621
  url: string;
622
622
  apiKey: string;
623
+ /** Registered app identity persisted by `palbase web link`. */
624
+ appId: string;
623
625
  /** Informational — url+apiKey are already branch-specific (endpointRef embeds the branch slug); gen bakes all three consistently. */
624
626
  branch?: string;
625
- /**
626
- * F2 app-registration: the registered app `identifier` from
627
- * `palbase-config.json` — for web this is the declared ORIGIN (e.g.
628
- * `https://app.example.com`). When non-empty, `configure` REFUSES to build the
629
- * runtime if `window.location.origin` does not match (SDK-REFUSES), and the
630
- * value rides on `X-Palbase-Bundle` on EVERY request so the Kong gate can match
631
- * it (the IDENTICAL header + value the iOS SDK sends). Empty/absent → legacy /
632
- * tooling: no guard, no header.
633
- */
634
- identifier?: string;
635
627
  oauth?: PalbeOAuthConfig;
636
628
  /** Refresh-token persistence. Default: endpoint-scoped localStorage in browsers, memory elsewhere. */
637
629
  storage?: SessionStorageAdapter;
@@ -1690,14 +1682,6 @@ declare class PalbeRealtime {
1690
1682
 
1691
1683
  interface PalbeRuntime {
1692
1684
  config: PalbeConfig;
1693
- /**
1694
- * F2 app-registration: the registered app `identifier` (web ORIGIN) stashed at
1695
- * configure. Rides on `X-Palbase-Bundle` on EVERY request (request.ts) so the
1696
- * Kong gate can match it. Empty string when the binding is unconfigured/tooling
1697
- * (no header is sent). Origin-match is enforced in `buildRuntime` BEFORE this
1698
- * runtime is returned — a mismatch throws there and no runtime is built.
1699
- */
1700
- appIdentifier: string;
1701
1685
  http: HttpClient$1;
1702
1686
  tokenManager: TokenManager$1;
1703
1687
  authClient: AuthClient;
@@ -1978,4 +1962,4 @@ declare class PalbeAnalytics {
1978
1962
  private post;
1979
1963
  }
1980
1964
 
1981
- export { type AnalyticsProperties as A, type PresenceState as B, Call as C, type RealtimeConnectionState as D, type RealtimeHandler as E, type FlagsView as F, type RealtimePayload as G, type RealtimeStatus as H, type RealtimeStatusSnapshot as I, type RealtimeSubscription as J, type ResolvedMention as K, type ResolvedReply as L, type MagicLinkResult as M, type NotifyScope as N, type OAuthExchangeResult as O, PalbeAnalytics as P, type Unsubscribe as Q, RealtimeChannel as R, type SentReceipt as S, type PalbeRuntime as T, type UnreadView as U, buildRuntime as V, PalbePerf as W, type AuthChangeEvent as a, type AuthState as b, type AuthSuccess as c, type AuthUser as d, type CallChangeCallback as e, type CallParticipant as f, type CallState as g, Chat as h, type ChatBackend as i, type ChatDraft as j, type ChatKind as k, type ChatMember as l, type ChatMessage as m, type ChatMessageKind as n, type ChatRole as o, type ChatState as p, type CommsPrefs as q, type MentionRange as r, type MessageDirection as s, PalbeAuth as t, PalbeCalls as u, type PalbeConfig as v, PalbeFlags as w, PalbeMessaging as x, type PalbeOAuthConfig as y, PalbeRealtime as z };
1965
+ export { type AuthUser as A, PalbeMessaging as B, Chat as C, type PalbeOAuthConfig as D, PalbeRealtime as E, type FlagsView as F, type PresenceState as G, RealtimeChannel as H, type RealtimeHandler as I, type RealtimeStatus as J, type RealtimeStatusSnapshot as K, type RealtimeSubscription as L, type MagicLinkResult as M, type NotifyScope as N, type OAuthExchangeResult as O, type PalbeConfig as P, type ResolvedMention as Q, type RealtimeConnectionState as R, type ResolvedReply as S, type SentReceipt as T, type UnreadView as U, type Unsubscribe as V, PalbePerf as W, type RealtimePayload as a, type ChatMember as b, type ChatMessage as c, type PalbeRuntime as d, buildRuntime as e, type AnalyticsProperties as f, type AuthChangeEvent as g, type AuthState as h, type AuthSuccess as i, Call as j, type CallChangeCallback as k, type CallParticipant as l, type CallState as m, type ChatBackend as n, type ChatDraft as o, type ChatKind as p, type ChatMessageKind as q, type ChatRole as r, type ChatState as s, type CommsPrefs as t, type MentionRange as u, type MessageDirection as v, PalbeAnalytics as w, PalbeAuth as x, PalbeCalls as y, PalbeFlags as z };
@@ -0,0 +1,10 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ export {
8
+ __export
9
+ };
10
+ //# sourceMappingURL=chunk-PZ5AY32C.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,8 +1,6 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
1
+ import {
2
+ __export
3
+ } from "./chunk-PZ5AY32C.js";
6
4
 
7
5
  // ../core/dist/index.js
8
6
  var CACHE_TTL_MS = 5 * 60 * 1e3;
@@ -422,12 +420,6 @@ async function palbeRequest(rt, method, path, spec = {}) {
422
420
  if (MUTATING.has(method) && !callerHasKey) {
423
421
  headers["Idempotency-Key"] = crypto.randomUUID();
424
422
  }
425
- if (rt.appIdentifier !== "") {
426
- const callerHasBundle = Object.keys(headers).some(
427
- (k) => k.toLowerCase() === "x-palbase-bundle"
428
- );
429
- if (!callerHasBundle) headers["X-Palbase-Bundle"] = rt.appIdentifier;
430
- }
431
423
  const attempt = async () => {
432
424
  try {
433
425
  return await rt.http.request(method, path, {
@@ -1411,23 +1403,6 @@ var PalbeAnalytics = class {
1411
1403
  }
1412
1404
  };
1413
1405
 
1414
- // src/app-config.ts
1415
- function loadAppConfig(raw) {
1416
- if (typeof raw !== "object" || raw === null) {
1417
- throw new Error("app_config_invalid: expected a JSON object");
1418
- }
1419
- const r = raw;
1420
- const str = (k) => typeof r[k] === "string" ? r[k] : "";
1421
- return { appId: str("app_id"), identifier: str("identifier"), envPreset: str("env_preset") };
1422
- }
1423
- function assertOriginMatches(cfg, runtimeOrigin) {
1424
- if (cfg.identifier === "") return;
1425
- if (runtimeOrigin === "") return;
1426
- if (runtimeOrigin !== cfg.identifier) {
1427
- throw new Error(`app_config_mismatch: expected origin ${cfg.identifier}, got ${runtimeOrigin}`);
1428
- }
1429
- }
1430
-
1431
1406
  // src/auth-wire.ts
1432
1407
  function asWireAuthResult(raw) {
1433
1408
  if (typeof raw !== "object" || raw === null) return null;
@@ -8241,6 +8216,14 @@ function observeWebVitals(record) {
8241
8216
  };
8242
8217
  }
8243
8218
 
8219
+ // src/runtime-metadata.ts
8220
+ var APP_METADATA_HEADER = "X-Palbase-Bundle";
8221
+ function applyBrowserOriginHeader(headers) {
8222
+ if (Object.keys(headers).some((key) => key.toLowerCase() === "x-palbase-bundle")) return;
8223
+ const origin = typeof window !== "undefined" && typeof window.location !== "undefined" ? window.location.origin : "";
8224
+ if (origin !== "") headers[APP_METADATA_HEADER] = origin;
8225
+ }
8226
+
8244
8227
  // src/realtime/anon-token.ts
8245
8228
  var REFRESH_SKEW_MS = 6e4;
8246
8229
  var AnonTokenProvider = class {
@@ -8283,11 +8266,16 @@ var AnonTokenProvider = class {
8283
8266
  */
8284
8267
  async mint() {
8285
8268
  const base = this.rt.config.url.replace(/\/+$/, "");
8269
+ const headers = {
8270
+ apikey: this.rt.config.apiKey,
8271
+ ...this.rt.config.headers
8272
+ };
8273
+ applyBrowserOriginHeader(headers);
8286
8274
  let response;
8287
8275
  try {
8288
8276
  response = await fetch(`${base}/auth/anonymous`, {
8289
8277
  method: "POST",
8290
- headers: { apikey: this.rt.config.apiKey }
8278
+ headers
8291
8279
  });
8292
8280
  } catch (e) {
8293
8281
  throw new BackendError("network", {
@@ -8928,17 +8916,15 @@ function defaultSessionStorage(key) {
8928
8916
  }
8929
8917
 
8930
8918
  // src/version.ts
8931
- var VERSION = "1.9.0";
8919
+ var VERSION = "2.0.0";
8932
8920
 
8933
8921
  // src/runtime.ts
8934
8922
  function buildRuntime(config) {
8935
- const appIdentifier = config.identifier ?? "";
8936
- const runtimeOrigin = typeof window !== "undefined" && typeof window.location !== "undefined" ? window.location.origin : "";
8937
- assertOriginMatches(loadAppConfig({ identifier: appIdentifier }), runtimeOrigin);
8938
8923
  const http = new HttpClient(config.apiKey, {
8939
8924
  url: config.url,
8940
8925
  headers: { "X-Client-Info": `palbe-web/${VERSION}`, ...config.headers }
8941
8926
  });
8927
+ http.addInterceptor(({ headers }) => applyBrowserOriginHeader(headers));
8942
8928
  const tokenManager = new TokenManager();
8943
8929
  http.tokenManager = tokenManager;
8944
8930
  const authClient = new AuthClient(http, tokenManager);
@@ -8987,7 +8973,6 @@ function buildRuntime(config) {
8987
8973
  let perf;
8988
8974
  const rt = {
8989
8975
  config,
8990
- appIdentifier,
8991
8976
  http,
8992
8977
  tokenManager,
8993
8978
  authClient,
@@ -9146,7 +9131,9 @@ async function buildHeaders(rt, extra) {
9146
9131
  if (token) headers.Authorization = `Bearer ${token}`;
9147
9132
  const callerHasKey = Object.keys(extra ?? {}).some((k) => k.toLowerCase() === "idempotency-key");
9148
9133
  if (!callerHasKey) headers["Idempotency-Key"] = crypto.randomUUID();
9149
- return { ...headers, ...extra };
9134
+ const merged = { ...headers, ...extra };
9135
+ applyBrowserOriginHeader(merged);
9136
+ return merged;
9150
9137
  }
9151
9138
  function buildForm(options) {
9152
9139
  const form = new FormData();
@@ -9342,4 +9329,4 @@ export {
9342
9329
  pb,
9343
9330
  createBoundClient
9344
9331
  };
9345
- //# sourceMappingURL=chunk-I3ZMB7XM.js.map
9332
+ //# sourceMappingURL=chunk-V6VTX65P.js.map