@wise/dynamic-flow-client 3.4.0 → 3.5.0-experimental-6654c72
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/errorBoundary/ErrorBoundary.js +44 -0
- package/build/common/errorBoundary/ErrorBoundaryAlert.js +12 -0
- package/build/common/httpClientContext/HttpClientContext.js +35 -0
- package/build/common/httpClientContext/index.js +1 -0
- package/build/common/makeHttpClient/index.js +1 -0
- package/build/common/makeHttpClient/makeHttpClient.js +34 -0
- package/build/common/messages/external-confirmation.messages.js +23 -0
- package/build/common/messages/generic-error.messages.js +18 -0
- package/build/common/messages/help.messages.js +8 -0
- package/build/common/messages/multi-file-upload.messages.js +18 -0
- package/build/common/messages/multi-select.messages.js +8 -0
- package/build/common/messages/paragraph.messages.js +13 -0
- package/build/common/messages/repeatable.messages.js +23 -0
- package/build/common/messages/validation.array.messages.js +13 -0
- package/build/common/messages/validation.messages.js +53 -0
- package/build/common/utils/api-utils.js +4 -0
- package/build/i18n/de.json +2 -1
- package/build/i18n/es.json +1 -0
- package/build/i18n/fr.json +1 -0
- package/build/i18n/hu.json +1 -0
- package/build/i18n/id.json +1 -0
- package/build/i18n/index.js +36 -0
- package/build/i18n/it.json +1 -0
- package/build/i18n/ja.json +1 -0
- package/build/i18n/pl.json +1 -0
- package/build/i18n/pt.json +1 -0
- package/build/i18n/ro.json +1 -0
- package/build/i18n/ru.json +1 -0
- package/build/i18n/th.json +1 -0
- package/build/i18n/tr.json +1 -0
- package/build/i18n/zh_CN.json +1 -0
- package/build/i18n/zh_HK.json +1 -0
- package/build/legacy/common/constants/DateMode.js +4 -0
- package/build/legacy/common/constants/FeatureName.js +4 -0
- package/build/legacy/common/constants/FormControlType.js +21 -0
- package/build/legacy/common/constants/MonthFormat.js +4 -0
- package/build/legacy/common/constants/Size.js +7 -0
- package/build/legacy/common/constants/index.js +4 -0
- package/build/legacy/common/contexts/dynamicFlowContexts/DynamicFlowContexts.js +36 -0
- package/build/legacy/common/contexts/dynamicFlowContexts/usePendingPromiseCounter.js +13 -0
- package/build/legacy/common/contexts/eventsContext/EventsContext.js +38 -0
- package/build/legacy/common/contexts/featureContext/FeatureContext.js +22 -0
- package/build/legacy/common/contexts/index.js +3 -0
- package/build/legacy/common/contexts/logContext/LogContext.js +44 -0
- package/build/legacy/common/hooks/index.js +7 -0
- package/build/legacy/common/hooks/useDebouncedFunction/useDebouncedFunction.js +9 -0
- package/build/legacy/common/hooks/useExternal/useExternal.js +15 -0
- package/build/legacy/common/hooks/useExternalStepPolling/useExternalStepPolling.js +70 -0
- package/build/legacy/common/hooks/usePersistAsync/usePersistAsync.js +172 -0
- package/build/legacy/common/hooks/usePolling/usePolling.js +51 -0
- package/build/legacy/common/hooks/usePrevious/usePrevious.js +8 -0
- package/build/legacy/common/hooks/useStepPolling/useStepPolling.js +43 -0
- package/build/legacy/common/messages.js +8 -0
- package/build/legacy/common/utils/api-utils.js +6 -0
- package/build/legacy/common/utils/date-utils.js +22 -0
- package/build/legacy/common/utils/debounce.js +38 -0
- package/build/legacy/common/utils/file-utils.js +45 -0
- package/build/legacy/common/utils/id-utils.js +5 -0
- package/build/legacy/common/utils/index.js +11 -0
- package/build/legacy/common/utils/is-equal.js +21 -0
- package/build/legacy/common/utils/misc-utils.js +4 -0
- package/build/legacy/common/utils/mobile-utils.js +23 -0
- package/build/legacy/common/utils/model-utils.js +33 -0
- package/build/legacy/common/utils/schema-utils.js +113 -0
- package/build/legacy/common/utils/step-utils.js +32 -0
- package/build/legacy/common/validators/index.js +5 -0
- package/build/legacy/common/validators/models/model-utils.js +119 -0
- package/build/legacy/common/validators/models/model-validators.js +62 -0
- package/build/legacy/common/validators/schemas/schema-validators.js +101 -0
- package/build/legacy/common/validators/types/type-validators.js +14 -0
- package/build/legacy/common/validators/validationFailures/validation-failures.js +139 -0
- package/build/legacy/common/validators/validationFailures/validation-failures.utils.js +40 -0
- package/build/legacy/common/validators/values/value-validators.js +6 -0
- package/build/legacy/dynamic-flow-types.js +1 -0
- package/build/legacy/dynamicFlow/BackButton.js +22 -0
- package/build/legacy/dynamicFlow/DynamicFlow.js +346 -0
- package/build/legacy/dynamicFlow/DynamicFlowStep.js +37 -0
- package/build/legacy/dynamicFlow/DynamicFlowTypes.js +1 -0
- package/build/legacy/dynamicFlow/index.js +1 -0
- package/build/legacy/dynamicFlow/utils/index.js +5 -0
- package/build/legacy/dynamicFlow/utils/responseParsers/response-parsers.js +185 -0
- package/build/legacy/dynamicFlow/utils/useDebouncedRefresh/useDebouncedRefresh.js +26 -0
- package/build/legacy/dynamicFlow/utils/useDynamicFlowState.js +137 -0
- package/build/legacy/dynamicFlow/utils/useLoader.js +22 -0
- package/build/legacy/formControl/FormControl.js +266 -0
- package/build/legacy/formControl/index.js +1 -0
- package/build/legacy/formControl/utils/getAutocompleteString.js +80 -0
- package/build/legacy/formControl/utils/index.js +2 -0
- package/build/legacy/formControl/utils/value-utils.js +108 -0
- package/build/legacy/jsonSchemaForm/JsonSchemaForm.js +24 -0
- package/build/legacy/jsonSchemaForm/allOfSchema/AllOfSchema.js +50 -0
- package/build/legacy/jsonSchemaForm/allOfSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/ArraySchema.js +25 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/ArrayListSchema.js +34 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multiSelectSchema/MultiSelectSchema.js +84 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/MultipleFileUploadSchema.js +141 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/index.js +2 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/upload-utils.js +79 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/useFormattedDefaultErrorMessages.js +14 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/ItemSummary.js +7 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/RepeatableSchema.js +134 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/RepeatableSchemaStep.js +85 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/utils/summary-utils.js +135 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/basicTypeSchema/BasicTypeSchema.js +111 -0
- package/build/legacy/jsonSchemaForm/basicTypeSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/controlFeedback/ControlFeedback.js +86 -0
- package/build/legacy/jsonSchemaForm/controlFeedback/index.js +1 -0
- package/build/legacy/jsonSchemaForm/genericSchema/GenericSchema.js +85 -0
- package/build/legacy/jsonSchemaForm/genericSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/help/Help.js +20 -0
- package/build/legacy/jsonSchemaForm/help/index.js +1 -0
- package/build/legacy/jsonSchemaForm/index.js +1 -0
- package/build/legacy/jsonSchemaForm/objectSchema/ObjectSchema.js +77 -0
- package/build/legacy/jsonSchemaForm/objectSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/oneOfSchema/OneOfSchema.js +155 -0
- package/build/legacy/jsonSchemaForm/oneOfSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/oneOfSchema/utils.js +68 -0
- package/build/legacy/jsonSchemaForm/persistAsyncSchema/PersistAsyncSchema.js +26 -0
- package/build/legacy/jsonSchemaForm/persistAsyncSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBasicSchema/PersistAsyncBasicSchema.js +165 -0
- package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBasicSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/PersistAsyncBlobSchema.js +131 -0
- package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/UploadInputAdapter.js +31 -0
- package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/promotedOneOfSchema/PromotedOneOfSchema.js +72 -0
- package/build/legacy/jsonSchemaForm/promotedOneOfSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promoted-one-of-utils.js +8 -0
- package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfCheckboxControl.js +27 -0
- package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfControl.js +31 -0
- package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfRadioControl.js +32 -0
- package/build/legacy/jsonSchemaForm/readOnlySchema/ReadOnlySchema.js +54 -0
- package/build/legacy/jsonSchemaForm/readOnlySchema/ReadOnlySchema.messages.js +13 -0
- package/build/legacy/jsonSchemaForm/readOnlySchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/schemaFormControl/SchemaFormControl.js +133 -0
- package/build/legacy/jsonSchemaForm/schemaFormControl/index.js +1 -0
- package/build/legacy/jsonSchemaForm/schemaFormControl/utils/index.js +1 -0
- package/build/legacy/jsonSchemaForm/schemaFormControl/utils/mapping-utils.js +107 -0
- package/build/legacy/jsonSchemaForm/validationAsyncSchema/ValidationAsyncSchema.js +150 -0
- package/build/legacy/jsonSchemaForm/validationAsyncSchema/index.js +1 -0
- package/build/legacy/layout/DynamicLayout.js +68 -0
- package/build/legacy/layout/alert/DynamicAlert.js +29 -0
- package/build/legacy/layout/box/DynamicBox.js +41 -0
- package/build/legacy/layout/button/DynamicButton.js +27 -0
- package/build/legacy/layout/button/utils.js +45 -0
- package/build/legacy/layout/columns/DynamicColumns.js +38 -0
- package/build/legacy/layout/decision/DynamicDecision.js +21 -0
- package/build/legacy/layout/divider/DynamicDivider.js +9 -0
- package/build/legacy/layout/external/DynamicExternal.js +32 -0
- package/build/legacy/layout/external/DynamicExternal.messages.js +8 -0
- package/build/legacy/layout/form/DynamicForm.js +22 -0
- package/build/legacy/layout/heading/DynamicHeading.js +51 -0
- package/build/legacy/layout/icon/DynamicIcon.js +17 -0
- package/build/legacy/layout/icon/FlagIcon.js +198 -0
- package/build/legacy/layout/icon/NamedIcon.js +19 -0
- package/build/legacy/layout/image/DynamicImage.js +111 -0
- package/build/legacy/layout/index.js +20 -0
- package/build/legacy/layout/instructions/DynamicInstructions.js +30 -0
- package/build/legacy/layout/list/DynamicStatusList.js +37 -0
- package/build/legacy/layout/loadingIndicator/DynamicLoadingIndicator.js +11 -0
- package/build/legacy/layout/markdown/DynamicMarkdown.js +23 -0
- package/build/legacy/layout/modal/DynamicModal.js +26 -0
- package/build/legacy/layout/paragraph/DynamicParagraph.js +46 -0
- package/build/legacy/layout/paragraph/useSnackBarIfAvailable.js +9 -0
- package/build/legacy/layout/review/DynamicReview.js +58 -0
- package/build/legacy/layout/search/DynamicSearch.js +58 -0
- package/build/legacy/layout/search/SearchInput.js +17 -0
- package/build/legacy/layout/search/SearchResults.js +31 -0
- package/build/legacy/layout/search/useSearch.js +137 -0
- package/build/legacy/layout/utils/getNavigationOptionMedia.js +28 -0
- package/build/legacy/layout/utils/index.js +32 -0
- package/build/legacy/step/cameraStep/CameraStep.js +124 -0
- package/build/legacy/step/cameraStep/cameraCapture/CameraCapture.js +161 -0
- package/build/legacy/step/cameraStep/cameraCapture/CameraCapture.messages.js +58 -0
- package/build/legacy/step/cameraStep/cameraCapture/components/bottomBar/BottomBar.js +28 -0
- package/build/legacy/step/cameraStep/cameraCapture/components/index.js +3 -0
- package/build/legacy/step/cameraStep/cameraCapture/components/orientationLockOverlay/OrientationLockOverlay.js +19 -0
- package/build/legacy/step/cameraStep/cameraCapture/components/orientationLockOverlay/OrientationLockOverlay.messages.js +8 -0
- package/build/legacy/step/cameraStep/cameraCapture/hooks/useFullScreenOrientationLock.js +60 -0
- package/build/legacy/step/cameraStep/cameraCapture/hooks/useVideoConstraints.js +80 -0
- package/build/legacy/step/cameraStep/cameraCapture/index.js +1 -0
- package/build/legacy/step/cameraStep/cameraCapture/overlay/Overlay.js +77 -0
- package/build/legacy/step/cameraStep/cameraCapture/screens/cameraErrorScreen/CameraErrorScreen.js +18 -0
- package/build/legacy/step/cameraStep/cameraCapture/screens/index.js +1 -0
- package/build/legacy/step/cameraStep/cameraCapture/tracking/index.js +109 -0
- package/build/legacy/step/cameraStep/cameraCapture/types/index.js +7 -0
- package/build/legacy/step/cameraStep/cameraCapture/utils/index.js +107 -0
- package/build/legacy/step/cameraStep/index.js +1 -0
- package/build/legacy/step/externalConfirmationStep/ExternalConfirmationStep.js +64 -0
- package/build/legacy/step/externalConfirmationStep/index.js +1 -0
- package/build/legacy/step/index.js +3 -0
- package/build/legacy/step/layoutStep/LayoutStep.js +33 -0
- package/build/legacy/step/layoutStep/index.js +1 -0
- package/build/legacy/step/layoutStep/utils/index.js +2 -0
- package/build/legacy/step/layoutStep/utils/inline-reference-utils.js +105 -0
- package/build/legacy/step/layoutStep/utils/layout-utils.js +212 -0
- package/build/main.js +4791 -226
- package/build/main.min.js +1 -1
- package/build/main.mjs +4792 -227
- package/build/revamp/domain/components/AlertComponent.js +50 -0
- package/build/revamp/domain/components/AllOfComponent.js +72 -0
- package/build/revamp/domain/components/BooleanInputComponent.js +108 -0
- package/build/revamp/domain/components/BoxComponent.js +65 -0
- package/build/revamp/domain/components/ButtonComponent.js +50 -0
- package/build/revamp/domain/components/ColumnsComponent.js +74 -0
- package/build/revamp/domain/components/ConstComponent.js +50 -0
- package/build/revamp/domain/components/ContainerComponent.js +65 -0
- package/build/revamp/domain/components/DateInputComponent.js +127 -0
- package/build/revamp/domain/components/DecisionComponent.js +50 -0
- package/build/revamp/domain/components/DividerComponent.js +50 -0
- package/build/revamp/domain/components/FormComponent.js +65 -0
- package/build/revamp/domain/components/HeadingComponent.js +50 -0
- package/build/revamp/domain/components/ImageComponent.js +50 -0
- package/build/revamp/domain/components/InstructionsComponent.js +50 -0
- package/build/revamp/domain/components/IntegerInputComponent.js +125 -0
- package/build/revamp/domain/components/LoadingIndicatorComponent.js +50 -0
- package/build/revamp/domain/components/MarkdownComponent.js +50 -0
- package/build/revamp/domain/components/ModalComponent.js +65 -0
- package/build/revamp/domain/components/MultiUploadInputComponent.js +190 -0
- package/build/revamp/domain/components/NumberInputComponent.js +125 -0
- package/build/revamp/domain/components/ObjectComponent.js +104 -0
- package/build/revamp/domain/components/ParagraphComponent.js +50 -0
- package/build/revamp/domain/components/ReviewComponent.js +50 -0
- package/build/revamp/domain/components/SelectInputComponent.js +138 -0
- package/build/revamp/domain/components/StatusListComponent.js +50 -0
- package/build/revamp/domain/components/StepDomainComponent.js +93 -0
- package/build/revamp/domain/components/TextInputComponent.js +125 -0
- package/build/revamp/domain/components/UploadInputComponent.js +151 -0
- package/build/revamp/domain/components/repeatableComponent/RepeatableComponent.js +148 -0
- package/build/revamp/domain/components/searchComponent/SearchComponent.js +108 -0
- package/build/revamp/domain/components/utils/component-utils.js +18 -0
- package/build/revamp/domain/components/utils/debounce.js +38 -0
- package/build/revamp/domain/components/utils/file-utils.js +46 -0
- package/build/revamp/domain/components/utils/getComponentForLocalValueKey.js +31 -0
- package/build/revamp/domain/components/utils/isPartialLocalValueMatch.js +40 -0
- package/build/revamp/domain/features/events.js +1 -0
- package/build/revamp/domain/features/persistAsync/getComponentPersistAsync.js +133 -0
- package/build/revamp/domain/features/persistAsync/getPerformPersistAsync.js +103 -0
- package/build/revamp/domain/features/refresh/getPerformRefresh.js +53 -0
- package/build/revamp/domain/features/summary/summary-utils.js +39 -0
- package/build/revamp/domain/features/utils/http-utils.js +34 -0
- package/build/revamp/domain/features/utils/response-utils.js +9 -0
- package/build/revamp/domain/features/validation/validation-functions.js +12 -0
- package/build/revamp/domain/features/validation/value-checks.js +111 -0
- package/build/revamp/domain/features/validationAsync/getComponentValidationAsync.js +94 -0
- package/build/revamp/domain/features/validationAsync/getPerformValidationAsync.js +107 -0
- package/build/revamp/domain/mappers/types.js +1 -0
- package/build/revamp/domain/types.js +1 -0
- package/build/revamp/flow/response-utils.js +88 -0
- package/build/revamp/renderers/CoreContainerRenderer.js +8 -0
- package/build/revamp/renderers/LoadingContext.js +7 -0
- package/build/revamp/renderers/types.js +1 -0
- package/build/revamp/types.js +1 -0
- package/build/revamp/utils/component-utils.js +86 -0
- package/build/revamp/utils/type-utils.js +56 -0
- package/build/revamp/utils/type-validators.js +16 -0
- package/build/revamp/wise/renderers/AlertRenderer.js +11 -0
- package/build/revamp/wise/renderers/BooleanInputRenderer.js +34 -0
- package/build/revamp/wise/renderers/BoxRenderer.js +30 -0
- package/build/revamp/wise/renderers/ButtonRenderer.js +64 -0
- package/build/revamp/wise/renderers/ColumnsRenderer.js +25 -0
- package/build/revamp/wise/renderers/components/FieldInput.js +20 -0
- package/build/revamp/wise/renderers/components/Help.js +21 -0
- package/build/revamp/wise/renderers/components/LabelContentWithHelp.js +6 -0
- package/build/revamp/wise/renderers/utils/layout-utils.js +31 -0
- package/build/types/legacy/step/externalConfirmationStep/ExternalConfirmationStep.d.ts +1 -1
- package/build/types/revamp/domain/components/StepDomainComponent.d.ts +4 -2
- package/build/types/revamp/renderers/step/ExternalConfirmationDialog.d.ts +6 -0
- package/build/types/revamp/renderers/{StepRenderer.d.ts → step/StepRenderer.d.ts} +1 -1
- package/build/types/revamp/renderers/step/useExternal.d.ts +4 -0
- package/build/types/revamp/renderers/stepComponentToProps.d.ts +1 -1
- package/build/types/revamp/renderers/types.d.ts +3 -0
- package/package.json +13 -13
- /package/build/types/{legacy/step/externalConfirmationStep/ExternalConfirmationStep.messages.d.ts → common/messages/external-confirmation.messages.d.ts} +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { createContext, useContext, useMemo } from 'react';
|
|
14
|
+
var EventsContext = createContext({
|
|
15
|
+
triggerEvent: function () {
|
|
16
|
+
// noop
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
export function EventsContextProvider(_a) {
|
|
20
|
+
var metadata = _a.metadata, children = _a.children, onEvent = _a.onEvent;
|
|
21
|
+
var value = useMemo(function () { return ({ triggerEvent: getEventDispatcher(onEvent, metadata) }); }, [onEvent, metadata]);
|
|
22
|
+
return _jsx(EventsContext.Provider, __assign({ value: value }, { children: children }));
|
|
23
|
+
}
|
|
24
|
+
export function useEventDispatcher() {
|
|
25
|
+
var triggerEvent = useContext(EventsContext).triggerEvent;
|
|
26
|
+
return triggerEvent;
|
|
27
|
+
}
|
|
28
|
+
export var getEventDispatcher = function (onEvent, metadata) {
|
|
29
|
+
return function (eventName, properties) {
|
|
30
|
+
if (properties === void 0) { properties = {}; }
|
|
31
|
+
try {
|
|
32
|
+
onEvent(eventName, __assign(__assign({}, metadata), properties));
|
|
33
|
+
}
|
|
34
|
+
catch (_a) {
|
|
35
|
+
// noop
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { createContext, useContext } from 'react';
|
|
14
|
+
var FeatureContext = createContext([]);
|
|
15
|
+
export function FeatureContextProvider(_a) {
|
|
16
|
+
var features = _a.features, children = _a.children;
|
|
17
|
+
return _jsx(FeatureContext.Provider, __assign({ value: features }, { children: children }));
|
|
18
|
+
}
|
|
19
|
+
export var useFeatureFlag = function (featureName) {
|
|
20
|
+
var features = useContext(FeatureContext);
|
|
21
|
+
return features === null || features === void 0 ? void 0 : features.find(function (feature) { return feature.featureName === featureName; });
|
|
22
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { createContext, useContext, useMemo } from 'react';
|
|
14
|
+
export var getLogger = function (level, onLog, flowId, stepId) {
|
|
15
|
+
if (flowId === void 0) { flowId = 'UNKNOWN-FLOW-ID'; }
|
|
16
|
+
if (stepId === void 0) { stepId = 'UNKNOWN-FLOW-ID'; }
|
|
17
|
+
return function (title, description, extra) {
|
|
18
|
+
try {
|
|
19
|
+
onLog(level, "Dynamic Flow ".concat(level, " - ").concat(title, " - ").concat(description), __assign({ flowId: flowId, stepId: stepId }, extra));
|
|
20
|
+
}
|
|
21
|
+
catch (_a) {
|
|
22
|
+
// noop
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
var LogContext = createContext(null);
|
|
27
|
+
export function LogProvider(_a) {
|
|
28
|
+
var flowId = _a.flowId, stepId = _a.stepId, children = _a.children, onLog = _a.onLog;
|
|
29
|
+
var value = useMemo(function () { return ({
|
|
30
|
+
debug: getLogger('debug', onLog, flowId, stepId),
|
|
31
|
+
info: getLogger('info', onLog, flowId, stepId),
|
|
32
|
+
warning: getLogger('warning', onLog, flowId, stepId),
|
|
33
|
+
error: getLogger('error', onLog, flowId, stepId),
|
|
34
|
+
critical: getLogger('critical', onLog, flowId, stepId)
|
|
35
|
+
}); }, [onLog, flowId, stepId]);
|
|
36
|
+
return _jsx(LogContext.Provider, __assign({ value: value }, { children: children }));
|
|
37
|
+
}
|
|
38
|
+
export var useLogger = function () {
|
|
39
|
+
var logging = useContext(LogContext);
|
|
40
|
+
if (logging == null) {
|
|
41
|
+
throw new Error('Logging context not found. Did you forget to wrap your component in a <LogProvider />?');
|
|
42
|
+
}
|
|
43
|
+
return logging;
|
|
44
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './useDebouncedFunction/useDebouncedFunction';
|
|
2
|
+
export * from './useExternal/useExternal';
|
|
3
|
+
export * from './useExternalStepPolling/useExternalStepPolling';
|
|
4
|
+
export * from './usePersistAsync/usePersistAsync';
|
|
5
|
+
export * from './usePolling/usePolling';
|
|
6
|
+
export * from './usePrevious/usePrevious';
|
|
7
|
+
export * from './useStepPolling/useStepPolling';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* References:
|
|
2
|
+
- https://github.com/gnbaron/use-lodash-debounce
|
|
3
|
+
- https://dmitripavlutin.com/react-throttle-debounce/
|
|
4
|
+
*/
|
|
5
|
+
import { useCallback } from 'react';
|
|
6
|
+
import { debounce } from '../../utils';
|
|
7
|
+
export function useDebouncedFunction(callback, waitMs) {
|
|
8
|
+
return useCallback(debounce(callback, waitMs), [callback, waitMs]);
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
export function useExternal(url) {
|
|
3
|
+
// If we fail to open the window, the user will need to open this on their own
|
|
4
|
+
var _a = useState(null), externalWindow = _a[0], setExternalWindow = _a[1];
|
|
5
|
+
var _b = useState(false), hasManuallyTriggered = _b[0], setHasManuallyTriggered = _b[1];
|
|
6
|
+
var dismissConfirmation = function () { return setHasManuallyTriggered(true); };
|
|
7
|
+
useEffect(function () {
|
|
8
|
+
if (url) {
|
|
9
|
+
setHasManuallyTriggered(false);
|
|
10
|
+
setExternalWindow(window.open(url, '_blank'));
|
|
11
|
+
}
|
|
12
|
+
}, [url]);
|
|
13
|
+
var requiresManualTrigger = Boolean(url && !externalWindow && !hasManuallyTriggered);
|
|
14
|
+
return { requiresManualTrigger: requiresManualTrigger, dismissConfirmation: dismissConfirmation };
|
|
15
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { useCallback, useMemo } from 'react';
|
|
13
|
+
import { usePolling } from '..';
|
|
14
|
+
import { useHttpClient } from '../../../../common/httpClientContext';
|
|
15
|
+
/** @deprecated External step is no longer supported */
|
|
16
|
+
export function useExternalStepPolling(polling, onAction) {
|
|
17
|
+
var httpClient = useHttpClient();
|
|
18
|
+
var asyncFn = useMemo(function () {
|
|
19
|
+
if (polling) {
|
|
20
|
+
return function () {
|
|
21
|
+
return httpClient(polling.url)
|
|
22
|
+
.then(function (response) {
|
|
23
|
+
if (response.ok) {
|
|
24
|
+
try {
|
|
25
|
+
return response.json();
|
|
26
|
+
}
|
|
27
|
+
catch (_a) {
|
|
28
|
+
throw new Error('failed');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
throw new Error('failed');
|
|
33
|
+
}
|
|
34
|
+
})["catch"](function (error) {
|
|
35
|
+
throw new Error(error.message === 'failed' ? 'failed' : 'network failed');
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
}, [polling, httpClient]);
|
|
41
|
+
var onPollingResponse = useCallback(function (pollingResponse) {
|
|
42
|
+
var responseHandlers = (polling === null || polling === void 0 ? void 0 : polling.responseHandlers) || [];
|
|
43
|
+
var responseHandler = responseHandlers.find(function (handler) { return handler.result === pollingResponse.result; });
|
|
44
|
+
if (responseHandler === null || responseHandler === void 0 ? void 0 : responseHandler.action) {
|
|
45
|
+
var action = responseHandler.action;
|
|
46
|
+
if (action.exit) {
|
|
47
|
+
var mergedResult = __assign(__assign({}, (action.result || {})), (pollingResponse.data || {}));
|
|
48
|
+
onAction(__assign(__assign({}, action), { result: mergedResult }));
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
var mergedData = __assign(__assign({}, (action.data || {})), (pollingResponse.data || {}));
|
|
52
|
+
onAction(__assign(__assign({}, action), { data: mergedData }));
|
|
53
|
+
}
|
|
54
|
+
return false; // stop polling
|
|
55
|
+
}
|
|
56
|
+
return true; // continue polling
|
|
57
|
+
}, [polling === null || polling === void 0 ? void 0 : polling.responseHandlers, onAction]);
|
|
58
|
+
usePolling({
|
|
59
|
+
asyncFn: asyncFn,
|
|
60
|
+
interval: (polling === null || polling === void 0 ? void 0 : polling.interval) || 0,
|
|
61
|
+
maxAttempts: (polling === null || polling === void 0 ? void 0 : polling.maxAttempts) || 0,
|
|
62
|
+
maxConsecutiveFails: (polling === null || polling === void 0 ? void 0 : polling.maxConsecutiveFails) || 0,
|
|
63
|
+
onPollingResponse: onPollingResponse,
|
|
64
|
+
onFailure: useCallback(function () {
|
|
65
|
+
if (polling) {
|
|
66
|
+
onAction(polling.onError.action);
|
|
67
|
+
}
|
|
68
|
+
}, [onAction, polling])
|
|
69
|
+
});
|
|
70
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
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;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import { useState } from 'react';
|
|
49
|
+
import { useIntl } from 'react-intl';
|
|
50
|
+
import { isBlobSchema } from '../../utils';
|
|
51
|
+
import { isNull, isObject, isNumber, isString, isValidSchema } from '../../validators';
|
|
52
|
+
import messages from '../../../../common/messages/generic-error.messages';
|
|
53
|
+
import { getErrorFromResponse } from '../../../jsonSchemaForm/persistAsyncSchema/persistAsyncBasicSchema/PersistAsyncBasicSchema'; // FIXME: extract these functions form that schema component to either here or their own module
|
|
54
|
+
import { useHttpClient } from '../../../../common/httpClientContext';
|
|
55
|
+
export var usePersistAsync = function (persistAsync) {
|
|
56
|
+
var _a = useState(null), abortController = _a[0], setAbortController = _a[1];
|
|
57
|
+
var httpClient = useHttpClient();
|
|
58
|
+
var intl = useIntl();
|
|
59
|
+
var schema = persistAsync.schema;
|
|
60
|
+
function handlePersistAsync(model) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
62
|
+
var isInvalidSchema;
|
|
63
|
+
return __generator(this, function (_a) {
|
|
64
|
+
switch (_a.label) {
|
|
65
|
+
case 0:
|
|
66
|
+
isInvalidSchema = model instanceof Blob ? !isBlobSchema(schema) : !isValidSchema(model, schema);
|
|
67
|
+
if (isNull(model) || isInvalidSchema) {
|
|
68
|
+
handleError();
|
|
69
|
+
}
|
|
70
|
+
return [4 /*yield*/, performPersistAsync(model)];
|
|
71
|
+
case 1:
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/return-await
|
|
73
|
+
return [2 /*return*/, _a.sent()];
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
var abortCurrentRequestAndGetNewAbortSignal = function () {
|
|
79
|
+
if (abortController) {
|
|
80
|
+
abortController.abort();
|
|
81
|
+
}
|
|
82
|
+
var newAbortController = new AbortController();
|
|
83
|
+
setAbortController(newAbortController);
|
|
84
|
+
return newAbortController.signal;
|
|
85
|
+
};
|
|
86
|
+
function constructFetchInit(model) {
|
|
87
|
+
var _a;
|
|
88
|
+
var isBlob = isBlobSchema(schema);
|
|
89
|
+
var signal = abortCurrentRequestAndGetNewAbortSignal();
|
|
90
|
+
var requestKey = persistAsync.param;
|
|
91
|
+
var requestBody = isBlob
|
|
92
|
+
? wrapInFormData(requestKey, model)
|
|
93
|
+
: JSON.stringify((_a = {}, _a[requestKey] = model, _a));
|
|
94
|
+
return {
|
|
95
|
+
method: persistAsync.method,
|
|
96
|
+
headers: __assign({}, (!isBlob && { 'Content-Type': 'application/json' })),
|
|
97
|
+
body: requestBody,
|
|
98
|
+
signal: signal
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function performPersistAsync(payload) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
103
|
+
var response, jsonResponse, id, error_1;
|
|
104
|
+
return __generator(this, function (_a) {
|
|
105
|
+
switch (_a.label) {
|
|
106
|
+
case 0:
|
|
107
|
+
_a.trys.push([0, 3, , 4]);
|
|
108
|
+
return [4 /*yield*/, httpClient(persistAsync.url, constructFetchInit(payload))];
|
|
109
|
+
case 1:
|
|
110
|
+
response = _a.sent();
|
|
111
|
+
if (!response.ok) {
|
|
112
|
+
// eslint-disable-next-line @typescript-eslint/return-await
|
|
113
|
+
return [2 /*return*/, handleHTTPError(response)];
|
|
114
|
+
}
|
|
115
|
+
return [4 /*yield*/, response.json()];
|
|
116
|
+
case 2:
|
|
117
|
+
jsonResponse = _a.sent();
|
|
118
|
+
if (isObject(jsonResponse)) {
|
|
119
|
+
id = jsonResponse[persistAsync.idProperty];
|
|
120
|
+
if (isString(id) || isNumber(id)) {
|
|
121
|
+
return [2 /*return*/, { data: id }];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return [2 /*return*/, handleError()];
|
|
125
|
+
case 3:
|
|
126
|
+
error_1 = _a.sent();
|
|
127
|
+
return [2 /*return*/, handleError(error_1)];
|
|
128
|
+
case 4: return [2 /*return*/];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function handleHTTPError(response) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
135
|
+
var jsonResponse, error;
|
|
136
|
+
return __generator(this, function (_a) {
|
|
137
|
+
switch (_a.label) {
|
|
138
|
+
case 0:
|
|
139
|
+
if (!(response.status === 422)) return [3 /*break*/, 2];
|
|
140
|
+
return [4 /*yield*/, response.json()];
|
|
141
|
+
case 1:
|
|
142
|
+
jsonResponse = _a.sent();
|
|
143
|
+
if (isObject(jsonResponse)) {
|
|
144
|
+
error = getErrorFromResponse(persistAsync.param, jsonResponse);
|
|
145
|
+
if (isString(error)) {
|
|
146
|
+
throw new Error(error);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
_a.label = 2;
|
|
150
|
+
case 2: throw new Error(intl.formatMessage(messages.genericErrorRetryHint));
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
var handleError = function (error) {
|
|
156
|
+
var message = hasStringMessage(error)
|
|
157
|
+
? error.message
|
|
158
|
+
: intl.formatMessage(messages.genericErrorRetryHint);
|
|
159
|
+
throw new Error(message);
|
|
160
|
+
};
|
|
161
|
+
return handlePersistAsync;
|
|
162
|
+
};
|
|
163
|
+
function wrapInFormData(key, value) {
|
|
164
|
+
var formData = new FormData();
|
|
165
|
+
if (value !== null) {
|
|
166
|
+
formData.append(key, value);
|
|
167
|
+
}
|
|
168
|
+
return formData;
|
|
169
|
+
}
|
|
170
|
+
function hasStringMessage(value) {
|
|
171
|
+
return isObject(value) && 'message' in value && typeof value.message === 'string';
|
|
172
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
export function usePolling(_a) {
|
|
3
|
+
var asyncFn = _a.asyncFn, interval = _a.interval, maxAttempts = _a.maxAttempts, maxConsecutiveFails = _a.maxConsecutiveFails, onPollingResponse = _a.onPollingResponse, onFailure = _a.onFailure;
|
|
4
|
+
var onPollingResponseReference = useRef(onPollingResponse);
|
|
5
|
+
var onFailureReference = useRef(onFailure);
|
|
6
|
+
var poll = useMemo(function () {
|
|
7
|
+
return createPollingClosure(asyncFn, maxAttempts, maxConsecutiveFails, function (pollingResponse) { return onPollingResponseReference.current(pollingResponse); }, function () { return onFailureReference.current(); });
|
|
8
|
+
}, [asyncFn, maxAttempts, maxConsecutiveFails]);
|
|
9
|
+
// eslint-disable-next-line consistent-return
|
|
10
|
+
useEffect(function () {
|
|
11
|
+
if (interval > 0) {
|
|
12
|
+
var intervalReference_1 = setInterval(function () {
|
|
13
|
+
poll();
|
|
14
|
+
}, interval);
|
|
15
|
+
return function () { return clearInterval(intervalReference_1); };
|
|
16
|
+
}
|
|
17
|
+
}, [poll, interval]);
|
|
18
|
+
useEffect(function () {
|
|
19
|
+
onPollingResponseReference.current = onPollingResponse;
|
|
20
|
+
onFailureReference.current = onFailure;
|
|
21
|
+
}, [onPollingResponse, onFailure]);
|
|
22
|
+
}
|
|
23
|
+
export function createPollingClosure(asyncFn, maxAttempts, maxConsecutiveFails, onPollingResponse, onFailure) {
|
|
24
|
+
var isPolling = true;
|
|
25
|
+
var consecutiveFailures = 0;
|
|
26
|
+
var attemptCount = 0;
|
|
27
|
+
return asyncFn
|
|
28
|
+
? function () {
|
|
29
|
+
if (isPolling) {
|
|
30
|
+
attemptCount++;
|
|
31
|
+
asyncFn()
|
|
32
|
+
.then(function (pollingResponse) {
|
|
33
|
+
consecutiveFailures = 0;
|
|
34
|
+
isPolling = onPollingResponse(pollingResponse);
|
|
35
|
+
})["catch"](function (error) {
|
|
36
|
+
// do not fail on network errors
|
|
37
|
+
if (error.message !== 'network failed') {
|
|
38
|
+
consecutiveFailures += 1;
|
|
39
|
+
}
|
|
40
|
+
})["finally"](function () {
|
|
41
|
+
if (consecutiveFailures >= maxConsecutiveFails || attemptCount >= maxAttempts) {
|
|
42
|
+
onFailure();
|
|
43
|
+
isPolling = false;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
: function () {
|
|
49
|
+
//
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
|
+
import { usePolling } from '..';
|
|
3
|
+
import { useHttpClient } from '../../../../common/httpClientContext';
|
|
4
|
+
export function useStepPolling(polling, onAction) {
|
|
5
|
+
var httpClient = useHttpClient();
|
|
6
|
+
var asyncFn = useMemo(function () {
|
|
7
|
+
if (polling) {
|
|
8
|
+
return function () {
|
|
9
|
+
return httpClient(polling.url)
|
|
10
|
+
.then(function (response) {
|
|
11
|
+
if (response.ok) {
|
|
12
|
+
return response
|
|
13
|
+
.json()
|
|
14
|
+
.then(function (pollingResponse) { return pollingResponse; })["catch"](function (error) { return null; });
|
|
15
|
+
}
|
|
16
|
+
throw new Error('failed');
|
|
17
|
+
})["catch"](function (error) {
|
|
18
|
+
throw new Error(error.message === 'failed' ? 'failed' : 'network failed');
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
}, [polling, httpClient]);
|
|
24
|
+
var onPollingResponse = useCallback(function (pollingResponse) {
|
|
25
|
+
if (pollingResponse === null || pollingResponse === void 0 ? void 0 : pollingResponse.action) {
|
|
26
|
+
onAction(pollingResponse.action);
|
|
27
|
+
return false; // stop polling
|
|
28
|
+
}
|
|
29
|
+
return true; // continue polling
|
|
30
|
+
}, [onAction]);
|
|
31
|
+
usePolling({
|
|
32
|
+
asyncFn: asyncFn,
|
|
33
|
+
interval: 1000 * ((polling === null || polling === void 0 ? void 0 : polling.interval) || 0),
|
|
34
|
+
maxAttempts: (polling === null || polling === void 0 ? void 0 : polling.maxAttempts) || 0,
|
|
35
|
+
maxConsecutiveFails: 1,
|
|
36
|
+
onPollingResponse: onPollingResponse,
|
|
37
|
+
onFailure: useCallback(function () {
|
|
38
|
+
if (polling) {
|
|
39
|
+
onAction(polling.onError.action);
|
|
40
|
+
}
|
|
41
|
+
}, [onAction, polling])
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isNumber } from '../validators';
|
|
2
|
+
// function taken from: https://stackoverflow.com/questions/23593052/format-javascript-date-as-yyyy-mm-dd
|
|
3
|
+
function formatDate(date) {
|
|
4
|
+
var d = new Date(date);
|
|
5
|
+
var month = String(d.getMonth() + 1);
|
|
6
|
+
var day = String(d.getDate());
|
|
7
|
+
var year = d.getFullYear();
|
|
8
|
+
var formattedMonth = month.length < 2 ? "0".concat(month) : month;
|
|
9
|
+
var formattedDay = day.length < 2 ? "0".concat(day) : day;
|
|
10
|
+
return [year, formattedMonth, formattedDay].join('-');
|
|
11
|
+
}
|
|
12
|
+
export var dateStringToDate = function (dateString) {
|
|
13
|
+
if (!dateString) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
var _a = dateString.split('-').map(function (number) { return parseInt(number, 10); }), year = _a[0], month = _a[1], date = _a[2];
|
|
17
|
+
if (!isNumber(year) || !isNumber(month) || !isNumber(date)) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return new Date(year, month - 1, date);
|
|
21
|
+
};
|
|
22
|
+
export var dateToDateString = function (date) { return formatDate(date); };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export var debounce = function (callback, waitMs) {
|
|
2
|
+
var timeoutId;
|
|
3
|
+
var lastArgs;
|
|
4
|
+
var clearTimer = function () {
|
|
5
|
+
if (timeoutId) {
|
|
6
|
+
clearTimeout(timeoutId);
|
|
7
|
+
timeoutId = null;
|
|
8
|
+
}
|
|
9
|
+
lastArgs = null;
|
|
10
|
+
};
|
|
11
|
+
var debouncedFn = function () {
|
|
12
|
+
var args = [];
|
|
13
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
14
|
+
args[_i] = arguments[_i];
|
|
15
|
+
}
|
|
16
|
+
lastArgs = args;
|
|
17
|
+
if (timeoutId !== null) {
|
|
18
|
+
clearTimeout(timeoutId);
|
|
19
|
+
}
|
|
20
|
+
timeoutId = setTimeout(function () {
|
|
21
|
+
callback.apply(void 0, lastArgs);
|
|
22
|
+
timeoutId = null;
|
|
23
|
+
lastArgs = null;
|
|
24
|
+
}, waitMs);
|
|
25
|
+
};
|
|
26
|
+
debouncedFn.cancel = function () {
|
|
27
|
+
if (timeoutId !== null) {
|
|
28
|
+
clearTimer();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
debouncedFn.flush = function () {
|
|
32
|
+
if (timeoutId !== null) {
|
|
33
|
+
callback.apply(void 0, lastArgs);
|
|
34
|
+
clearTimer();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
return debouncedFn;
|
|
38
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
export function toKilobytes(sizeInBytes) {
|
|
13
|
+
var ONE_KB_IN_BYTES = 1024;
|
|
14
|
+
return Math.floor(sizeInBytes / ONE_KB_IN_BYTES);
|
|
15
|
+
}
|
|
16
|
+
// TODO: Refactor: This is duplicate logic as in CameraStep.tsx
|
|
17
|
+
export var toBase64 = function (file) {
|
|
18
|
+
return new Promise(function (resolve, reject) {
|
|
19
|
+
// we can safely assume the type of reader.result is string
|
|
20
|
+
// because we're calling reader.readAsDataURL
|
|
21
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/FileReader/result
|
|
22
|
+
var reader = new FileReader();
|
|
23
|
+
reader.readAsDataURL(file);
|
|
24
|
+
reader.addEventListener('load', function () { return resolve(reader.result); });
|
|
25
|
+
reader.addEventListener('error', function (error) { return reject(error); });
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
export function areFilesSame(newFiles, files) {
|
|
29
|
+
var fileIdToExistingFileMap = files.reduce(function (map, fileObject) {
|
|
30
|
+
var _a;
|
|
31
|
+
return (__assign(__assign({}, map), (_a = {}, _a[fileObject.id] = fileObject, _a)));
|
|
32
|
+
}, {});
|
|
33
|
+
for (var _i = 0, newFiles_1 = newFiles; _i < newFiles_1.length; _i++) {
|
|
34
|
+
var newFile = newFiles_1[_i];
|
|
35
|
+
var existingFileObject = fileIdToExistingFileMap[newFile.id];
|
|
36
|
+
var fileDoesNotExistAlready = !existingFileObject;
|
|
37
|
+
if (fileDoesNotExistAlready) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (existingFileObject.status !== newFile.status) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './api-utils';
|
|
2
|
+
export * from './date-utils';
|
|
3
|
+
export * from './debounce';
|
|
4
|
+
export * from './is-equal';
|
|
5
|
+
export * from './file-utils';
|
|
6
|
+
export * from './id-utils';
|
|
7
|
+
export * from './step-utils';
|
|
8
|
+
export * from './model-utils';
|
|
9
|
+
export * from './misc-utils';
|
|
10
|
+
export * from './schema-utils';
|
|
11
|
+
export * from './mobile-utils';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export var isEqual = function (a, b) {
|
|
2
|
+
if (a === b) {
|
|
3
|
+
return true;
|
|
4
|
+
}
|
|
5
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
6
|
+
return a.length === b.length && a.every(function (item, index) { return isEqual(item, b[index]); });
|
|
7
|
+
}
|
|
8
|
+
if (isNonNullObject(a) && isNonNullObject(b) && isObjectEquals(a, b)) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
};
|
|
13
|
+
var isObjectEquals = function (a, b) {
|
|
14
|
+
var keysA = Object.keys(a);
|
|
15
|
+
var keysB = Object.keys(b);
|
|
16
|
+
return (keysA.length === keysB.length &&
|
|
17
|
+
keysA.every(function (key) { return Object.hasOwnProperty.call(b, key) && isEqual(a[key], b[key]); }));
|
|
18
|
+
};
|
|
19
|
+
var isNonNullObject = function (a) {
|
|
20
|
+
return typeof a === 'object' && a !== null;
|
|
21
|
+
};
|