@simplito/privmx-webendpoint
Version:
PrivMX Web Endpoint library
35 lines (34 loc) • 1.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendEntry = sendEntry;
const files_1 = require("./files");
/**
* Sends an entry to the specified inbox.
*
* @param {InboxApi} inboxApi - The API instance used to interact with the inbox.
* @param {string} inboxId - The ID of the target inbox where the entry will be sent.
* @param {InboxEntryPayload} payload - The data payload for the inbox entry, including files, metadata, and other information.
*
* @returns {Promise<void>} A promise that resolves when the entry has been successfully sent.
*
*/
async function sendEntry(inboxApi, inboxId, payload) {
const preparedFiles = payload.files
? await Promise.all(payload.files.map((file) => {
return files_1.FileUploader.prepareInboxUpload({
inboxApi,
file: file.content,
privateMeta: file.privateMeta,
publicMeta: file.publicMeta,
});
}))
: [];
const inboxEntryHandle = await inboxApi.prepareEntry(inboxId, payload.data, preparedFiles.map((file) => file.handle));
const uploaders = await Promise.all(preparedFiles.map((file) => files_1.FileUploader.uploadInboxFile({
inboxApi,
inboxHandle: inboxEntryHandle,
preparedFileUpload: file,
})));
await Promise.all(uploaders.map((uploader) => uploader.uploadFileContent()));
await inboxApi.sendEntry(inboxEntryHandle);
}