@lotics/app-sdk 0.11.0 → 0.12.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.
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.js +0 -1
- package/dist/src/rpc.js +20 -3
- package/package.json +1 -1
- package/dist/src/download.d.ts +0 -1
- package/dist/src/download.js +0 -30
package/dist/src/index.d.ts
CHANGED
|
@@ -13,7 +13,6 @@ export { mount } from "./mount.js";
|
|
|
13
13
|
export type { MountOptions } from "./mount.js";
|
|
14
14
|
export { useWorkflow, useQuery, useFileUpload } from "./hooks.js";
|
|
15
15
|
export type { UploadedFile } from "./hooks.js";
|
|
16
|
-
export { downloadFileFromUrl } from "./download.js";
|
|
17
16
|
export { rpc } from "./rpc.js";
|
|
18
17
|
export type { RpcOp } from "./rpc.js";
|
|
19
18
|
export { readMembers } from "./members.js";
|
package/dist/src/index.js
CHANGED
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
|
-
/**
|
|
4
|
-
|
|
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 !==
|
|
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
package/dist/src/download.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function downloadFileFromUrl(url: string, filename: string): Promise<void>;
|
package/dist/src/download.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// File download primitive for Lotics custom-code apps. Uses fetch+blob+anchor
|
|
2
|
-
// because the app runs inside a sandboxed iframe — `window.open(url, "_blank")`
|
|
3
|
-
// is silently dropped without `allow-popups`, and direct anchor navigation
|
|
4
|
-
// without the `download` attribute doesn't trigger a save dialog for inline
|
|
5
|
-
// MIME types (HTML, JSON, PDFs, etc.).
|
|
6
|
-
//
|
|
7
|
-
// `cache: "no-store"` matches the frontend convention — avoids CORS cache
|
|
8
|
-
// collisions where a prior <img> load cached the response without an
|
|
9
|
-
// `Access-Control-Allow-Origin` header, breaking subsequent fetches.
|
|
10
|
-
export async function downloadFileFromUrl(url, filename) {
|
|
11
|
-
if (!url)
|
|
12
|
-
throw new Error("downloadFileFromUrl: empty url");
|
|
13
|
-
const response = await fetch(url, { cache: "no-store" });
|
|
14
|
-
if (!response.ok) {
|
|
15
|
-
throw new Error(`File download failed: ${response.status} ${response.statusText}`);
|
|
16
|
-
}
|
|
17
|
-
const blob = await response.blob();
|
|
18
|
-
const blobUrl = URL.createObjectURL(blob);
|
|
19
|
-
try {
|
|
20
|
-
const link = document.createElement("a");
|
|
21
|
-
link.href = blobUrl;
|
|
22
|
-
link.download = filename;
|
|
23
|
-
document.body.appendChild(link);
|
|
24
|
-
link.click();
|
|
25
|
-
link.remove();
|
|
26
|
-
}
|
|
27
|
-
finally {
|
|
28
|
-
URL.revokeObjectURL(blobUrl);
|
|
29
|
-
}
|
|
30
|
-
}
|