@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,40 @@
|
|
|
1
|
+
import { isArray, isNumber, isString, isUndefined } from '..';
|
|
2
|
+
function isValidRequired(value, isRequired) {
|
|
3
|
+
if (isRequired === void 0) { isRequired = false; }
|
|
4
|
+
return !isRequired || !isUndefined(value);
|
|
5
|
+
}
|
|
6
|
+
function isValidRequiredArray(value, isRequired) {
|
|
7
|
+
if (isRequired === void 0) { isRequired = false; }
|
|
8
|
+
return !isRequired || isArray(value);
|
|
9
|
+
}
|
|
10
|
+
function isValidMinLength(value, minLength) {
|
|
11
|
+
return !isNumber(minLength) || (isString(value) && value.length >= minLength);
|
|
12
|
+
}
|
|
13
|
+
function isValidMaxLength(value, maxLength) {
|
|
14
|
+
return !isNumber(maxLength) || (isString(value) && value.length <= maxLength);
|
|
15
|
+
}
|
|
16
|
+
function isValidPattern(value, pattern) {
|
|
17
|
+
if (pattern === undefined) {
|
|
18
|
+
return true; // no pattern, therefore the value is valid
|
|
19
|
+
}
|
|
20
|
+
if (value === undefined || value === null) {
|
|
21
|
+
return false; // no value, but there's a pattern, therefore the value is NOT valid
|
|
22
|
+
}
|
|
23
|
+
var regex = new RegExp(pattern);
|
|
24
|
+
return Boolean(regex.test(value));
|
|
25
|
+
}
|
|
26
|
+
function isValidMaximum(value, maximum) {
|
|
27
|
+
return ((!isNumber(maximum) && !isString(maximum)) ||
|
|
28
|
+
((isNumber(value) || isString(value)) && value <= maximum));
|
|
29
|
+
}
|
|
30
|
+
function isValidMinimum(value, minimum) {
|
|
31
|
+
return ((!isNumber(minimum) && !isString(minimum)) ||
|
|
32
|
+
((isNumber(value) || isString(value)) && value >= minimum));
|
|
33
|
+
}
|
|
34
|
+
function isValidMinItems(value, minItems) {
|
|
35
|
+
return !isNumber(minItems) || (isArray(value) && value.length >= minItems);
|
|
36
|
+
}
|
|
37
|
+
function isValidMaxItems(value, maxItems) {
|
|
38
|
+
return !isNumber(maxItems) || (isArray(value) && value.length <= maxItems);
|
|
39
|
+
}
|
|
40
|
+
export { isValidRequired, isValidMinLength, isValidMaxLength, isValidPattern, isValidMaximum, isValidMinimum, isValidMinItems, isValidMaxItems, isValidRequiredArray, };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { Avatar } from '@transferwise/components';
|
|
14
|
+
import { ArrowLeft } from '@transferwise/icons';
|
|
15
|
+
function BackButton(_a) {
|
|
16
|
+
var title = _a.title, action = _a.action, onAction = _a.onAction;
|
|
17
|
+
return (_jsxs("a", __assign({ href: "/", className: "df-back-btn", "aria-label": title, onClick: function (event) {
|
|
18
|
+
event.preventDefault();
|
|
19
|
+
onAction(__assign(__assign({}, action), { skipValidation: true }));
|
|
20
|
+
} }, { children: [_jsx("span", __assign({ className: "sr-only" }, { children: title })), _jsx(Avatar, __assign({ type: "icon" }, { children: _jsx(ArrowLeft, { size: "24" }) }))] })));
|
|
21
|
+
}
|
|
22
|
+
export default BackButton;
|
|
@@ -0,0 +1,346 @@
|
|
|
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 { jsx as _jsx } from "react/jsx-runtime";
|
|
49
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
50
|
+
import { useIntl } from 'react-intl';
|
|
51
|
+
import { DynamicFlowProvider, getEventDispatcher, EventsContextProvider, LogProvider, getLogger, } from '../common/contexts';
|
|
52
|
+
import { FeatureContextProvider } from '../common/contexts/featureContext/FeatureContext';
|
|
53
|
+
import { isObjectModel } from '../common/utils';
|
|
54
|
+
import { isValidSchema } from '../common/validators';
|
|
55
|
+
import { DynamicFlowStep } from './DynamicFlowStep';
|
|
56
|
+
import { ErrorBoundary, useLoader, useDynamicFlowState, useDebouncedRefresh, parseFetchResponse, getJsonObjectOrNull, parseErrorResponse, } from './utils';
|
|
57
|
+
import { HttpClientProvider } from '../../common/httpClientContext';
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
59
|
+
var noop = function () { };
|
|
60
|
+
/**
|
|
61
|
+
* ## DynamicFlow
|
|
62
|
+
*
|
|
63
|
+
* The dynamic flow component is responsible for the asynchronous actions occuring
|
|
64
|
+
* within a dynamic flow, managing transitions between steps as well as refreshing
|
|
65
|
+
* requirements. It doesn't control any view logic, but takes the step definition
|
|
66
|
+
* and reformats it to use a LayoutStep for presentation.
|
|
67
|
+
*
|
|
68
|
+
*/
|
|
69
|
+
// eslint-disable-next-line react/function-component-definition
|
|
70
|
+
var DynamicFlowComponent = function (_a) {
|
|
71
|
+
var flowId = _a.flowId, httpClient = _a.httpClient, initialAction = _a.initialAction, initialStep = _a.initialStep, loaderConfig = _a.loaderConfig, _b = _a.displayStepTitle, displayStepTitle = _b === void 0 ? true : _b, features = _a.features, onCompletion = _a.onCompletion, onError = _a.onError, _c = _a.onEvent, onEvent = _c === void 0 ? noop : _c, _d = _a.onLog, onLog = _d === void 0 ? noop : _d;
|
|
72
|
+
var locale = useIntl().locale;
|
|
73
|
+
var _e = useDynamicFlowState(initialStep), formErrors = _e.formErrors, globalError = _e.globalError, step = _e.step, models = _e.models, etag = _e.etag, modelIsValid = _e.modelIsValid, setFormErrors = _e.setFormErrors, setGlobalError = _e.setGlobalError, setStepAndEtag = _e.setStepAndEtag, setSchemaModel = _e.setSchemaModel;
|
|
74
|
+
var _f = useState(false), submitted = _f[0], setSubmitted = _f[1];
|
|
75
|
+
var _g = useLoader(loaderConfig, initialStep ? 'idle' : 'initial'), isLoading = _g.isLoading, loader = _g.loader, setLoadingState = _g.setLoadingState;
|
|
76
|
+
var logCritical = getLogger('critical', onLog, flowId, (step === null || step === void 0 ? void 0 : step.id) || (step === null || step === void 0 ? void 0 : step.key));
|
|
77
|
+
var logWarning = getLogger('warning', onLog, flowId, (step === null || step === void 0 ? void 0 : step.id) || (step === null || step === void 0 ? void 0 : step.key));
|
|
78
|
+
var warnIfNoStepLayout = function (step) {
|
|
79
|
+
if (step && !step.layout) {
|
|
80
|
+
logWarning('Deprecation warning', 'Support for steps with no layout is being dropped. Please add a layout array to your step.', {
|
|
81
|
+
stepId: step.id || step.key
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
var analyticsMetadata = useMemo(function () { var _a; return (__assign({ flowId: flowId, stepId: (step === null || step === void 0 ? void 0 : step.id) || (step === null || step === void 0 ? void 0 : step.key) }, ((_a = step === null || step === void 0 ? void 0 : step.analytics) !== null && _a !== void 0 ? _a : {}))); }, [flowId, step]);
|
|
86
|
+
var dispatchEvent = useMemo(function () { return getEventDispatcher(onEvent, analyticsMetadata); }, [onEvent, analyticsMetadata]);
|
|
87
|
+
var dfHttpClient = useCallback(function (_a) {
|
|
88
|
+
var action = _a.action, data = _a.data, etag = _a.etag;
|
|
89
|
+
var url = action.url, _b = action.method, method = _b === void 0 ? 'POST' : _b;
|
|
90
|
+
return httpClient(url !== null && url !== void 0 ? url : '', {
|
|
91
|
+
method: method,
|
|
92
|
+
headers: __assign({ 'accept-language': locale, 'Content-Type': 'application/json' }, (etag ? { 'If-None-Match': etag } : {})),
|
|
93
|
+
credentials: 'include',
|
|
94
|
+
body: method === 'GET' ? undefined : JSON.stringify(data)
|
|
95
|
+
});
|
|
96
|
+
}, [httpClient, locale]);
|
|
97
|
+
var performAction = function (action, data) {
|
|
98
|
+
if (data === void 0) { data = {}; }
|
|
99
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
100
|
+
var response, error_1;
|
|
101
|
+
return __generator(this, function (_a) {
|
|
102
|
+
switch (_a.label) {
|
|
103
|
+
case 0:
|
|
104
|
+
setLoadingState(!step ? 'initial' : 'submission');
|
|
105
|
+
dispatchEvent('Dynamic Flow - Step Submitted', { actionId: action.id || action.$id });
|
|
106
|
+
_a.label = 1;
|
|
107
|
+
case 1:
|
|
108
|
+
_a.trys.push([1, 6, , 7]);
|
|
109
|
+
return [4 /*yield*/, dfHttpClient({ action: action, data: data })];
|
|
110
|
+
case 2:
|
|
111
|
+
response = _a.sent();
|
|
112
|
+
if (!(action.exit && response.ok)) return [3 /*break*/, 4];
|
|
113
|
+
return [4 /*yield*/, handleExitResponse(response, action.result)];
|
|
114
|
+
case 3:
|
|
115
|
+
_a.sent();
|
|
116
|
+
return [2 /*return*/];
|
|
117
|
+
case 4: return [4 /*yield*/, handleResponse(response, 'submission')];
|
|
118
|
+
case 5:
|
|
119
|
+
_a.sent();
|
|
120
|
+
return [3 /*break*/, 7];
|
|
121
|
+
case 6:
|
|
122
|
+
error_1 = _a.sent();
|
|
123
|
+
completeWithError(error_1, action.exit ? 'Error fetching exit result' : 'Error fetching next step');
|
|
124
|
+
return [3 /*break*/, 7];
|
|
125
|
+
case 7: return [2 /*return*/];
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
var performRefresh = function (url, data, etag) { return __awaiter(void 0, void 0, void 0, function () {
|
|
131
|
+
var response, error_2;
|
|
132
|
+
return __generator(this, function (_a) {
|
|
133
|
+
switch (_a.label) {
|
|
134
|
+
case 0:
|
|
135
|
+
setLoadingState('refresh');
|
|
136
|
+
dispatchEvent('Dynamic Flow - Step Refreshed', { status: 'pending' });
|
|
137
|
+
_a.label = 1;
|
|
138
|
+
case 1:
|
|
139
|
+
_a.trys.push([1, 4, , 5]);
|
|
140
|
+
return [4 /*yield*/, dfHttpClient({ action: { url: url, method: 'POST' }, data: data, etag: etag })];
|
|
141
|
+
case 2:
|
|
142
|
+
response = _a.sent();
|
|
143
|
+
return [4 /*yield*/, handleResponse(response, 'refresh')];
|
|
144
|
+
case 3:
|
|
145
|
+
_a.sent();
|
|
146
|
+
return [3 /*break*/, 5];
|
|
147
|
+
case 4:
|
|
148
|
+
error_2 = _a.sent();
|
|
149
|
+
completeWithError(error_2, 'Error fetching refresh step');
|
|
150
|
+
return [3 /*break*/, 5];
|
|
151
|
+
case 5: return [2 /*return*/];
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}); };
|
|
155
|
+
var handleExitResponse = function (response, actionResult) { return __awaiter(void 0, void 0, void 0, function () {
|
|
156
|
+
var exitResult;
|
|
157
|
+
return __generator(this, function (_a) {
|
|
158
|
+
switch (_a.label) {
|
|
159
|
+
case 0: return [4 /*yield*/, getJsonObjectOrNull(response)];
|
|
160
|
+
case 1:
|
|
161
|
+
exitResult = _a.sent();
|
|
162
|
+
dispatchEventAndComplete(__assign(__assign({}, exitResult), actionResult));
|
|
163
|
+
return [2 /*return*/];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}); };
|
|
167
|
+
var debouncedRefresh = useDebouncedRefresh(performRefresh);
|
|
168
|
+
var dispatchEventAndComplete = useCallback(function (result) {
|
|
169
|
+
dispatchEvent('Dynamic Flow - Flow Finished', { result: 'success' });
|
|
170
|
+
onCompletion(result);
|
|
171
|
+
}, [onCompletion, dispatchEvent]);
|
|
172
|
+
useEffect(function () {
|
|
173
|
+
dispatchEvent('Dynamic Flow - Flow Started', {});
|
|
174
|
+
}, []);
|
|
175
|
+
useEffect(function () {
|
|
176
|
+
if (!initialStep) {
|
|
177
|
+
var action = __assign({ id: '#initial-step-request', method: 'GET' }, initialAction);
|
|
178
|
+
void performAction(action, action.data);
|
|
179
|
+
}
|
|
180
|
+
if (initialStep) {
|
|
181
|
+
warnIfNoStepLayout(initialStep);
|
|
182
|
+
}
|
|
183
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
184
|
+
}, [httpClient, locale, JSON.stringify(initialStep), JSON.stringify(initialAction)]);
|
|
185
|
+
var handleResponse = function (response, fetchType) { return __awaiter(void 0, void 0, void 0, function () {
|
|
186
|
+
var errorResponse, result, error_3;
|
|
187
|
+
return __generator(this, function (_a) {
|
|
188
|
+
switch (_a.label) {
|
|
189
|
+
case 0:
|
|
190
|
+
_a.trys.push([0, 4, , 5]);
|
|
191
|
+
if (response.status === 304) {
|
|
192
|
+
setLoadingState('idle');
|
|
193
|
+
return [2 /*return*/];
|
|
194
|
+
}
|
|
195
|
+
if (!!response.ok) return [3 /*break*/, 2];
|
|
196
|
+
return [4 /*yield*/, parseErrorResponse(response)];
|
|
197
|
+
case 1:
|
|
198
|
+
errorResponse = _a.sent();
|
|
199
|
+
void updateAfterError(errorResponse);
|
|
200
|
+
return [2 /*return*/];
|
|
201
|
+
case 2: return [4 /*yield*/, parseFetchResponse(response)];
|
|
202
|
+
case 3:
|
|
203
|
+
result = _a.sent();
|
|
204
|
+
if (result.type === 'action') {
|
|
205
|
+
void performAction(result.action, result.action.data);
|
|
206
|
+
}
|
|
207
|
+
else if (result.type === 'exit') {
|
|
208
|
+
dispatchEventAndComplete(result.result);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
updateStep(result.step, result.etag, fetchType);
|
|
212
|
+
}
|
|
213
|
+
return [3 /*break*/, 5];
|
|
214
|
+
case 4:
|
|
215
|
+
error_3 = _a.sent();
|
|
216
|
+
completeWithError(error_3, 'Error parsing fetch response', fetchType, response.status);
|
|
217
|
+
return [3 /*break*/, 5];
|
|
218
|
+
case 5: return [2 /*return*/];
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}); };
|
|
222
|
+
var updateStep = function (newStep, etag, fetchType) {
|
|
223
|
+
warnIfNoStepLayout(newStep);
|
|
224
|
+
setStepAndEtag(newStep, etag);
|
|
225
|
+
setLoadingState('idle');
|
|
226
|
+
if (fetchType === 'submission') {
|
|
227
|
+
setSubmitted(false);
|
|
228
|
+
dispatchEvent('Dynamic Flow - Step Started', __assign({ stepId: newStep.id || newStep.key }, newStep === null || newStep === void 0 ? void 0 : newStep.analytics));
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
dispatchEvent('Dynamic Flow - Step Refreshed', { status: 'success' });
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
var updateAfterError = function (errorBody) { return __awaiter(void 0, void 0, void 0, function () {
|
|
235
|
+
var refreshUrl;
|
|
236
|
+
return __generator(this, function (_a) {
|
|
237
|
+
switch (_a.label) {
|
|
238
|
+
case 0:
|
|
239
|
+
refreshUrl = errorBody.refreshUrl || errorBody.refreshFormUrl;
|
|
240
|
+
if (!refreshUrl) return [3 /*break*/, 2];
|
|
241
|
+
return [4 /*yield*/, performRefresh(refreshUrl, combineModels(models), etag)];
|
|
242
|
+
case 1:
|
|
243
|
+
_a.sent();
|
|
244
|
+
_a.label = 2;
|
|
245
|
+
case 2:
|
|
246
|
+
if (errorBody.validation) {
|
|
247
|
+
setFormErrors(errorBody.validation);
|
|
248
|
+
}
|
|
249
|
+
if (errorBody.error) {
|
|
250
|
+
setGlobalError(errorBody.error);
|
|
251
|
+
}
|
|
252
|
+
setLoadingState('idle');
|
|
253
|
+
return [2 /*return*/];
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}); };
|
|
257
|
+
var completeWithError = function (error, message, fetchType, responseStatus) {
|
|
258
|
+
logCritical('Error fetching', message);
|
|
259
|
+
if (fetchType === 'refresh') {
|
|
260
|
+
dispatchEvent('Dynamic Flow - Step Refreshed', { status: 'failure' });
|
|
261
|
+
}
|
|
262
|
+
dispatchEvent('Dynamic Flow - Flow Finished', { status: 'failure' });
|
|
263
|
+
onError(error, responseStatus);
|
|
264
|
+
setLoadingState('idle');
|
|
265
|
+
};
|
|
266
|
+
var onModelChange = function (onModelChangeProps) {
|
|
267
|
+
var model = onModelChangeProps.model, formSchema = onModelChangeProps.formSchema;
|
|
268
|
+
var _a = formSchema.$id, $id = _a === void 0 ? '' : _a;
|
|
269
|
+
setGlobalError(null);
|
|
270
|
+
if (!isObjectModel(model)) {
|
|
271
|
+
// TODO: DF-473 - Remove type assertions once we're confident people have had time to fix any errors
|
|
272
|
+
logCritical('Invalid model on change', 'onModelChange was called but the model argument is not an object');
|
|
273
|
+
}
|
|
274
|
+
var objectModel = model;
|
|
275
|
+
setSchemaModel($id, objectModel, function (updatedModels) {
|
|
276
|
+
refreshOnChangeIfNeeded(onModelChangeProps, updatedModels);
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
var refreshOnChangeIfNeeded = function (props, updatedModels) {
|
|
280
|
+
var triggerSchema = props.triggerSchema;
|
|
281
|
+
if (shouldTriggerRefresh(props)) {
|
|
282
|
+
var triggerSchemaRefreshUrl = triggerSchema.refreshUrl || triggerSchema.refreshFormUrl;
|
|
283
|
+
var stepRefreshUrl = (step === null || step === void 0 ? void 0 : step.refreshUrl) || (step === null || step === void 0 ? void 0 : step.refreshFormUrl);
|
|
284
|
+
var refreshUrl = triggerSchemaRefreshUrl || stepRefreshUrl;
|
|
285
|
+
if (refreshUrl) {
|
|
286
|
+
debouncedRefresh(refreshUrl, combineModels(updatedModels), etag, triggerSchema);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
// FIXME: We should annotate the entire onAction function with the type OnAction
|
|
291
|
+
var onAction = function (action) { return __awaiter(void 0, void 0, void 0, function () {
|
|
292
|
+
var data, method, skipValidation, submissionData;
|
|
293
|
+
return __generator(this, function (_a) {
|
|
294
|
+
switch (_a.label) {
|
|
295
|
+
case 0:
|
|
296
|
+
if (isLoading || action.disabled) {
|
|
297
|
+
return [2 /*return*/];
|
|
298
|
+
}
|
|
299
|
+
if (action.exit && !action.url) {
|
|
300
|
+
dispatchEventAndComplete(action.result);
|
|
301
|
+
return [2 /*return*/];
|
|
302
|
+
}
|
|
303
|
+
data = action.data, method = action.method, skipValidation = action.skipValidation;
|
|
304
|
+
submissionData = __assign(__assign({}, combineModels(models)), data);
|
|
305
|
+
if (!isSubmissionMethod(method)) return [3 /*break*/, 3];
|
|
306
|
+
setFormErrors(null);
|
|
307
|
+
if (!skipValidation) {
|
|
308
|
+
setSubmitted(true);
|
|
309
|
+
}
|
|
310
|
+
if (!(modelIsValid || skipValidation)) return [3 /*break*/, 2];
|
|
311
|
+
return [4 /*yield*/, performAction(action, submissionData)];
|
|
312
|
+
case 1:
|
|
313
|
+
_a.sent();
|
|
314
|
+
_a.label = 2;
|
|
315
|
+
case 2: return [3 /*break*/, 5];
|
|
316
|
+
case 3: return [4 /*yield*/, performAction(action)];
|
|
317
|
+
case 4:
|
|
318
|
+
_a.sent();
|
|
319
|
+
_a.label = 5;
|
|
320
|
+
case 5: return [2 /*return*/];
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}); };
|
|
324
|
+
return (_jsx(LogProvider, __assign({ flowId: flowId, stepId: (step === null || step === void 0 ? void 0 : step.id) || (step === null || step === void 0 ? void 0 : step.key), onLog: onLog }, { children: _jsx(EventsContextProvider, __assign({ metadata: analyticsMetadata, onEvent: onEvent }, { children: _jsx(DynamicFlowProvider, __assign({ loading: isLoading }, { children: _jsx(HttpClientProvider, __assign({ httpClient: httpClient }, { children: _jsx(FeatureContextProvider, __assign({ features: features }, { children: loader !== null ? (loader) : (_jsx(DynamicFlowStep, { step: step, model: combineModels(models), submitted: submitted, globalError: globalError, formErrors: formErrors, stepLayoutOptions: { displayStepTitle: displayStepTitle }, onAction: function (action) {
|
|
325
|
+
void onAction(action);
|
|
326
|
+
}, onModelChange: onModelChange })) })) })) })) })) })));
|
|
327
|
+
};
|
|
328
|
+
function DynamicFlow(props) {
|
|
329
|
+
return (_jsx(ErrorBoundary, __assign({ onError: props.onError }, { children: _jsx(DynamicFlowComponent, __assign({}, props)) })));
|
|
330
|
+
}
|
|
331
|
+
export default DynamicFlow;
|
|
332
|
+
var combineModels = function (formModels) {
|
|
333
|
+
return Object.values(formModels).reduce(function (previous, model) { return (__assign(__assign({}, previous), model)); }, {});
|
|
334
|
+
};
|
|
335
|
+
var isSubmissionMethod = function (method) {
|
|
336
|
+
if (method === void 0) { method = 'POST'; }
|
|
337
|
+
var submissionMethods = ['POST', 'PUT', 'PATCH'];
|
|
338
|
+
return submissionMethods.includes(method.toUpperCase());
|
|
339
|
+
};
|
|
340
|
+
var shouldTriggerRefresh = function (props) {
|
|
341
|
+
var type = props.type, triggerSchema = props.triggerSchema, triggerModel = props.triggerModel, _a = props.lastTriggerModel, lastTriggerModel = _a === void 0 ? null : _a;
|
|
342
|
+
var isValid = function () { return isValidSchema(triggerModel, triggerSchema); };
|
|
343
|
+
var wasValid = function () { return isValidSchema(lastTriggerModel, triggerSchema); };
|
|
344
|
+
var hasRefreshOnChange = (triggerSchema === null || triggerSchema === void 0 ? void 0 : triggerSchema.refreshStepOnChange) || (triggerSchema === null || triggerSchema === void 0 ? void 0 : triggerSchema.refreshFormOnChange);
|
|
345
|
+
return type !== 'init' && hasRefreshOnChange && (isValid() || wasValid());
|
|
346
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
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, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { useExternal } from '../common/hooks';
|
|
14
|
+
import { isCameraStep } from '../common/utils';
|
|
15
|
+
import { DynamicAlert } from '../layout';
|
|
16
|
+
import { CameraStep, LayoutStep, ExternalConfirmationStep } from '../step';
|
|
17
|
+
import BackButton from './BackButton';
|
|
18
|
+
export function DynamicFlowStep(props) {
|
|
19
|
+
var _a, _b, _c;
|
|
20
|
+
var step = props.step, globalError = props.globalError, onAction = props.onAction;
|
|
21
|
+
var externalUrl = (_a = step === null || step === void 0 ? void 0 : step.external) === null || _a === void 0 ? void 0 : _a.url;
|
|
22
|
+
var backButton = ((_b = step === null || step === void 0 ? void 0 : step.navigation) === null || _b === void 0 ? void 0 : _b.back) || ((_c = step === null || step === void 0 ? void 0 : step.navigation) === null || _c === void 0 ? void 0 : _c.backButton);
|
|
23
|
+
var _d = useExternal(externalUrl), requiresManualTrigger = _d.requiresManualTrigger, dismissConfirmation = _d.dismissConfirmation;
|
|
24
|
+
if (step === undefined) {
|
|
25
|
+
if (globalError) {
|
|
26
|
+
return (_jsx(DynamicAlert, { component: { context: 'negative', markdown: globalError, margin: 'lg' } }));
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
if (externalUrl && requiresManualTrigger) {
|
|
31
|
+
return _jsx(ExternalConfirmationStep, { url: externalUrl, onClose: dismissConfirmation });
|
|
32
|
+
}
|
|
33
|
+
if (isCameraStep(step)) {
|
|
34
|
+
return _jsx(CameraStep, __assign({}, props, { step: step }));
|
|
35
|
+
}
|
|
36
|
+
return (_jsxs(_Fragment, { children: [backButton && _jsx(BackButton, __assign({}, backButton, { onAction: onAction })), globalError ? (_jsx(DynamicAlert, { component: { context: 'negative', markdown: globalError, margin: 'lg' } })) : null, _jsx(LayoutStep, __assign({}, props, { stepSpecification: step }))] }));
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './DynamicFlow';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export * from './useDebouncedRefresh/useDebouncedRefresh';
|
|
2
|
+
export * from './useDynamicFlowState';
|
|
3
|
+
export * from './useLoader';
|
|
4
|
+
export { default as ErrorBoundary } from '../../../common/errorBoundary/ErrorBoundary';
|
|
5
|
+
export * from './responseParsers/response-parsers';
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
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;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import { isObject } from '../../../common/validators';
|
|
38
|
+
var parseFetchResponseByResponseType = function (response, type) { return __awaiter(void 0, void 0, void 0, function () {
|
|
39
|
+
return __generator(this, function (_a) {
|
|
40
|
+
switch (type) {
|
|
41
|
+
case 'step':
|
|
42
|
+
return [2 /*return*/, parseStepResponse(response)];
|
|
43
|
+
case 'exit':
|
|
44
|
+
return [2 /*return*/, parseExitResponse(response)];
|
|
45
|
+
case 'action':
|
|
46
|
+
return [2 /*return*/, parseActionResponse(response)];
|
|
47
|
+
default:
|
|
48
|
+
throw new Error("Unsupported X-Df-Response-Type. Allowed values are 'step', 'action', 'exit'.");
|
|
49
|
+
}
|
|
50
|
+
return [2 /*return*/];
|
|
51
|
+
});
|
|
52
|
+
}); };
|
|
53
|
+
var parseStepResponse = function (response) { return __awaiter(void 0, void 0, void 0, function () {
|
|
54
|
+
var jsonBody, etag;
|
|
55
|
+
return __generator(this, function (_a) {
|
|
56
|
+
switch (_a.label) {
|
|
57
|
+
case 0: return [4 /*yield*/, parseResponseJson(response)];
|
|
58
|
+
case 1:
|
|
59
|
+
jsonBody = _a.sent();
|
|
60
|
+
if (!isObject(jsonBody)) {
|
|
61
|
+
throw new Error('Incorrect response body in response. Expected an object.');
|
|
62
|
+
}
|
|
63
|
+
etag = response.headers.get('etag') || undefined;
|
|
64
|
+
return [2 /*return*/, { type: 'step', step: jsonBody, etag: etag }];
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}); };
|
|
68
|
+
var parseActionResponse = function (response) { return __awaiter(void 0, void 0, void 0, function () {
|
|
69
|
+
var jsonBody, action;
|
|
70
|
+
return __generator(this, function (_a) {
|
|
71
|
+
switch (_a.label) {
|
|
72
|
+
case 0: return [4 /*yield*/, parseResponseJson(response)];
|
|
73
|
+
case 1:
|
|
74
|
+
jsonBody = _a.sent();
|
|
75
|
+
if (!isObject(jsonBody)) {
|
|
76
|
+
throw new Error('Incorrect response body in response. Expected an object.');
|
|
77
|
+
}
|
|
78
|
+
if (!isObject(jsonBody.action)) {
|
|
79
|
+
throw new Error('Incorrect response body in action response. Expected an object satisfying the type { action: Action }.');
|
|
80
|
+
}
|
|
81
|
+
action = jsonBody.action;
|
|
82
|
+
if (action.exit === true && isObject(action.result)) {
|
|
83
|
+
return [2 /*return*/, { type: 'exit', result: action.result }];
|
|
84
|
+
}
|
|
85
|
+
return [2 /*return*/, { type: 'action', action: jsonBody.action }];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}); };
|
|
89
|
+
var parseExitResponse = function (response) { return __awaiter(void 0, void 0, void 0, function () {
|
|
90
|
+
var _a;
|
|
91
|
+
return __generator(this, function (_b) {
|
|
92
|
+
switch (_b.label) {
|
|
93
|
+
case 0:
|
|
94
|
+
_a = { type: 'exit' };
|
|
95
|
+
return [4 /*yield*/, getJsonObjectOrNull(response)];
|
|
96
|
+
case 1: return [2 /*return*/, (_a.result = _b.sent(), _a)];
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}); };
|
|
100
|
+
export var parseFetchResponse = function (response) { return __awaiter(void 0, void 0, void 0, function () {
|
|
101
|
+
var type, jsonBody;
|
|
102
|
+
var _a, _b;
|
|
103
|
+
return __generator(this, function (_c) {
|
|
104
|
+
switch (_c.label) {
|
|
105
|
+
case 0:
|
|
106
|
+
assertResponseIsValid(response);
|
|
107
|
+
if ((_a = response.headers) === null || _a === void 0 ? void 0 : _a.has('X-Df-Response-Type')) {
|
|
108
|
+
type = response.headers.get('X-Df-Response-Type');
|
|
109
|
+
return [2 /*return*/, parseFetchResponseByResponseType(response, type)];
|
|
110
|
+
}
|
|
111
|
+
if ((_b = response.headers) === null || _b === void 0 ? void 0 : _b.has('X-Df-Exit')) {
|
|
112
|
+
return [2 /*return*/, parseExitResponse(response)];
|
|
113
|
+
}
|
|
114
|
+
return [4 /*yield*/, parseResponseJson(response.clone())];
|
|
115
|
+
case 1:
|
|
116
|
+
jsonBody = _c.sent();
|
|
117
|
+
if (isObject(jsonBody) && jsonBody.action) {
|
|
118
|
+
return [2 /*return*/, parseActionResponse(response)];
|
|
119
|
+
}
|
|
120
|
+
return [2 /*return*/, parseStepResponse(response)];
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}); };
|
|
124
|
+
export var parseErrorResponse = function (response) { return __awaiter(void 0, void 0, void 0, function () {
|
|
125
|
+
var jsonBody;
|
|
126
|
+
return __generator(this, function (_a) {
|
|
127
|
+
switch (_a.label) {
|
|
128
|
+
case 0:
|
|
129
|
+
assertResponseIsValid(response);
|
|
130
|
+
return [4 /*yield*/, parseResponseJson(response)];
|
|
131
|
+
case 1:
|
|
132
|
+
jsonBody = _a.sent();
|
|
133
|
+
if (!isObject(jsonBody)) {
|
|
134
|
+
throw new Error('Incorrect response body in error response. Expected an object.');
|
|
135
|
+
}
|
|
136
|
+
if (!jsonBody.refreshFormUrl && !jsonBody.refreshUrl && !jsonBody.validation && !jsonBody.error) {
|
|
137
|
+
// eslint-disable-next-line @typescript-eslint/no-throw-literal
|
|
138
|
+
throw jsonBody;
|
|
139
|
+
}
|
|
140
|
+
return [2 /*return*/, jsonBody];
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}); };
|
|
144
|
+
export var getJsonObjectOrNull = function (response) { return __awaiter(void 0, void 0, void 0, function () {
|
|
145
|
+
var result;
|
|
146
|
+
return __generator(this, function (_a) {
|
|
147
|
+
switch (_a.label) {
|
|
148
|
+
case 0:
|
|
149
|
+
assertResponseIsValid(response);
|
|
150
|
+
return [4 /*yield*/, parseResponseJson(response)];
|
|
151
|
+
case 1:
|
|
152
|
+
result = _a.sent();
|
|
153
|
+
return [2 /*return*/, isObject(result) ? result : null];
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}); };
|
|
157
|
+
var parseResponseJson = function (response) { return __awaiter(void 0, void 0, void 0, function () {
|
|
158
|
+
var _a;
|
|
159
|
+
return __generator(this, function (_b) {
|
|
160
|
+
switch (_b.label) {
|
|
161
|
+
case 0:
|
|
162
|
+
_b.trys.push([0, 2, , 3]);
|
|
163
|
+
return [4 /*yield*/, response.json()];
|
|
164
|
+
case 1: return [2 /*return*/, (_b.sent())];
|
|
165
|
+
case 2:
|
|
166
|
+
_a = _b.sent();
|
|
167
|
+
return [2 /*return*/, null];
|
|
168
|
+
case 3: return [2 /*return*/];
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}); };
|
|
172
|
+
var assertResponseIsValid = function (response) {
|
|
173
|
+
if (!isResponse(response)) {
|
|
174
|
+
throw new Error('Incorrect type of response from fetch. Expected object of type Response.');
|
|
175
|
+
}
|
|
176
|
+
if (response.bodyUsed) {
|
|
177
|
+
throw new Error('The body of the provided Response object has already been used. Every request must respond with a new Response object.');
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
var isResponse = function (response) {
|
|
181
|
+
return typeof response === 'object' &&
|
|
182
|
+
response !== null &&
|
|
183
|
+
'clone' in response &&
|
|
184
|
+
'bodyUsed' in response;
|
|
185
|
+
};
|