@wise/dynamic-flow-client 5.8.1 → 5.9.0
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/DynamicFlowCore.js +5 -0
- package/build/common/errorBoundary/ErrorBoundary.js +26 -0
- package/build/common/errorBoundary/ErrorBoundary.test.js +29 -0
- package/build/common/errorBoundary/ErrorBoundaryAlert.js +11 -0
- package/build/common/makeHttpClient/api-utils.js +3 -0
- package/build/common/makeHttpClient/index.js +1 -0
- package/build/common/makeHttpClient/makeHttpClient.js +10 -0
- package/build/common/makeHttpClient/makeHttpClient.test.js +186 -0
- package/build/common/messages/external-confirmation.messages.js +23 -0
- package/build/common/messages/file-upload.messages.js +13 -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/search.messages.js +8 -0
- package/build/common/messages/validation.array.messages.js +13 -0
- package/build/common/messages/validation.messages.js +53 -0
- package/build/controller/FlowController.js +368 -0
- package/build/controller/executePoll.js +49 -0
- package/build/controller/executeRefresh.js +39 -0
- package/build/controller/executeRequest.js +77 -0
- package/build/controller/executeSubmission.js +69 -0
- package/build/controller/getErrorMessage.js +7 -0
- package/build/controller/getRequestAbortController.js +13 -0
- package/build/controller/getResponseType.js +35 -0
- package/build/controller/getSafeHttpClient.js +8 -0
- package/build/controller/getStepCounter.js +16 -0
- package/build/controller/handleErrorResponse.js +26 -0
- package/build/controller/makeSafeHttpClient.js +8 -0
- package/build/controller/response-utils.js +72 -0
- package/build/domain/components/AlertComponent.js +1 -0
- package/build/domain/components/AllOfComponent.js +40 -0
- package/build/domain/components/BooleanInputComponent.js +50 -0
- package/build/domain/components/BoxComponent.js +3 -0
- package/build/domain/components/ButtonComponent.js +1 -0
- package/build/domain/components/ColumnsComponent.js +3 -0
- package/build/domain/components/ConstComponent.js +18 -0
- package/build/domain/components/ContainerComponent.js +3 -0
- package/build/domain/components/DateInputComponent.js +75 -0
- package/build/domain/components/DecisionComponent.js +1 -0
- package/build/domain/components/DividerComponent.js +1 -0
- package/build/domain/components/FormComponent.js +3 -0
- package/build/domain/components/FormattedValueComponent.js +44 -0
- package/build/domain/components/HeadingComponent.js +1 -0
- package/build/domain/components/ImageComponent.js +1 -0
- package/build/domain/components/InstructionsComponent.js +1 -0
- package/build/domain/components/IntegerInputComponent.js +74 -0
- package/build/domain/components/ListComponent.js +1 -0
- package/build/domain/components/LoadingIndicatorComponent.js +1 -0
- package/build/domain/components/MarkdownComponent.js +1 -0
- package/build/domain/components/MediaComponent.js +1 -0
- package/build/domain/components/ModalComponent.js +16 -0
- package/build/domain/components/ModalLayoutComponent.js +3 -0
- package/build/domain/components/MoneyInputComponent.js +57 -0
- package/build/domain/components/MultiSelectInputComponent.js +81 -0
- package/build/domain/components/MultiUploadInputComponent.js +88 -0
- package/build/domain/components/NumberInputComponent.js +73 -0
- package/build/domain/components/ObjectComponent.js +45 -0
- package/build/domain/components/ParagraphComponent.js +1 -0
- package/build/domain/components/PersistAsyncComponent.js +92 -0
- package/build/domain/components/ProgressComponent.js +1 -0
- package/build/domain/components/RepeatableComponent.js +103 -0
- package/build/domain/components/ReviewComponent.js +1 -0
- package/build/domain/components/RootDomainComponent.js +173 -0
- package/build/domain/components/SectionComponent.js +5 -0
- package/build/domain/components/SelectInputComponent.js +88 -0
- package/build/domain/components/StatusListComponent.js +1 -0
- package/build/domain/components/SubflowDomainComponent.js +9 -0
- package/build/domain/components/TabsComponent.js +1 -0
- package/build/domain/components/TextInputComponent.js +76 -0
- package/build/domain/components/TupleComponent.js +41 -0
- package/build/domain/components/UploadInputComponent.js +83 -0
- package/build/domain/components/UpsellComponent.js +25 -0
- package/build/domain/components/searchComponent/SearchComponent.js +92 -0
- package/build/domain/components/searchComponent/SearchComponent.test.js +190 -0
- package/build/domain/components/step/ExternalConfirmationComponent.js +28 -0
- package/build/domain/components/step/StepDomainComponent.js +73 -0
- package/build/domain/components/step/ToolbarComponent.js +1 -0
- package/build/domain/components/utils/WithUpdate.js +1 -0
- package/build/domain/components/utils/component-utils.js +12 -0
- package/build/domain/components/utils/debounce.js +34 -0
- package/build/domain/components/utils/debounce.test.js +67 -0
- package/build/domain/components/utils/file-utils.js +21 -0
- package/build/domain/components/utils/file-utils.test.js +27 -0
- package/build/domain/components/utils/getRandomId.js +1 -0
- package/build/domain/components/utils/isExactLocalValueMatch.js +14 -0
- package/build/domain/components/utils/isOrWasValid.js +5 -0
- package/build/domain/components/utils/isPartialModelMatch.js +18 -0
- package/build/domain/components/utils/isPartialModelMatch.test.js +74 -0
- package/build/domain/features/eventNames.js +24 -0
- package/build/domain/features/events.js +1 -0
- package/build/domain/features/persistAsync/getComponentMultiPersistAsync.js +50 -0
- package/build/domain/features/persistAsync/getInitialPersistedState.js +7 -0
- package/build/domain/features/persistAsync/getPerformPersistAsync.js +43 -0
- package/build/domain/features/persistAsync/getPerformPersistAsync.test.js +139 -0
- package/build/domain/features/polling/getStepPolling.js +43 -0
- package/build/domain/features/polling/getStepPolling.test.js +90 -0
- package/build/domain/features/prefetch/getStepPrefetch.js +43 -0
- package/build/domain/features/prefetch/request-cache.js +49 -0
- package/build/domain/features/prefetch/request-cache.test.js +70 -0
- package/build/domain/features/refreshAfter/getStepRefreshAfter.js +24 -0
- package/build/domain/features/refreshAfter/getStepRefreshAfter.test.js +40 -0
- package/build/domain/features/schema-on-change/getDebouncedSchemaOnChange.js +50 -0
- package/build/domain/features/schema-on-change/getSchemaOnChange.js +34 -0
- package/build/domain/features/search/getPerformSearchFunction.js +75 -0
- package/build/domain/features/search/getPerformSearchFunction.test.js +301 -0
- package/build/domain/features/summary/summary-utils.js +40 -0
- package/build/domain/features/summary/summary-utils.test.js +125 -0
- package/build/domain/features/utils/http-utils.js +21 -0
- package/build/domain/features/utils/response-utils.js +9 -0
- package/build/domain/features/validation/spec-utils.js +19 -0
- package/build/domain/features/validation/validateStringPattern.js +24 -0
- package/build/domain/features/validation/validation-functions.js +6 -0
- package/build/domain/features/validation/validation-functions.test.js +108 -0
- package/build/domain/features/validation/value-checks.js +125 -0
- package/build/domain/features/validation/value-checks.test.js +262 -0
- package/build/domain/features/validationAsync/getComponentValidationAsync.js +53 -0
- package/build/domain/features/validationAsync/getComponentValidationAsync.test.js +67 -0
- package/build/domain/features/validationAsync/getInitialValidationAsyncState.js +5 -0
- package/build/domain/features/validationAsync/getPerformValidationAsync.js +45 -0
- package/build/domain/features/validationAsync/getPerformValidationAsync.test.js +143 -0
- package/build/domain/mappers/layout/alertLayoutToComponent.js +16 -0
- package/build/domain/mappers/layout/boxLayoutToComponent.js +13 -0
- package/build/domain/mappers/layout/buttonLayoutToComponent.js +77 -0
- package/build/domain/mappers/layout/columnsLayoutToComponent.js +13 -0
- package/build/domain/mappers/layout/decisionLayoutToComponent.js +22 -0
- package/build/domain/mappers/layout/deprecatedListLayoutToComponent.js +30 -0
- package/build/domain/mappers/layout/dividerLayoutToComponent.js +2 -0
- package/build/domain/mappers/layout/formLayoutToComponent.js +19 -0
- package/build/domain/mappers/layout/headingLayoutToComponent.js +12 -0
- package/build/domain/mappers/layout/imageLayoutToComponent.js +20 -0
- package/build/domain/mappers/layout/infoLayoutToComponent.js +12 -0
- package/build/domain/mappers/layout/instructionsLayoutToComponent.js +12 -0
- package/build/domain/mappers/layout/listLayoutToComponent.js +39 -0
- package/build/domain/mappers/layout/loadingIndicatorLayoutToComponent.js +9 -0
- package/build/domain/mappers/layout/markdownLayoutToComponent.js +12 -0
- package/build/domain/mappers/layout/mediaLayoutToComponent.js +12 -0
- package/build/domain/mappers/layout/modalLayoutToComponent.js +17 -0
- package/build/domain/mappers/layout/modalToComponent.js +8 -0
- package/build/domain/mappers/layout/paragraphLayoutToComponent.js +12 -0
- package/build/domain/mappers/layout/progressLayoutToComponent.js +15 -0
- package/build/domain/mappers/layout/reviewLayoutToComponent.js +48 -0
- package/build/domain/mappers/layout/searchLayoutToComponent.js +44 -0
- package/build/domain/mappers/layout/sectionLayoutToComponent.js +15 -0
- package/build/domain/mappers/layout/statusListLayoutToComponent.js +15 -0
- package/build/domain/mappers/layout/tabsLayoutToComponent.js +16 -0
- package/build/domain/mappers/layout/upsellLayoutToComponent.js +25 -0
- package/build/domain/mappers/mapLayoutToComponent.js +81 -0
- package/build/domain/mappers/mapSchemaToComponent.js +61 -0
- package/build/domain/mappers/mapSchemaToComponent.test.js +112 -0
- package/build/domain/mappers/mapStepSchemas.js +17 -0
- package/build/domain/mappers/mapStepToComponent.js +132 -0
- package/build/domain/mappers/mapStepToComponent.test.js +221 -0
- package/build/domain/mappers/mapToolbarToComponent.js +15 -0
- package/build/domain/mappers/schema/allOfSchemaToComponent.js +16 -0
- package/build/domain/mappers/schema/arraySchemaToComponent/arraySchemaToComponent.js +26 -0
- package/build/domain/mappers/schema/arraySchemaToComponent/arraySchemaToMultiSelectComponent.js +55 -0
- package/build/domain/mappers/schema/arraySchemaToComponent/arraySchemaToMultiUploadComponent.js +67 -0
- package/build/domain/mappers/schema/arraySchemaToComponent/arraySchemaToRepeatableComponent.js +57 -0
- package/build/domain/mappers/schema/arraySchemaToComponent/arraySchemaToTupleComponent.js +20 -0
- package/build/domain/mappers/schema/blobSchemaToComponent.js +15 -0
- package/build/domain/mappers/schema/booleanSchemaToComponent.js +29 -0
- package/build/domain/mappers/schema/constSchemaToComponent.js +23 -0
- package/build/domain/mappers/schema/integerSchemaToComponent.js +28 -0
- package/build/domain/mappers/schema/numberSchemaToComponent.js +26 -0
- package/build/domain/mappers/schema/objectSchemaToComponent/assertDisplayOrder.js +23 -0
- package/build/domain/mappers/schema/objectSchemaToComponent/objectSchemaToFormattedValueComponent.js +9 -0
- package/build/domain/mappers/schema/objectSchemaToComponent/objectSchemaToMoneyInputComponent.js +119 -0
- package/build/domain/mappers/schema/objectSchemaToComponent/objectSchemaToMoneyInputComponent.test.js +96 -0
- package/build/domain/mappers/schema/objectSchemaToComponent/objectSchemaToObjectComponent.js +31 -0
- package/build/domain/mappers/schema/objectSchemaToComponent/objectSchemaToObjectComponent.test.js +99 -0
- package/build/domain/mappers/schema/oneOfSchemaToComponent/oneOfSchemaToComponent.js +76 -0
- package/build/domain/mappers/schema/oneOfSchemaToComponent/oneOfSchemaToComponent.test.js +265 -0
- package/build/domain/mappers/schema/persistAsyncSchemaToComponent.js +29 -0
- package/build/domain/mappers/schema/stringSchemaToComponent/stringSchemaToComponent.js +18 -0
- package/build/domain/mappers/schema/stringSchemaToComponent/stringSchemaToComponent.test.js +133 -0
- package/build/domain/mappers/schema/stringSchemaToComponent/stringSchemaToDateInputComponent.js +48 -0
- package/build/domain/mappers/schema/stringSchemaToComponent/stringSchemaToTextInputComponent.js +37 -0
- package/build/domain/mappers/schema/stringSchemaToComponent/stringSchemaToUploadInputComponent.js +28 -0
- package/build/domain/mappers/schema/tests/test-utils.js +16 -0
- package/build/domain/mappers/schema/types.js +1 -0
- package/build/domain/mappers/schema/utils/getPerformPersistAsyncFn.js +19 -0
- package/build/domain/mappers/schema/utils/getValidationAsyncInitialState.js +23 -0
- package/build/domain/mappers/schema/utils/mapCommonSchemaProps.js +16 -0
- package/build/domain/mappers/types.js +1 -0
- package/build/domain/mappers/utils/FeatureFlags.js +22 -0
- package/build/domain/mappers/utils/behavior-utils.js +44 -0
- package/build/domain/mappers/utils/call-to-action-utils.js +21 -0
- package/build/domain/mappers/utils/getAutocompleteString.js +76 -0
- package/build/domain/mappers/utils/getAutocompleteString.test.js +21 -0
- package/build/domain/mappers/utils/groupLayoutByPinned.js +38 -0
- package/build/domain/mappers/utils/groupLayoutByPinned.test.js +166 -0
- package/build/domain/mappers/utils/image.js +9 -0
- package/build/domain/mappers/utils/layout-utils.js +11 -0
- package/build/domain/mappers/utils/legacy-utils.js +49 -0
- package/build/domain/mappers/utils/media-utils.js +14 -0
- package/build/domain/mappers/utils/suggestions-utils.js +26 -0
- package/build/domain/mappers/utils/suggestions-utils.test.js +36 -0
- package/build/domain/mappers/utils/tags-utils.js +1 -0
- package/build/domain/mappers/utils/utils.js +35 -0
- package/build/domain/types.js +1 -0
- package/build/getSubflowCallbacks.js +38 -0
- package/build/i18n/index.js +40 -0
- package/build/index.js +8 -0
- package/build/main.js +112 -54
- package/build/main.mjs +111 -53
- package/build/renderers/CoreContainerRenderer.js +5 -0
- package/build/renderers/CoreRootRenderer.js +12 -0
- package/build/renderers/EmptyLoadingStateRenderer.js +5 -0
- package/build/renderers/getRenderFunction.js +24 -0
- package/build/renderers/getSchemaErrorMessageFunction.js +97 -0
- package/build/renderers/mappers/alertComponentToProps.js +2 -0
- package/build/renderers/mappers/allOfComponentToProps.js +6 -0
- package/build/renderers/mappers/booleanInputComponentToProps.js +5 -0
- package/build/renderers/mappers/boxComponentToProps.js +13 -0
- package/build/renderers/mappers/buttonComponentToProps.js +4 -0
- package/build/renderers/mappers/columnsComponentToProps.js +11 -0
- package/build/renderers/mappers/componentToRendererProps.js +164 -0
- package/build/renderers/mappers/constComponentToProps.js +5 -0
- package/build/renderers/mappers/containerComponentToProps.js +7 -0
- package/build/renderers/mappers/dateInputComponentToProps.js +2 -0
- package/build/renderers/mappers/decisionComponentToProps.js +16 -0
- package/build/renderers/mappers/dividerComponentToProps.js +2 -0
- package/build/renderers/mappers/externalComponentToProps.js +3 -0
- package/build/renderers/mappers/formComponentToProps.js +12 -0
- package/build/renderers/mappers/formattedValueComponentToProps.js +5 -0
- package/build/renderers/mappers/headingComponentToProps.js +2 -0
- package/build/renderers/mappers/hiddenComponentToProps.js +4 -0
- package/build/renderers/mappers/imageComponentToProps.js +2 -0
- package/build/renderers/mappers/instructionsComponentToProps.js +2 -0
- package/build/renderers/mappers/integerInputComponentToProps.js +2 -0
- package/build/renderers/mappers/listComponentToProps.js +2 -0
- package/build/renderers/mappers/loadingIndicatorComponentToProps.js +2 -0
- package/build/renderers/mappers/markdownComponentToProps.js +2 -0
- package/build/renderers/mappers/mediaComponentToProps.js +2 -0
- package/build/renderers/mappers/modalComponentToProps.js +11 -0
- package/build/renderers/mappers/modalLayoutComponentToProps.js +16 -0
- package/build/renderers/mappers/moneyInputComponentToProps.js +36 -0
- package/build/renderers/mappers/multiSelectComponentToProps.js +23 -0
- package/build/renderers/mappers/multiUploadInputComponentToProps.js +12 -0
- package/build/renderers/mappers/numberInputComponentToProps.js +2 -0
- package/build/renderers/mappers/objectComponentToProps.js +8 -0
- package/build/renderers/mappers/paragraphComponentToProps.js +2 -0
- package/build/renderers/mappers/persistAsyncComponentToProps.js +8 -0
- package/build/renderers/mappers/progressComponentToProps.js +2 -0
- package/build/renderers/mappers/repeatableComponentToProps.js +30 -0
- package/build/renderers/mappers/reviewComponentToProps.js +2 -0
- package/build/renderers/mappers/rootComponentToProps.js +21 -0
- package/build/renderers/mappers/searchComponentToProps.js +57 -0
- package/build/renderers/mappers/sectionComponentToProps.js +6 -0
- package/build/renderers/mappers/selectInputComponentToProps.js +26 -0
- package/build/renderers/mappers/statusListComponentToProps.js +2 -0
- package/build/renderers/mappers/subflowComponentToRendererProps.js +4 -0
- package/build/renderers/mappers/tabsComponentToProps.js +14 -0
- package/build/renderers/mappers/textInputComponentToProps.js +2 -0
- package/build/renderers/mappers/tupleComponentToProps.js +8 -0
- package/build/renderers/mappers/uploadInputComponentToProps.js +8 -0
- package/build/renderers/mappers/upsellComponentToProps.js +2 -0
- package/build/renderers/mappers/utils/getValidationState.js +12 -0
- package/build/renderers/mappers/utils/inputComponentToProps.js +26 -0
- package/build/renderers/mappers/utils/mapErrorsToValidationState.js +9 -0
- package/build/renderers/mappers/utils/pick.js +8 -0
- package/build/renderers/mappers/utils/selectInputOptionsToProps.js +11 -0
- package/build/renderers/stepComponentToProps.js +32 -0
- package/build/renderers/utils.js +69 -0
- package/build/renderers/utils.test.js +70 -0
- package/build/stories/dev-tools/ContainerQueries.story.js +66 -0
- package/build/stories/dev-tools/Debugger.story.js +38 -0
- package/build/stories/dev-tools/FixtureSelect.story.js +23 -0
- package/build/stories/dev-tools/TestServer.story.js +32 -0
- package/build/stories/examples/NativeFlow.story.js +80 -0
- package/build/stories/examples/Recipients.story.js +568 -0
- package/build/stories/spec/behavior/Copy.story.js +59 -0
- package/build/stories/spec/behavior/Modal.story.js +76 -0
- package/build/stories/spec/behavior/Subflow.story.js +267 -0
- package/build/stories/spec/layouts/Decision.story.js +241 -0
- package/build/stories/spec/layouts/Image.story.js +42 -0
- package/build/stories/spec/layouts/Modal.story.js +81 -0
- package/build/stories/spec/layouts/Search.story.js +325 -0
- package/build/stories/spec/layouts/Upsell.story.js +55 -0
- package/build/stories/spec/layouts/button/Button.story.js +100 -0
- package/build/stories/spec/layouts/button/PinnedButton.story.js +81 -0
- package/build/stories/spec/response/ActionResponse.story.js +66 -0
- package/build/stories/spec/schemas/MultiSelect.story.js +148 -0
- package/build/stories/spec/schemas/Upload.story.js +168 -0
- package/build/stories/spec/schemas/const/ConstLayout.story.js +159 -0
- package/build/stories/spec/schemas/const/ObjectConst.story.js +94 -0
- package/build/stories/spec/schemas/features/PersistAsync.story.js +176 -0
- package/build/stories/spec/schemas/features/ValidationAsync.story.js +103 -0
- package/build/stories/spec/schemas/object/FormattedValue.story.js +92 -0
- package/build/stories/spec/schemas/object/MoneyInput.story.js +240 -0
- package/build/stories/spec/schemas/oneOf/OneOfInitialisation.story.js +55 -0
- package/build/stories/spec/step/Controls.story.js +109 -0
- package/build/stories/spec/step/DFModal.story.js +58 -0
- package/build/stories/spec/step/Footer.story.js +70 -0
- package/build/stories/spec/step/Navigation.story.js +20 -0
- package/build/stories/spec/step/Tags.story.js +39 -0
- package/build/stories/spec/step/ToolBar.story.js +60 -0
- package/build/stories/spec/step/features/ErrorHandling.story.js +92 -0
- package/build/stories/spec/step/features/External.story.js +44 -0
- package/build/stories/spec/step/features/Polling.story.js +108 -0
- package/build/stories/spec/step/features/RefreshAfter.story.js +92 -0
- package/build/stories/spec/step/features/refresh/Refresh.story.js +258 -0
- package/build/stories/spec/step/features/refresh/RefreshWithPersistAsync.story.js +958 -0
- package/build/stories/types.js +1 -0
- package/build/stories/utils/fixtureHttpClient.js +70 -0
- package/build/stories/utils/getBasicStep.js +223 -0
- package/build/stories/utils/mockSearchHandler.js +71 -0
- package/build/stories/utils/render-utils.js +41 -0
- package/build/stories/visual-tests/layouts/NotUsingListItem.story.js +17 -0
- package/build/test-utils/DynamicFlowWise.js +32 -0
- package/build/test-utils/DynamicFlowWiseModal.js +34 -0
- package/build/test-utils/NeptuneProviders.js +11 -0
- package/build/test-utils/component-utils.js +5 -0
- package/build/test-utils/fetch-utils.js +45 -0
- package/build/test-utils/getMergedTestRenderers.js +34 -0
- package/build/test-utils/getRandomId.js +1 -0
- package/build/test-utils/index.js +3 -0
- package/build/test-utils/rtl-utils.js +7 -0
- package/build/test-utils/step-utils.js +6 -0
- package/build/test-utils/wait.js +3 -0
- package/build/tests/AlertLayout.test.js +78 -0
- package/build/tests/ArrayTuple.test.js +118 -0
- package/build/tests/ButtonLayout.test.js +308 -0
- package/build/tests/ConstLayout.test.js +95 -0
- package/build/tests/DateInput.test.js +163 -0
- package/build/tests/DecisionLayout.test.js +146 -0
- package/build/tests/DynamicFlow.test.js +147 -0
- package/build/tests/External.test.js +169 -0
- package/build/tests/Flow.test.js +328 -0
- package/build/tests/FormLayout.test.js +28 -0
- package/build/tests/FormattedValue.test.js +107 -0
- package/build/tests/ImageRenderer.test.js +78 -0
- package/build/tests/InitialAction.test.js +179 -0
- package/build/tests/InitialStep.test.js +168 -0
- package/build/tests/InstructionsLayout.test.js +45 -0
- package/build/tests/ListLayout.test.js +145 -0
- package/build/tests/Logging.test.js +53 -0
- package/build/tests/ModalBehavior.test.js +149 -0
- package/build/tests/MoneyInput.test.js +316 -0
- package/build/tests/MultiUpload.test.js +293 -0
- package/build/tests/NativeBack.test.js +267 -0
- package/build/tests/OneOfInitialisation.test.js +571 -0
- package/build/tests/PersistAsync.test.js +653 -0
- package/build/tests/Polling.test.js +617 -0
- package/build/tests/Prefetching.test.js +230 -0
- package/build/tests/RefreshAfter.test.js +63 -0
- package/build/tests/RefreshOnChange.ResponseHandling.test.js +205 -0
- package/build/tests/RefreshOnChange.test.js +233 -0
- package/build/tests/RefreshOnChange.with.Segmented.test.js +348 -0
- package/build/tests/RefreshOnChange.with.Tabs.test.js +358 -0
- package/build/tests/RefreshOnChangePreserve.test.js +224 -0
- package/build/tests/RendererProps.test.js +342 -0
- package/build/tests/Repeatable.test.js +107 -0
- package/build/tests/Rerendering.test.js +67 -0
- package/build/tests/ReviewLayout.test.js +274 -0
- package/build/tests/SchemaOnChange.test.js +133 -0
- package/build/tests/ScrollToError.test.js +217 -0
- package/build/tests/SegmentedControl.test.js +49 -0
- package/build/tests/SingleFileUpload.test.js +88 -0
- package/build/tests/StatusList.test.js +85 -0
- package/build/tests/Subflow.test.js +710 -0
- package/build/tests/Submission.ResponseHandling.test.js +557 -0
- package/build/tests/Submission.merging.test.js +202 -0
- package/build/tests/Submission.test.js +523 -0
- package/build/tests/Tags.test.js +475 -0
- package/build/tests/Upsell.test.js +126 -0
- package/build/tests/ValidationAsync.test.js +295 -0
- package/build/tests/legacy/Actions.test.js +158 -0
- package/build/tests/legacy/BackButton.test.js +114 -0
- package/build/tests/legacy/HiddenSchemas.test.js +246 -0
- package/build/tests/legacy/MultiSelect.test.js +497 -0
- package/build/tests/legacy/MultipleFileUploadSchema.test.js +341 -0
- package/build/tests/legacy/PersistAsync.blob-schema.test.js +224 -0
- package/build/tests/legacy/PersistAsync.string-schema.test.js +211 -0
- package/build/tests/legacy/RefreshStepOnChange.debouncing.test.js +209 -0
- package/build/tests/legacy/RefreshStepOnChange.test.js +424 -0
- package/build/tests/legacy/Search.test.js +437 -0
- package/build/tests/renderers/MultiSelectInputRendererProps.test.js +58 -0
- package/build/tests/renderers/SelectInputRendererProps.test.js +42 -0
- package/build/tests/renderers/TextInputRenderer.test.js +51 -0
- package/build/types/domain/components/UpsellComponent.d.ts +2 -3
- package/build/types/domain/components/UpsellComponent.d.ts.map +1 -1
- package/build/types/domain/components/searchComponent/SearchComponent.d.ts +5 -4
- package/build/types/domain/components/searchComponent/SearchComponent.d.ts.map +1 -1
- package/build/types/domain/features/search/getPerformSearchFunction.d.ts +1 -1
- package/build/types/domain/features/search/getPerformSearchFunction.d.ts.map +1 -1
- package/build/types/domain/mappers/layout/searchLayoutToComponent.d.ts +2 -1
- package/build/types/domain/mappers/layout/searchLayoutToComponent.d.ts.map +1 -1
- package/build/types/domain/mappers/layout/upsellLayoutToComponent.d.ts +1 -1
- package/build/types/domain/mappers/layout/upsellLayoutToComponent.d.ts.map +1 -1
- package/build/types/renderers/EmptyLoadingStateRenderer.d.ts +3 -0
- package/build/types/renderers/EmptyLoadingStateRenderer.d.ts.map +1 -0
- package/build/types/renderers/mappers/rootComponentToProps.d.ts.map +1 -1
- package/build/types/renderers/mappers/searchComponentToProps.d.ts +1 -1
- package/build/types/renderers/mappers/searchComponentToProps.d.ts.map +1 -1
- package/build/types/renderers/mappers/upsellComponentToProps.d.ts +2 -2
- package/build/types/renderers/mappers/upsellComponentToProps.d.ts.map +1 -1
- package/build/types/test-utils/getMergedTestRenderers.d.ts +1 -1
- package/build/types/test-utils/getMergedTestRenderers.d.ts.map +1 -1
- package/build/types/useDynamicFlow.d.ts.map +1 -1
- package/build/types.js +1 -0
- package/build/useDynamicFlow.js +104 -0
- package/build/useDynamicFlowModal.js +58 -0
- package/build/utils/analyse-step.js +14 -0
- package/build/utils/component-utils.js +8 -0
- package/build/utils/component-utils.test.js +113 -0
- package/build/utils/getScrollToTop.js +12 -0
- package/build/utils/normalise-flow-id.js +1 -0
- package/build/utils/normalise-flow-id.test.js +24 -0
- package/build/utils/openLinkInNewTab.js +10 -0
- package/build/utils/recursiveMerge.js +40 -0
- package/build/utils/recursiveMerge.test.js +93 -0
- package/build/utils/type-utils.js +21 -0
- package/build/utils/type-validators.js +11 -0
- package/build/utils/type-validators.test.js +180 -0
- package/build/utils/useStableCallback.js +15 -0
- package/package.json +4 -4
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { createRootDomainComponent } from '../domain/components/RootDomainComponent';
|
|
13
|
+
import { createSubflowDomainComponent } from '../domain/components/SubflowDomainComponent';
|
|
14
|
+
import { normaliseRequestCache } from '../domain/features/prefetch/request-cache';
|
|
15
|
+
import { modalToComponent } from '../domain/mappers/layout/modalToComponent';
|
|
16
|
+
import { mapStepToComponent } from '../domain/mappers/mapStepToComponent';
|
|
17
|
+
import { getSubflowCallbacks } from '../getSubflowCallbacks';
|
|
18
|
+
import { analyseStep } from '../utils/analyse-step';
|
|
19
|
+
import { executePoll } from './executePoll';
|
|
20
|
+
import { executeRefresh } from './executeRefresh';
|
|
21
|
+
import { executeSubmission } from './executeSubmission';
|
|
22
|
+
import { getErrorMessage } from './getErrorMessage';
|
|
23
|
+
import { getRequestAbortController } from './getRequestAbortController';
|
|
24
|
+
import { getStepCounter } from './getStepCounter';
|
|
25
|
+
const noop = () => { };
|
|
26
|
+
export const createFlowController = (props) => {
|
|
27
|
+
const { flowId, initialAction, initialStep, backConfig, features, getErrorMessageFunctions, scrollToTop, httpClient, onChange, onCancellation, onCompletion, onCopy, onLink, onError, onEvent, onLog, onValueChange } = props, rest = __rest(props, ["flowId", "initialAction", "initialStep", "backConfig", "features", "getErrorMessageFunctions", "scrollToTop", "httpClient", "onChange", "onCancellation", "onCompletion", "onCopy", "onLink", "onError", "onEvent", "onLog", "onValueChange"]);
|
|
28
|
+
const rootComponent = createRootDomainComponent(onChange, scrollToTop, backConfig, normaliseRequestCache(rest.requestCache));
|
|
29
|
+
const stepCount = getStepCounter();
|
|
30
|
+
const abortController = getRequestAbortController();
|
|
31
|
+
const createStep = (newStep, etag) => {
|
|
32
|
+
// TODO remove, move to root domain component
|
|
33
|
+
if (rootComponent.hasStep()) {
|
|
34
|
+
stepCount.increment();
|
|
35
|
+
}
|
|
36
|
+
const component = createStepComponent(newStep, etag, null);
|
|
37
|
+
if (component) {
|
|
38
|
+
rootComponent.pushStep(component);
|
|
39
|
+
rootComponent.setLoadingState('idle');
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const updateStep = (newStep, etag) => {
|
|
43
|
+
var _a;
|
|
44
|
+
const component = createStepComponent(newStep, etag, (_a = rootComponent.getLocalValue()) !== null && _a !== void 0 ? _a : null);
|
|
45
|
+
if (component) {
|
|
46
|
+
rootComponent.updateStep(component);
|
|
47
|
+
rootComponent.setLoadingState('idle');
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const getMapperProps = () => ({
|
|
51
|
+
uid: `${rootComponent.uid}:${stepCount.current}`,
|
|
52
|
+
loadingState: 'idle',
|
|
53
|
+
onComponentUpdate: onChange,
|
|
54
|
+
flowRequestCache: rootComponent.requestCache,
|
|
55
|
+
getErrorMessageFunctions,
|
|
56
|
+
trackEvent,
|
|
57
|
+
logEvent,
|
|
58
|
+
features,
|
|
59
|
+
httpClient,
|
|
60
|
+
onBehavior,
|
|
61
|
+
onPoll,
|
|
62
|
+
onValueChange,
|
|
63
|
+
});
|
|
64
|
+
const createStepComponent = (newStep, etag, localValue) => {
|
|
65
|
+
rootComponent.stop();
|
|
66
|
+
analyseStep(newStep, logEvent);
|
|
67
|
+
try {
|
|
68
|
+
return mapStepToComponent(Object.assign({ stepLocalValue: localValue, step: newStep, etag }, getMapperProps()));
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
closeWithError(error);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const getStep = () => {
|
|
75
|
+
var _a;
|
|
76
|
+
const stepComponent = rootComponent.getStep();
|
|
77
|
+
return (_a = stepComponent === null || stepComponent === void 0 ? void 0 : stepComponent.step) !== null && _a !== void 0 ? _a : initialStep;
|
|
78
|
+
};
|
|
79
|
+
const trackEvent = (eventName, properties) => {
|
|
80
|
+
var _a, _b;
|
|
81
|
+
const step = getStep();
|
|
82
|
+
const stepId = (_b = (_a = step === null || step === void 0 ? void 0 : step.id) !== null && _a !== void 0 ? _a : step === null || step === void 0 ? void 0 : step.key) !== null && _b !== void 0 ? _b : null;
|
|
83
|
+
const analytics = step === null || step === void 0 ? void 0 : step.analytics;
|
|
84
|
+
const metadata = Object.assign(Object.assign(Object.assign(Object.assign({ flowId, integrationId: flowId }, (step ? { stepCount: stepCount.current } : {})), (stepId !== null ? { stepId } : {})), analytics), properties);
|
|
85
|
+
try {
|
|
86
|
+
onEvent === null || onEvent === void 0 ? void 0 : onEvent(`Dynamic Flow - ${eventName}`, Object.assign({}, metadata));
|
|
87
|
+
}
|
|
88
|
+
catch (_c) { }
|
|
89
|
+
};
|
|
90
|
+
const logEvent = (level, message, properties) => {
|
|
91
|
+
var _a, _b;
|
|
92
|
+
const step = getStep();
|
|
93
|
+
const stepId = (_b = (_a = step === null || step === void 0 ? void 0 : step.id) !== null && _a !== void 0 ? _a : step === null || step === void 0 ? void 0 : step.key) !== null && _b !== void 0 ? _b : null;
|
|
94
|
+
try {
|
|
95
|
+
onLog === null || onLog === void 0 ? void 0 : onLog(level, message, Object.assign(Object.assign(Object.assign(Object.assign({}, properties), { flowId }), (stepId !== null ? { stepId } : {})), (rootComponent.hasStep() || initialStep ? { stepCount: stepCount.current } : {})));
|
|
96
|
+
}
|
|
97
|
+
catch (_c) { }
|
|
98
|
+
};
|
|
99
|
+
const closeWithError = (error, analytics, statusCode) => {
|
|
100
|
+
rootComponent.stop();
|
|
101
|
+
trackEvent('Failed', Object.assign({}, analytics));
|
|
102
|
+
logEvent('error', 'Dynamic Flow failed', { errorMessage: getErrorMessage(error), analytics });
|
|
103
|
+
onError(error, statusCode);
|
|
104
|
+
};
|
|
105
|
+
const closeWithCancellation = () => {
|
|
106
|
+
trackEvent('Cancelled');
|
|
107
|
+
onCancellation === null || onCancellation === void 0 ? void 0 : onCancellation();
|
|
108
|
+
};
|
|
109
|
+
const onBehavior = async (behavior) => {
|
|
110
|
+
var _a, _b, _c;
|
|
111
|
+
switch (behavior.type) {
|
|
112
|
+
case 'back': {
|
|
113
|
+
if (behavior.action) {
|
|
114
|
+
onAction(behavior.action, null)
|
|
115
|
+
.then(() => {
|
|
116
|
+
rootComponent.clearStack();
|
|
117
|
+
})
|
|
118
|
+
.catch(() => { });
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
if (features.isEnabled('nativeBack')) {
|
|
122
|
+
if (rootComponent.stepStack.length > 1) {
|
|
123
|
+
rootComponent.navigateBack();
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
closeWithCancellation();
|
|
127
|
+
}
|
|
128
|
+
rootComponent.setLoadingState('idle');
|
|
129
|
+
}
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
case 'action': {
|
|
133
|
+
if (rootComponent.isBusy()) {
|
|
134
|
+
return { abort: () => { } };
|
|
135
|
+
}
|
|
136
|
+
rootComponent.dismissAllModals();
|
|
137
|
+
const { action } = behavior;
|
|
138
|
+
const skipValidation = action.method === 'GET' || Boolean(action.skipValidation);
|
|
139
|
+
const canSubmit = skipValidation || rootComponent.validate();
|
|
140
|
+
try {
|
|
141
|
+
if (canSubmit) {
|
|
142
|
+
rootComponent.setLoadingState('submitting');
|
|
143
|
+
const model = await rootComponent.getSubmittableValue();
|
|
144
|
+
void onAction(action, model);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
rootComponent.setLoadingState('idle');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch (_d) {
|
|
151
|
+
// It's ok to ignore errors here because when this only throw when persisting fails.
|
|
152
|
+
// And when persisting fails, the UI is already showing an error.
|
|
153
|
+
// If persisting succeeded before, then it would NOT FAIL now,
|
|
154
|
+
// because we don't re-try persisting for successful fields when submitting.
|
|
155
|
+
rootComponent.setLoadingState('idle');
|
|
156
|
+
}
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
case 'copy': {
|
|
160
|
+
navigator.clipboard
|
|
161
|
+
.writeText(behavior.content)
|
|
162
|
+
.then(() => onCopy === null || onCopy === void 0 ? void 0 : onCopy(behavior.content))
|
|
163
|
+
.catch(() => onCopy === null || onCopy === void 0 ? void 0 : onCopy(null));
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
case 'non-merging-action': {
|
|
167
|
+
rootComponent.dismissAllModals();
|
|
168
|
+
const { action } = behavior;
|
|
169
|
+
rootComponent.setLoadingState('submitting');
|
|
170
|
+
void onAction(action, null);
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
case 'refresh': {
|
|
174
|
+
rootComponent.dismissAllModals();
|
|
175
|
+
void onRefresh({ refreshUrl: behavior.url, analytics: behavior.analytics });
|
|
176
|
+
return {
|
|
177
|
+
abort: () => {
|
|
178
|
+
abortController.abort();
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
case 'link': {
|
|
183
|
+
onLink(behavior.url);
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
case 'modal': {
|
|
187
|
+
const currentStep = (_a = rootComponent.getStep()) === null || _a === void 0 ? void 0 : _a.step;
|
|
188
|
+
if (currentStep) {
|
|
189
|
+
rootComponent.showModal(modalToComponent(rootComponent.uid, behavior, Object.assign(Object.assign({ step: currentStep, stepLocalValue: rootComponent.getLocalValue() }, getMapperProps()), { registerSubmissionBehavior: () => { } }), rootComponent.getSchemaComponents()));
|
|
190
|
+
}
|
|
191
|
+
rootComponent.setLoadingState('idle');
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
case 'dismiss':
|
|
195
|
+
rootComponent.dismissModal();
|
|
196
|
+
break;
|
|
197
|
+
case 'subflow': {
|
|
198
|
+
rootComponent.setLoadingState('submitting');
|
|
199
|
+
const { launchConfig } = behavior;
|
|
200
|
+
const { request, presentation } = launchConfig;
|
|
201
|
+
const callbacks = getSubflowCallbacks({
|
|
202
|
+
behavior,
|
|
203
|
+
close: () => rootComponent.closeSubflow(),
|
|
204
|
+
onBehavior,
|
|
205
|
+
onError: closeWithError,
|
|
206
|
+
onEvent: onEvent !== null && onEvent !== void 0 ? onEvent : noop,
|
|
207
|
+
restart: () => {
|
|
208
|
+
rootComponent.setLoadingState('idle');
|
|
209
|
+
rootComponent.start();
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
const component = createSubflowDomainComponent(Object.assign(Object.assign({}, callbacks), { initialRequest: request, requestCache: (_c = (_b = rootComponent.getStep()) === null || _b === void 0 ? void 0 : _b.requestCache) !== null && _c !== void 0 ? _c : rootComponent.requestCache, presentation }), onChange);
|
|
213
|
+
rootComponent.stop();
|
|
214
|
+
rootComponent.addSubflow(component);
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
case 'none':
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
return { abort: () => { } };
|
|
221
|
+
};
|
|
222
|
+
const onAction = async (action, model) => {
|
|
223
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
224
|
+
try {
|
|
225
|
+
rootComponent.setLoadingState('submitting');
|
|
226
|
+
const command = await executeSubmission({
|
|
227
|
+
action,
|
|
228
|
+
model,
|
|
229
|
+
isInitial: !rootComponent.hasStep(),
|
|
230
|
+
requestCache: (_b = (_a = rootComponent.getStep()) === null || _a === void 0 ? void 0 : _a.requestCache) !== null && _b !== void 0 ? _b : rootComponent.requestCache,
|
|
231
|
+
httpClient,
|
|
232
|
+
trackEvent,
|
|
233
|
+
logEvent,
|
|
234
|
+
});
|
|
235
|
+
switch (command.type) {
|
|
236
|
+
case 'complete': {
|
|
237
|
+
onCompletion(command.result);
|
|
238
|
+
rootComponent.stop();
|
|
239
|
+
trackEvent('Succeeded');
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
case 'replace-step': {
|
|
243
|
+
const isFirstStep = !rootComponent.hasStep();
|
|
244
|
+
rootComponent.closeSubflow();
|
|
245
|
+
createStep(command.step, command.etag);
|
|
246
|
+
trackEvent('Step Shown', { isFirstStep });
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
case 'error': {
|
|
250
|
+
rootComponent.setLoadingState('idle');
|
|
251
|
+
const genericErrorMessage = getErrorMessageFunctions().genericErrorWithRetry();
|
|
252
|
+
const errors = (_d = (_c = command.body) === null || _c === void 0 ? void 0 : _c.errors) !== null && _d !== void 0 ? _d : { error: genericErrorMessage };
|
|
253
|
+
const currentStep = rootComponent.getStep();
|
|
254
|
+
if (currentStep) {
|
|
255
|
+
updateStep(Object.assign(Object.assign({}, currentStep.step), { errors, // but with the new errors
|
|
256
|
+
model, polling: undefined, external: undefined }), (_f = (_e = rootComponent.getStep()) === null || _e === void 0 ? void 0 : _e.etag) !== null && _f !== void 0 ? _f : null);
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
const errorMessage = ((_h = (_g = command.body) === null || _g === void 0 ? void 0 : _g.errors) === null || _h === void 0 ? void 0 : _h.error) || ((_j = command.httpError) === null || _j === void 0 ? void 0 : _j.message) || 'Initial request failed';
|
|
260
|
+
closeWithError(new Error(errorMessage, {
|
|
261
|
+
cause: `method: ${action.method}, url: ${action.url}`,
|
|
262
|
+
}), {}, (_k = command.httpError) === null || _k === void 0 ? void 0 : _k.statusCode);
|
|
263
|
+
}
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
case 'refresh': {
|
|
267
|
+
const { refreshUrl, errors = {} } = command.body;
|
|
268
|
+
void onRefresh({ refreshUrl, errorsOverride: errors });
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
case 'behavior': {
|
|
272
|
+
void onBehavior(command.behavior);
|
|
273
|
+
rootComponent.setLoadingState('idle');
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
catch (error) {
|
|
279
|
+
closeWithError(error);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
const onRefresh = async ({ refreshUrl, errorsOverride, analytics, }) => {
|
|
283
|
+
var _a, _b, _c;
|
|
284
|
+
try {
|
|
285
|
+
rootComponent.setLoadingState('refreshing');
|
|
286
|
+
const model = rootComponent.getSubmittableValueSync();
|
|
287
|
+
const command = await executeRefresh({
|
|
288
|
+
abortSignal: abortController.abortAndGetNewSignal(),
|
|
289
|
+
url: (_a = refreshUrl !== null && refreshUrl !== void 0 ? refreshUrl : rootComponent.getRefreshUrl()) !== null && _a !== void 0 ? _a : '',
|
|
290
|
+
model,
|
|
291
|
+
etag: (_c = (_b = rootComponent.getStep()) === null || _b === void 0 ? void 0 : _b.etag) !== null && _c !== void 0 ? _c : null,
|
|
292
|
+
analytics,
|
|
293
|
+
httpClient,
|
|
294
|
+
trackEvent,
|
|
295
|
+
logEvent,
|
|
296
|
+
});
|
|
297
|
+
switch (command.type) {
|
|
298
|
+
case 'refresh-step':
|
|
299
|
+
{
|
|
300
|
+
const errors = errorsOverride !== null && errorsOverride !== void 0 ? errorsOverride : command.step.errors;
|
|
301
|
+
updateStep(Object.assign(Object.assign({}, command.step), { errors }), command.etag);
|
|
302
|
+
}
|
|
303
|
+
break;
|
|
304
|
+
case 'noop':
|
|
305
|
+
rootComponent.setLoadingState('idle');
|
|
306
|
+
break;
|
|
307
|
+
case 'error': {
|
|
308
|
+
closeWithError(new Error('Failed to refresh'), command.body.analytics, command.statusCode);
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
// this should never happen. executeRefresh never throws
|
|
315
|
+
closeWithError(error, undefined);
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
const onPoll = async (url, errorBehavior, signal) => {
|
|
319
|
+
const command = await executePoll({
|
|
320
|
+
httpClient,
|
|
321
|
+
url,
|
|
322
|
+
errorBehavior,
|
|
323
|
+
signal,
|
|
324
|
+
trackEvent,
|
|
325
|
+
});
|
|
326
|
+
switch (command.type) {
|
|
327
|
+
case 'replace-step':
|
|
328
|
+
createStep(command.step, command.etag);
|
|
329
|
+
return true;
|
|
330
|
+
case 'behavior':
|
|
331
|
+
void onBehavior(command.behavior);
|
|
332
|
+
return true;
|
|
333
|
+
case 'complete':
|
|
334
|
+
onCompletion(command.result);
|
|
335
|
+
return true;
|
|
336
|
+
case 'continue':
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
let initState = 'initial';
|
|
341
|
+
if (initialStep) {
|
|
342
|
+
initState = 'created';
|
|
343
|
+
trackEvent('Initiated');
|
|
344
|
+
createStep(initialStep, null);
|
|
345
|
+
trackEvent('Step Shown', { isFirstStep: true });
|
|
346
|
+
}
|
|
347
|
+
const start = () => {
|
|
348
|
+
if (initState === 'initial' && initialAction) {
|
|
349
|
+
initState = 'created';
|
|
350
|
+
trackEvent('Initiated');
|
|
351
|
+
rootComponent.setLoadingState('submitting');
|
|
352
|
+
void onAction(Object.assign({ method: 'GET' }, initialAction), null).then(() => {
|
|
353
|
+
initState = 'started';
|
|
354
|
+
rootComponent.start();
|
|
355
|
+
});
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
if (initState === 'created') {
|
|
359
|
+
initState = 'started';
|
|
360
|
+
rootComponent.start();
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
return {
|
|
364
|
+
rootComponent,
|
|
365
|
+
start,
|
|
366
|
+
cancel: closeWithCancellation,
|
|
367
|
+
};
|
|
368
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { getResponseTypeFromHeader } from './getResponseType';
|
|
2
|
+
import { assertActionResponseBody, assertStepResponseBody, isActionResponseBody, parseResponseBodyAsJsonElement, } from './response-utils';
|
|
3
|
+
export const executePoll = async (props) => {
|
|
4
|
+
const { errorBehavior, signal, url, httpClient, trackEvent } = props;
|
|
5
|
+
try {
|
|
6
|
+
const response = await httpClient(url !== null && url !== void 0 ? url : '', {
|
|
7
|
+
method: 'GET',
|
|
8
|
+
signal,
|
|
9
|
+
});
|
|
10
|
+
if (!response.ok) {
|
|
11
|
+
trackEvent('Polling Failed', { url, statusCode: response.status, variant: 'revamp' });
|
|
12
|
+
return { type: 'behavior', behavior: errorBehavior };
|
|
13
|
+
}
|
|
14
|
+
const responseType = getResponseTypeFromHeader(response.headers);
|
|
15
|
+
const body = await parseResponseBodyAsJsonElement(response);
|
|
16
|
+
try {
|
|
17
|
+
switch (responseType) {
|
|
18
|
+
case 'step': {
|
|
19
|
+
const etag = response.headers.get('etag') || null;
|
|
20
|
+
assertStepResponseBody(body);
|
|
21
|
+
return { type: 'replace-step', step: body, etag };
|
|
22
|
+
}
|
|
23
|
+
case 'exit': {
|
|
24
|
+
return { type: 'complete', result: body };
|
|
25
|
+
}
|
|
26
|
+
case 'action': {
|
|
27
|
+
assertActionResponseBody(body);
|
|
28
|
+
return { type: 'behavior', behavior: actionResponseBodyToBehavior(body) };
|
|
29
|
+
}
|
|
30
|
+
default: {
|
|
31
|
+
if (isActionResponseBody(body)) {
|
|
32
|
+
return { type: 'behavior', behavior: actionResponseBodyToBehavior(body) };
|
|
33
|
+
}
|
|
34
|
+
return { type: 'continue' };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (_a) {
|
|
39
|
+
return { type: 'behavior', behavior: errorBehavior };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (_b) {
|
|
43
|
+
return { type: 'continue' };
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const actionResponseBodyToBehavior = (body) => ({
|
|
47
|
+
type: 'non-merging-action',
|
|
48
|
+
action: body.action,
|
|
49
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getErrorMessage } from './getErrorMessage';
|
|
2
|
+
import { assertStepResponseBody, isErrorResponseBody, parseResponseBodyAsJsonElement, } from './response-utils';
|
|
3
|
+
export const executeRefresh = async (props) => {
|
|
4
|
+
const { abortSignal, url, model, etag, analytics, httpClient, trackEvent, logEvent } = props;
|
|
5
|
+
trackEvent('Refresh Triggered', analytics);
|
|
6
|
+
try {
|
|
7
|
+
const response = await httpClient(url !== null && url !== void 0 ? url : '', {
|
|
8
|
+
method: 'POST',
|
|
9
|
+
body: JSON.stringify(model),
|
|
10
|
+
headers: Object.assign({ 'Content-Type': 'application/json' }, (etag ? { 'If-None-Match': etag } : {})),
|
|
11
|
+
signal: abortSignal,
|
|
12
|
+
});
|
|
13
|
+
if (response.status === 304) {
|
|
14
|
+
trackEvent('Refresh Succeeded', analytics);
|
|
15
|
+
return { type: 'noop' };
|
|
16
|
+
}
|
|
17
|
+
if (!response.ok) {
|
|
18
|
+
const responseBody = await parseResponseBodyAsJsonElement(response).catch(() => ({}));
|
|
19
|
+
const body = isErrorResponseBody(responseBody) ? responseBody : {};
|
|
20
|
+
trackEvent('Refresh Failed', Object.assign(Object.assign(Object.assign({}, analytics), body.analytics), { statusCode: response.status }));
|
|
21
|
+
logEvent('error', 'Dynamic Flow - Refresh Failed', Object.assign(Object.assign({}, analytics), { statusCode: response.status }));
|
|
22
|
+
return { type: 'error', body, statusCode: response.status };
|
|
23
|
+
}
|
|
24
|
+
const newEtag = response.headers.get('etag') || null;
|
|
25
|
+
const body = await parseResponseBodyAsJsonElement(response);
|
|
26
|
+
assertStepResponseBody(body);
|
|
27
|
+
trackEvent('Refresh Succeeded', analytics);
|
|
28
|
+
return { type: 'refresh-step', step: body, etag: newEtag };
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (error instanceof DOMException && error.name === 'AbortError') {
|
|
32
|
+
trackEvent('Refresh Aborted', analytics);
|
|
33
|
+
return { type: 'noop' };
|
|
34
|
+
}
|
|
35
|
+
trackEvent('Refresh Failed', analytics);
|
|
36
|
+
logEvent('error', 'Dynamic Flow - Refresh Failed', Object.assign(Object.assign({}, analytics), { errorMessage: getErrorMessage(error) }));
|
|
37
|
+
return { type: 'error', body: {} };
|
|
38
|
+
}
|
|
39
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { handleErrorResponse } from './handleErrorResponse';
|
|
2
|
+
import { getResponseType } from './getResponseType';
|
|
3
|
+
import { assertActionResponseBody, assertModalResponseBody, assertStepResponseBody, assertSubflowResponseBody, parseResponseBodyAsJsonElement, } from './response-utils';
|
|
4
|
+
import { makeSafeHttpClient } from './makeSafeHttpClient';
|
|
5
|
+
import { normaliseBehavior } from '../domain/mappers/utils/behavior-utils';
|
|
6
|
+
export const executeRequest = async (props) => {
|
|
7
|
+
const { exit, request, requestCache, httpClient, trackEvent, logEvent } = props;
|
|
8
|
+
const { url, method, body } = request;
|
|
9
|
+
const response = await getCachedOrFetch([
|
|
10
|
+
url,
|
|
11
|
+
{
|
|
12
|
+
method,
|
|
13
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
14
|
+
headers: { 'Content-Type': 'application/json' },
|
|
15
|
+
},
|
|
16
|
+
], requestCache, httpClient);
|
|
17
|
+
if (!response) {
|
|
18
|
+
const extra = { errorMessage: 'Network Error' };
|
|
19
|
+
trackEvent('Request Failed', extra);
|
|
20
|
+
logEvent('error', 'Dynamic Flow - Request Failed Unexpectedly', extra);
|
|
21
|
+
return { type: 'error' };
|
|
22
|
+
}
|
|
23
|
+
if (!response.ok) {
|
|
24
|
+
return handleErrorResponse(response, undefined, trackEvent);
|
|
25
|
+
}
|
|
26
|
+
const responseBody = await parseResponseBodyAsJsonElement(response);
|
|
27
|
+
const responseType = getResponseType(response.headers, responseBody);
|
|
28
|
+
if (exit) {
|
|
29
|
+
return { type: 'complete', result: responseBody };
|
|
30
|
+
}
|
|
31
|
+
switch (responseType) {
|
|
32
|
+
case 'step': {
|
|
33
|
+
const etag = response.headers.get('etag') || null;
|
|
34
|
+
assertStepResponseBody(responseBody);
|
|
35
|
+
return { type: 'replace-step', step: responseBody, etag };
|
|
36
|
+
}
|
|
37
|
+
case 'exit': {
|
|
38
|
+
return { type: 'complete', result: responseBody };
|
|
39
|
+
}
|
|
40
|
+
case 'action': {
|
|
41
|
+
assertActionResponseBody(responseBody);
|
|
42
|
+
return {
|
|
43
|
+
type: 'behavior',
|
|
44
|
+
behavior: {
|
|
45
|
+
type: 'action',
|
|
46
|
+
action: responseBody.action,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
case 'subflow': {
|
|
51
|
+
assertSubflowResponseBody(responseBody);
|
|
52
|
+
return {
|
|
53
|
+
type: 'behavior',
|
|
54
|
+
behavior: Object.assign(Object.assign({}, responseBody), { type: 'subflow', onCompletion: responseBody.onCompletion
|
|
55
|
+
? normaliseBehavior(responseBody.onCompletion, [])
|
|
56
|
+
: undefined, onError: responseBody.onError ? normaliseBehavior(responseBody.onError, []) : undefined }),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
case 'modal': {
|
|
60
|
+
assertModalResponseBody(responseBody);
|
|
61
|
+
return { type: 'behavior', behavior: Object.assign(Object.assign({}, responseBody), { type: 'modal' }) };
|
|
62
|
+
}
|
|
63
|
+
default: {
|
|
64
|
+
throw new Error(`Unsupported response type: ${String(responseType)}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const getCachedOrFetch = async (requestParams, requestCache, httpClient) => {
|
|
69
|
+
const cachedPromise = requestCache.get(requestParams);
|
|
70
|
+
if (cachedPromise) {
|
|
71
|
+
const cachedResponse = await cachedPromise;
|
|
72
|
+
if (cachedResponse === null || cachedResponse === void 0 ? void 0 : cachedResponse.ok) {
|
|
73
|
+
return cachedResponse;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return makeSafeHttpClient(httpClient)(...requestParams);
|
|
77
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { recursiveMerge } from '../utils/recursiveMerge';
|
|
2
|
+
import { getErrorMessage } from './getErrorMessage';
|
|
3
|
+
import { executeRequest } from './executeRequest';
|
|
4
|
+
export const executeSubmission = async (props) => {
|
|
5
|
+
const { httpClient, requestCache, trackEvent, logEvent } = props;
|
|
6
|
+
const triggerAction = async (action, model, isInitial) => {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
const { exit, url, result = null, id: actionId } = action;
|
|
9
|
+
const trackSubmissionEvent = !isInitial ? trackEvent : () => { };
|
|
10
|
+
trackSubmissionEvent('Action Triggered', { actionId });
|
|
11
|
+
if (exit && !url) {
|
|
12
|
+
trackSubmissionEvent('Action Succeeded', { actionId });
|
|
13
|
+
return { type: 'complete', result };
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const command = await executeRequest({
|
|
17
|
+
exit,
|
|
18
|
+
request: createRequestFromAction(action, model),
|
|
19
|
+
requestCache,
|
|
20
|
+
httpClient,
|
|
21
|
+
trackEvent: (name, properties) => {
|
|
22
|
+
trackSubmissionEvent(name, Object.assign(Object.assign({}, properties), { actionId }));
|
|
23
|
+
},
|
|
24
|
+
logEvent,
|
|
25
|
+
});
|
|
26
|
+
switch (command.type) {
|
|
27
|
+
case 'error': {
|
|
28
|
+
trackSubmissionEvent('Action Failed', Object.assign({ actionId, statusCode: (_a = command.httpError) === null || _a === void 0 ? void 0 : _a.statusCode }, (_b = command.body) === null || _b === void 0 ? void 0 : _b.analytics));
|
|
29
|
+
return command;
|
|
30
|
+
}
|
|
31
|
+
case 'behavior': {
|
|
32
|
+
if (command.behavior.type === 'action') {
|
|
33
|
+
trackSubmissionEvent('Action Succeeded', { actionId });
|
|
34
|
+
return await executeSubmission({
|
|
35
|
+
action: command.behavior.action,
|
|
36
|
+
isInitial: false,
|
|
37
|
+
model: null,
|
|
38
|
+
requestCache,
|
|
39
|
+
httpClient,
|
|
40
|
+
trackEvent,
|
|
41
|
+
logEvent,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
trackSubmissionEvent('Action Succeeded', { actionId });
|
|
45
|
+
return command;
|
|
46
|
+
}
|
|
47
|
+
case 'complete': {
|
|
48
|
+
trackSubmissionEvent('Action Succeeded', { actionId });
|
|
49
|
+
return Object.assign(Object.assign({}, command), { result: recursiveMerge(command.result, result) });
|
|
50
|
+
}
|
|
51
|
+
default: {
|
|
52
|
+
trackSubmissionEvent('Action Succeeded', { actionId });
|
|
53
|
+
return command;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
const errorMessage = getErrorMessage(error);
|
|
59
|
+
trackSubmissionEvent('Action Failed', { actionId, errorMessage });
|
|
60
|
+
logEvent('error', 'Dynamic Flow - Action Failed Unexpectedly', { actionId, errorMessage });
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
return triggerAction(props.action, props.model, props.isInitial);
|
|
65
|
+
};
|
|
66
|
+
export const createRequestFromAction = (action, model) => {
|
|
67
|
+
var _a, _b, _c;
|
|
68
|
+
return (Object.assign(Object.assign({}, action), { url: (_a = action.url) !== null && _a !== void 0 ? _a : '', method: (_b = action.method) !== null && _b !== void 0 ? _b : 'POST', body: action.method === 'GET' ? undefined : recursiveMerge(model, (_c = action.data) !== null && _c !== void 0 ? _c : null) }));
|
|
69
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const getRequestAbortController = () => {
|
|
2
|
+
let abortController = new AbortController();
|
|
3
|
+
return {
|
|
4
|
+
abortAndGetNewSignal() {
|
|
5
|
+
abortController.abort();
|
|
6
|
+
abortController = new AbortController();
|
|
7
|
+
return abortController.signal;
|
|
8
|
+
},
|
|
9
|
+
abort() {
|
|
10
|
+
abortController.abort();
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isObject } from '../utils/type-validators';
|
|
2
|
+
const responseTypes = ['step', 'action', 'exit', 'modal', 'subflow'];
|
|
3
|
+
/**
|
|
4
|
+
* Returns either 'step', 'action', or 'exit' based on the response headers and body.
|
|
5
|
+
* This function takes a response body parameter because, for legacy reasons, we still need to consider the body
|
|
6
|
+
* to determine the response type, in cases where the response headers are not set.
|
|
7
|
+
* Ideally it should just be a matter of checking the "X-Df-Response-Type" response header.
|
|
8
|
+
*/
|
|
9
|
+
export const getResponseType = (headers, body) => {
|
|
10
|
+
const headerResponseType = getResponseTypeFromHeader(headers);
|
|
11
|
+
if (headerResponseType) {
|
|
12
|
+
return headerResponseType;
|
|
13
|
+
}
|
|
14
|
+
if (isObject(body) && body.action) {
|
|
15
|
+
// TODO: use Zod to validate the action object
|
|
16
|
+
return 'action';
|
|
17
|
+
}
|
|
18
|
+
return 'step';
|
|
19
|
+
};
|
|
20
|
+
export const getResponseTypeFromHeader = (headers) => {
|
|
21
|
+
if (headers === null || headers === void 0 ? void 0 : headers.has('X-Df-Response-Type')) {
|
|
22
|
+
const type = headers.get('X-Df-Response-Type');
|
|
23
|
+
assertDFResponseType(type);
|
|
24
|
+
return type;
|
|
25
|
+
}
|
|
26
|
+
if (headers === null || headers === void 0 ? void 0 : headers.has('X-Df-Exit')) {
|
|
27
|
+
return 'exit';
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
};
|
|
31
|
+
function assertDFResponseType(type) {
|
|
32
|
+
if (!responseTypes.includes(type)) {
|
|
33
|
+
throw new Error("Unsupported X-Df-Response-Type. Allowed values are 'step', 'action', 'exit', 'error', 'modal', 'subflow'.");
|
|
34
|
+
}
|
|
35
|
+
}
|