@lotics/app-sdk 0.9.0 → 0.10.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.
@@ -0,0 +1 @@
1
+ export declare function downloadFileFromUrl(url: string, filename: string): Promise<void>;
@@ -0,0 +1,30 @@
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
+ }
@@ -13,6 +13,7 @@ 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";
16
17
  export { rpc } from "./rpc.js";
17
18
  export type { RpcOp } from "./rpc.js";
18
19
  export type { AppFixture } from "./mock.js";
package/dist/src/index.js CHANGED
@@ -11,4 +11,5 @@
11
11
  */
12
12
  export { mount } from "./mount.js";
13
13
  export { useWorkflow, useQuery, useFileUpload } from "./hooks.js";
14
+ export { downloadFileFromUrl } from "./download.js";
14
15
  export { rpc } from "./rpc.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lotics/app-sdk",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Runtime SDK for Lotics custom-code apps — typed hooks, postMessage bridge, mount entry point",
5
5
  "type": "module",
6
6
  "exports": {