@wise/dynamic-flow-client 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/common/constants/DateMode.js +2 -2
- package/build/common/constants/FormControlType.js +2 -2
- package/build/common/constants/MonthFormat.js +2 -2
- package/build/common/constants/SchemaType.js +2 -2
- package/build/common/constants/Size.js +2 -2
- package/build/common/constants/index.js +1 -1
- package/build/common/contexts/dynamicFlowContexts/DynamicFlowContexts.js +15 -27
- package/build/common/contexts/dynamicFlowContexts/usePendingPromiseCounter.js +11 -9
- package/build/common/contexts/eventsContext/EventsContext.js +11 -28
- package/build/common/contexts/fetcherContexts/FetcherContexts.js +14 -27
- package/build/common/contexts/index.js +1 -1
- package/build/common/contexts/logContext/LogContext.js +12 -30
- package/build/common/hooks/index.js +1 -1
- package/build/common/hooks/useDebouncedFunction/useDebouncedFunction.js +3 -3
- package/build/common/hooks/useExternal/useExternal.js +8 -8
- package/build/common/hooks/useExternalStepPolling/useExternalStepPolling.js +20 -31
- package/build/common/hooks/usePersistAsync/usePersistAsync.js +60 -139
- package/build/common/hooks/usePolling/usePolling.js +20 -21
- package/build/common/hooks/usePrevious/usePrevious.js +5 -5
- package/build/common/hooks/useStepPolling/useStepPolling.js +15 -14
- package/build/common/makeFetcher/index.js +1 -1
- package/build/common/makeFetcher/makeFetcher.js +10 -24
- package/build/common/messages.js +5 -5
- package/build/common/utils/api-utils.js +3 -4
- package/build/common/utils/date-utils.js +11 -11
- package/build/common/utils/debounce.js +11 -15
- package/build/common/utils/file-utils.js +12 -25
- package/build/common/utils/id-utils.js +4 -5
- package/build/common/utils/index.js +1 -1
- package/build/common/utils/is-equal.js +8 -8
- package/build/common/utils/schema-utils.js +6 -6
- package/build/common/utils/step-utils.js +14 -14
- package/build/common/validators/index.js +7 -7
- package/build/common/validators/models/model-validators.js +8 -8
- package/build/common/validators/models/models.utils.js +29 -42
- package/build/common/validators/schemas/schema-validators.js +11 -13
- package/build/common/validators/types/type-validators.js +9 -13
- package/build/common/validators/validationFailures/validation-failures.js +14 -14
- package/build/common/validators/validationFailures/validation-failures.utils.js +5 -7
- package/build/common/validators/values/value-validators.js +4 -6
- package/build/dynamicFlow/DynamicFlow.js +185 -307
- package/build/dynamicFlow/DynamicFlowStep.js +12 -23
- package/build/dynamicFlow/DynamicFlowTypes.js +1 -1
- package/build/dynamicFlow/index.js +6 -14
- package/build/dynamicFlow/stories/DynamicFlow.story.js +20 -20
- package/build/dynamicFlow/stories/EditableDynamicFlow.js +20 -33
- package/build/dynamicFlow/stories/fixtureFetcher.js +46 -104
- package/build/dynamicFlow/utils/errorBoundary/ErrorBoundary.js +22 -40
- package/build/dynamicFlow/utils/errorBoundary/ErrorBoundary.messages.js +6 -6
- package/build/dynamicFlow/utils/errorBoundary/ErrorBoundaryAlert.js +10 -11
- package/build/dynamicFlow/utils/index.js +5 -2
- package/build/dynamicFlow/utils/responseParsers/response-parsers.js +53 -118
- package/build/dynamicFlow/utils/useDebouncedRefresh/useDebouncedRefresh.js +9 -9
- package/build/dynamicFlow/utils/useDynamicFlowState.js +51 -74
- package/build/dynamicFlow/utils/useLoader.js +9 -20
- package/build/fixtures/components/alert.js +8 -8
- package/build/fixtures/components/box.js +7 -7
- package/build/fixtures/components/button.js +25 -36
- package/build/fixtures/components/columns.js +10 -10
- package/build/fixtures/components/copyable.js +6 -6
- package/build/fixtures/components/decision.js +15 -15
- package/build/fixtures/components/heading.js +7 -7
- package/build/fixtures/components/image.js +10 -10
- package/build/fixtures/components/index.js +17 -25
- package/build/fixtures/components/info.js +22 -6
- package/build/fixtures/components/list.js +8 -8
- package/build/fixtures/components/loading-indicator.js +5 -5
- package/build/fixtures/components/paragraph.js +9 -9
- package/build/fixtures/components/review.js +11 -11
- package/build/fixtures/examples/camera-capture.js +29 -29
- package/build/fixtures/examples/index.js +9 -17
- package/build/fixtures/examples/recipient-update.js +69 -69
- package/build/fixtures/examples/recipient.js +63 -63
- package/build/fixtures/examples/single-file-upload.js +21 -21
- package/build/fixtures/examples/step-validation-errors.js +21 -21
- package/build/fixtures/features/action-response.js +8 -8
- package/build/fixtures/features/external.js +8 -8
- package/build/fixtures/features/index.js +9 -17
- package/build/fixtures/features/persist-async.js +11 -11
- package/build/fixtures/features/polling.js +9 -9
- package/build/fixtures/features/validation-async.js +10 -10
- package/build/fixtures/index.js +11 -22
- package/build/fixtures/jsonSchemaForm/allOf.js +30 -30
- package/build/fixtures/jsonSchemaForm/audRecipient.js +271 -271
- package/build/fixtures/jsonSchemaForm/currency.js +12 -12
- package/build/fixtures/jsonSchemaForm/multipleFileUploadBase64.js +11 -11
- package/build/fixtures/jsonSchemaForm/multipleFileUploadBlob.js +11 -11
- package/build/fixtures/jsonSchemaForm/oneOf.js +27 -27
- package/build/fixtures/jsonSchemaForm/oneOfTabs.js +16 -16
- package/build/fixtures/jsonSchemaForm/promotedOneOf.js +17 -17
- package/build/fixtures/jsonSchemaForm/promotedOneOfCheckbox.js +30 -30
- package/build/fixtures/jsonSchemaForm/simple.js +16 -16
- package/build/fixtures/jsonSchemaForm/uploadPersistAsync.js +19 -19
- package/build/fixtures/jsonSchemaForm/validationAsync.js +8 -8
- package/build/fixtures/layouts/all.js +37 -37
- package/build/fixtures/layouts/final-step-layout.js +9 -9
- package/build/fixtures/layouts/index.js +10 -18
- package/build/fixtures/layouts/list.js +10 -10
- package/build/fixtures/layouts/pay-in.js +23 -23
- package/build/fixtures/layouts/review.js +38 -38
- package/build/fixtures/layouts/success.js +15 -15
- package/build/fixtures/responses/action-response-final.js +8 -8
- package/build/fixtures/responses/action.js +3 -3
- package/build/fixtures/responses/exit.js +3 -3
- package/build/fixtures/responses/index.js +8 -16
- package/build/fixtures/responses/recipient-update-final.js +8 -8
- package/build/fixtures/schemas/basic-form.js +11 -11
- package/build/fixtures/schemas/index.js +8 -16
- package/build/fixtures/schemas/number-and-integer.js +11 -11
- package/build/fixtures/schemas/one-of.js +43 -46
- package/build/fixtures/schemas/string-formats.js +15 -15
- package/build/fixtures/utils/image-util.js +8 -8
- package/build/formControl/FormControl.js +118 -148
- package/build/formControl/index.js +6 -14
- package/build/formControl/utils/index.js +1 -1
- package/build/formControl/utils/value-utils.js +18 -23
- package/build/i18n/index.js +31 -31
- package/build/index.js +13 -10
- package/build/jsonSchemaForm/JsonSchemaForm.js +12 -24
- package/build/jsonSchemaForm/allOfSchema/AllOfSchema.js +24 -37
- package/build/jsonSchemaForm/allOfSchema/index.js +6 -14
- package/build/jsonSchemaForm/arrayTypeSchema/ArraySchema.js +9 -20
- package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/ArrayListSchema.js +9 -20
- package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/index.js +6 -14
- package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/MultipleFileUploadSchema.js +56 -115
- package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/MultipleFileUploadSchema.messages.js +7 -7
- package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/index.js +6 -14
- package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/index.js +1 -1
- package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/upload-utils.js +19 -71
- package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/useFormattedDefaultErrorMessages.js +10 -11
- package/build/jsonSchemaForm/arrayTypeSchema/index.js +6 -14
- package/build/jsonSchemaForm/basicTypeSchema/BasicTypeSchema.js +45 -62
- package/build/jsonSchemaForm/basicTypeSchema/index.js +6 -14
- package/build/jsonSchemaForm/controlFeedback/ControlFeedback.js +39 -50
- package/build/jsonSchemaForm/controlFeedback/ControlFeedback.messages.js +18 -18
- package/build/jsonSchemaForm/controlFeedback/index.js +6 -14
- package/build/jsonSchemaForm/genericSchema/GenericSchema.js +52 -61
- package/build/jsonSchemaForm/genericSchema/index.js +6 -14
- package/build/jsonSchemaForm/help/Help.js +9 -9
- package/build/jsonSchemaForm/help/Help.messages.js +5 -5
- package/build/jsonSchemaForm/help/index.js +6 -14
- package/build/jsonSchemaForm/index.js +6 -14
- package/build/jsonSchemaForm/objectSchema/ObjectSchema.js +28 -49
- package/build/jsonSchemaForm/objectSchema/index.js +6 -14
- package/build/jsonSchemaForm/oneOfSchema/OneOfSchema.js +54 -74
- package/build/jsonSchemaForm/oneOfSchema/index.js +6 -14
- package/build/jsonSchemaForm/oneOfSchema/utils/const-schema-utils.js +3 -3
- package/build/jsonSchemaForm/oneOfSchema/utils/index.js +1 -1
- package/build/jsonSchemaForm/oneOfSchema/utils/one-of-utils.js +19 -20
- package/build/jsonSchemaForm/persistAsyncSchema/PersistAsyncSchema.js +11 -22
- package/build/jsonSchemaForm/persistAsyncSchema/PersistAsyncSchema.messages.js +5 -5
- package/build/jsonSchemaForm/persistAsyncSchema/index.js +6 -14
- package/build/jsonSchemaForm/persistAsyncSchema/persistAsyncBasicSchema/PersistAsyncBasicSchema.js +73 -127
- package/build/jsonSchemaForm/persistAsyncSchema/persistAsyncBasicSchema/index.js +6 -14
- package/build/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/PersistAsyncBlobSchema.js +45 -110
- package/build/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/UploadInputAdapter.js +17 -17
- package/build/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/index.js +6 -14
- package/build/jsonSchemaForm/promotedOneOfSchema/PromotedOneOfSchema.js +28 -47
- package/build/jsonSchemaForm/promotedOneOfSchema/index.js +6 -14
- package/build/jsonSchemaForm/promotedOneOfSchema/promoted-one-of-utils.js +4 -4
- package/build/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfCheckboxControl.js +13 -24
- package/build/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfControl.js +11 -22
- package/build/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfRadioControl.js +12 -23
- package/build/jsonSchemaForm/readOnlySchema/ReadOnlySchema.js +24 -26
- package/build/jsonSchemaForm/readOnlySchema/ReadOnlySchema.messages.js +6 -6
- package/build/jsonSchemaForm/readOnlySchema/index.js +6 -14
- package/build/jsonSchemaForm/schemaFormControl/SchemaFormControl.js +26 -39
- package/build/jsonSchemaForm/schemaFormControl/index.js +6 -14
- package/build/jsonSchemaForm/schemaFormControl/utils/currency-utils.js +5 -5
- package/build/jsonSchemaForm/schemaFormControl/utils/index.js +1 -1
- package/build/jsonSchemaForm/schemaFormControl/utils/mapping-utils.js +30 -47
- package/build/jsonSchemaForm/validationAsyncSchema/ValidationAsyncSchema.js +57 -119
- package/build/jsonSchemaForm/validationAsyncSchema/index.js +6 -14
- package/build/layout/DynamicLayout.js +10 -21
- package/build/layout/alert/DynamicAlert.js +9 -9
- package/build/layout/box/DynamicBox.js +12 -23
- package/build/layout/button/DynamicButton.js +16 -27
- package/build/layout/columns/DynamicColumns.js +13 -24
- package/build/layout/decision/DynamicDecision.js +16 -27
- package/build/layout/divider/DynamicDivider.js +7 -8
- package/build/layout/external/DynamicExternal.js +16 -28
- package/build/layout/external/DynamicExternal.messages.js +5 -5
- package/build/layout/form/DynamicForm.js +10 -21
- package/build/layout/heading/DynamicHeading.js +12 -23
- package/build/layout/icon/DynamicIcon.js +9 -10
- package/build/layout/image/DynamicImage.js +43 -93
- package/build/layout/index.js +21 -29
- package/build/layout/info/DynamicInfo.js +7 -19
- package/build/layout/list/DynamicList.js +14 -26
- package/build/layout/loadingIndicator/DynamicLoadingIndicator.js +8 -9
- package/build/layout/paragraph/DynamicParagraph.js +19 -37
- package/build/layout/paragraph/DynamicParagraph.messages.js +6 -6
- package/build/layout/paragraph/useSnackBarIfAvailable.js +4 -4
- package/build/layout/review/DynamicReview.js +14 -26
- package/build/layout/utils.js +4 -6
- package/build/step/cameraStep/CameraStep.js +42 -88
- package/build/step/cameraStep/cameraCapture/CameraCapture.js +48 -105
- package/build/step/cameraStep/cameraCapture/CameraCapture.messages.js +7 -7
- package/build/step/cameraStep/cameraCapture/components/index.js +10 -28
- package/build/step/cameraStep/cameraCapture/hooks/index.js +17 -72
- package/build/step/cameraStep/cameraCapture/index.js +6 -14
- package/build/step/cameraStep/cameraCapture/overlay/Overlay.js +33 -45
- package/build/step/cameraStep/cameraCapture/screens/CameraNotSupported/CameraNotSupported.js +8 -19
- package/build/step/cameraStep/cameraCapture/screens/CameraNotSupported/CameraNotSupported.messages.js +6 -6
- package/build/step/cameraStep/cameraCapture/screens/NoCameraAccess/NoCameraAccess.js +9 -21
- package/build/step/cameraStep/cameraCapture/screens/NoCameraAccess/NoCameraAccess.messages.js +7 -7
- package/build/step/cameraStep/cameraCapture/screens/index.js +6 -14
- package/build/step/cameraStep/cameraCapture/tracking/index.js +17 -99
- package/build/step/cameraStep/cameraCapture/utils/index.js +33 -96
- package/build/step/cameraStep/index.js +6 -14
- package/build/step/externalConfirmationStep/ExternalConfirmationStep.js +20 -21
- package/build/step/externalConfirmationStep/ExternalConfirmationStep.messages.js +8 -8
- package/build/step/externalConfirmationStep/index.js +6 -14
- package/build/step/index.js +7 -15
- package/build/step/layoutStep/LayoutStep.js +19 -19
- package/build/step/layoutStep/index.js +6 -14
- package/build/step/layoutStep/utils/index.js +3 -14
- package/build/step/layoutStep/utils/inline-reference-utils.js +29 -46
- package/build/step/layoutStep/utils/layout-utils.js +34 -53
- package/build/types/common/FormControl.js +1 -1
- package/build/types/index.js +13 -13
- package/build/types/specification/Action.js +1 -1
- package/build/types/specification/FileUploadSchema.js +1 -1
- package/build/types/specification/LayoutComponent.js +1 -1
- package/build/types/specification/Model.js +9 -17
- package/build/types/specification/PersistAsync.js +1 -1
- package/build/types/specification/Polling.js +1 -1
- package/build/types/specification/Promotion.js +1 -1
- package/build/types/specification/Schema.js +8 -8
- package/build/types/specification/Step.js +3 -5
- package/build/types/specification/ValidationAsync.js +1 -1
- package/build/types/specification/core.js +1 -1
- package/package.json +1 -1
|
@@ -1,172 +1,93 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
4
|
};
|
|
52
|
-
exports
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
6
|
exports.usePersistAsync = void 0;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
function handlePersistAsync(model) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
isInvalidSchema = model instanceof Blob ? !(0, types_1.isBlobSchema)(schema) : !(0, validators_2.isValidSchema)(model, schema);
|
|
74
|
-
if ((0, validators_1.isNull)(model) || isInvalidSchema) {
|
|
75
|
-
handleError();
|
|
76
|
-
}
|
|
77
|
-
return [4 /*yield*/, performPersistAsync(model)];
|
|
78
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
});
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const react_intl_1 = require("react-intl");
|
|
9
|
+
const validators_1 = require("../../../common/validators");
|
|
10
|
+
const PersistAsyncSchema_messages_1 = __importDefault(require("../../../jsonSchemaForm/persistAsyncSchema/PersistAsyncSchema.messages"));
|
|
11
|
+
const PersistAsyncBasicSchema_1 = require("../../../jsonSchemaForm/persistAsyncSchema/persistAsyncBasicSchema/PersistAsyncBasicSchema"); // FIXME: extract these functions form that schema component to either here or their own module
|
|
12
|
+
const types_1 = require("../../../types");
|
|
13
|
+
const contexts_1 = require("../../contexts");
|
|
14
|
+
const validators_2 = require("../../validators");
|
|
15
|
+
const usePersistAsync = (persistAsync) => {
|
|
16
|
+
const [abortController, setAbortController] = (0, react_1.useState)(null);
|
|
17
|
+
const fetcher = (0, contexts_1.useFetcher)();
|
|
18
|
+
const intl = (0, react_intl_1.useIntl)();
|
|
19
|
+
const { schema } = persistAsync;
|
|
20
|
+
async function handlePersistAsync(model) {
|
|
21
|
+
const isInvalidSchema = model instanceof Blob ? !(0, types_1.isBlobSchema)(schema) : !(0, validators_2.isValidSchema)(model, schema);
|
|
22
|
+
if ((0, validators_1.isNull)(model) || isInvalidSchema) {
|
|
23
|
+
handleError();
|
|
24
|
+
}
|
|
25
|
+
return await performPersistAsync(model);
|
|
82
26
|
}
|
|
83
|
-
|
|
27
|
+
const abortCurrentRequestAndGetNewAbortSignal = () => {
|
|
84
28
|
if (abortController) {
|
|
85
29
|
abortController.abort();
|
|
86
30
|
}
|
|
87
|
-
|
|
31
|
+
const newAbortController = new AbortController();
|
|
88
32
|
setAbortController(newAbortController);
|
|
89
33
|
return newAbortController.signal;
|
|
90
34
|
};
|
|
91
35
|
function constructFetchInit(model) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
var requestBody = isBlob
|
|
36
|
+
const isBlob = (0, types_1.isBlobSchema)(schema);
|
|
37
|
+
const signal = abortCurrentRequestAndGetNewAbortSignal();
|
|
38
|
+
const requestKey = persistAsync.param;
|
|
39
|
+
const requestBody = isBlob
|
|
97
40
|
? wrapInFormData(requestKey, model)
|
|
98
|
-
: JSON.stringify(
|
|
41
|
+
: JSON.stringify({ [requestKey]: model });
|
|
99
42
|
return {
|
|
100
43
|
method: persistAsync.method,
|
|
101
|
-
headers:
|
|
44
|
+
headers: Object.assign({}, (!isBlob && { 'Content-Type': 'application/json' })),
|
|
102
45
|
body: requestBody,
|
|
103
|
-
signal
|
|
46
|
+
signal,
|
|
104
47
|
};
|
|
105
48
|
}
|
|
106
|
-
function performPersistAsync(payload) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return [2 /*return*/, handleHTTPError(response)];
|
|
118
|
-
}
|
|
119
|
-
return [4 /*yield*/, response.json()];
|
|
120
|
-
case 2:
|
|
121
|
-
jsonResponse = _a.sent();
|
|
122
|
-
if ((0, validators_1.isObject)(jsonResponse)) {
|
|
123
|
-
id = jsonResponse[persistAsync.idProperty];
|
|
124
|
-
if ((0, validators_1.isString)(id) || (0, validators_1.isNumber)(id)) {
|
|
125
|
-
return [2 /*return*/, { data: id }];
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return [2 /*return*/, handleError()];
|
|
129
|
-
case 3:
|
|
130
|
-
error_1 = _a.sent();
|
|
131
|
-
return [2 /*return*/, handleError(error_1)];
|
|
132
|
-
case 4: return [2 /*return*/];
|
|
49
|
+
async function performPersistAsync(payload) {
|
|
50
|
+
try {
|
|
51
|
+
const response = await fetcher(persistAsync.url, constructFetchInit(payload));
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
return handleHTTPError(response);
|
|
54
|
+
}
|
|
55
|
+
const jsonResponse = await response.json();
|
|
56
|
+
if ((0, validators_1.isObject)(jsonResponse)) {
|
|
57
|
+
const id = jsonResponse[persistAsync.idProperty];
|
|
58
|
+
if ((0, validators_1.isString)(id) || (0, validators_1.isNumber)(id)) {
|
|
59
|
+
return { data: id };
|
|
133
60
|
}
|
|
134
|
-
}
|
|
135
|
-
|
|
61
|
+
}
|
|
62
|
+
return handleError();
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
return handleError(error);
|
|
66
|
+
}
|
|
136
67
|
}
|
|
137
|
-
function handleHTTPError(response) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return [4 /*yield*/, response.json()];
|
|
145
|
-
case 1:
|
|
146
|
-
jsonResponse = _a.sent();
|
|
147
|
-
if ((0, validators_1.isObject)(jsonResponse)) {
|
|
148
|
-
error = (0, PersistAsyncBasicSchema_1.getErrorFromResponse)(persistAsync.param, jsonResponse);
|
|
149
|
-
if ((0, validators_1.isString)(error)) {
|
|
150
|
-
throw new Error(error);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
_a.label = 2;
|
|
154
|
-
case 2: throw new Error(intl.formatMessage(PersistAsyncSchema_messages_1["default"].genericError));
|
|
68
|
+
async function handleHTTPError(response) {
|
|
69
|
+
if (response.status === 422) {
|
|
70
|
+
const jsonResponse = await response.json();
|
|
71
|
+
if ((0, validators_1.isObject)(jsonResponse)) {
|
|
72
|
+
const error = (0, PersistAsyncBasicSchema_1.getErrorFromResponse)(persistAsync.param, jsonResponse);
|
|
73
|
+
if ((0, validators_1.isString)(error)) {
|
|
74
|
+
throw new Error(error);
|
|
155
75
|
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
throw new Error(intl.formatMessage(PersistAsyncSchema_messages_1.default.genericError));
|
|
158
79
|
}
|
|
159
|
-
|
|
160
|
-
|
|
80
|
+
const handleError = (error) => {
|
|
81
|
+
const message = hasStringMessage(error)
|
|
161
82
|
? error.message
|
|
162
|
-
: intl.formatMessage(PersistAsyncSchema_messages_1
|
|
83
|
+
: intl.formatMessage(PersistAsyncSchema_messages_1.default.genericError);
|
|
163
84
|
throw new Error(message);
|
|
164
85
|
};
|
|
165
86
|
return handlePersistAsync;
|
|
166
87
|
};
|
|
167
88
|
exports.usePersistAsync = usePersistAsync;
|
|
168
89
|
function wrapInFormData(key, value) {
|
|
169
|
-
|
|
90
|
+
const formData = new FormData();
|
|
170
91
|
if (value !== null) {
|
|
171
92
|
formData.append(key, value);
|
|
172
93
|
}
|
|
@@ -1,44 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createPollingClosure = exports.usePolling = void 0;
|
|
4
4
|
/* eslint-disable fp/no-mutation */
|
|
5
|
-
|
|
6
|
-
function usePolling(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return createPollingClosure(asyncFn, maxAttempts, maxConsecutiveFails, function (pollingResponse) { return onPollingResponseReference.current(pollingResponse); }, function () { return onFailureReference.current(); });
|
|
12
|
-
}, [asyncFn, maxAttempts, maxConsecutiveFails]);
|
|
13
|
-
(0, react_1.useEffect)(function () {
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
function usePolling({ asyncFn, interval, maxAttempts, maxConsecutiveFails, onPollingResponse, onFailure, }) {
|
|
7
|
+
const onPollingResponseReference = (0, react_1.useRef)(onPollingResponse);
|
|
8
|
+
const onFailureReference = (0, react_1.useRef)(onFailure);
|
|
9
|
+
const poll = (0, react_1.useMemo)(() => createPollingClosure(asyncFn, maxAttempts, maxConsecutiveFails, (pollingResponse) => onPollingResponseReference.current(pollingResponse), () => onFailureReference.current()), [asyncFn, maxAttempts, maxConsecutiveFails]);
|
|
10
|
+
(0, react_1.useEffect)(() => {
|
|
14
11
|
if (interval > 0) {
|
|
15
|
-
|
|
12
|
+
const intervalReference = setInterval(() => {
|
|
16
13
|
poll();
|
|
17
14
|
}, interval);
|
|
18
|
-
return
|
|
15
|
+
return () => clearInterval(intervalReference);
|
|
19
16
|
}
|
|
20
17
|
}, [poll, interval]);
|
|
21
|
-
(0, react_1.useEffect)(
|
|
18
|
+
(0, react_1.useEffect)(() => {
|
|
22
19
|
onPollingResponseReference.current = onPollingResponse;
|
|
23
20
|
onFailureReference.current = onFailure;
|
|
24
21
|
}, [onPollingResponse, onFailure]);
|
|
25
22
|
}
|
|
26
23
|
exports.usePolling = usePolling;
|
|
27
24
|
function createPollingClosure(asyncFn, maxAttempts, maxConsecutiveFails, onPollingResponse, onFailure) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
let isPolling = true;
|
|
26
|
+
let consecutiveFailures = 0;
|
|
27
|
+
let attemptCount = 0;
|
|
31
28
|
return asyncFn
|
|
32
|
-
?
|
|
29
|
+
? () => {
|
|
33
30
|
if (isPolling) {
|
|
34
31
|
attemptCount++;
|
|
35
32
|
asyncFn()
|
|
36
|
-
.then(
|
|
33
|
+
.then((pollingResponse) => {
|
|
37
34
|
consecutiveFailures = 0;
|
|
38
35
|
isPolling = onPollingResponse(pollingResponse);
|
|
39
|
-
})
|
|
36
|
+
})
|
|
37
|
+
.catch(() => {
|
|
40
38
|
consecutiveFailures++;
|
|
41
|
-
})
|
|
39
|
+
})
|
|
40
|
+
.finally(() => {
|
|
42
41
|
if (consecutiveFailures >= maxConsecutiveFails || attemptCount >= maxAttempts) {
|
|
43
42
|
onFailure();
|
|
44
43
|
isPolling = false;
|
|
@@ -46,7 +45,7 @@ function createPollingClosure(asyncFn, maxAttempts, maxConsecutiveFails, onPolli
|
|
|
46
45
|
});
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
|
-
:
|
|
48
|
+
: () => {
|
|
50
49
|
//
|
|
51
50
|
};
|
|
52
51
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.usePrevious = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
(0, react_1.useEffect)(
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const usePrevious = (value) => {
|
|
6
|
+
const reference = (0, react_1.useRef)();
|
|
7
|
+
(0, react_1.useEffect)(() => {
|
|
8
8
|
reference.current = value;
|
|
9
9
|
}, [value]);
|
|
10
10
|
return reference.current;
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useStepPolling = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const __1 = require("..");
|
|
6
|
+
const contexts_1 = require("../../contexts");
|
|
7
7
|
function useStepPolling(polling, onAction) {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const fetcher = (0, contexts_1.useFetcher)();
|
|
9
|
+
const asyncFn = (0, react_1.useMemo)(() => {
|
|
10
10
|
if (polling) {
|
|
11
|
-
return
|
|
12
|
-
return fetcher(polling.url).then(
|
|
11
|
+
return () => {
|
|
12
|
+
return fetcher(polling.url).then((response) => {
|
|
13
13
|
if (response.ok) {
|
|
14
14
|
return response
|
|
15
15
|
.json()
|
|
16
|
-
.then(
|
|
16
|
+
.then((pollingResponse) => pollingResponse)
|
|
17
|
+
.catch((error) => null);
|
|
17
18
|
}
|
|
18
19
|
else {
|
|
19
20
|
throw new Error('failed');
|
|
@@ -25,7 +26,7 @@ function useStepPolling(polling, onAction) {
|
|
|
25
26
|
return undefined;
|
|
26
27
|
}
|
|
27
28
|
}, [polling, fetcher]);
|
|
28
|
-
|
|
29
|
+
const onPollingResponse = (0, react_1.useCallback)((pollingResponse) => {
|
|
29
30
|
if (pollingResponse === null || pollingResponse === void 0 ? void 0 : pollingResponse.action) {
|
|
30
31
|
onAction(pollingResponse.action);
|
|
31
32
|
return false; // stop polling
|
|
@@ -33,16 +34,16 @@ function useStepPolling(polling, onAction) {
|
|
|
33
34
|
return true; // continue polling
|
|
34
35
|
}, [onAction]);
|
|
35
36
|
(0, __1.usePolling)({
|
|
36
|
-
asyncFn
|
|
37
|
+
asyncFn,
|
|
37
38
|
interval: 1000 * ((polling === null || polling === void 0 ? void 0 : polling.interval) || 0),
|
|
38
39
|
maxAttempts: (polling === null || polling === void 0 ? void 0 : polling.maxAttempts) || 0,
|
|
39
40
|
maxConsecutiveFails: 1,
|
|
40
|
-
onPollingResponse
|
|
41
|
-
onFailure: (0, react_1.useCallback)(
|
|
41
|
+
onPollingResponse,
|
|
42
|
+
onFailure: (0, react_1.useCallback)(() => {
|
|
42
43
|
if (polling) {
|
|
43
44
|
onAction(polling.onError.action);
|
|
44
45
|
}
|
|
45
|
-
}, [onAction, polling])
|
|
46
|
+
}, [onAction, polling]),
|
|
46
47
|
});
|
|
47
48
|
}
|
|
48
49
|
exports.useStepPolling = useStepPolling;
|
|
@@ -13,5 +13,5 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
-
exports
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./makeFetcher"), exports);
|
|
@@ -1,36 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
exports.__esModule = true;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.makeFetcher = void 0;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return fetch(resource, __assign(__assign({}, (init || {})), { headers: headers }));
|
|
21
|
-
};
|
|
4
|
+
const api_utils_1 = require("../utils/api-utils");
|
|
5
|
+
const makeFetcher = (baseUrl, additionalHeaders) => (input, init) => {
|
|
6
|
+
const resource = applyBaseUrl(input, baseUrl || '');
|
|
7
|
+
const headers = mergeHeaders(init === null || init === void 0 ? void 0 : init.headers, additionalHeaders);
|
|
8
|
+
return fetch(resource, Object.assign(Object.assign({}, (init || {})), { headers }));
|
|
22
9
|
};
|
|
23
10
|
exports.makeFetcher = makeFetcher;
|
|
24
|
-
|
|
11
|
+
const applyBaseUrl = (input, baseUrl) => {
|
|
25
12
|
return typeof input === 'string' && (0, api_utils_1.isRelativePath)(input) ? baseUrl + input : input;
|
|
26
13
|
};
|
|
27
|
-
|
|
14
|
+
const mergeHeaders = (initHeaders, additionalHeaders) => {
|
|
28
15
|
if (!initHeaders && !additionalHeaders) {
|
|
29
16
|
return {};
|
|
30
17
|
}
|
|
31
|
-
|
|
32
|
-
for (
|
|
33
|
-
var _b = _a[_i], key = _b[0], value = _b[1];
|
|
18
|
+
const headers = new Headers(initHeaders);
|
|
19
|
+
for (const [key, value] of Object.entries(additionalHeaders || {})) {
|
|
34
20
|
headers.set(key, value);
|
|
35
21
|
}
|
|
36
22
|
return headers;
|
package/build/common/messages.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
3
|
-
|
|
4
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_intl_1 = require("react-intl");
|
|
4
|
+
exports.default = (0, react_intl_1.defineMessages)({
|
|
5
5
|
required: {
|
|
6
6
|
id: 'dynamicFlows.DefaultErrorMessages.required',
|
|
7
7
|
defaultMessage: 'Please fill out this field.',
|
|
8
|
-
description: 'Customer has left the required field empty'
|
|
9
|
-
}
|
|
8
|
+
description: 'Customer has left the required field empty',
|
|
9
|
+
},
|
|
10
10
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isRelativePath = exports.getJson = exports.isStatus422 = exports.isStatus2xx = void 0;
|
|
4
4
|
function isStatus2xx(status) {
|
|
5
5
|
return status >= 200 && status < 300;
|
|
@@ -13,8 +13,7 @@ function getJson(response) {
|
|
|
13
13
|
return response.json();
|
|
14
14
|
}
|
|
15
15
|
exports.getJson = getJson;
|
|
16
|
-
function isRelativePath(url) {
|
|
17
|
-
|
|
18
|
-
return (['https://', 'http://', 'data:'].some(function (prefix) { return url.slice(0, prefix.length) === prefix && url.length > prefix.length; }) === false);
|
|
16
|
+
function isRelativePath(url = '') {
|
|
17
|
+
return (['https://', 'http://', 'data:'].some((prefix) => url.slice(0, prefix.length) === prefix && url.length > prefix.length) === false);
|
|
19
18
|
}
|
|
20
19
|
exports.isRelativePath = isRelativePath;
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.dateToDateString = exports.dateStringToDate = void 0;
|
|
4
|
-
|
|
4
|
+
const validators_1 = require("../validators");
|
|
5
5
|
// function taken from: https://stackoverflow.com/questions/23593052/format-javascript-date-as-yyyy-mm-dd
|
|
6
6
|
function formatDate(date) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
const d = new Date(date);
|
|
8
|
+
const month = `${d.getMonth() + 1}`;
|
|
9
|
+
const day = `${d.getDate()}`;
|
|
10
|
+
const year = d.getFullYear();
|
|
11
|
+
const formattedMonth = month.length < 2 ? `0${month}` : month;
|
|
12
|
+
const formattedDay = day.length < 2 ? `0${day}` : day;
|
|
13
13
|
return [year, formattedMonth, formattedDay].join('-');
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
const dateStringToDate = (dateString) => {
|
|
16
16
|
if (!dateString) {
|
|
17
17
|
return null;
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
const [year, month, date] = dateString.split('-').map((number) => parseInt(number, 10));
|
|
20
20
|
if (!(0, validators_1.isNumber)(year) || !(0, validators_1.isNumber)(month) || !(0, validators_1.isNumber)(date)) {
|
|
21
21
|
return null;
|
|
22
22
|
}
|
|
23
23
|
return new Date(year, month - 1, date);
|
|
24
24
|
};
|
|
25
25
|
exports.dateStringToDate = dateStringToDate;
|
|
26
|
-
|
|
26
|
+
const dateToDateString = (date) => formatDate(date);
|
|
27
27
|
exports.dateToDateString = dateToDateString;
|
|
@@ -1,39 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.debounce = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const debounce = (callback, waitMs) => {
|
|
5
|
+
let timeoutId;
|
|
6
|
+
let lastArgs;
|
|
7
|
+
const clearTimer = () => {
|
|
8
8
|
if (timeoutId) {
|
|
9
9
|
clearTimeout(timeoutId);
|
|
10
10
|
timeoutId = null;
|
|
11
11
|
}
|
|
12
12
|
lastArgs = null;
|
|
13
13
|
};
|
|
14
|
-
|
|
15
|
-
var args = [];
|
|
16
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
17
|
-
args[_i] = arguments[_i];
|
|
18
|
-
}
|
|
14
|
+
const debouncedFn = (...args) => {
|
|
19
15
|
lastArgs = args;
|
|
20
16
|
if (timeoutId !== null) {
|
|
21
17
|
clearTimeout(timeoutId);
|
|
22
18
|
}
|
|
23
|
-
timeoutId = setTimeout(
|
|
24
|
-
callback
|
|
19
|
+
timeoutId = setTimeout(() => {
|
|
20
|
+
callback(...lastArgs);
|
|
25
21
|
timeoutId = null;
|
|
26
22
|
lastArgs = null;
|
|
27
23
|
}, waitMs);
|
|
28
24
|
};
|
|
29
|
-
debouncedFn.cancel =
|
|
25
|
+
debouncedFn.cancel = () => {
|
|
30
26
|
if (timeoutId !== null) {
|
|
31
27
|
clearTimer();
|
|
32
28
|
}
|
|
33
29
|
};
|
|
34
|
-
debouncedFn.flush =
|
|
30
|
+
debouncedFn.flush = () => {
|
|
35
31
|
if (timeoutId !== null) {
|
|
36
|
-
callback
|
|
32
|
+
callback(...lastArgs);
|
|
37
33
|
clearTimer();
|
|
38
34
|
}
|
|
39
35
|
};
|
|
@@ -1,44 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
exports.__esModule = true;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.areFilesSame = exports.toBase64 = exports.toKilobytes = void 0;
|
|
15
4
|
function toKilobytes(sizeInBytes) {
|
|
16
|
-
|
|
5
|
+
const ONE_KB_IN_BYTES = 1024;
|
|
17
6
|
return Math.floor(sizeInBytes / ONE_KB_IN_BYTES);
|
|
18
7
|
}
|
|
19
8
|
exports.toKilobytes = toKilobytes;
|
|
20
9
|
//TODO: Refactor: This is duplicate logic as in CameraStep.tsx
|
|
21
|
-
|
|
22
|
-
return new Promise(
|
|
10
|
+
const toBase64 = (file) => {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
23
12
|
// we can safely assume the type of reader.result is string
|
|
24
13
|
// because we're calling reader.readAsDataURL
|
|
25
14
|
// https://developer.mozilla.org/en-US/docs/Web/API/FileReader/result
|
|
26
|
-
|
|
15
|
+
const reader = new FileReader();
|
|
27
16
|
reader.readAsDataURL(file);
|
|
28
|
-
reader.addEventListener('load',
|
|
29
|
-
reader.addEventListener('error',
|
|
17
|
+
reader.addEventListener('load', () => resolve(reader.result));
|
|
18
|
+
reader.addEventListener('error', (error) => reject(error));
|
|
30
19
|
});
|
|
31
20
|
};
|
|
32
21
|
exports.toBase64 = toBase64;
|
|
33
22
|
function areFilesSame(newFiles, files) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return __assign(__assign({}, map), (_a = {}, _a[fileObject.id] = fileObject, _a));
|
|
23
|
+
const fileIdToExistingFileMap = files.reduce((map, fileObject) => {
|
|
24
|
+
return Object.assign(Object.assign({}, map), { [fileObject.id]: fileObject });
|
|
37
25
|
}, {});
|
|
38
|
-
for (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var fileDoesNotExistAlready = !existingFileObject;
|
|
26
|
+
for (const newFile of newFiles) {
|
|
27
|
+
const existingFileObject = fileIdToExistingFileMap[newFile.id];
|
|
28
|
+
const fileDoesNotExistAlready = !existingFileObject;
|
|
42
29
|
if (fileDoesNotExistAlready) {
|
|
43
30
|
return false;
|
|
44
31
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateRandomId = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return "".concat(prefixString).concat(Math.floor(100000000 * Math.random()));
|
|
4
|
+
const generateRandomId = (prefix = '') => {
|
|
5
|
+
const prefixString = prefix ? `${prefix}-` : '';
|
|
6
|
+
return `${prefixString}${Math.floor(100000000 * Math.random())}`;
|
|
8
7
|
};
|
|
9
8
|
exports.generateRandomId = generateRandomId;
|