@palbase/web 1.10.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.
@@ -7,7 +7,7 @@ import {
7
7
  __configure,
8
8
  endpointRefFromApiKey,
9
9
  getRuntime
10
- } from "../chunk-4ZJHHXD3.js";
10
+ } from "../chunk-V6VTX65P.js";
11
11
  import "../chunk-PZ5AY32C.js";
12
12
 
13
13
  // src/next/client.ts
@@ -566,12 +566,6 @@ async function palbeRequest(rt, method, path, spec = {}) {
566
566
  if (MUTATING.has(method) && !callerHasKey) {
567
567
  headers["Idempotency-Key"] = crypto.randomUUID();
568
568
  }
569
- if (rt.appIdentifier !== "") {
570
- const callerHasBundle = Object.keys(headers).some(
571
- (k) => k.toLowerCase() === "x-palbase-bundle"
572
- );
573
- if (!callerHasBundle) headers["X-Palbase-Bundle"] = rt.appIdentifier;
574
- }
575
569
  const attempt = async () => {
576
570
  try {
577
571
  return await rt.http.request(method, path, {
@@ -1465,23 +1459,6 @@ var PalbeAnalytics = class {
1465
1459
  }
1466
1460
  };
1467
1461
 
1468
- // src/app-config.ts
1469
- function loadAppConfig(raw) {
1470
- if (typeof raw !== "object" || raw === null) {
1471
- throw new Error("app_config_invalid: expected a JSON object");
1472
- }
1473
- const r = raw;
1474
- const str = (k) => typeof r[k] === "string" ? r[k] : "";
1475
- return { appId: str("app_id"), identifier: str("identifier"), envPreset: str("env_preset") };
1476
- }
1477
- function assertOriginMatches(cfg, runtimeOrigin) {
1478
- if (cfg.identifier === "") return;
1479
- if (runtimeOrigin === "") return;
1480
- if (runtimeOrigin !== cfg.identifier) {
1481
- throw new Error(`app_config_mismatch: expected origin ${cfg.identifier}, got ${runtimeOrigin}`);
1482
- }
1483
- }
1484
-
1485
1462
  // src/auth-facade.ts
1486
1463
  function mapWireUser(raw) {
1487
1464
  return {
@@ -8278,6 +8255,14 @@ function observeWebVitals(record) {
8278
8255
  };
8279
8256
  }
8280
8257
 
8258
+ // src/runtime-metadata.ts
8259
+ var APP_METADATA_HEADER = "X-Palbase-Bundle";
8260
+ function applyBrowserOriginHeader(headers) {
8261
+ if (Object.keys(headers).some((key) => key.toLowerCase() === "x-palbase-bundle")) return;
8262
+ const origin = typeof window !== "undefined" && typeof window.location !== "undefined" ? window.location.origin : "";
8263
+ if (origin !== "") headers[APP_METADATA_HEADER] = origin;
8264
+ }
8265
+
8281
8266
  // src/realtime/anon-token.ts
8282
8267
  var REFRESH_SKEW_MS = 6e4;
8283
8268
  var AnonTokenProvider = class {
@@ -8320,11 +8305,16 @@ var AnonTokenProvider = class {
8320
8305
  */
8321
8306
  async mint() {
8322
8307
  const base = this.rt.config.url.replace(/\/+$/, "");
8308
+ const headers = {
8309
+ apikey: this.rt.config.apiKey,
8310
+ ...this.rt.config.headers
8311
+ };
8312
+ applyBrowserOriginHeader(headers);
8323
8313
  let response;
8324
8314
  try {
8325
8315
  response = await fetch(`${base}/auth/anonymous`, {
8326
8316
  method: "POST",
8327
- headers: { apikey: this.rt.config.apiKey }
8317
+ headers
8328
8318
  });
8329
8319
  } catch (e) {
8330
8320
  throw new BackendError("network", {
@@ -8965,17 +8955,15 @@ function defaultSessionStorage(key) {
8965
8955
  }
8966
8956
 
8967
8957
  // src/version.ts
8968
- var VERSION = "1.10.0";
8958
+ var VERSION = "2.0.0";
8969
8959
 
8970
8960
  // src/runtime.ts
8971
8961
  function buildRuntime(config) {
8972
- const appIdentifier = config.identifier ?? "";
8973
- const runtimeOrigin = typeof window !== "undefined" && typeof window.location !== "undefined" ? window.location.origin : "";
8974
- assertOriginMatches(loadAppConfig({ identifier: appIdentifier }), runtimeOrigin);
8975
8962
  const http = new HttpClient(config.apiKey, {
8976
8963
  url: config.url,
8977
8964
  headers: { "X-Client-Info": `palbe-web/${VERSION}`, ...config.headers }
8978
8965
  });
8966
+ http.addInterceptor(({ headers }) => applyBrowserOriginHeader(headers));
8979
8967
  const tokenManager = new TokenManager();
8980
8968
  http.tokenManager = tokenManager;
8981
8969
  const authClient = new AuthClient(http, tokenManager);
@@ -9024,7 +9012,6 @@ function buildRuntime(config) {
9024
9012
  let perf;
9025
9013
  const rt = {
9026
9014
  config,
9027
- appIdentifier,
9028
9015
  http,
9029
9016
  tokenManager,
9030
9017
  authClient,
@@ -9183,7 +9170,9 @@ async function buildHeaders(rt, extra) {
9183
9170
  if (token) headers.Authorization = `Bearer ${token}`;
9184
9171
  const callerHasKey = Object.keys(extra ?? {}).some((k) => k.toLowerCase() === "idempotency-key");
9185
9172
  if (!callerHasKey) headers["Idempotency-Key"] = crypto.randomUUID();
9186
- return { ...headers, ...extra };
9173
+ const merged = { ...headers, ...extra };
9174
+ applyBrowserOriginHeader(merged);
9175
+ return merged;
9187
9176
  }
9188
9177
  function buildForm(options) {
9189
9178
  const form = new FormData();