@lotics/app-sdk 0.11.0 → 0.11.1

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/dist/src/rpc.js +20 -3
  2. package/package.json +1 -1
package/dist/src/rpc.js CHANGED
@@ -1,8 +1,25 @@
1
1
  import { promptForPassword } from "./password_gate.js";
2
2
  import { runUploadPipeline } from "./upload/pipeline.js";
3
- /** The embedding Lotics host's origin — present iff the app is bridged. */
4
- const hostOrigin = new URLSearchParams(window.location.search).get("lotics_host");
3
+ /**
4
+ * The embedding Lotics host's origin — present iff the app is bridged.
5
+ *
6
+ * Lazy + memoized so the module's top level doesn't touch `window`. The SDK
7
+ * gets imported by `frontend/lib/download.ts`, which Jest pulls in at module
8
+ * evaluation time before its jsdom environment finishes setting up
9
+ * `window.location` — eager reads crash every test suite that transitively
10
+ * imports the SDK.
11
+ *
12
+ * `undefined` = not yet computed; `string | null` = computed result.
13
+ */
14
+ let hostOriginCache;
15
+ function getHostOrigin() {
16
+ if (hostOriginCache === undefined) {
17
+ hostOriginCache = new URLSearchParams(window.location.search).get("lotics_host");
18
+ }
19
+ return hostOriginCache;
20
+ }
5
21
  export function rpc(op, payload) {
22
+ const hostOrigin = getHostOrigin();
6
23
  return hostOrigin
7
24
  ? rpcBridged(op, payload, hostOrigin)
8
25
  : rpcStandalone(op, payload);
@@ -16,7 +33,7 @@ function ensureListener() {
16
33
  listenerInstalled = true;
17
34
  window.addEventListener("message", (event) => {
18
35
  // Accept only messages from the parent window, at the host origin.
19
- if (event.source !== window.parent || event.origin !== hostOrigin)
36
+ if (event.source !== window.parent || event.origin !== getHostOrigin())
20
37
  return;
21
38
  const msg = event.data;
22
39
  if (!msg || typeof msg.id !== "number")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lotics/app-sdk",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "description": "Runtime SDK for Lotics custom-code apps — typed hooks, postMessage bridge, mount entry point",
5
5
  "type": "module",
6
6
  "exports": {