@pylonsync/sync 0.3.36 → 0.3.41

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +19 -3
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.3.36",
6
+ "version": "0.3.41",
7
7
  "type": "module",
8
8
  "main": "src/index.ts",
9
9
  "types": "src/index.ts",
package/src/index.ts CHANGED
@@ -1532,13 +1532,29 @@ export async function getServerData(
1532
1532
  // Convenience factory
1533
1533
  // ---------------------------------------------------------------------------
1534
1534
 
1535
- /** Create a sync engine connected to the pylon dev server. */
1535
+ /**
1536
+ * Create a sync engine connected to the pylon backend.
1537
+ *
1538
+ * Default `baseUrl` resolution order:
1539
+ * 1. Explicit `baseUrl` argument — wins always.
1540
+ * 2. `window.location.origin` when running in a browser — same-origin
1541
+ * deployments (Next.js + Vercel rewrites, embedded SPA, etc.) want
1542
+ * this and forgetting to pass it should NOT silently leak
1543
+ * `localhost:4321` requests in production.
1544
+ * 3. `http://localhost:4321` — the `pylon dev` default for SSR /
1545
+ * non-browser callers (Node scripts, tests).
1546
+ */
1536
1547
  export function createSyncEngine(
1537
- baseUrl = "http://localhost:4321",
1548
+ baseUrl?: string,
1538
1549
  options?: Partial<SyncEngineConfig>,
1539
1550
  ): SyncEngine {
1551
+ const resolved =
1552
+ baseUrl ??
1553
+ (typeof window !== "undefined" && window.location?.origin
1554
+ ? window.location.origin
1555
+ : "http://localhost:4321");
1540
1556
  return new SyncEngine({
1541
1557
  ...(options ?? {}),
1542
- baseUrl,
1558
+ baseUrl: resolved,
1543
1559
  });
1544
1560
  }