npm package diff
Package: @forge/bridge
Versions: 5.6.1-next.5-experimental-44e92a2 - 5.7.0-next.9
File: package/out/object-store/download.js
Index: package/out/object-store/download.js
===================================================================
--- package/out/object-store/download.js
+++ package/out/object-store/download.js
@@ -0,0 +1,52 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.download = void 0;
+const invoke_1 = require("../invoke");
+const errors_1 = require("../errors");
+const download = async ({ functionKey, keys }) => {
+    if (!functionKey || functionKey.length === 0) {
+        throw new errors_1.BridgeAPIError('functionKey is required to filter and generate download URLs');
+    }
+    if (!Array.isArray(keys) || keys.length === 0) {
+        throw new errors_1.BridgeAPIError('keys array is required and must not be empty');
+    }
+    const downloadUrlsTokeys = (await (0, invoke_1.invoke)(functionKey, {
+        keys
+    }));
+    if (!downloadUrlsTokeys || typeof downloadUrlsTokeys !== 'object') {
+        throw new errors_1.BridgeAPIError('Invalid response from functionKey');
+    }
+    const downloadPromises = Object.entries(downloadUrlsTokeys).map(async ([downloadUrl, key]) => {
+        try {
+            const response = await fetch(downloadUrl, {
+                method: 'GET'
+            });
+            if (!response.ok) {
+                return {
+                    success: false,
+                    key: key,
+                    status: response.status,
+                    error: `Download failed with status ${response.status}`
+                };
+            }
+            const blob = await response.blob();
+            return {
+                success: true,
+                key: key,
+                blob,
+                status: response.status
+            };
+        }
+        catch (error) {
+            return {
+                success: false,
+                key: key,
+                status: 503,
+                error: error instanceof Error ? error.message : 'Download failed'
+            };
+        }
+    });
+    const results = await Promise.all(downloadPromises);
+    return results;
+};
+exports.download = download;