npm package diff

Package: @forge/bridge

Versions: 5.8.0-next.8 - 5.8.0-next.9

File: package/out/object-store/upload.js

Index: package/out/object-store/upload.js
===================================================================
--- package/out/object-store/upload.js
+++ package/out/object-store/upload.js
@@ -2,8 +2,17 @@
 Object.defineProperty(exports, "__esModule", { value: true });
 exports.upload = void 0;
 const invoke_1 = require("../invoke");
 const errors_1 = require("../errors");
+const base64ToBlob = (base64, mimeType) => {
+    const byteCharacters = atob(base64);
+    const byteNumbers = new Array(byteCharacters.length);
+    for (let i = 0; i < byteCharacters.length; i++) {
+        byteNumbers[i] = byteCharacters.charCodeAt(i);
+    }
+    const byteArray = new Uint8Array(byteNumbers);
+    return new Blob([byteArray], { type: mimeType || 'application/octet-stream' });
+};
 const getObjectMetadata = async (blob) => {
     const length = blob.size;
     const arrayBuffer = await blob.arrayBuffer();
     const hashBuffer = await crypto.subtle.digest('SHA-256', arrayBuffer);
@@ -22,17 +31,32 @@
     }
     if (!Array.isArray(objects) || objects.length === 0) {
         throw new errors_1.BridgeAPIError('objects array is required and must not be empty');
     }
-    const allObjectMetadata = await Promise.all(objects.map((obj) => getObjectMetadata(obj)));
+    const blobs = objects.map((obj, index) => {
+        if (obj instanceof Blob) {
+            return obj;
+        }
+        const isBase64Object = obj && typeof obj === 'object' && 'data' in obj && typeof obj.data === 'string';
+        if (!isBase64Object) {
+            throw new errors_1.BridgeAPIError(`Invalid object type at index ${index}. Only Blob or Base64Object (with data string and optional mimeType) are accepted.`);
+        }
+        try {
+            return base64ToBlob(obj.data, obj.mimeType);
+        }
+        catch (e) {
+            throw new errors_1.BridgeAPIError(`Invalid base64 data at index ${index}. The data string must be valid base64 encoded.`);
+        }
+    });
+    const allObjectMetadata = await Promise.all(blobs.map((blob) => getObjectMetadata(blob)));
     const presignedURLsToObjectMetadata = (await (0, invoke_1.invoke)(functionKey, {
         allObjectMetadata
     }));
     if (!presignedURLsToObjectMetadata || typeof presignedURLsToObjectMetadata !== 'object') {
         throw new errors_1.BridgeAPIError('Invalid response from functionKey');
     }
     const checksumToBlobMap = new Map();
-    objects.forEach((blob, index) => {
+    blobs.forEach((blob, index) => {
         const metadata = allObjectMetadata[index];
         checksumToBlobMap.set(metadata.checksum, blob);
     });
     const uploadPromises = Object.entries(presignedURLsToObjectMetadata).map(async ([presignedUrl, metadata]) => {