Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rpldy/uploader

Package Overview
Dependencies
Maintainers
1
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rpldy/uploader - npm Package Compare versions

Comparing version 0.15.0 to 0.16.0

lib/cjs/queue/itemHelpers.js

3

lib/cjs/batch.js

@@ -33,3 +33,4 @@ "use strict";

loaded: 0,
orgItemCount: items.length
orgItemCount: items.length,
additionalInfo: null
};

@@ -36,0 +37,0 @@ };

@@ -17,2 +17,4 @@ "use strict";

BATCH_CANCEL: "BATCH-CANCEL",
BATCH_ERROR: "BATCH-ERROR",
BATCH_FINALIZE: "BATCH-FINALIZE",
ITEM_START: "FILE-START",

@@ -19,0 +21,0 @@ ITEM_CANCEL: "FILE-CANCEL",

@@ -6,3 +6,3 @@ "use strict";

});
exports.triggerUploaderBatchEvent = exports.removePendingBatches = exports.preparePendingForUpload = exports.loadNewBatchForItem = exports.isNewBatchStarting = exports.isItemBelongsToBatch = exports.incrementBatchFinishedCounter = exports.getIsItemBatchReady = exports.getIsBatchFinalized = exports.getBatchFromState = exports.getBatchFromItemId = exports.getBatchDataFromItemId = exports.detachRecycledFromPreviousBatch = exports.cleanUpFinishedBatches = exports.cancelBatchForItem = void 0;
exports.triggerUploaderBatchEvent = exports.removePendingBatches = exports.preparePendingForUpload = exports.loadNewBatchForItem = exports.isNewBatchStarting = exports.incrementBatchFinishedCounter = exports.getIsItemBatchReady = exports.getIsBatchFinalized = exports.getBatchFromState = exports.getBatchFromItemId = exports.getBatchDataFromItemId = exports.failBatchForItem = exports.detachRecycledFromPreviousBatch = exports.cleanUpFinishedBatches = exports.cancelBatchForItem = void 0;

@@ -15,4 +15,17 @@ var _shared = require("@rpldy/shared");

var _preSendPrepare = require("./preSendPrepare");
var _itemHelpers = require("./itemHelpers");
const prepareBatchStartItems = (0, _preSendPrepare.getItemsPrepareUpdater)(_consts.UPLOADER_EVENTS.BATCH_START, batch => batch.items, null, function () {
let {
batch
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
if (batch) {
throw new Error(`BATCH_START event handlers cannot update batch data. Only items & options`);
}
});
const BATCH_READY_STATES = [_shared.BATCH_STATES.ADDED, _shared.BATCH_STATES.PROCESSING, _shared.BATCH_STATES.UPLOADING];
const BATCH_FINISHED_STATES = [_shared.BATCH_STATES.ABORTED, _shared.BATCH_STATES.CANCELLED, _shared.BATCH_STATES.FINISHED];
const BATCH_FINISHED_STATES = [_shared.BATCH_STATES.ABORTED, _shared.BATCH_STATES.CANCELLED, _shared.BATCH_STATES.FINISHED, _shared.BATCH_STATES.ERROR];

@@ -27,8 +40,2 @@ const getBatchFromState = (state, id) => state.batches[id].batch;

const isItemBelongsToBatch = (queue, itemId, batchId) => {
return queue.getState().items[itemId].batchId === batchId;
};
exports.isItemBelongsToBatch = isItemBelongsToBatch;
const getBatchDataFromItemId = (queue, itemId) => {

@@ -50,14 +57,7 @@ const state = queue.getState();

const batch = getBatch(queue, batchId);
queue.updateState(state => {
batch.items.forEach(_ref => {
let {
id
} = _ref;
delete state.items[id];
const index = state.itemQueue.indexOf(id);
if (~index) {
state.itemQueue.splice(index, 1);
}
});
batch.items.forEach(_ref => {
let {
id
} = _ref;
return (0, _itemHelpers.finalizeItem)(queue, id, true);
});

@@ -72,2 +72,7 @@ };

const finalizeBatch = (queue, batchId, eventType) => {
triggerUploaderBatchEvent(queue, batchId, eventType);
triggerUploaderBatchEvent(queue, batchId, _consts.UPLOADER_EVENTS.BATCH_FINALIZE);
};
const cancelBatchForItem = (queue, itemId) => {

@@ -85,3 +90,3 @@ const batch = getBatchFromItemId(queue, itemId),

});
triggerUploaderBatchEvent(queue, batchId, _consts.UPLOADER_EVENTS.BATCH_CANCEL);
finalizeBatch(queue, batchId, _consts.UPLOADER_EVENTS.BATCH_CANCEL);
removeBatchItems(queue, batchId);

@@ -93,2 +98,22 @@ removeBatch(queue, batchId);

const failBatchForItem = (queue, itemId, err) => {
const batch = getBatchFromItemId(queue, itemId),
batchId = batch.id;
_shared.logger.debugLog("uploady.uploader.batchHelpers: failing batch: ", {
batch
});
queue.updateState(state => {
const batch = getBatchFromState(state, batchId);
batch.state = _shared.BATCH_STATES.ERROR;
batch.additionalInfo = err.message;
});
finalizeBatch(queue, batchId, _consts.UPLOADER_EVENTS.BATCH_ERROR);
removeBatchItems(queue, batchId);
removeBatch(queue, batchId);
};
exports.failBatchForItem = failBatchForItem;
const isNewBatchStarting = (queue, itemId) => {

@@ -103,4 +128,8 @@ const batch = getBatchFromItemId(queue, itemId);

const batch = getBatchFromItemId(queue, itemId);
return queue.runCancellable(_consts.UPLOADER_EVENTS.BATCH_START, batch).then(isCancelled => {
if (!isCancelled) {
return prepareBatchStartItems(queue, batch).then(_ref2 => {
let {
cancelled
} = _ref2;
if (!cancelled) {
queue.updateState(state => {

@@ -111,3 +140,3 @@ state.currentBatch = batch.id;

return !isCancelled;
return !cancelled;
});

@@ -119,3 +148,3 @@ };

const cleanUpFinishedBatches = queue => {
//TODO: schedule clean up on requestAnimationFrame
//TODO: schedule clean up on requestIdle
const state = queue.getState();

@@ -139,6 +168,6 @@ Object.keys(state.batches).forEach(batchId => {

batch.completed = 100;
batch.loaded = batch.items.reduce((res, _ref2) => {
batch.loaded = batch.items.reduce((res, _ref3) => {
let {
loaded
} = _ref2;
} = _ref3;
return res + loaded;

@@ -164,3 +193,3 @@ }, 0);

if (!alreadyFinalized) {
triggerUploaderBatchEvent(queue, batchId, _consts.UPLOADER_EVENTS.BATCH_FINISH);
finalizeBatch(queue, batchId, _consts.UPLOADER_EVENTS.BATCH_FINISH);
}

@@ -182,6 +211,6 @@

const eventBatch = { ...(0, _simpleState.unwrap)(batch),
items: batch.items.map(_ref3 => {
items: batch.items.map(_ref4 => {
let {
id
} = _ref3;
} = _ref4;
return (0, _simpleState.unwrap)(stateItems[id]);

@@ -215,6 +244,6 @@ })

const batch = getBatchFromState(state, batchId);
const index = batch.items.findIndex(_ref4 => {
const index = batch.items.findIndex(_ref5 => {
let {
id
} = _ref4;
} = _ref5;
return id === item.id;

@@ -221,0 +250,0 @@ });

@@ -14,63 +14,11 @@ "use strict";

var _preSendPrepare = require("./preSendPrepare");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const mergeWithUndefined = (0, _shared.getMerge)({
undefinedOverwrites: true
});
const preparePreRequestItems = (0, _preSendPrepare.getItemsPrepareUpdater)(_consts.UPLOADER_EVENTS.REQUEST_PRE_SEND, items => items, (items, options) => ({
items,
options
}));
const triggerPreSendUpdate = (queue, items, options) => {
return (0, _shared.triggerUpdater)(queue.trigger, _consts.UPLOADER_EVENTS.REQUEST_PRE_SEND, {
items,
options
}) // $FlowFixMe - https://github.com/facebook/flow/issues/8215
.then(updated => {
if (updated) {
_shared.logger.debugLog(`uploader.queue: REQUEST_PRE_SEND event returned updated items/options`, updated);
if (updated.items) {
//can't change items count at this point.
if (updated.items.length !== items.length || !(0, _shared.isSamePropInArrays)(updated.items, items, ["id", "batchId", "recycled"])) {
throw new Error(`REQUEST_PRE_SEND event handlers must return same items with same ids`);
}
items = updated.items;
}
if (updated.options) {
options = mergeWithUndefined({}, options, updated.options);
}
}
return {
items,
options,
cancelled: updated === false
};
});
};
const prepareAllowedItems = (queue, items) => {
const allowedIds = items.map(item => item.id);
queue.updateState(state => {
state.activeIds = state.activeIds.concat(allowedIds);
});
return triggerPreSendUpdate(queue, items, queue.getState().batches[items[0].batchId].batchOptions).then(prepared => {
if (!prepared.cancelled) {
//update potentially changed data back into queue state
queue.updateState(state => {
prepared.items.forEach(i => {
state.items[i.id] = i;
});
state.batches[items[0].batchId].batchOptions = prepared.options;
}); //use objects from internal state(proxies) - not objects from userland
const updatedState = queue.getState();
prepared.items = prepared.items.map(item => updatedState.items[item.id]);
prepared.options = updatedState.batches[items[0].batchId].batchOptions;
}
return prepared;
});
};
const updateUploadingState = (queue, items, sendResult) => {

@@ -141,8 +89,67 @@ queue.updateState(state => {

return !!cancelledItemsIds.length;
};
const reportPreparedError = (error, queue, items, next) => {
const finishedData = items.map(_ref => {
let {
id
} = _ref;
return {
id,
info: {
status: 0,
state: _shared.FILE_STATES.ERROR,
response: error
}
};
});
(0, _processFinishedRequest.default)(queue, finishedData, next); //report about failed items
}; //make sure item is still pending. Something might have changed while waiting for ITEM_START handling. Maybe someone called abort...
const getAllowedItem = (id, queue) => queue.getState().items[id]; //send group of items to be uploaded
const getAllowedItem = (id, queue) => {
const item = queue.getState().items[id];
return item && !_consts.ITEM_FINALIZE_STATES.includes(item.state) ? item : undefined;
};
const processAllowedItems = _ref2 => {
let {
allowedItems,
cancelledResults,
queue,
items,
ids,
next
} = _ref2;
const afterPreparePromise = allowedItems.length ? preparePreRequestItems(queue, allowedItems) : Promise.resolve();
return afterPreparePromise.catch(err => {
_shared.logger.debugLog("uploader.queue: encountered error while preparing items for request", err);
reportPreparedError(err, queue, items, next);
}).then(itemsSendData => {
let nextP;
if (itemsSendData) {
if (itemsSendData.cancelled) {
cancelledResults = ids.map(() => true);
} else {
//we dont need to wait for the response here
sendAllowedItems(queue, {
items: itemsSendData.items,
options: itemsSendData.options
}, next);
}
} //if no cancelled we can go to process more items immediately (and not wait for upload responses)
if (!reportCancelledItems(queue, items, cancelledResults, next)) {
nextP = next(queue); //when concurrent is allowed, we can go ahead and process more
} //returning promise for testing purposes
return nextP;
});
}; //send group of items to be uploaded
const processBatchItems = (queue, ids, next) => {

@@ -153,2 +160,3 @@ const state = queue.getState(); //ids will have more than one when grouping is allowed

items = items.filter(item => !!~ids.indexOf(item.id)); //allow user code cancel items from start event handler(s)
//returning promise for testing purposes

@@ -159,30 +167,9 @@ return Promise.all(items.map(i => queue.runCancellable(_consts.UPLOADER_EVENTS.ITEM_START, i))).then(cancelledResults => {

allowedItems,
cancelledResults
cancelledResults,
queue,
items,
ids,
next
};
}).then(_ref => {
let {
allowedItems,
cancelledResults
} = _ref;
const afterPreparePromise = allowedItems.length ? prepareAllowedItems(queue, allowedItems).then() : Promise.resolve();
return afterPreparePromise.then(itemsSendData => {
let nextP;
if (itemsSendData) {
if (itemsSendData.cancelled) {
cancelledResults = ids.map(() => true);
} else {
//we dont need to wait for the response here
sendAllowedItems(queue, itemsSendData, next);
}
} //if no cancelled we can go to process more items immediately (and not wait for upload responses)
if (!reportCancelledItems(queue, items, cancelledResults, next)) {
nextP = next(queue); //when concurrent is allowed, we can go ahead and process more
}
return nextP;
});
});
}).then(processAllowedItems);
};

@@ -189,0 +176,0 @@

@@ -14,2 +14,4 @@ "use strict";

var _itemHelpers = require("./itemHelpers");
const FILE_STATE_TO_EVENT_MAP = {

@@ -72,18 +74,7 @@ [_shared.FILE_STATES.PENDING]: null,

const index = state.itemQueue.indexOf(id);
if (~index) {
queue.updateState(state => {
state.itemQueue.splice(index, 1);
const activeIndex = state.activeIds.indexOf(id);
if (~activeIndex) {
state.activeIds.splice(activeIndex, 1);
}
});
}
(0, _itemHelpers.finalizeItem)(queue, id);
}); //ensure finished batches are remove from state
(0, _batchHelpers.cleanUpFinishedBatches)(queue);
return next(queue);
next(queue);
};

@@ -90,0 +81,0 @@

@@ -14,7 +14,9 @@ "use strict";

var _itemHelpers = require("./itemHelpers");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const getIsItemInActiveRequest = (queue, itemId) => {
return !!~queue.getState().activeIds // $FlowFixMe - no flat
.flat().indexOf(itemId);
return queue.getState().activeIds // $FlowIssue - no flat
.flat().includes(itemId);
};

@@ -59,3 +61,3 @@

nextId = itemQueue[nextItemIndex + nextGroup.length];
nextBelongsToSameBatch = nextId && (0, _batchHelpers.isItemBelongsToBatch)(queue, nextId, batchId);
nextBelongsToSameBatch = nextId && (0, _itemHelpers.isItemBelongsToBatch)(queue, nextId, batchId);
}

@@ -72,5 +74,41 @@ } else {

const updateItemsAsActive = (queue, ids) => {
queue.updateState(state => {
//immediately mark items as active to support concurrent uploads without getting into infinite loops
state.activeIds = state.activeIds.concat(ids);
});
};
const processNextWithBatch = (queue, ids) => {
let newBatchP;
updateItemsAsActive(queue, ids);
if ((0, _batchHelpers.isNewBatchStarting)(queue, ids[0])) {
newBatchP = (0, _batchHelpers.loadNewBatchForItem)(queue, ids[0]).then(allowBatch => {
let cancelled = !allowBatch;
if (cancelled) {
(0, _batchHelpers.cancelBatchForItem)(queue, ids[0]);
processNext(queue);
}
return cancelled;
}).catch(err => {
_shared.logger.debugLog("uploader.processor: encountered error while preparing batch for request", err);
(0, _batchHelpers.failBatchForItem)(queue, ids[0], err);
processNext(queue);
return true;
});
} else {
newBatchP = Promise.resolve(false);
}
return newBatchP;
};
const processNext = queue => {
//using promise only for testing purposes, actual code doesnt require awaiting on this method
let processPromise;
const ids = getNextIdGroup(queue);
let resultP = Promise.resolve();

@@ -87,25 +125,13 @@ if (ids) {

ids,
state: queue.getState(),
currentCount
});
let cancelled = false;
let newBatchP = Promise.resolve(false);
processPromise = processNextWithBatch(queue, ids).then(failedOrCancelled => {
if (!failedOrCancelled) {
(0, _processBatchItems.default)(queue, ids, processNext);
if ((0, _batchHelpers.isNewBatchStarting)(queue, ids[0])) {
newBatchP = (0, _batchHelpers.loadNewBatchForItem)(queue, ids[0]).then(allowBatch => {
cancelled = !allowBatch;
if (cancelled) {
(0, _batchHelpers.cancelBatchForItem)(queue, ids[0]);
if (concurrent) {
//concurrent process next immediately (otherwise async event callbacks will hang processing next until they complete)
processNext(queue);
}
return cancelled;
});
}
resultP = newBatchP.then(cancelled => {
if (!cancelled) {
(0, _processBatchItems.default)(queue, ids, processNext);
}

@@ -116,3 +142,3 @@ });

return resultP;
return processPromise;
};

@@ -119,0 +145,0 @@

@@ -23,3 +23,4 @@ import { BATCH_STATES, createBatchItem } from "@rpldy/shared";

loaded: 0,
orgItemCount: items.length
orgItemCount: items.length,
additionalInfo: null
};

@@ -26,0 +27,0 @@ };

@@ -9,2 +9,4 @@ import { devFreeze, FILE_STATES } from "@rpldy/shared";

BATCH_CANCEL: "BATCH-CANCEL",
BATCH_ERROR: "BATCH-ERROR",
BATCH_FINALIZE: "BATCH-FINALIZE",
ITEM_START: "FILE-START",

@@ -11,0 +13,0 @@ ITEM_CANCEL: "FILE-CANCEL",

import { BATCH_STATES, logger, merge, FILE_STATES } from "@rpldy/shared";
import { unwrap } from "@rpldy/simple-state";
import { UPLOADER_EVENTS } from "../consts";
import { getItemsPrepareUpdater } from "./preSendPrepare";
import { finalizeItem } from "./itemHelpers";
const prepareBatchStartItems = getItemsPrepareUpdater(UPLOADER_EVENTS.BATCH_START, batch => batch.items, null, function () {
let {
batch
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
if (batch) {
throw new Error(`BATCH_START event handlers cannot update batch data. Only items & options`);
}
});
const BATCH_READY_STATES = [BATCH_STATES.ADDED, BATCH_STATES.PROCESSING, BATCH_STATES.UPLOADING];
const BATCH_FINISHED_STATES = [BATCH_STATES.ABORTED, BATCH_STATES.CANCELLED, BATCH_STATES.FINISHED];
const BATCH_FINISHED_STATES = [BATCH_STATES.ABORTED, BATCH_STATES.CANCELLED, BATCH_STATES.FINISHED, BATCH_STATES.ERROR];

@@ -13,6 +24,2 @@ const getBatchFromState = (state, id) => state.batches[id].batch;

const isItemBelongsToBatch = (queue, itemId, batchId) => {
return queue.getState().items[itemId].batchId === batchId;
};
const getBatchDataFromItemId = (queue, itemId) => {

@@ -30,14 +37,7 @@ const state = queue.getState();

const batch = getBatch(queue, batchId);
queue.updateState(state => {
batch.items.forEach(_ref => {
let {
id
} = _ref;
delete state.items[id];
const index = state.itemQueue.indexOf(id);
if (~index) {
state.itemQueue.splice(index, 1);
}
});
batch.items.forEach(_ref => {
let {
id
} = _ref;
return finalizeItem(queue, id, true);
});

@@ -52,2 +52,7 @@ };

const finalizeBatch = (queue, batchId, eventType) => {
triggerUploaderBatchEvent(queue, batchId, eventType);
triggerUploaderBatchEvent(queue, batchId, UPLOADER_EVENTS.BATCH_FINALIZE);
};
const cancelBatchForItem = (queue, itemId) => {

@@ -63,3 +68,3 @@ const batch = getBatchFromItemId(queue, itemId),

});
triggerUploaderBatchEvent(queue, batchId, UPLOADER_EVENTS.BATCH_CANCEL);
finalizeBatch(queue, batchId, UPLOADER_EVENTS.BATCH_CANCEL);
removeBatchItems(queue, batchId);

@@ -69,2 +74,18 @@ removeBatch(queue, batchId);

const failBatchForItem = (queue, itemId, err) => {
const batch = getBatchFromItemId(queue, itemId),
batchId = batch.id;
logger.debugLog("uploady.uploader.batchHelpers: failing batch: ", {
batch
});
queue.updateState(state => {
const batch = getBatchFromState(state, batchId);
batch.state = BATCH_STATES.ERROR;
batch.additionalInfo = err.message;
});
finalizeBatch(queue, batchId, UPLOADER_EVENTS.BATCH_ERROR);
removeBatchItems(queue, batchId);
removeBatch(queue, batchId);
};
const isNewBatchStarting = (queue, itemId) => {

@@ -77,4 +98,8 @@ const batch = getBatchFromItemId(queue, itemId);

const batch = getBatchFromItemId(queue, itemId);
return queue.runCancellable(UPLOADER_EVENTS.BATCH_START, batch).then(isCancelled => {
if (!isCancelled) {
return prepareBatchStartItems(queue, batch).then(_ref2 => {
let {
cancelled
} = _ref2;
if (!cancelled) {
queue.updateState(state => {

@@ -85,3 +110,3 @@ state.currentBatch = batch.id;

return !isCancelled;
return !cancelled;
});

@@ -91,3 +116,3 @@ };

const cleanUpFinishedBatches = queue => {
//TODO: schedule clean up on requestAnimationFrame
//TODO: schedule clean up on requestIdle
const state = queue.getState();

@@ -111,6 +136,6 @@ Object.keys(state.batches).forEach(batchId => {

batch.completed = 100;
batch.loaded = batch.items.reduce((res, _ref2) => {
batch.loaded = batch.items.reduce((res, _ref3) => {
let {
loaded
} = _ref2;
} = _ref3;
return res + loaded;

@@ -135,3 +160,3 @@ }, 0);

if (!alreadyFinalized) {
triggerUploaderBatchEvent(queue, batchId, UPLOADER_EVENTS.BATCH_FINISH);
finalizeBatch(queue, batchId, UPLOADER_EVENTS.BATCH_FINISH);
}

@@ -151,6 +176,6 @@

const eventBatch = { ...unwrap(batch),
items: batch.items.map(_ref3 => {
items: batch.items.map(_ref4 => {
let {
id
} = _ref3;
} = _ref4;
return unwrap(stateItems[id]);

@@ -180,6 +205,6 @@ })

const batch = getBatchFromState(state, batchId);
const index = batch.items.findIndex(_ref4 => {
const index = batch.items.findIndex(_ref5 => {
let {
id
} = _ref4;
} = _ref5;
return id === item.id;

@@ -233,2 +258,2 @@ });

export { loadNewBatchForItem, isNewBatchStarting, cancelBatchForItem, getBatchFromItemId, isItemBelongsToBatch, getBatchDataFromItemId, cleanUpFinishedBatches, triggerUploaderBatchEvent, getIsItemBatchReady, getBatchFromState, detachRecycledFromPreviousBatch, preparePendingForUpload, removePendingBatches, incrementBatchFinishedCounter, getIsBatchFinalized };
export { loadNewBatchForItem, isNewBatchStarting, cancelBatchForItem, getBatchFromItemId, getBatchDataFromItemId, cleanUpFinishedBatches, triggerUploaderBatchEvent, getIsItemBatchReady, getBatchFromState, detachRecycledFromPreviousBatch, preparePendingForUpload, removePendingBatches, incrementBatchFinishedCounter, getIsBatchFinalized, failBatchForItem };

@@ -1,63 +0,10 @@

import { triggerUpdater, isSamePropInArrays, FILE_STATES, logger, getMerge } from "@rpldy/shared";
import { UPLOADER_EVENTS } from "../consts";
import { FILE_STATES, logger } from "@rpldy/shared";
import { ITEM_FINALIZE_STATES, UPLOADER_EVENTS } from "../consts";
import processFinishedRequest from "./processFinishedRequest";
const mergeWithUndefined = getMerge({
undefinedOverwrites: true
});
import { getItemsPrepareUpdater } from "./preSendPrepare";
const preparePreRequestItems = getItemsPrepareUpdater(UPLOADER_EVENTS.REQUEST_PRE_SEND, items => items, (items, options) => ({
items,
options
}));
const triggerPreSendUpdate = (queue, items, options) => {
return triggerUpdater(queue.trigger, UPLOADER_EVENTS.REQUEST_PRE_SEND, {
items,
options
}) // $FlowFixMe - https://github.com/facebook/flow/issues/8215
.then(updated => {
if (updated) {
logger.debugLog(`uploader.queue: REQUEST_PRE_SEND event returned updated items/options`, updated);
if (updated.items) {
//can't change items count at this point.
if (updated.items.length !== items.length || !isSamePropInArrays(updated.items, items, ["id", "batchId", "recycled"])) {
throw new Error(`REQUEST_PRE_SEND event handlers must return same items with same ids`);
}
items = updated.items;
}
if (updated.options) {
options = mergeWithUndefined({}, options, updated.options);
}
}
return {
items,
options,
cancelled: updated === false
};
});
};
const prepareAllowedItems = (queue, items) => {
const allowedIds = items.map(item => item.id);
queue.updateState(state => {
state.activeIds = state.activeIds.concat(allowedIds);
});
return triggerPreSendUpdate(queue, items, queue.getState().batches[items[0].batchId].batchOptions).then(prepared => {
if (!prepared.cancelled) {
//update potentially changed data back into queue state
queue.updateState(state => {
prepared.items.forEach(i => {
state.items[i.id] = i;
});
state.batches[items[0].batchId].batchOptions = prepared.options;
}); //use objects from internal state(proxies) - not objects from userland
const updatedState = queue.getState();
prepared.items = prepared.items.map(item => updatedState.items[item.id]);
prepared.options = updatedState.batches[items[0].batchId].batchOptions;
}
return prepared;
});
};
const updateUploadingState = (queue, items, sendResult) => {

@@ -127,8 +74,66 @@ queue.updateState(state => {

return !!cancelledItemsIds.length;
};
const reportPreparedError = (error, queue, items, next) => {
const finishedData = items.map(_ref => {
let {
id
} = _ref;
return {
id,
info: {
status: 0,
state: FILE_STATES.ERROR,
response: error
}
};
});
processFinishedRequest(queue, finishedData, next); //report about failed items
}; //make sure item is still pending. Something might have changed while waiting for ITEM_START handling. Maybe someone called abort...
const getAllowedItem = (id, queue) => queue.getState().items[id]; //send group of items to be uploaded
const getAllowedItem = (id, queue) => {
const item = queue.getState().items[id];
return item && !ITEM_FINALIZE_STATES.includes(item.state) ? item : undefined;
};
const processAllowedItems = _ref2 => {
let {
allowedItems,
cancelledResults,
queue,
items,
ids,
next
} = _ref2;
const afterPreparePromise = allowedItems.length ? preparePreRequestItems(queue, allowedItems) : Promise.resolve();
return afterPreparePromise.catch(err => {
logger.debugLog("uploader.queue: encountered error while preparing items for request", err);
reportPreparedError(err, queue, items, next);
}).then(itemsSendData => {
let nextP;
if (itemsSendData) {
if (itemsSendData.cancelled) {
cancelledResults = ids.map(() => true);
} else {
//we dont need to wait for the response here
sendAllowedItems(queue, {
items: itemsSendData.items,
options: itemsSendData.options
}, next);
}
} //if no cancelled we can go to process more items immediately (and not wait for upload responses)
if (!reportCancelledItems(queue, items, cancelledResults, next)) {
nextP = next(queue); //when concurrent is allowed, we can go ahead and process more
} //returning promise for testing purposes
return nextP;
});
}; //send group of items to be uploaded
const processBatchItems = (queue, ids, next) => {

@@ -139,2 +144,3 @@ const state = queue.getState(); //ids will have more than one when grouping is allowed

items = items.filter(item => !!~ids.indexOf(item.id)); //allow user code cancel items from start event handler(s)
//returning promise for testing purposes

@@ -145,32 +151,11 @@ return Promise.all(items.map(i => queue.runCancellable(UPLOADER_EVENTS.ITEM_START, i))).then(cancelledResults => {

allowedItems,
cancelledResults
cancelledResults,
queue,
items,
ids,
next
};
}).then(_ref => {
let {
allowedItems,
cancelledResults
} = _ref;
const afterPreparePromise = allowedItems.length ? prepareAllowedItems(queue, allowedItems).then() : Promise.resolve();
return afterPreparePromise.then(itemsSendData => {
let nextP;
if (itemsSendData) {
if (itemsSendData.cancelled) {
cancelledResults = ids.map(() => true);
} else {
//we dont need to wait for the response here
sendAllowedItems(queue, itemsSendData, next);
}
} //if no cancelled we can go to process more items immediately (and not wait for upload responses)
if (!reportCancelledItems(queue, items, cancelledResults, next)) {
nextP = next(queue); //when concurrent is allowed, we can go ahead and process more
}
return nextP;
});
});
}).then(processAllowedItems);
};
export default processBatchItems;
import { FILE_STATES, logger } from "@rpldy/shared";
import { UPLOADER_EVENTS, ITEM_FINALIZE_STATES } from "../consts";
import { cleanUpFinishedBatches, incrementBatchFinishedCounter } from "./batchHelpers";
import { finalizeItem } from "./itemHelpers";
export const FILE_STATE_TO_EVENT_MAP = {

@@ -59,20 +60,9 @@ [FILE_STATES.PENDING]: null,

const index = state.itemQueue.indexOf(id);
if (~index) {
queue.updateState(state => {
state.itemQueue.splice(index, 1);
const activeIndex = state.activeIds.indexOf(id);
if (~activeIndex) {
state.activeIds.splice(activeIndex, 1);
}
});
}
finalizeItem(queue, id);
}); //ensure finished batches are remove from state
cleanUpFinishedBatches(queue);
return next(queue);
next(queue);
};
export default processFinishedRequest;
import { FILE_STATES, logger } from "@rpldy/shared";
import processBatchItems from "./processBatchItems";
import { getBatchDataFromItemId, getIsItemBatchReady, isNewBatchStarting, cancelBatchForItem, loadNewBatchForItem, isItemBelongsToBatch } from "./batchHelpers";
import { getBatchDataFromItemId, getIsItemBatchReady, isNewBatchStarting, cancelBatchForItem, loadNewBatchForItem, failBatchForItem } from "./batchHelpers";
import { isItemBelongsToBatch } from "./itemHelpers";
const getIsItemInActiveRequest = (queue, itemId) => {
return !!~queue.getState().activeIds // $FlowFixMe - no flat
.flat().indexOf(itemId);
return queue.getState().activeIds // $FlowIssue - no flat
.flat().includes(itemId);
};

@@ -54,5 +55,40 @@

const updateItemsAsActive = (queue, ids) => {
queue.updateState(state => {
//immediately mark items as active to support concurrent uploads without getting into infinite loops
state.activeIds = state.activeIds.concat(ids);
});
};
const processNextWithBatch = (queue, ids) => {
let newBatchP;
updateItemsAsActive(queue, ids);
if (isNewBatchStarting(queue, ids[0])) {
newBatchP = loadNewBatchForItem(queue, ids[0]).then(allowBatch => {
let cancelled = !allowBatch;
if (cancelled) {
cancelBatchForItem(queue, ids[0]);
processNext(queue);
}
return cancelled;
}).catch(err => {
logger.debugLog("uploader.processor: encountered error while preparing batch for request", err);
failBatchForItem(queue, ids[0], err);
processNext(queue);
return true;
});
} else {
newBatchP = Promise.resolve(false);
}
return newBatchP;
};
const processNext = queue => {
//using promise only for testing purposes, actual code doesnt require awaiting on this method
let processPromise;
const ids = getNextIdGroup(queue);
let resultP = Promise.resolve();

@@ -69,24 +105,12 @@ if (ids) {

ids,
state: queue.getState(),
currentCount
});
let cancelled = false;
let newBatchP = Promise.resolve(false);
processPromise = processNextWithBatch(queue, ids).then(failedOrCancelled => {
if (!failedOrCancelled) {
processBatchItems(queue, ids, processNext);
if (isNewBatchStarting(queue, ids[0])) {
newBatchP = loadNewBatchForItem(queue, ids[0]).then(allowBatch => {
cancelled = !allowBatch;
if (cancelled) {
cancelBatchForItem(queue, ids[0]);
if (concurrent) {
//concurrent process next immediately (otherwise async event callbacks will hang processing next until they complete)
processNext(queue);
}
return cancelled;
});
}
resultP = newBatchP.then(cancelled => {
if (!cancelled) {
processBatchItems(queue, ids, processNext);
}

@@ -97,5 +121,5 @@ });

return resultP;
return processPromise;
};
export default processNext;

@@ -25,3 +25,3 @@ /*!

*/
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.rpldy=t():e.rpldy=t()}(window,(function(){return function(e){function t(t){for(var r,i,s=t[0],c=t[1],d=t[2],u=0,p=[];u<s.length;u++)i=s[u],Object.prototype.hasOwnProperty.call(o,i)&&o[i]&&p.push(o[i][0]),o[i]=0;for(r in c)Object.prototype.hasOwnProperty.call(c,r)&&(e[r]=c[r]);for(l&&l(t);p.length;)p.shift()();return a.push.apply(a,d||[]),n()}function n(){for(var e,t=0;t<a.length;t++){for(var n=a[t],r=!0,s=1;s<n.length;s++){var c=n[s];0!==o[c]&&(r=!1)}r&&(a.splice(t--,1),e=i(i.s=n[0]))}return e}var r={},o={core:0},a=[];function i(t){if(r[t])return r[t].exports;var n=r[t]={i:t,l:!1,exports:{}};return e[t].call(n.exports,n,n.exports,i),n.l=!0,n.exports}i.m=e,i.c=r,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)i.d(n,r,function(t){return e[t]}.bind(null,r));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="";var s=window.webpackJsonprpldy=window.webpackJsonprpldy||[],c=s.push.bind(s);s.push=t,s=s.slice();for(var d=0;d<s.length;d++)t(s[d]);var l=c;return a.push([0,"polyfills"]),n()}({0:function(e,t,n){n("Xsbf"),n("mHo/"),n("GjXi"),e.exports=n("SXZu")},DVTP:function(e,t){e.exports=function(){return!0}},GjXi:function(e,t,n){"use strict";n.r(t),n.d(t,"send",(function(){return f})),n.d(t,"getXhrSend",(function(){return p})),n.d(t,"XHR_SENDER_TYPE",(function(){return o})),n.d(t,"MissingUrlError",(function(){return a}));var r=n("mHo/");const o="rpldy-sender";class a extends Error{constructor(e){super(e+" didn't receive upload URL"),this.name="MissingUrlError"}}const i=function(e,t){for(var n=arguments.length,r=new Array(n>2?n-2:0),o=2;o<n;o++)r[o-2]=arguments[o];"set"in e?e.set(t,...r):("delete"in e&&e.delete(t),e.append(t,...r))};var s=(e,t)=>{const n=new FormData;return t.params&&Object.entries(t.params).forEach(e=>{let[r,o]=e;(t.formDataAllowUndefined||void 0!==o)&&i(n,r,o)}),((e,t,n)=>{const o=1===t.length;t.forEach((t,a)=>{const s=o?n.paramName:Object(r.isFunction)(n.formatGroupParamName)?n.formatGroupParamName(a,n.paramName):`${n.paramName}[${a}]`;t.file?i(e,s,t.file,t.file.name):t.url&&i(e,s,t.url)})})(n,e,t),n};const c=[200,201,202,203,204],d=(e,t,n,o,a)=>{let i;const c=null!=a&&a.getRequestData?a.getRequestData(e,n):((e,t)=>{let n;if(t.sendWithFormData)r.logger.debugLog(`uploady.sender: sending ${e.length} item(s) as form data`),n=s(e,t);else{if(e.length>1)throw new Error("XHR Sender - Request without form data can only contain 1 item. received "+e.length);const t=e[0];r.logger.debugLog(`uploady.sender: sending item ${t.id} as request body`),n=t.file||t.url}return n})(e,n),d=function(){let a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:t,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:c,d=arguments.length>2?arguments[2]:void 0;d=Object(r.merge)({...Object(r.pick)(n,["method","headers","withCredentials"]),preSend:t=>{t.upload.onprogress=t=>{t.lengthComputable&&o&&o(t,e.slice())}}},d);const l=Object(r.request)(a,s,d);return i=l.xhr,l},l=null!=a&&a.preRequestHandler?a.preRequestHandler(d,e,t,n,o,a):d();return{url:t,count:e.length,pXhr:l,getXhr:()=>i,aborted:!1}},l=(e,t,n)=>{let r=e;const o=null==t?void 0:t["content-type"];if(n.forceJsonResponse||null!=o&&o.includes("json"))try{r=JSON.parse(e)}catch{}return r},u=(e,t)=>e.pXhr.then(e=>{var n,o;let a,i,s;r.logger.debugLog("uploady.sender: received upload response ",e),a=~c.indexOf(e.status)?r.FILE_STATES.FINISHED:r.FILE_STATES.ERROR,s=e.status;const d=Object(r.parseResponseHeaders)(e);return i={data:null!==(n=null===(o=t.formatServerResponse)||void 0===o?void 0:o.call(t,e.response,s,d))&&void 0!==n?n:l(e.response,d,t),headers:d},{status:s,state:a,response:i}}).catch(t=>{let n,o;return e.aborted?(n=r.FILE_STATES.ABORTED,o="aborted"):(r.logger.debugLog("uploady.sender: upload failed: ",t),n=r.FILE_STATES.ERROR,o=t),{error:!0,state:n,response:o,status:0}});var p=e=>(t,n,i,s)=>{if(!n)throw new a(o);r.logger.debugLog("uploady.sender: sending file: ",{items:t,url:n,options:i});const c=d(t,n,i,s,e);return{request:u(c,i),abort:()=>(e=>{let t=!1;const{aborted:n,getXhr:o}=e,a=o();return!n&&a&&a.readyState&&4!==a.readyState&&(r.logger.debugLog(`uploady.sender: cancelling request with ${e.count} items to: ${e.url}`),a.abort(),e.aborted=!0,t=!0),t})(c),senderType:o}};const f=p();t.default=f},SXZu:function(e,t,n){"use strict";n.r(t),n.d(t,"UPLOADER_EVENTS",(function(){return h})),n.d(t,"DEFAULT_OPTIONS",(function(){return Q})),n.d(t,"composeEnhancers",(function(){return re})),n.d(t,"createUploader",(function(){return ne})),n.d(t,"send",(function(){return k.send})),n.d(t,"getXhrSend",(function(){return k.getXhrSend})),n.d(t,"XHR_SENDER_TYPE",(function(){return k.XHR_SENDER_TYPE})),n.d(t,"MissingUrlError",(function(){return k.MissingUrlError}));var r=n("Xsbf"),o=n("mHo/");const a=Symbol.for("__rpldy-sstt-proxy__"),i=Symbol.for("__rpldy-sstt-state__"),s=e=>!Object(o.isProduction)()&&!!e&&!!~Object.getOwnPropertySymbols(e).indexOf(a),c=e=>Array.isArray(e)||Object(o.isPlainObject)(e)&&!(e=>Object(o.hasWindow)()&&e instanceof File||e.name&&e.size&&e.uri)(e),d=Object(o.getMerge)({withSymbols:!0,predicate:e=>e!==a&&e!==i}),l=e=>!!Object(o.isProduction)()||e[i].isUpdateable,u=(e,t)=>{Object(o.isProduction)()||(e[i].isUpdateable=t)},p=(e,t)=>{let n;return c(e)&&(s(e)||(e[a]=!0,n=new Proxy(e,t)),Object.keys(e).forEach(n=>{e[n]=p(e[n],t)})),n||e},f=e=>s(e)?Object(o.clone)(e,d):e;var g=e=>{const t={set:(e,r,o)=>(l(n)&&(e[r]=p(o,t)),!0),get:(e,t)=>t===a?f(e):e[t],defineProperty:()=>{throw new Error("Simple State doesnt support defining property")},setPrototypeOf:()=>{throw new Error("Simple State doesnt support setting prototype")},deleteProperty:(e,t)=>(l(n)&&delete e[t],!0)};Object(o.isProduction)()||s(e)||Object.defineProperty(e,i,{value:{isUpdateable:!1},configurable:!0});const n=Object(o.isProduction)()?e:p(e,t);return{state:n,update:e=>{if(!Object(o.isProduction)()&&l(n))throw new Error("Can't call update on State already being updated!");try{u(n,!0),e(n)}finally{u(n,!1)}return n},unwrap:e=>e?f(e):s(n)?f(n):n}};const h=Object(o.devFreeze)({BATCH_ADD:"BATCH-ADD",BATCH_START:"BATCH-START",BATCH_PROGRESS:"BATCH_PROGRESS",BATCH_FINISH:"BATCH-FINISH",BATCH_ABORT:"BATCH-ABORT",BATCH_CANCEL:"BATCH-CANCEL",ITEM_START:"FILE-START",ITEM_CANCEL:"FILE-CANCEL",ITEM_PROGRESS:"FILE-PROGRESS",ITEM_FINISH:"FILE-FINISH",ITEM_ABORT:"FILE-ABORT",ITEM_ERROR:"FILE-ERROR",ITEM_FINALIZE:"FILE-FINALIZE",REQUEST_PRE_SEND:"REQUEST_PRE_SEND",ALL_ABORT:"ALL_ABORT"}),E=Object(o.devFreeze)({ITEM_PROGRESS:"ITEM_PROGRESS",BATCH_PROGRESS:"BATCH_PROGRESS"}),b=[o.FILE_STATES.FINISHED,o.FILE_STATES.ERROR,o.FILE_STATES.CANCELLED,o.FILE_STATES.ABORTED],S=[o.BATCH_STATES.ADDED,o.BATCH_STATES.PROCESSING,o.BATCH_STATES.UPLOADING],m=[o.BATCH_STATES.ABORTED,o.BATCH_STATES.CANCELLED,o.BATCH_STATES.FINISHED],T=(e,t)=>e.batches[t].batch,A=(e,t,n)=>e.getState().items[t].batchId===n,v=(e,t)=>{const n=e.getState(),r=n.items[t];return n.batches[r.batchId]},O=(e,t)=>v(e,t).batch,y=(e,t)=>{const n=((e,t)=>T(e.getState(),t))(e,t);e.updateState(e=>{n.items.forEach(t=>{let{id:n}=t;delete e.items[n];const r=e.itemQueue.indexOf(n);~r&&e.itemQueue.splice(r,1)})})},_=(e,t)=>{e.updateState(e=>{delete e.batches[t]})},I=(e,t,n)=>{const r=e.getState(),o=T(r,t),a=r.items,i={...f(o),items:o.items.map(e=>{let{id:t}=e;return f(a[t])})};e.trigger(n,i)},R=(e,t)=>{const n=O(e,t);return S.includes(n.state)},w=e=>m.includes(e.state),P={[o.FILE_STATES.PENDING]:null,[o.FILE_STATES.ADDED]:h.ITEM_START,[o.FILE_STATES.FINISHED]:h.ITEM_FINISH,[o.FILE_STATES.ERROR]:h.ITEM_ERROR,[o.FILE_STATES.CANCELLED]:h.ITEM_CANCEL,[o.FILE_STATES.ABORTED]:h.ITEM_ABORT,[o.FILE_STATES.UPLOADING]:h.ITEM_PROGRESS},C=e=>!!~b.indexOf(e.state);var D=(e,t,n)=>(t.forEach(t=>{const n=e.getState(),{id:r,info:a}=t;if(o.logger.debugLog("uploader.processor.queue: request finished for item - ",{id:r,info:a}),n.items[r]){e.updateState(e=>{const t=e.items[r];t.state=a.state,t.uploadResponse=a.response,t.uploadStatus=a.status,C(t)&&delete e.aborts[r]});const t=e.getState().items[r];a.state===o.FILE_STATES.FINISHED&&t.completed<100&&e.handleItemProgress(t,100,t.file?t.file.size:0),P[t.state]&&e.trigger(P[t.state],t),C(t)&&(((e,t)=>{e.updateState(e=>{e.batches[t].finishedCounter+=1})})(e,t.batchId),e.trigger(h.ITEM_FINALIZE,t))}const i=n.itemQueue.indexOf(r);~i&&e.updateState(e=>{e.itemQueue.splice(i,1);const t=e.activeIds.indexOf(r);~t&&e.activeIds.splice(t,1)})}),(e=>{const t=e.getState();Object.keys(t.batches).forEach(n=>{const{batch:r,finishedCounter:a}=t.batches[n],{orgItemCount:i}=r,s=w(r);i===a&&(s||100===r.completed||(e.updateState(e=>{const t=T(e,n);t.completed=100,t.loaded=t.items.reduce((e,t)=>{let{loaded:n}=t;return e+n},0)}),I(e,n,h.BATCH_PROGRESS)),e.updateState(e=>{const t=T(e,n);t.state=s?t.state:o.BATCH_STATES.FINISHED,e.currentBatch===n&&(e.currentBatch=null)}),o.logger.debugLog("uploady.uploader.batchHelpers: cleaning up batch: "+r.id),s||I(e,n,h.BATCH_FINISH),y(e,n),_(e,n))})})(e),n(e));const L=Object(o.getMerge)({undefinedOverwrites:!0}),j=(e,t)=>{const n=t.map(e=>e.id);return e.updateState(e=>{e.activeIds=e.activeIds.concat(n)}),((e,t,n)=>Object(o.triggerUpdater)(e.trigger,h.REQUEST_PRE_SEND,{items:t,options:n}).then(e=>{if(e){if(o.logger.debugLog("uploader.queue: REQUEST_PRE_SEND event returned updated items/options",e),e.items){if(e.items.length!==t.length||!Object(o.isSamePropInArrays)(e.items,t,["id","batchId","recycled"]))throw new Error("REQUEST_PRE_SEND event handlers must return same items with same ids");t=e.items}e.options&&(n=L({},n,e.options))}return{items:t,options:n,cancelled:!1===e}}))(e,t,e.getState().batches[t[0].batchId].batchOptions).then(n=>{if(!n.cancelled){e.updateState(e=>{n.items.forEach(t=>{e.items[t.id]=t}),e.batches[t[0].batchId].batchOptions=n.options});const r=e.getState();n.items=n.items.map(e=>r.items[e.id]),n.options=r.batches[t[0].batchId].batchOptions}return n})},B=(e,t,n)=>{const{items:r,options:a}=t,i=e.getState().batches[r[0].batchId].batch;let s;try{s=e.sender.send(r,i,a)}catch(e){o.logger.debugLog("uploader.queue: sender failed with unexpected error",e),s={request:Promise.resolve({status:0,state:o.FILE_STATES.ERROR,response:e.message}),abort:()=>!1,senderType:"exception-handler"}}const{request:c}=s;return((e,t,n)=>{e.updateState(e=>{t.forEach(t=>{e.items[t.id].state=o.FILE_STATES.UPLOADING,e.aborts[t.id]=n.abort})})})(e,r,s),c.then(t=>{const o=r.map(e=>({id:e.id,info:t}));D(e,o,n)})};var N=(e,t,n)=>{const r=e.getState();let a=Object.values(r.items);return a=a.filter(e=>!!~t.indexOf(e.id)),Promise.all(a.map(t=>e.runCancellable(h.ITEM_START,t))).then(t=>({allowedItems:t.map((t,n)=>t?null:((e,t)=>t.getState().items[e])(a[n].id,e)).filter(Boolean),cancelledResults:t})).then(r=>{let{allowedItems:i,cancelledResults:s}=r;return(i.length?j(e,i).then():Promise.resolve()).then(r=>{let i;return r&&(r.cancelled?s=t.map(()=>!0):B(e,r,n)),((e,t,n,r)=>{const a=n.map((e,n)=>e?t[n].id:null).filter(Boolean);if(a.length){const t=a.map(e=>({id:e,info:{status:0,state:o.FILE_STATES.CANCELLED,response:"cancel"}}));D(e,t,r)}return!!a.length})(e,a,s,n)||(i=n(e)),i})})};const F=(e,t)=>!!~e.getState().activeIds.flat().indexOf(t),H=e=>{const t=e.getState().itemQueue,n=(e=>{const t=e.getState(),n=t.itemQueue,r=t.items;let a=0,i=n[a];for(;i&&(F(e,i)||!R(e,i)||r[i].state!==o.FILE_STATES.ADDED);)a+=1,i=n[a];return i?a:-1})(e);let r,a=t[n];if(a){const o=v(e,a),i=o.batch.id,s=o.batchOptions.maxGroupSize||0;if(o.batchOptions.grouped&&s>1){r=[];let o=!0;for(;r.length<s&&o;)r.push(a),a=t[n+r.length],o=a&&A(e,a,i)}else r=[a]}return r},x=e=>{const t=H(e);let n=Promise.resolve();if(t){const r=e.getCurrentActiveCount(),{concurrent:a=0,maxConcurrent:i=0}=e.getOptions();if(!r||a&&r<i){o.logger.debugLog("uploader.processor: Processing next upload - ",{ids:t,state:e.getState(),currentCount:r});let a=!1,i=Promise.resolve(!1);((e,t)=>{const n=O(e,t);return e.getState().currentBatch!==n.id})(e,t[0])&&(i=((e,t)=>{const n=O(e,t);return e.runCancellable(h.BATCH_START,n).then(t=>(t||e.updateState(e=>{e.currentBatch=n.id}),!t))})(e,t[0]).then(n=>(a=!n,a&&(((e,t)=>{const n=O(e,t),r=n.id;o.logger.debugLog("uploady.uploader.batchHelpers: cancelling batch: ",{batch:n}),e.updateState(e=>{T(e,r).state=o.BATCH_STATES.CANCELLED}),I(e,r,h.BATCH_CANCEL),y(e,r),_(e,r)})(e,t[0]),x(e)),a))),n=i.then(n=>{n||N(e,t,x)})}}return n};var G=x;const U=(e,t,n)=>(o.logger.debugLog(`uploader.queue: aborting ${t.state} item - `,t),D(e,[{id:t.id,info:{status:0,state:o.FILE_STATES.ABORTED,response:"aborted"}}],n),!0),M={[o.FILE_STATES.UPLOADING]:(e,t)=>(o.logger.debugLog("uploader.queue: aborting uploading item - ",t),e.getState().aborts[t.id]()),[o.FILE_STATES.ADDED]:U,[o.FILE_STATES.PENDING]:U},q=(e,t,n)=>{const r=e.getState().items[t],o=null==r?void 0:r.state;return!!M[o]&&M[o](e,r,n)};var $=(e,t,n,r,a)=>{const{state:i,update:s}=g({itemQueue:[],currentBatch:null,batches:{},items:{},activeIds:[],aborts:{}}),c=()=>i,d=e=>{s(e)},l=e=>{if(i.items[e.id]&&!e.recycled)throw new Error(`Uploader queue conflict - item ${e.id} already exists`);e.recycled&&((e,t)=>{const{previousBatch:n}=t;if(t.recycled&&n&&e.getState().batches[n]){const{id:r}=O(e,t.id);r===n&&e.updateState(e=>{const n=T(e,r),o=n.items.findIndex(e=>{let{id:n}=e;return n===t.id});~o&&n.items.splice(o,1)})}})(p,e),d(t=>{t.items[e.id]=e,t.itemQueue.push(e.id)})},u=(e,n,r)=>{i.items[e.id]&&(d(t=>{const o=t.items[e.id];o.loaded=r,o.completed=n}),t(h.ITEM_PROGRESS,c().items[e.id]))};r.on(E.ITEM_PROGRESS,u),r.on(E.BATCH_PROGRESS,e=>{var n;const r=null===(n=i.batches[e.id])||void 0===n?void 0:n.batch.items;if(r){const[n,o]=r.reduce((e,t)=>{let{completed:n,loaded:r}=t;return e[0]+=n,e[1]+=r,e},[0,0]);d(t=>{const a=t.batches[e.id].batch;a.completed=n/r.length,a.loaded=o}),t(h.BATCH_PROGRESS,i.batches[e.id].batch)}});const p={uploaderId:a,getOptions:()=>e,getCurrentActiveCount:()=>i.activeIds.length,getState:c,updateState:d,trigger:t,runCancellable:function(e){if(!Object(o.isFunction)(n))throw new Error("Uploader queue - cancellable is of wrong type");for(var t=arguments.length,r=new Array(t>1?t-1:0),a=1;a<t;a++)r[a-1]=arguments[a];return n(e,...r)},sender:r,handleItemProgress:u};return Object(o.hasWindow)()&&o.logger.isDebugOn()&&(window[`__rpldy_${a}_queue_state`]=p),{updateState:d,getState:p.getState,runCancellable:p.runCancellable,uploadBatch:(e,t)=>{t&&d(n=>{n.batches[e.id].batchOptions=t}),G(p)},addBatch:(e,t)=>(d(n=>{n.batches[e.id]={batch:e,batchOptions:t,finishedCounter:0}}),e.items.forEach(l),T(i,e.id)),abortItem:e=>((e,t,n)=>q(e,t,n))(p,e,G),abortBatch:e=>{((e,t,n)=>{const r=e.getState().batches[t],a=null==r?void 0:r.batch;a&&!w(a)&&(e.updateState(e=>{T(e,t).state=o.BATCH_STATES.ABORTED}),I(e,t,h.BATCH_ABORT),a.items.forEach(t=>q(e,t.id,n)))})(p,e,G)},abortAll:()=>{((e,t)=>{const n=e.getState().items;Object.keys(n).forEach(n=>q(e,n,t)),e.trigger(h.ALL_ABORT)})(p,G)},clearPendingBatches:()=>{(e=>{const t=e.getState().batches;Object.keys(t).filter(e=>t[e].batch.state===o.BATCH_STATES.PENDING).forEach(t=>{y(e,t),_(e,t)})})(p)},uploadPendingBatches:e=>{((e,t)=>{e.updateState(e=>{Object.keys(e.batches).forEach(n=>{const r=e.batches[n],{batch:a,batchOptions:i}=r;a.state===o.BATCH_STATES.PENDING&&(a.items.forEach(e=>{e.state=o.FILE_STATES.ADDED}),a.state=o.BATCH_STATES.ADDED,r.batchOptions=Object(o.merge)({},i,t))})})})(p,e),G(p)}}},k=n("GjXi");const X=()=>!0,Q=Object(o.devFreeze)({autoUpload:!0,clearPendingOnAdd:!1,inputFieldName:"file",concurrent:!1,maxConcurrent:2,grouped:!1,maxGroupSize:5,method:"POST",params:{},fileFilter:X,forceJsonResponse:!1,withCredentials:!1,destination:{},send:null,sendWithFormData:!0,formDataAllowUndefined:!1}),z=(e,t,n,r)=>{((e,t,n,r)=>{e.forEach(e=>{o.logger.debugLog(`uploady.uploader.processor: file: ${e.id} progress event: loaded(${n}) - completed(${t})`),r(E.ITEM_PROGRESS,e,t,n)})})(e,Math.min(n.loaded/n.total*100,100)/e.length,n.loaded/e.length,r),r(E.BATCH_PROGRESS,t)};var J=()=>{const{trigger:e,target:t}=Object(r.default)({send:(t,n,r)=>{const a=r.destination,i=null==a?void 0:a.url,s=Object(o.throttle)(r=>z(t,n,r,e),50,!0);return(Object(o.isFunction)(r.send)?r.send:k.default)(t,i,{method:(null==a?void 0:a.method)||r.method||Q.method,paramName:(null==a?void 0:a.filesParamName)||r.inputFieldName||"file",params:{...r.params,...null==a?void 0:a.params},forceJsonResponse:r.forceJsonResponse,withCredentials:r.withCredentials,formatGroupParamName:r.formatGroupParamName,headers:null==a?void 0:a.headers,sendWithFormData:r.sendWithFormData,formatServerResponse:r.formatServerResponse,formDataAllowUndefined:r.formDataAllowUndefined},s)}},Object.values(E));return t};const W=Object(o.hasWindow)()&&"FileList"in window,Z=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=e;return Object(o.isProduction)()||(t<3&&s(e)?n=f(e):t<3&&c(e)&&(n=Array.isArray(e)?e.map(e=>Z(e,t+1)):Object.keys(e).reduce((n,r)=>(n[r]=Z(e[r],t+1),n),{}))),n};let V=0;var Y=(e,t,n)=>{V+=1;const r="batch-"+V,a=(e=>W&&e instanceof FileList||"[object FileList]"===e.toString())(e);e=Array.isArray(e)||a?e:[e];const i=!n.autoUpload,s=((e,t,n,r)=>Array.prototype.filter.call(t,r||X).map(t=>Object(o.createBatchItem)(t,e,n)))(r,e,i,n.fileFilter);return{id:r,uploaderId:t,items:s,state:i?o.BATCH_STATES.PENDING:o.BATCH_STATES.ADDED,completed:0,loaded:0,orgItemCount:s.length}};var K=(e,t,n,r)=>{const o=J(),a=$(n,e,t,o,r);return{process:(e,t)=>{a.uploadBatch(e,t)},abortBatch:e=>{a.abortBatch(e)},abort:e=>{e?a.abortItem(e):a.abortAll()},addNewBatch:(e,t,n)=>{const r=Y(e,t,n);return a.addBatch(r,n)},runCancellable:a.runCancellable,clearPendingBatches:()=>{a.clearPendingBatches()},processPendingBatches:e=>{a.uploadPendingBatches(e)}}};const ee=Object.values(h);let te=0;var ne=e=>{te+=1;const t="uploader-"+te;let n=!1;const a={};o.logger.debugLog(`uploady.uploader: creating new instance (${t})`,{options:e,counter:te});let i=(e=>{return{...Q,...e,destination:e&&e.destination?(t=e.destination,{params:{},...t}):null};var t})(e);const s=()=>{p.clearPendingBatches()};let{trigger:c,target:d}=Object(r.default)({id:t,update:e=>(i=Object(o.merge)({},i,e),d),add:(e,t)=>{const n=Object(o.merge)({},i,t);n.clearPendingOnAdd&&s();const r=p.addNewBatch(e,d.id,n);let a;return r.items.length?a=p.runCancellable(h.BATCH_ADD,r,n).then(e=>{e?(r.state=o.BATCH_STATES.CANCELLED,l(h.BATCH_CANCEL,r)):(o.logger.debugLog(`uploady.uploader [${d.id}]: new items added - auto upload =\n ${String(n.autoUpload)}`,r.items),n.autoUpload&&p.process(r))}):o.logger.debugLog(`uploady.uploader: no items to add. batch ${r.id} is empty. check fileFilter if this isn't intended`),a||Promise.resolve()},upload:e=>{p.processPendingBatches(e)},abort:e=>{p.abort(e)},abortBatch:e=>{p.abortBatch(e)},getOptions:()=>Object(o.clone)(i),clearPending:s,registerExtension:(e,t)=>{Object(o.invariant)(n,"Uploady - uploader extensions can only be registered by enhancers"),Object(o.invariant)(!a[e],"Uploady - uploader extension by this name [%s] already exists",e),o.logger.debugLog("uploady.uploader: registering extension: "+e.toString(),t),a[e]=t},getExtension:e=>a[e]},ee,{canAddEvents:!1,canRemoveEvents:!1});const l=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];const a=Object(r.createLifePack)(()=>n.map(Z));return c(e,a)},u=Object(o.triggerCancellable)(l);if(i.enhancer){n=!0;const e=i.enhancer(d,l);n=!1,d=e||d}const p=K(l,u,i,d.id);return Object(o.devFreeze)(d)};var re=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return t.reduce((e,t)=>t(e,...r)||e,e)}};t.default=ne},Xsbf:function(e,t,n){"use strict";n.r(t),n.d(t,"default",(function(){return y})),n.d(t,"addLife",(function(){return y})),n.d(t,"isLE",(function(){return f})),n.d(t,"createLifePack",(function(){return _}));var r=n("JlUD"),o=n.n(r),a=n("mHo/");var i=Object(a.devFreeze)({allowRegisterNonExistent:!0,canAddEvents:!0,canRemoveEvents:!0,collectStats:!1});const s=(e,t)=>{if(!Object(a.isFunction)(e))throw new Error(`'${t}' is not a valid function`)},c=e=>void 0===e,d=Symbol.for("__le__"),l=Symbol.for("__le__pack__"),u=e=>e?e[d]:null,p=e=>{const t=u(e);if(!t)throw new Error("Didnt find LE internal object. Something very bad happened!");return t},f=e=>!!u(e),g=function(e,t,n){let r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];s(n,"cb");const o=p(e);if(!o.options.allowRegisterNonExistent&&!~o.events.indexOf(t))throw new Error(`Cannot register for event ${t.toString()} that wasn't already defined (allowRegisterNonExistent = false)`);const a=o.registry[t]||[];return a.find(e=>e.cb===n)||(a.push({name:t,cb:n,once:r}),o.registry[t]=a),()=>v.call(e,t,n)},h=(e,t)=>{const n=p(e).registry;return t?n[t]?n[t].slice():[]:Object.values(n).flat()},E={on:function(e,t){return g(this,e,t)},once:function(e,t){return g(this,e,t,!0)},off:v,getEvents:function(){return p(this).events.slice()}},b=()=>Object.entries(E).reduce((e,t)=>{let[n,r]=t;return e[n]={value:r},e},{}),S={trigger:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];const a=h(this,e);let i;if(a.length){var s;let t;1===n.length&&!0===(null===(s=n[0])||void 0===s?void 0:s[l])&&(t=n[0].resolve()),i=a.map(r=>{let o;return r.once&&A(this,e,r.cb),o=t?r.cb(...t):n.length?1===n.length?r.cb(n[0]):2===n.length?r.cb(n[0],n[1]):3===n.length?r.cb(n[0],n[1],n[2]):r.cb(...n):r.cb(),o}).filter(e=>!c(e)).map(e=>o()(e)?e:Promise.resolve(e))}return i&&(i.length?i:void 0)},addEvent:function(e){const t=p(this);if(!t.options.canAddEvents)throw new Error("Cannot add new events (canAddEvents = false)");if(~t.events.indexOf(e))throw new Error(`Event '${e}' already defined`);t.events.push(e)},removeEvent:function(e){const t=p(this);if(!t.options.canRemoveEvents)throw new Error("Cannot remove events (canRemoveEvents = false)");{const n=t.events.indexOf(e);t.events.splice(n,1)}},hasEvent:function(e){return!!~p(this).events.indexOf(e)},hasEventRegistrations:function(e){return!!h(this,e).length},assign:function(e){const t=p(this);return O(e,t.options,t.events,t.registry,t.stats),m(e)}},m=e=>Object.keys(S).reduce((t,n)=>(t[n]=S[n].bind(e),t),{target:e,...S}),T=function(e,t){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const r=p(e).registry;!r[t]||!n&&r[t].length||delete r[t]},A=(e,t,n)=>{const r=p(e).registry;r[t]&&(n?(r[t]=r[t].filter(e=>e.cb!==n),T(e,t)):T(e,t,!0))};function v(e,t){A(this,e,t)}const O=function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};Object.defineProperties(e,{[d]:{value:Object.seal({registry:r,events:n,options:t,stats:o})},...b()})};var y=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=arguments.length>2?arguments[2]:void 0;return e=e||{},n={...i,...n},f(e)||O(e,n,t),m(e)};var _=e=>{const t={resolve:()=>[].concat(e())};return Object.defineProperty(t,l,{value:!0,configurable:!1}),t}},"mHo/":function(e,t,n){"use strict";n.r(t),n.d(t,"BATCH_STATES",(function(){return c})),n.d(t,"FILE_STATES",(function(){return d})),n.d(t,"invariant",(function(){return a.a})),n.d(t,"throttle",(function(){return s.a})),n.d(t,"logger",(function(){return r})),n.d(t,"triggerCancellable",(function(){return h})),n.d(t,"triggerUpdater",(function(){return b})),n.d(t,"createBatchItem",(function(){return O})),n.d(t,"request",(function(){return I})),n.d(t,"parseResponseHeaders",(function(){return _})),n.d(t,"isFunction",(function(){return w.a})),n.d(t,"isPlainObject",(function(){return j})),n.d(t,"isSamePropInArrays",(function(){return P})),n.d(t,"devFreeze",(function(){return L})),n.d(t,"merge",(function(){return H})),n.d(t,"getMerge",(function(){return F})),n.d(t,"clone",(function(){return x})),n.d(t,"pick",(function(){return G})),n.d(t,"hasWindow",(function(){return l})),n.d(t,"isProduction",(function(){return D.a}));var r={};n.r(r),n.d(r,"isDebugOn",(function(){return p})),n.d(r,"setDebug",(function(){return f})),n.d(r,"debugLog",(function(){return g}));var o=n("kvau"),a=n.n(o),i=n("uDTZ"),s=n.n(i);const c={PENDING:"pending",ADDED:"added",PROCESSING:"processing",UPLOADING:"uploading",CANCELLED:"cancelled",FINISHED:"finished",ABORTED:"aborted"},d={PENDING:"pending",ADDED:"added",UPLOADING:"uploading",CANCELLED:"cancelled",FINISHED:"finished",ERROR:"error",ABORTED:"aborted"};var l=()=>"object"==typeof window&&!!window.document;let u;const p=()=>("boolean"!=typeof u&&(u=l()&&("location"in window&&!!~window.location.search.indexOf("rpldy_debug=true")||!0===window["__rpldy-logger-debug__"])),!!u),f=e=>{l()&&(window["__rpldy-logger-debug__"]=e),u=!!e||null},g=function(){p()&&console.log(...arguments)};var h=function(e,t){const n=function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return new Promise((n,o)=>{const a=e(t,...r);a&&a.length?Promise.all(a).catch(o).then(e=>e&&n(!!~e.findIndex(e=>!1===e))):n(!1)})};for(var r=arguments.length,o=new Array(r>2?r-2:0),a=2;a<r;a++)o[a-2]=arguments[a];return t?n(t,...o):n};const E=e=>null==e;var b=function(e,t){const n=function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return new Promise((n,o)=>{const a=e(t,...r);a&&a.length?Promise.all(a).catch(o).then(e=>{let t;if(e)for(;E(t)&&e.length;)t=e.pop();n(E(t)?void 0:t)}):n()})};for(var r=arguments.length,o=new Array(r>2?r-2:0),a=2;a<r;a++)o[a-2]=arguments[a];return t?n(t,...o):n};const S=Symbol.for("__rpldy-bi__");let m=0;const T=(e,t)=>(e.url=t,e),A=(e,t)=>(e.file=t,e),v=e=>e&&(e instanceof File||e instanceof Blob||"object"==typeof e&&e.name&&e.type);var O=function(e,t){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];m+=e.id&&e.batchId?0:1;const r=e.id&&e.batchId?e.id:`${t}.item-${m}`,o=n?d.PENDING:d.ADDED;let a={id:r,batchId:t,state:o,uploadStatus:0,completed:0,loaded:0,aborted:!1,recycled:!1,previousBatch:null};if(Object.defineProperty(a,S,{value:!0,writable:!0}),"object"==typeof e&&!0===e[S]&&(a.recycled=!0,a.previousBatch=e.batchId,e=e.file||e.url),"string"==typeof e)a=T(a,e);else{if(!v(e))throw new Error("Unknown type of file added: "+typeof e);a=A(a,e)}return a};const y=(e,t)=>{t&&Object.keys(t).forEach(n=>{void 0!==t[n]&&e.setRequestHeader(n,t[n])})};var _=e=>{let t;try{t=e.getAllResponseHeaders().trim().split(/[\r\n]+/).reduce((e,t)=>{const[n,r]=t.split(": ");return e[n]=r,e},{})}catch(t){g("uploady.request: failed to read response headers",e)}return t},I=function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const r=new XMLHttpRequest,o=new Promise((o,a)=>{r.onerror=()=>a(r),r.ontimeout=()=>a(r),r.onabort=()=>a(r),r.onload=()=>o(r),r.open(n.method||"GET",e),y(r,n.headers),r.withCredentials=!!n.withCredentials,n.preSend&&n.preSend(r),r.send(t)});return o.xhr=r,o},R=n("r5yn"),w=n.n(R);var P=(e,t,n)=>{let r=!0;const o=(e=>{const t=[].concat(e);return e=>e.map(e=>t.map(t=>e[t]).join())})(n);if(e&&t&&e.length===t.length){const n=o(e),a=o(t);r=!!n.find((e,t)=>e!==a[t])}return!r},C=n("DVTP"),D=n.n(C);var L=e=>D()()?e:Object.freeze(e);var j=e=>{var t;return!!e&&"object"==typeof e&&("Object"===(null===(t=Object.getPrototypeOf(e))||void 0===t?void 0:t.constructor.name)||null===Object.getPrototypeOf(e))};const B=e=>j(e)||Array.isArray(e),N=(e,t)=>{const n=Object.keys(e);return t.withSymbols?n.concat(Object.getOwnPropertySymbols(e)):n},F=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=function(n){for(var r=arguments.length,o=new Array(r>1?r-1:0),a=1;a<r;a++)o[a-1]=arguments[a];return n&&o.length&&o.forEach(r=>{r&&N(r,e).forEach(o=>{const a=r[o];e.predicate&&!e.predicate(o,a)||(void 0!==a||e.undefinedOverwrites)&&(B(a)?(void 0!==n[o]&&j(n[o])||(n[o]=Array.isArray(a)?[]:{}),t(n[o],a)):n[o]=a)})}),n};return t};var H=F();var x=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:H;return B(e)?t(Array.isArray(e)?[]:{},e):e};var G=(e,t)=>e&&Object.keys(e).reduce((n,r)=>(~t.indexOf(r)&&(n[r]=e[r]),n),{})},r5yn:function(e,t){e.exports=function(e){return"function"==typeof e}}})}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.rpldy=t():e.rpldy=t()}(window,(function(){return function(e){function t(t){for(var r,i,s=t[0],c=t[1],d=t[2],u=0,p=[];u<s.length;u++)i=s[u],Object.prototype.hasOwnProperty.call(o,i)&&o[i]&&p.push(o[i][0]),o[i]=0;for(r in c)Object.prototype.hasOwnProperty.call(c,r)&&(e[r]=c[r]);for(l&&l(t);p.length;)p.shift()();return a.push.apply(a,d||[]),n()}function n(){for(var e,t=0;t<a.length;t++){for(var n=a[t],r=!0,s=1;s<n.length;s++){var c=n[s];0!==o[c]&&(r=!1)}r&&(a.splice(t--,1),e=i(i.s=n[0]))}return e}var r={},o={core:0},a=[];function i(t){if(r[t])return r[t].exports;var n=r[t]={i:t,l:!1,exports:{}};return e[t].call(n.exports,n,n.exports,i),n.l=!0,n.exports}i.m=e,i.c=r,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)i.d(n,r,function(t){return e[t]}.bind(null,r));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="";var s=window.webpackJsonprpldy=window.webpackJsonprpldy||[],c=s.push.bind(s);s.push=t,s=s.slice();for(var d=0;d<s.length;d++)t(s[d]);var l=c;return a.push([0,"polyfills"]),n()}({0:function(e,t,n){n("Xsbf"),n("mHo/"),n("GjXi"),e.exports=n("SXZu")},DVTP:function(e,t){e.exports=function(){return!0}},GjXi:function(e,t,n){"use strict";n.r(t),n.d(t,"send",(function(){return g})),n.d(t,"getXhrSend",(function(){return p})),n.d(t,"XHR_SENDER_TYPE",(function(){return o})),n.d(t,"MissingUrlError",(function(){return a}));var r=n("mHo/");const o="rpldy-sender";class a extends Error{constructor(e){super(e+" didn't receive upload URL"),this.name="MissingUrlError"}}const i=function(e,t){for(var n=arguments.length,r=new Array(n>2?n-2:0),o=2;o<n;o++)r[o-2]=arguments[o];"set"in e?e.set(t,...r):("delete"in e&&e.delete(t),e.append(t,...r))};var s=(e,t)=>{const n=new FormData;return t.params&&Object.entries(t.params).forEach(e=>{let[r,o]=e;(t.formDataAllowUndefined||void 0!==o)&&i(n,r,o)}),((e,t,n)=>{const o=1===t.length;t.forEach((t,a)=>{const s=o?n.paramName:Object(r.isFunction)(n.formatGroupParamName)?n.formatGroupParamName(a,n.paramName):`${n.paramName}[${a}]`;t.file?i(e,s,t.file,t.file.name):t.url&&i(e,s,t.url)})})(n,e,t),n};const c=[200,201,202,203,204],d=(e,t,n,o,a)=>{let i;const c=null!=a&&a.getRequestData?a.getRequestData(e,n):((e,t)=>{let n;if(t.sendWithFormData)r.logger.debugLog(`uploady.sender: sending ${e.length} item(s) as form data`),n=s(e,t);else{if(e.length>1)throw new Error("XHR Sender - Request without form data can only contain 1 item. received "+e.length);const t=e[0];r.logger.debugLog(`uploady.sender: sending item ${t.id} as request body`),n=t.file||t.url}return n})(e,n),d=function(){let a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:t,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:c,d=arguments.length>2?arguments[2]:void 0;d=Object(r.merge)({...Object(r.pick)(n,["method","headers","withCredentials"]),preSend:t=>{t.upload.onprogress=t=>{t.lengthComputable&&o&&o(t,e.slice())}}},d);const l=Object(r.request)(a,s,d);return i=l.xhr,l},l=null!=a&&a.preRequestHandler?a.preRequestHandler(d,e,t,n,o,a):d();return{url:t,count:e.length,pXhr:l,getXhr:()=>i,aborted:!1}},l=(e,t,n)=>{let r=e;const o=null==t?void 0:t["content-type"];if(n.forceJsonResponse||null!=o&&o.includes("json"))try{r=JSON.parse(e)}catch{}return r},u=(e,t)=>e.pXhr.then(e=>{var n,o;let a,i,s;r.logger.debugLog("uploady.sender: received upload response ",e),a=~c.indexOf(e.status)?r.FILE_STATES.FINISHED:r.FILE_STATES.ERROR,s=e.status;const d=Object(r.parseResponseHeaders)(e);return i={data:null!==(n=null===(o=t.formatServerResponse)||void 0===o?void 0:o.call(t,e.response,s,d))&&void 0!==n?n:l(e.response,d,t),headers:d},{status:s,state:a,response:i}}).catch(t=>{let n,o;return e.aborted?(n=r.FILE_STATES.ABORTED,o="aborted"):(r.logger.debugLog("uploady.sender: upload failed: ",t),n=r.FILE_STATES.ERROR,o=t),{error:!0,state:n,response:o,status:0}});var p=e=>(t,n,i,s)=>{if(!n)throw new a(o);r.logger.debugLog("uploady.sender: sending file: ",{items:t,url:n,options:i});const c=d(t,n,i,s,e);return{request:u(c,i),abort:()=>(e=>{let t=!1;const{aborted:n,getXhr:o}=e,a=o();return!n&&a&&a.readyState&&4!==a.readyState&&(r.logger.debugLog(`uploady.sender: cancelling request with ${e.count} items to: ${e.url}`),a.abort(),e.aborted=!0,t=!0),t})(c),senderType:o}};const g=p();t.default=g},SXZu:function(e,t,n){"use strict";n.r(t),n.d(t,"UPLOADER_EVENTS",(function(){return h})),n.d(t,"DEFAULT_OPTIONS",(function(){return ee})),n.d(t,"composeEnhancers",(function(){return ue})),n.d(t,"createUploader",(function(){return le})),n.d(t,"send",(function(){return Y.send})),n.d(t,"getXhrSend",(function(){return Y.getXhrSend})),n.d(t,"XHR_SENDER_TYPE",(function(){return Y.XHR_SENDER_TYPE})),n.d(t,"MissingUrlError",(function(){return Y.MissingUrlError}));var r=n("Xsbf"),o=n("mHo/");const a=Symbol.for("__rpldy-sstt-proxy__"),i=Symbol.for("__rpldy-sstt-state__"),s=e=>!Object(o.isProduction)()&&!!e&&!!~Object.getOwnPropertySymbols(e).indexOf(a),c=e=>Array.isArray(e)||Object(o.isPlainObject)(e)&&!(e=>Object(o.hasWindow)()&&e instanceof File||e.name&&e.size&&e.uri)(e),d=Object(o.getMerge)({withSymbols:!0,predicate:e=>e!==a&&e!==i}),l=e=>!!Object(o.isProduction)()||e[i].isUpdateable,u=(e,t)=>{Object(o.isProduction)()||(e[i].isUpdateable=t)},p=(e,t)=>{let n;return c(e)&&(s(e)||(e[a]=!0,n=new Proxy(e,t)),Object.keys(e).forEach(n=>{e[n]=p(e[n],t)})),n||e},g=e=>s(e)?Object(o.clone)(e,d):e;var f=e=>{const t={set:(e,r,o)=>(l(n)&&(e[r]=p(o,t)),!0),get:(e,t)=>t===a?g(e):e[t],defineProperty:()=>{throw new Error("Simple State doesnt support defining property")},setPrototypeOf:()=>{throw new Error("Simple State doesnt support setting prototype")},deleteProperty:(e,t)=>(l(n)&&delete e[t],!0)};Object(o.isProduction)()||s(e)||Object.defineProperty(e,i,{value:{isUpdateable:!1},configurable:!0});const n=Object(o.isProduction)()?e:p(e,t);return{state:n,update:e=>{if(!Object(o.isProduction)()&&l(n))throw new Error("Can't call update on State already being updated!");try{u(n,!0),e(n)}finally{u(n,!1)}return n},unwrap:e=>e?g(e):s(n)?g(n):n}};const h=Object(o.devFreeze)({BATCH_ADD:"BATCH-ADD",BATCH_START:"BATCH-START",BATCH_PROGRESS:"BATCH_PROGRESS",BATCH_FINISH:"BATCH-FINISH",BATCH_ABORT:"BATCH-ABORT",BATCH_CANCEL:"BATCH-CANCEL",BATCH_ERROR:"BATCH-ERROR",BATCH_FINALIZE:"BATCH-FINALIZE",ITEM_START:"FILE-START",ITEM_CANCEL:"FILE-CANCEL",ITEM_PROGRESS:"FILE-PROGRESS",ITEM_FINISH:"FILE-FINISH",ITEM_ABORT:"FILE-ABORT",ITEM_ERROR:"FILE-ERROR",ITEM_FINALIZE:"FILE-FINALIZE",REQUEST_PRE_SEND:"REQUEST_PRE_SEND",ALL_ABORT:"ALL_ABORT"}),E=Object(o.devFreeze)({ITEM_PROGRESS:"ITEM_PROGRESS",BATCH_PROGRESS:"BATCH_PROGRESS"}),b=[o.FILE_STATES.FINISHED,o.FILE_STATES.ERROR,o.FILE_STATES.CANCELLED,o.FILE_STATES.ABORTED],S=Object(o.getMerge)({undefinedOverwrites:!0}),m=(e,t,n,r,a,i)=>Object(o.triggerUpdater)(e.trigger,a,t,r).then(e=>(null==i||i(e),((e,t,n,r)=>{if(r){if(o.logger.debugLog(`uploader.queue: REQUEST_PRE_SEND(${e}) event returned updated items/options`,r),r.items){if(r.items.length!==t.length||!Object(o.isSamePropInArrays)(r.items,t,["id","batchId","recycled"]))throw new Error(`REQUEST_PRE_SEND(${e}) event handlers must return same items with same ids`);t=r.items}r.options&&(n=S({},n,r.options))}return{items:t,options:n,cancelled:!1===r}})(a,n,r,e))),T=(e,t,n,r,o,a)=>{const i=n(t),s=e.getState().batches[i[0].batchId].batchOptions,c=(null==r?void 0:r(t,s))||t;return m(e,c,i,s,a,o).then(t=>(t.cancelled||((e,t)=>{e.updateState(e=>{t.items.forEach(t=>{e.items[t.id]=t}),e.batches[t.items[0].batchId].batchOptions=t.options});const n=e.getState();t.items=t.items.map(e=>n.items[e.id]),t.options=n.batches[t.items[0].batchId].batchOptions})(e,t),t))},A=function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;return(o,a)=>T(o,a,t,n,r,e)},v=function(e,t){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const r=e.getState(),o=r.itemQueue.indexOf(t);~o&&e.updateState(e=>{n&&delete e.items[t],e.itemQueue.splice(o,1);const r=e.activeIds.indexOf(t);~r&&e.activeIds.splice(r,1)})},O=(e,t,n)=>e.getState().items[t].batchId===n,y=A(h.BATCH_START,e=>e.items,null,(function(){let{batch:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e)throw new Error("BATCH_START event handlers cannot update batch data. Only items & options")})),R=[o.BATCH_STATES.ADDED,o.BATCH_STATES.PROCESSING,o.BATCH_STATES.UPLOADING],_=[o.BATCH_STATES.ABORTED,o.BATCH_STATES.CANCELLED,o.BATCH_STATES.FINISHED,o.BATCH_STATES.ERROR],I=(e,t)=>e.batches[t].batch,w=(e,t)=>{const n=e.getState(),r=n.items[t];return n.batches[r.batchId]},C=(e,t)=>w(e,t).batch,L=(e,t)=>{((e,t)=>I(e.getState(),t))(e,t).items.forEach(t=>{let{id:n}=t;return v(e,n,!0)})},P=(e,t)=>{e.updateState(e=>{delete e.batches[t]})},D=(e,t,n)=>{B(e,t,n),B(e,t,h.BATCH_FINALIZE)},B=(e,t,n)=>{const r=e.getState(),o=I(r,t),a=r.items,i={...g(o),items:o.items.map(e=>{let{id:t}=e;return g(a[t])})};e.trigger(n,i)},j=(e,t)=>{const n=C(e,t);return R.includes(n.state)},N=e=>_.includes(e.state),H={[o.FILE_STATES.PENDING]:null,[o.FILE_STATES.ADDED]:h.ITEM_START,[o.FILE_STATES.FINISHED]:h.ITEM_FINISH,[o.FILE_STATES.ERROR]:h.ITEM_ERROR,[o.FILE_STATES.CANCELLED]:h.ITEM_CANCEL,[o.FILE_STATES.ABORTED]:h.ITEM_ABORT,[o.FILE_STATES.UPLOADING]:h.ITEM_PROGRESS},F=e=>!!~b.indexOf(e.state);var x=(e,t,n)=>{t.forEach(t=>{const n=e.getState(),{id:r,info:a}=t;if(o.logger.debugLog("uploader.processor.queue: request finished for item - ",{id:r,info:a}),n.items[r]){e.updateState(e=>{const t=e.items[r];t.state=a.state,t.uploadResponse=a.response,t.uploadStatus=a.status,F(t)&&delete e.aborts[r]});const t=e.getState().items[r];a.state===o.FILE_STATES.FINISHED&&t.completed<100&&e.handleItemProgress(t,100,t.file?t.file.size:0),H[t.state]&&e.trigger(H[t.state],t),F(t)&&(((e,t)=>{e.updateState(e=>{e.batches[t].finishedCounter+=1})})(e,t.batchId),e.trigger(h.ITEM_FINALIZE,t))}v(e,r)}),(e=>{const t=e.getState();Object.keys(t.batches).forEach(n=>{const{batch:r,finishedCounter:a}=t.batches[n],{orgItemCount:i}=r,s=N(r);i===a&&(s||100===r.completed||(e.updateState(e=>{const t=I(e,n);t.completed=100,t.loaded=t.items.reduce((e,t)=>{let{loaded:n}=t;return e+n},0)}),B(e,n,h.BATCH_PROGRESS)),e.updateState(e=>{const t=I(e,n);t.state=s?t.state:o.BATCH_STATES.FINISHED,e.currentBatch===n&&(e.currentBatch=null)}),o.logger.debugLog("uploady.uploader.batchHelpers: cleaning up batch: "+r.id),s||D(e,n,h.BATCH_FINISH),L(e,n),P(e,n))})})(e),n(e)};const G=A(h.REQUEST_PRE_SEND,e=>e,(e,t)=>({items:e,options:t})),U=(e,t,n)=>{const{items:r,options:a}=t,i=e.getState().batches[r[0].batchId].batch;let s;try{s=e.sender.send(r,i,a)}catch(e){o.logger.debugLog("uploader.queue: sender failed with unexpected error",e),s={request:Promise.resolve({status:0,state:o.FILE_STATES.ERROR,response:e.message}),abort:()=>!1,senderType:"exception-handler"}}const{request:c}=s;return((e,t,n)=>{e.updateState(e=>{t.forEach(t=>{e.items[t.id].state=o.FILE_STATES.UPLOADING,e.aborts[t.id]=n.abort})})})(e,r,s),c.then(t=>{const o=r.map(e=>({id:e.id,info:t}));x(e,o,n)})},M=e=>{let{allowedItems:t,cancelledResults:n,queue:r,items:a,ids:i,next:s}=e;return(t.length?G(r,t):Promise.resolve()).catch(e=>{o.logger.debugLog("uploader.queue: encountered error while preparing items for request",e),((e,t,n,r)=>{const a=n.map(t=>{let{id:n}=t;return{id:n,info:{status:0,state:o.FILE_STATES.ERROR,response:e}}});x(t,a,r)})(e,r,a,s)}).then(e=>{let t;return e&&(e.cancelled?n=i.map(()=>!0):U(r,{items:e.items,options:e.options},s)),((e,t,n,r)=>{const a=n.map((e,n)=>e?t[n].id:null).filter(Boolean);if(a.length){const t=a.map(e=>({id:e,info:{status:0,state:o.FILE_STATES.CANCELLED,response:"cancel"}}));x(e,t,r)}return!!a.length})(r,a,n,s)||(t=s(r)),t})};var q=(e,t,n)=>{const r=e.getState();let o=Object.values(r.items);return o=o.filter(e=>!!~t.indexOf(e.id)),Promise.all(o.map(t=>e.runCancellable(h.ITEM_START,t))).then(r=>({allowedItems:r.map((t,n)=>t?null:((e,t)=>{const n=t.getState().items[e];return n&&!b.includes(n.state)?n:void 0})(o[n].id,e)).filter(Boolean),cancelledResults:r,queue:e,items:o,ids:t,next:n})).then(M)};const $=(e,t)=>e.getState().activeIds.flat().includes(t),k=e=>{const t=e.getState().itemQueue,n=(e=>{const t=e.getState(),n=t.itemQueue,r=t.items;let a=0,i=n[a];for(;i&&($(e,i)||!j(e,i)||r[i].state!==o.FILE_STATES.ADDED);)a+=1,i=n[a];return i?a:-1})(e);let r,a=t[n];if(a){const o=w(e,a),i=o.batch.id,s=o.batchOptions.maxGroupSize||0;if(o.batchOptions.grouped&&s>1){r=[];let o=!0;for(;r.length<s&&o;)r.push(a),a=t[n+r.length],o=a&&O(e,a,i)}else r=[a]}return r},X=(e,t)=>{let n;return((e,t)=>{e.updateState(e=>{e.activeIds=e.activeIds.concat(t)})})(e,t),n=((e,t)=>{const n=C(e,t);return e.getState().currentBatch!==n.id})(e,t[0])?((e,t)=>{const n=C(e,t);return y(e,n).then(t=>{let{cancelled:r}=t;return r||e.updateState(e=>{e.currentBatch=n.id}),!r})})(e,t[0]).then(n=>{let r=!n;return r&&(((e,t)=>{const n=C(e,t),r=n.id;o.logger.debugLog("uploady.uploader.batchHelpers: cancelling batch: ",{batch:n}),e.updateState(e=>{I(e,r).state=o.BATCH_STATES.CANCELLED}),D(e,r,h.BATCH_CANCEL),L(e,r),P(e,r)})(e,t[0]),z(e)),r}).catch(n=>(o.logger.debugLog("uploader.processor: encountered error while preparing batch for request",n),((e,t,n)=>{const r=C(e,t),a=r.id;o.logger.debugLog("uploady.uploader.batchHelpers: failing batch: ",{batch:r}),e.updateState(e=>{const t=I(e,a);t.state=o.BATCH_STATES.ERROR,t.additionalInfo=n.message}),D(e,a,h.BATCH_ERROR),L(e,a),P(e,a)})(e,t[0],n),z(e),!0)):Promise.resolve(!1),n},z=e=>{let t;const n=k(e);if(n){const r=e.getCurrentActiveCount(),{concurrent:a=0,maxConcurrent:i=0}=e.getOptions();(!r||a&&r<i)&&(o.logger.debugLog("uploader.processor: Processing next upload - ",{ids:n,currentCount:r}),t=X(e,n).then(t=>{t||(q(e,n,z),a&&z(e))}))}return t};var Q=z;const Z=(e,t,n)=>(o.logger.debugLog(`uploader.queue: aborting ${t.state} item - `,t),x(e,[{id:t.id,info:{status:0,state:o.FILE_STATES.ABORTED,response:"aborted"}}],n),!0),J={[o.FILE_STATES.UPLOADING]:(e,t)=>(o.logger.debugLog("uploader.queue: aborting uploading item - ",t),e.getState().aborts[t.id]()),[o.FILE_STATES.ADDED]:Z,[o.FILE_STATES.PENDING]:Z},W=(e,t,n)=>{const r=e.getState().items[t],o=null==r?void 0:r.state;return!!J[o]&&J[o](e,r,n)};var V=(e,t,n,r,a)=>{const{state:i,update:s}=f({itemQueue:[],currentBatch:null,batches:{},items:{},activeIds:[],aborts:{}}),c=()=>i,d=e=>{s(e)},l=e=>{if(i.items[e.id]&&!e.recycled)throw new Error(`Uploader queue conflict - item ${e.id} already exists`);e.recycled&&((e,t)=>{const{previousBatch:n}=t;if(t.recycled&&n&&e.getState().batches[n]){const{id:r}=C(e,t.id);r===n&&e.updateState(e=>{const n=I(e,r),o=n.items.findIndex(e=>{let{id:n}=e;return n===t.id});~o&&n.items.splice(o,1)})}})(p,e),d(t=>{t.items[e.id]=e,t.itemQueue.push(e.id)})},u=(e,n,r)=>{i.items[e.id]&&(d(t=>{const o=t.items[e.id];o.loaded=r,o.completed=n}),t(h.ITEM_PROGRESS,c().items[e.id]))};r.on(E.ITEM_PROGRESS,u),r.on(E.BATCH_PROGRESS,e=>{var n;const r=null===(n=i.batches[e.id])||void 0===n?void 0:n.batch.items;if(r){const[n,o]=r.reduce((e,t)=>{let{completed:n,loaded:r}=t;return e[0]+=n,e[1]+=r,e},[0,0]);d(t=>{const a=t.batches[e.id].batch;a.completed=n/r.length,a.loaded=o}),t(h.BATCH_PROGRESS,i.batches[e.id].batch)}});const p={uploaderId:a,getOptions:()=>e,getCurrentActiveCount:()=>i.activeIds.length,getState:c,updateState:d,trigger:t,runCancellable:function(e){if(!Object(o.isFunction)(n))throw new Error("Uploader queue - cancellable is of wrong type");for(var t=arguments.length,r=new Array(t>1?t-1:0),a=1;a<t;a++)r[a-1]=arguments[a];return n(e,...r)},sender:r,handleItemProgress:u};return Object(o.hasWindow)()&&o.logger.isDebugOn()&&(window[`__rpldy_${a}_queue_state`]=p),{updateState:d,getState:p.getState,runCancellable:p.runCancellable,uploadBatch:(e,t)=>{t&&d(n=>{n.batches[e.id].batchOptions=t}),Q(p)},addBatch:(e,t)=>(d(n=>{n.batches[e.id]={batch:e,batchOptions:t,finishedCounter:0}}),e.items.forEach(l),I(i,e.id)),abortItem:e=>((e,t,n)=>W(e,t,n))(p,e,Q),abortBatch:e=>{((e,t,n)=>{const r=e.getState().batches[t],a=null==r?void 0:r.batch;a&&!N(a)&&(e.updateState(e=>{I(e,t).state=o.BATCH_STATES.ABORTED}),B(e,t,h.BATCH_ABORT),a.items.forEach(t=>W(e,t.id,n)))})(p,e,Q)},abortAll:()=>{((e,t)=>{const n=e.getState().items;Object.keys(n).forEach(n=>W(e,n,t)),e.trigger(h.ALL_ABORT)})(p,Q)},clearPendingBatches:()=>{(e=>{const t=e.getState().batches;Object.keys(t).filter(e=>t[e].batch.state===o.BATCH_STATES.PENDING).forEach(t=>{L(e,t),P(e,t)})})(p)},uploadPendingBatches:e=>{((e,t)=>{e.updateState(e=>{Object.keys(e.batches).forEach(n=>{const r=e.batches[n],{batch:a,batchOptions:i}=r;a.state===o.BATCH_STATES.PENDING&&(a.items.forEach(e=>{e.state=o.FILE_STATES.ADDED}),a.state=o.BATCH_STATES.ADDED,r.batchOptions=Object(o.merge)({},i,t))})})})(p,e),Q(p)}}},Y=n("GjXi");const K=()=>!0,ee=Object(o.devFreeze)({autoUpload:!0,clearPendingOnAdd:!1,inputFieldName:"file",concurrent:!1,maxConcurrent:2,grouped:!1,maxGroupSize:5,method:"POST",params:{},fileFilter:K,forceJsonResponse:!1,withCredentials:!1,destination:{},send:null,sendWithFormData:!0,formDataAllowUndefined:!1}),te=(e,t,n,r)=>{((e,t,n,r)=>{e.forEach(e=>{o.logger.debugLog(`uploady.uploader.processor: file: ${e.id} progress event: loaded(${n}) - completed(${t})`),r(E.ITEM_PROGRESS,e,t,n)})})(e,Math.min(n.loaded/n.total*100,100)/e.length,n.loaded/e.length,r),r(E.BATCH_PROGRESS,t)};var ne=()=>{const{trigger:e,target:t}=Object(r.default)({send:(t,n,r)=>{const a=r.destination,i=null==a?void 0:a.url,s=Object(o.throttle)(r=>te(t,n,r,e),50,!0);return(Object(o.isFunction)(r.send)?r.send:Y.default)(t,i,{method:(null==a?void 0:a.method)||r.method||ee.method,paramName:(null==a?void 0:a.filesParamName)||r.inputFieldName||"file",params:{...r.params,...null==a?void 0:a.params},forceJsonResponse:r.forceJsonResponse,withCredentials:r.withCredentials,formatGroupParamName:r.formatGroupParamName,headers:null==a?void 0:a.headers,sendWithFormData:r.sendWithFormData,formatServerResponse:r.formatServerResponse,formDataAllowUndefined:r.formDataAllowUndefined},s)}},Object.values(E));return t};const re=Object(o.hasWindow)()&&"FileList"in window,oe=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=e;return Object(o.isProduction)()||(t<3&&s(e)?n=g(e):t<3&&c(e)&&(n=Array.isArray(e)?e.map(e=>oe(e,t+1)):Object.keys(e).reduce((n,r)=>(n[r]=oe(e[r],t+1),n),{}))),n};let ae=0;var ie=(e,t,n)=>{ae+=1;const r="batch-"+ae,a=(e=>re&&e instanceof FileList||"[object FileList]"===e.toString())(e);e=Array.isArray(e)||a?e:[e];const i=!n.autoUpload,s=((e,t,n,r)=>Array.prototype.filter.call(t,r||K).map(t=>Object(o.createBatchItem)(t,e,n)))(r,e,i,n.fileFilter);return{id:r,uploaderId:t,items:s,state:i?o.BATCH_STATES.PENDING:o.BATCH_STATES.ADDED,completed:0,loaded:0,orgItemCount:s.length,additionalInfo:null}};var se=(e,t,n,r)=>{const o=ne(),a=V(n,e,t,o,r);return{process:(e,t)=>{a.uploadBatch(e,t)},abortBatch:e=>{a.abortBatch(e)},abort:e=>{e?a.abortItem(e):a.abortAll()},addNewBatch:(e,t,n)=>{const r=ie(e,t,n);return a.addBatch(r,n)},runCancellable:a.runCancellable,clearPendingBatches:()=>{a.clearPendingBatches()},processPendingBatches:e=>{a.uploadPendingBatches(e)}}};const ce=Object.values(h);let de=0;var le=e=>{de+=1;const t="uploader-"+de;let n=!1;const a={};o.logger.debugLog(`uploady.uploader: creating new instance (${t})`,{options:e,counter:de});let i=(e=>{return{...ee,...e,destination:e&&e.destination?(t=e.destination,{params:{},...t}):null};var t})(e);const s=()=>{p.clearPendingBatches()};let{trigger:c,target:d}=Object(r.default)({id:t,update:e=>(i=Object(o.merge)({},i,e),d),add:(e,t)=>{const n=Object(o.merge)({},i,t);n.clearPendingOnAdd&&s();const r=p.addNewBatch(e,d.id,n);let a;return r.items.length?a=p.runCancellable(h.BATCH_ADD,r,n).then(e=>{e?(r.state=o.BATCH_STATES.CANCELLED,l(h.BATCH_CANCEL,r)):(o.logger.debugLog(`uploady.uploader [${d.id}]: new items added - auto upload =\n ${String(n.autoUpload)}`,r.items),n.autoUpload&&p.process(r))}):o.logger.debugLog(`uploady.uploader: no items to add. batch ${r.id} is empty. check fileFilter if this isn't intended`),a||Promise.resolve()},upload:e=>{p.processPendingBatches(e)},abort:e=>{p.abort(e)},abortBatch:e=>{p.abortBatch(e)},getOptions:()=>Object(o.clone)(i),clearPending:s,registerExtension:(e,t)=>{Object(o.invariant)(n,"Uploady - uploader extensions can only be registered by enhancers"),Object(o.invariant)(!a[e],"Uploady - uploader extension by this name [%s] already exists",e),o.logger.debugLog("uploady.uploader: registering extension: "+e.toString(),t),a[e]=t},getExtension:e=>a[e]},ce,{canAddEvents:!1,canRemoveEvents:!1});const l=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];const a=Object(r.createLifePack)(()=>n.map(oe));return c(e,a)},u=Object(o.triggerCancellable)(l);if(i.enhancer){n=!0;const e=i.enhancer(d,l);n=!1,d=e||d}const p=se(l,u,i,d.id);return Object(o.devFreeze)(d)};var ue=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return t.reduce((e,t)=>t(e,...r)||e,e)}};t.default=le},Xsbf:function(e,t,n){"use strict";n.r(t),n.d(t,"default",(function(){return y})),n.d(t,"addLife",(function(){return y})),n.d(t,"isLE",(function(){return g})),n.d(t,"createLifePack",(function(){return R}));var r=n("JlUD"),o=n.n(r),a=n("mHo/");var i=Object(a.devFreeze)({allowRegisterNonExistent:!0,canAddEvents:!0,canRemoveEvents:!0,collectStats:!1});const s=(e,t)=>{if(!Object(a.isFunction)(e))throw new Error(`'${t}' is not a valid function`)},c=e=>void 0===e,d=Symbol.for("__le__"),l=Symbol.for("__le__pack__"),u=e=>e?e[d]:null,p=e=>{const t=u(e);if(!t)throw new Error("Didnt find LE internal object. Something very bad happened!");return t},g=e=>!!u(e),f=function(e,t,n){let r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];s(n,"cb");const o=p(e);if(!o.options.allowRegisterNonExistent&&!~o.events.indexOf(t))throw new Error(`Cannot register for event ${t.toString()} that wasn't already defined (allowRegisterNonExistent = false)`);const a=o.registry[t]||[];return a.find(e=>e.cb===n)||(a.push({name:t,cb:n,once:r}),o.registry[t]=a),()=>v.call(e,t,n)},h=(e,t)=>{const n=p(e).registry;return t?n[t]?n[t].slice():[]:Object.values(n).flat()},E={on:function(e,t){return f(this,e,t)},once:function(e,t){return f(this,e,t,!0)},off:v,getEvents:function(){return p(this).events.slice()}},b=()=>Object.entries(E).reduce((e,t)=>{let[n,r]=t;return e[n]={value:r},e},{}),S={trigger:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];const a=h(this,e);let i;if(a.length){var s;let t;1===n.length&&!0===(null===(s=n[0])||void 0===s?void 0:s[l])&&(t=n[0].resolve()),i=a.map(r=>{let o;return r.once&&A(this,e,r.cb),o=t?r.cb(...t):n.length?1===n.length?r.cb(n[0]):2===n.length?r.cb(n[0],n[1]):3===n.length?r.cb(n[0],n[1],n[2]):r.cb(...n):r.cb(),o}).filter(e=>!c(e)).map(e=>o()(e)?e:Promise.resolve(e))}return i&&(i.length?i:void 0)},addEvent:function(e){const t=p(this);if(!t.options.canAddEvents)throw new Error("Cannot add new events (canAddEvents = false)");if(~t.events.indexOf(e))throw new Error(`Event '${e}' already defined`);t.events.push(e)},removeEvent:function(e){const t=p(this);if(!t.options.canRemoveEvents)throw new Error("Cannot remove events (canRemoveEvents = false)");{const n=t.events.indexOf(e);t.events.splice(n,1)}},hasEvent:function(e){return!!~p(this).events.indexOf(e)},hasEventRegistrations:function(e){return!!h(this,e).length},assign:function(e){const t=p(this);return O(e,t.options,t.events,t.registry,t.stats),m(e)}},m=e=>Object.keys(S).reduce((t,n)=>(t[n]=S[n].bind(e),t),{target:e,...S}),T=function(e,t){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const r=p(e).registry;!r[t]||!n&&r[t].length||delete r[t]},A=(e,t,n)=>{const r=p(e).registry;r[t]&&(n?(r[t]=r[t].filter(e=>e.cb!==n),T(e,t)):T(e,t,!0))};function v(e,t){A(this,e,t)}const O=function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};Object.defineProperties(e,{[d]:{value:Object.seal({registry:r,events:n,options:t,stats:o})},...b()})};var y=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=arguments.length>2?arguments[2]:void 0;return e=e||{},n={...i,...n},g(e)||O(e,n,t),m(e)};var R=e=>{const t={resolve:()=>[].concat(e())};return Object.defineProperty(t,l,{value:!0,configurable:!1}),t}},"mHo/":function(e,t,n){"use strict";n.r(t),n.d(t,"BATCH_STATES",(function(){return c})),n.d(t,"FILE_STATES",(function(){return d})),n.d(t,"invariant",(function(){return a.a})),n.d(t,"throttle",(function(){return s.a})),n.d(t,"logger",(function(){return r})),n.d(t,"triggerCancellable",(function(){return h})),n.d(t,"triggerUpdater",(function(){return b})),n.d(t,"createBatchItem",(function(){return O})),n.d(t,"request",(function(){return _})),n.d(t,"parseResponseHeaders",(function(){return R})),n.d(t,"isFunction",(function(){return w.a})),n.d(t,"isPlainObject",(function(){return B})),n.d(t,"isSamePropInArrays",(function(){return C})),n.d(t,"devFreeze",(function(){return D})),n.d(t,"merge",(function(){return F})),n.d(t,"getMerge",(function(){return H})),n.d(t,"clone",(function(){return x})),n.d(t,"pick",(function(){return G})),n.d(t,"hasWindow",(function(){return l})),n.d(t,"isProduction",(function(){return P.a}));var r={};n.r(r),n.d(r,"isDebugOn",(function(){return p})),n.d(r,"setDebug",(function(){return g})),n.d(r,"debugLog",(function(){return f}));var o=n("kvau"),a=n.n(o),i=n("uDTZ"),s=n.n(i);const c={PENDING:"pending",ADDED:"added",PROCESSING:"processing",UPLOADING:"uploading",CANCELLED:"cancelled",FINISHED:"finished",ABORTED:"aborted",ERROR:"error"},d={PENDING:"pending",ADDED:"added",UPLOADING:"uploading",CANCELLED:"cancelled",FINISHED:"finished",ERROR:"error",ABORTED:"aborted"};var l=()=>"object"==typeof window&&!!window.document;let u;const p=()=>("boolean"!=typeof u&&(u=l()&&("location"in window&&!!~window.location.search.indexOf("rpldy_debug=true")||!0===window["__rpldy-logger-debug__"])),!!u),g=e=>{l()&&(window["__rpldy-logger-debug__"]=e),u=!!e||null},f=function(){p()&&console.log(...arguments)};var h=function(e,t){const n=function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return new Promise((n,o)=>{const a=e(t,...r);a&&a.length?Promise.all(a).catch(o).then(e=>e&&n(!!~e.findIndex(e=>!1===e))):n(!1)})};for(var r=arguments.length,o=new Array(r>2?r-2:0),a=2;a<r;a++)o[a-2]=arguments[a];return t?n(t,...o):n};const E=e=>null==e;var b=function(e,t){const n=function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return new Promise((n,o)=>{const a=e(t,...r);a&&a.length?Promise.all(a).catch(o).then(e=>{let t;if(e)for(;E(t)&&e.length;)t=e.pop();n(E(t)?void 0:t)}):n()})};for(var r=arguments.length,o=new Array(r>2?r-2:0),a=2;a<r;a++)o[a-2]=arguments[a];return t?n(t,...o):n};const S=Symbol.for("__rpldy-bi__");let m=0;const T=(e,t)=>(e.url=t,e),A=(e,t)=>(e.file=t,e),v=e=>e&&(e instanceof File||e instanceof Blob||"object"==typeof e&&e.name&&e.type);var O=function(e,t){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];m+=e.id&&e.batchId?0:1;const r=e.id&&e.batchId?e.id:`${t}.item-${m}`,o=n?d.PENDING:d.ADDED;let a={id:r,batchId:t,state:o,uploadStatus:0,completed:0,loaded:0,recycled:!1,previousBatch:null};if(Object.defineProperty(a,S,{value:!0,writable:!0}),"object"==typeof e&&!0===e[S]&&(a.recycled=!0,a.previousBatch=e.batchId,e=e.file||e.url),"string"==typeof e)a=T(a,e);else{if(!v(e))throw new Error("Unknown type of file added: "+typeof e);a=A(a,e)}return a};const y=(e,t)=>{t&&Object.keys(t).forEach(n=>{void 0!==t[n]&&e.setRequestHeader(n,t[n])})};var R=e=>{let t;try{t=e.getAllResponseHeaders().trim().split(/[\r\n]+/).reduce((e,t)=>{const[n,r]=t.split(": ");return e[n]=r,e},{})}catch(t){f("uploady.request: failed to read response headers",e)}return t},_=function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const r=new XMLHttpRequest,o=new Promise((o,a)=>{r.onerror=()=>a(r),r.ontimeout=()=>a(r),r.onabort=()=>a(r),r.onload=()=>o(r),r.open(n.method||"GET",e),y(r,n.headers),r.withCredentials=!!n.withCredentials,n.preSend&&n.preSend(r),r.send(t)});return o.xhr=r,o},I=n("r5yn"),w=n.n(I);var C=(e,t,n)=>{let r=!0;const o=(e=>{const t=[].concat(e);return e=>e.map(e=>t.map(t=>e[t]).join())})(n);if(e&&t&&e.length===t.length){const n=o(e),a=o(t);r=!!n.find((e,t)=>e!==a[t])}return!r},L=n("DVTP"),P=n.n(L);var D=e=>P()()?e:Object.freeze(e);var B=e=>{var t;return!!e&&"object"==typeof e&&("Object"===(null===(t=Object.getPrototypeOf(e))||void 0===t?void 0:t.constructor.name)||null===Object.getPrototypeOf(e))};const j=e=>B(e)||Array.isArray(e),N=(e,t)=>{const n=Object.keys(e);return t.withSymbols?n.concat(Object.getOwnPropertySymbols(e)):n},H=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const t=function(n){for(var r=arguments.length,o=new Array(r>1?r-1:0),a=1;a<r;a++)o[a-1]=arguments[a];return n&&o.length&&o.forEach(r=>{r&&N(r,e).forEach(o=>{const a=r[o];e.predicate&&!e.predicate(o,a)||(void 0!==a||e.undefinedOverwrites)&&(j(a)?(void 0!==n[o]&&B(n[o])||(n[o]=Array.isArray(a)?[]:{}),t(n[o],a)):n[o]=a)})}),n};return t};var F=H();var x=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:F;return j(e)?t(Array.isArray(e)?[]:{},e):e};var G=(e,t)=>e&&Object.keys(e).reduce((n,r)=>(~t.indexOf(r)&&(n[r]=e[r]),n),{})},r5yn:function(e,t){e.exports=function(e){return"function"==typeof e}}})}));
//# sourceMappingURL=rpldy-core.umd.min.js.map
{
"version": "0.15.0",
"version": "0.16.0",
"name": "@rpldy/uploader",

@@ -28,6 +28,6 @@ "description": "the processing and queuing engine for react-uploady",

"dependencies": {
"@rpldy/life-events": "^0.15.0",
"@rpldy/sender": "^0.15.0",
"@rpldy/shared": "^0.15.0",
"@rpldy/simple-state": "^0.15.0"
"@rpldy/life-events": "^0.16.0",
"@rpldy/sender": "^0.16.0",
"@rpldy/shared": "^0.16.0",
"@rpldy/simple-state": "^0.16.0"
},

@@ -40,3 +40,3 @@ "devDependencies": {

},
"gitHead": "7909b3aacc4afd229e4bc6810da8560be19706b2"
"gitHead": "d48d97673222581b5da36fafa1bd859945775c4c"
}

@@ -224,2 +224,16 @@ <a href="https://badge.fury.io/js/%40rpldy%2Fuploader">

### UPLOADER_EVENTS.BATCH_ERROR
Triggered in case the batch was failed with an error.
These errors will most likely occur due to invalid event handling.
For instance, by a handler (ex: BATCH_START) throwing an error.
- Parameters: _(batch)_
### UPLOADER_EVENTS.BATCH_FINALIZE
Triggered when all batch items have finished uploading or in case the batch was cancelled(abort) or had an error
- Parameters: _(batch)_
### UPLOADER_EVENTS.ITEM_START

@@ -226,0 +240,0 @@

@@ -61,2 +61,4 @@ import {

BATCH_CANCEL = "BATCH-CANCEL",
BATCH_ERROR = "BATCH-ERROR",
BATCH_FINALIZE = "BATCH-FINALIZE",

@@ -63,0 +65,0 @@ ITEM_START = "FILE-START",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc