npm package diff
Package: @forge/bridge
Versions: 5.7.0-next.7 - 5.7.0-next.8
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 ({ filterAndGenerateDownloadUrls, objectKeys }) => {
+    if (!(filterAndGenerateDownloadUrls === null || filterAndGenerateDownloadUrls === void 0 ? void 0 : filterAndGenerateDownloadUrls.function)) {
+        throw new errors_1.BridgeAPIError('filterAndGenerateDownloadUrls.function is required');
+    }
+    if (!Array.isArray(objectKeys) || objectKeys.length === 0) {
+        throw new errors_1.BridgeAPIError('objectKeys array is required and must not be empty');
+    }
+    const downloadUrlsToObjectKeys = (await (0, invoke_1.invoke)(filterAndGenerateDownloadUrls.function, {
+        objectKeys
+    }));
+    if (!downloadUrlsToObjectKeys || typeof downloadUrlsToObjectKeys !== 'object') {
+        throw new errors_1.BridgeAPIError('Invalid response from filterAndGenerateDownloadUrls function');
+    }
+    const downloadPromises = Object.entries(downloadUrlsToObjectKeys).map(async ([downloadUrl, key]) => {
+        try {
+            const response = await fetch(downloadUrl, {
+                method: 'GET'
+            });
+            if (!response.ok) {
+                return {
+                    success: false,
+                    objectKey: key,
+                    status: response.status,
+                    error: `Download failed with status ${response.status}`
+                };
+            }
+            const blob = await response.blob();
+            return {
+                success: true,
+                objectKey: key,
+                blob,
+                status: response.status
+            };
+        }
+        catch (error) {
+            return {
+                success: false,
+                objectKey: key,
+                status: 503,
+                error: error instanceof Error ? error.message : 'Download failed'
+            };
+        }
+    });
+    const results = await Promise.all(downloadPromises);
+    return results;
+};
+exports.download = download;