@wise/dynamic-flow-client 0.4.4 → 0.5.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/README.md +17 -22
- package/build/main.js +53 -59
- package/build/main.min.js +3 -3
- package/build/types/common/contexts/httpClientContext/HttpClientContext.d.ts +18 -0
- package/build/types/common/contexts/index.d.ts +1 -1
- package/build/types/common/makeHttpClient/index.d.ts +1 -0
- package/build/types/common/makeHttpClient/makeHttpClient.d.ts +2 -0
- package/build/types/dynamicFlow/DynamicFlowTypes.d.ts +3 -4
- package/build/types/dynamicFlow/stories/fixtureHttpClient.d.ts +2 -0
- package/build/types/dynamicFlow/utils/responseParsers/response-parsers.d.ts +2 -2
- package/build/types/index.d.ts +1 -1
- package/build/types/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/UploadInputAdapter.d.ts +2 -2
- package/package.json +1 -1
- package/build/types/common/contexts/fetcherContexts/FetcherContexts.d.ts +0 -18
- package/build/types/common/makeFetcher/index.d.ts +0 -1
- package/build/types/common/makeFetcher/makeFetcher.d.ts +0 -2
- package/build/types/dynamicFlow/stories/fixtureFetcher.d.ts +0 -2
package/README.md
CHANGED
|
@@ -75,18 +75,13 @@ return (
|
|
|
75
75
|
|
|
76
76
|
## Configuring your Flow
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
- with a `initialAction` or with an `initialStep`
|
|
81
|
-
- with a `baseUrl` or with a `fetcher` function
|
|
82
|
-
|
|
83
|
-
We recommend using a `initialAction` and a `fetcher` function.
|
|
78
|
+
DF can be initialised with `initialAction` (recommended) or with an `initialStep`.
|
|
84
79
|
|
|
85
80
|
```tsx
|
|
86
81
|
<DynamicFlow
|
|
87
82
|
initialAction={{ method: 'GET', url: '/my-amazing-new-flow' }}
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
httpClient={(...args) => fetch(...args)}
|
|
84
|
+
onCompletion={(result) => {
|
|
90
85
|
console.log('Flow exited with', result);
|
|
91
86
|
}}
|
|
92
87
|
onError={(error, statusCode) => {
|
|
@@ -102,37 +97,37 @@ In some cases you may want to obtain the initial step yourself, and then pass it
|
|
|
102
97
|
```tsx
|
|
103
98
|
<DynamicFlow
|
|
104
99
|
initialStep={someInitialStepIfoundLayingAroundHere}
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
httpClient={...}
|
|
101
|
+
onCompletion={...}
|
|
107
102
|
onError={...}
|
|
108
103
|
/>
|
|
109
104
|
```
|
|
110
105
|
|
|
111
|
-
### The `
|
|
106
|
+
### The `httpClient` function prop
|
|
112
107
|
|
|
113
|
-
You must pass a
|
|
108
|
+
You must pass a `httpClient` function. This can be `window.fetch` itself or some wrapper function where you inject authorisation headers and anything else you many need.
|
|
114
109
|
|
|
115
|
-
You can take advantage of the provided `
|
|
110
|
+
You can take advantage of the provided `makeHttpClient` utility function. This function takes `baseUrl` and `additionalHeaders` arguments. The `baseUrl` will be prefixed to any relative request URLs. Absolute URLs will not be altered. The `additionalHeaders` parameter can be used to add any request headers you need in all requests.
|
|
116
111
|
|
|
117
112
|
```tsx
|
|
118
|
-
import {
|
|
113
|
+
import { makeHttpClient, DynamicFlow } from '@wise/dynamic-flow-client';
|
|
119
114
|
|
|
120
|
-
const
|
|
115
|
+
const myHttpClient = makeHttpClient('/my-base-url', { 'X-Access-Token': 'an-access-token' });
|
|
121
116
|
|
|
122
117
|
<DynamicFlow
|
|
123
118
|
initialAction={{ method: 'GET', url: '/flow-starting-url' }}
|
|
124
|
-
|
|
125
|
-
|
|
119
|
+
httpClient={myHttpClient}
|
|
120
|
+
onCompletion={...}
|
|
126
121
|
onError={...}
|
|
127
122
|
/>
|
|
128
123
|
```
|
|
129
124
|
|
|
130
|
-
#### Custom `
|
|
125
|
+
#### Custom `httpClient` functions
|
|
131
126
|
|
|
132
|
-
If you want to write your own
|
|
127
|
+
If you want to write your own `httpClient` function (or if you're writing mocks), it's important that you return actual `Response` objects, and that you **do not throw**. Errors should result in a response with an error status code and potentially a body with an error message. For example:
|
|
133
128
|
|
|
134
129
|
```tsx
|
|
135
|
-
const
|
|
130
|
+
const mockHttpClient = (input, init) => {
|
|
136
131
|
switch (input) {
|
|
137
132
|
case '/standard':
|
|
138
133
|
return Promise.resolve(new Response(init.body));
|
|
@@ -150,12 +145,12 @@ Also, please make sure your mocks return a new `Response` instace every time. Th
|
|
|
150
145
|
```ts
|
|
151
146
|
const initialResponse = new Response(JSON.stringify(initialStep));
|
|
152
147
|
// ❌ wrong - the same instance is returned on each request
|
|
153
|
-
const
|
|
148
|
+
const mockHttpClient = (input, init) => Promise.resolve(initialResponse);
|
|
154
149
|
```
|
|
155
150
|
|
|
156
151
|
```ts
|
|
157
152
|
// ✅ correct - a new instance is returned on each request
|
|
158
|
-
const
|
|
153
|
+
const mockHttpClient = (input, init) => Promise.resolve(new Response(JSON.stringify(initialStep)));
|
|
159
154
|
```
|
|
160
155
|
|
|
161
156
|
### Telemetry
|
package/build/main.js
CHANGED
|
@@ -535,7 +535,7 @@ __export(src_exports, {
|
|
|
535
535
|
fixtures: () => fixtures,
|
|
536
536
|
inlineReferences: () => inlineReferences,
|
|
537
537
|
isValidSchema: () => isValidSchema,
|
|
538
|
-
|
|
538
|
+
makeHttpClient: () => makeHttpClient,
|
|
539
539
|
translations: () => i18n_default
|
|
540
540
|
});
|
|
541
541
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -910,7 +910,7 @@ function useEventDispatcher() {
|
|
|
910
910
|
}
|
|
911
911
|
var getEventDispatcher = (onEvent, metadata) => (eventName, properties = {}) => onEvent(eventName, __spreadValues(__spreadValues({}, metadata), properties));
|
|
912
912
|
|
|
913
|
-
// src/common/contexts/
|
|
913
|
+
// src/common/contexts/httpClientContext/HttpClientContext.tsx
|
|
914
914
|
var import_react4 = require("react");
|
|
915
915
|
|
|
916
916
|
// src/common/utils/api-utils.ts
|
|
@@ -926,8 +926,8 @@ function isRelativePath(url = "") {
|
|
|
926
926
|
) === false;
|
|
927
927
|
}
|
|
928
928
|
|
|
929
|
-
// src/common/
|
|
930
|
-
var
|
|
929
|
+
// src/common/makeHttpClient/makeHttpClient.ts
|
|
930
|
+
var makeHttpClient = (baseUrl, additionalHeaders) => (input, init) => {
|
|
931
931
|
const resource = applyBaseUrl(input, baseUrl || "");
|
|
932
932
|
const headers = mergeHeaders(init == null ? void 0 : init.headers, additionalHeaders);
|
|
933
933
|
return fetch(resource, __spreadProps(__spreadValues({}, init || {}), { headers }));
|
|
@@ -946,25 +946,22 @@ var mergeHeaders = (initHeaders, additionalHeaders) => {
|
|
|
946
946
|
return headers;
|
|
947
947
|
};
|
|
948
948
|
|
|
949
|
-
// src/common/contexts/
|
|
949
|
+
// src/common/contexts/httpClientContext/HttpClientContext.tsx
|
|
950
950
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
951
|
-
var
|
|
952
|
-
var
|
|
953
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
951
|
+
var HttpClientContext = (0, import_react4.createContext)(void 0);
|
|
952
|
+
var HttpClientProvider = ({ httpClient, children }) => {
|
|
953
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(HttpClientContext.Provider, { value: httpClient, children });
|
|
954
954
|
};
|
|
955
|
-
var
|
|
956
|
-
baseUrl,
|
|
957
|
-
children
|
|
958
|
-
}) => {
|
|
959
|
-
const fetcher = (0, import_react4.useMemo)(() => makeFetcher(baseUrl), [baseUrl]);
|
|
960
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FetcherContext.Provider, { value: fetcher, children });
|
|
955
|
+
var HttpClientProviderFromBaseUrl = ({ baseUrl, children }) => {
|
|
956
|
+
const httpClient = (0, import_react4.useMemo)(() => makeHttpClient(baseUrl), [baseUrl]);
|
|
957
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(HttpClientContext.Provider, { value: httpClient, children });
|
|
961
958
|
};
|
|
962
|
-
var
|
|
963
|
-
const contextFetch = (0, import_react4.useContext)(
|
|
959
|
+
var useHttpClient = () => {
|
|
960
|
+
const contextFetch = (0, import_react4.useContext)(HttpClientContext);
|
|
964
961
|
return contextFetch || fetch;
|
|
965
962
|
};
|
|
966
|
-
var
|
|
967
|
-
const context = (0, import_react4.useContext)(
|
|
963
|
+
var useHasHttpClientProvider = () => {
|
|
964
|
+
const context = (0, import_react4.useContext)(HttpClientContext);
|
|
968
965
|
return !!context;
|
|
969
966
|
};
|
|
970
967
|
|
|
@@ -1783,11 +1780,11 @@ function useExternal(url) {
|
|
|
1783
1780
|
// src/common/hooks/useExternalStepPolling/useExternalStepPolling.tsx
|
|
1784
1781
|
var import_react8 = require("react");
|
|
1785
1782
|
function useExternalStepPolling(polling, onAction) {
|
|
1786
|
-
const
|
|
1783
|
+
const httpClient = useHttpClient();
|
|
1787
1784
|
const asyncFn = (0, import_react8.useMemo)(() => {
|
|
1788
1785
|
if (polling) {
|
|
1789
1786
|
return () => {
|
|
1790
|
-
return
|
|
1787
|
+
return httpClient(polling.url).then((response) => {
|
|
1791
1788
|
if (response.ok) {
|
|
1792
1789
|
try {
|
|
1793
1790
|
return response.json();
|
|
@@ -1802,7 +1799,7 @@ function useExternalStepPolling(polling, onAction) {
|
|
|
1802
1799
|
} else {
|
|
1803
1800
|
return void 0;
|
|
1804
1801
|
}
|
|
1805
|
-
}, [polling,
|
|
1802
|
+
}, [polling, httpClient]);
|
|
1806
1803
|
const onPollingResponse = (0, import_react8.useCallback)(
|
|
1807
1804
|
(pollingResponse) => {
|
|
1808
1805
|
const responseHandlers = (polling == null ? void 0 : polling.responseHandlers) || [];
|
|
@@ -3824,7 +3821,7 @@ var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
|
3824
3821
|
var UploadInputAdapter = (props) => {
|
|
3825
3822
|
const {
|
|
3826
3823
|
id,
|
|
3827
|
-
|
|
3824
|
+
httpClient = fetch,
|
|
3828
3825
|
httpOptions,
|
|
3829
3826
|
fileId,
|
|
3830
3827
|
idProperty,
|
|
@@ -3839,7 +3836,7 @@ var UploadInputAdapter = (props) => {
|
|
|
3839
3836
|
const files = (0, import_react15.useMemo)(() => fileId ? [{ id: fileId, status: import_components10.Status.SUCCEEDED }] : [], [fileId]);
|
|
3840
3837
|
const uploadFile = (formData) => {
|
|
3841
3838
|
onEvent("Dynamic Flow - PersistAsync", { status: "pending", schemaId: id });
|
|
3842
|
-
return
|
|
3839
|
+
return httpClient(`${httpOptions.url}`, {
|
|
3843
3840
|
method: httpOptions.method || "POST",
|
|
3844
3841
|
body: formData
|
|
3845
3842
|
}).then((response) => {
|
|
@@ -3880,7 +3877,7 @@ var PersistAsyncBlobSchema = (props) => {
|
|
|
3880
3877
|
const [persistAsyncValidations, setPersistAsyncValidations] = (0, import_react16.useState)(null);
|
|
3881
3878
|
const [validations, setValidations] = (0, import_react16.useState)([]);
|
|
3882
3879
|
const [changed, setChanged] = (0, import_react16.useState)(false);
|
|
3883
|
-
const
|
|
3880
|
+
const httpClient = useHttpClient();
|
|
3884
3881
|
const onEvent = useEventDispatcher();
|
|
3885
3882
|
const refreshValidations = () => {
|
|
3886
3883
|
if (props.submitted) {
|
|
@@ -3928,7 +3925,7 @@ var PersistAsyncBlobSchema = (props) => {
|
|
|
3928
3925
|
usLabel: props.schema.title || props.schema.persistAsync.schema.title,
|
|
3929
3926
|
usPlaceholder: props.schema.description || props.schema.persistAsync.schema.description,
|
|
3930
3927
|
httpOptions: { url, method, fileInputName: props.schema.persistAsync.param },
|
|
3931
|
-
|
|
3928
|
+
httpClient,
|
|
3932
3929
|
onSuccess,
|
|
3933
3930
|
onFailure,
|
|
3934
3931
|
onCancel
|
|
@@ -4199,7 +4196,7 @@ var ValidationAsyncSchema = (props) => {
|
|
|
4199
4196
|
const [validationAsyncErrors, setValidationAsyncErrors] = (0, import_react18.useState)(null);
|
|
4200
4197
|
const [fieldSubmitted, setFieldSubmitted] = (0, import_react18.useState)(false);
|
|
4201
4198
|
const [abortController, setAbortController] = (0, import_react18.useState)(null);
|
|
4202
|
-
const
|
|
4199
|
+
const httpClient = useHttpClient();
|
|
4203
4200
|
const onEvent = useEventDispatcher();
|
|
4204
4201
|
const logger = useLogger();
|
|
4205
4202
|
const getValidationAsyncResponse = async (currentValidationAsyncModel, validationAsyncSpec) => {
|
|
@@ -4215,7 +4212,7 @@ var ValidationAsyncSchema = (props) => {
|
|
|
4215
4212
|
);
|
|
4216
4213
|
}
|
|
4217
4214
|
onEvent("Dynamic Flow - ValidationAsync", { status: "pending" });
|
|
4218
|
-
const response = await
|
|
4215
|
+
const response = await httpClient(validationAsyncSpec.url, {
|
|
4219
4216
|
method: validationAsyncSpec.method || "POST",
|
|
4220
4217
|
headers: { "Content-Type": "application/json" },
|
|
4221
4218
|
body: validationAsyncSpec.method === "GET" ? void 0 : JSON.stringify(requestBody),
|
|
@@ -4383,7 +4380,7 @@ var JsonSchemaForm = (props) => {
|
|
|
4383
4380
|
disabled: false,
|
|
4384
4381
|
baseUrl: ""
|
|
4385
4382
|
}, props);
|
|
4386
|
-
if (
|
|
4383
|
+
if (useHasHttpClientProvider() || schemaProps.baseUrl == null) {
|
|
4387
4384
|
return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(GenericSchema_default, __spreadValues({}, schemaProps));
|
|
4388
4385
|
}
|
|
4389
4386
|
return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
@@ -4403,7 +4400,7 @@ var Providers = ({ baseUrl, onEvent, onLog, children }) => {
|
|
|
4403
4400
|
{
|
|
4404
4401
|
metadata: { flowId: "JsonSchemaForm", stepId: "JsonSchemaForm" },
|
|
4405
4402
|
onEvent: onEvent != null ? onEvent : noop2,
|
|
4406
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
4403
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(HttpClientProviderFromBaseUrl, { baseUrl, children })
|
|
4407
4404
|
}
|
|
4408
4405
|
) });
|
|
4409
4406
|
};
|
|
@@ -4466,11 +4463,11 @@ var import_react19 = require("react");
|
|
|
4466
4463
|
var import_jsx_runtime38 = require("react/jsx-runtime");
|
|
4467
4464
|
var DynamicImage = ({ component: image }) => {
|
|
4468
4465
|
const { url, size, text, margin } = image;
|
|
4469
|
-
const
|
|
4466
|
+
const httpClient = useHttpClient();
|
|
4470
4467
|
const [imageSource, setImageSource] = (0, import_react19.useState)("");
|
|
4471
4468
|
(0, import_react19.useEffect)(() => {
|
|
4472
|
-
void getImageSource(
|
|
4473
|
-
}, [url,
|
|
4469
|
+
void getImageSource(httpClient, url).then(setImageSource);
|
|
4470
|
+
}, [url, httpClient]);
|
|
4474
4471
|
const imageProps = {
|
|
4475
4472
|
alt: text || "",
|
|
4476
4473
|
src: imageSource,
|
|
@@ -4490,11 +4487,11 @@ var readImageBlobAsDataURL = (imageBlob) => {
|
|
|
4490
4487
|
reader.readAsDataURL(imageBlob);
|
|
4491
4488
|
});
|
|
4492
4489
|
};
|
|
4493
|
-
var getImageSource = async (
|
|
4490
|
+
var getImageSource = async (httpClient, imageUrl) => {
|
|
4494
4491
|
var _a;
|
|
4495
4492
|
try {
|
|
4496
4493
|
if (isRelativePath(imageUrl) || (imageUrl == null ? void 0 : imageUrl.indexOf(`${(_a = window == null ? void 0 : window.location) == null ? void 0 : _a.origin}/`)) === 0) {
|
|
4497
|
-
return
|
|
4494
|
+
return httpClient(imageUrl, {
|
|
4498
4495
|
method: "GET",
|
|
4499
4496
|
headers: { "Content-Type": "image/image" },
|
|
4500
4497
|
credentials: "same-origin"
|
|
@@ -4588,10 +4585,10 @@ var DynamicLayout = (props) => {
|
|
|
4588
4585
|
return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", {}, getKey(component));
|
|
4589
4586
|
}
|
|
4590
4587
|
};
|
|
4591
|
-
if (
|
|
4588
|
+
if (useHasHttpClientProvider() || baseUrl == null) {
|
|
4592
4589
|
return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_jsx_runtime39.Fragment, { children: components.map(renderComponent) });
|
|
4593
4590
|
} else {
|
|
4594
|
-
return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
|
|
4591
|
+
return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(HttpClientProviderFromBaseUrl, { baseUrl, children: components.map(renderComponent) });
|
|
4595
4592
|
}
|
|
4596
4593
|
};
|
|
4597
4594
|
var DynamicLayout_default = DynamicLayout;
|
|
@@ -4882,7 +4879,7 @@ var controlTypesWithPersistOnChange = /* @__PURE__ */ new Set([
|
|
|
4882
4879
|
]);
|
|
4883
4880
|
var PersistAsyncBasicSchema = (props) => {
|
|
4884
4881
|
const intl = (0, import_react_intl15.useIntl)();
|
|
4885
|
-
const
|
|
4882
|
+
const httpClient = useHttpClient();
|
|
4886
4883
|
const onEvent = useEventDispatcher();
|
|
4887
4884
|
const [persistAsyncModel, setPersistAsyncModel] = (0, import_react22.useState)(null);
|
|
4888
4885
|
const previousPersistAsyncModel = usePrevious(persistAsyncModel);
|
|
@@ -4904,7 +4901,7 @@ var PersistAsyncBasicSchema = (props) => {
|
|
|
4904
4901
|
setFieldSubmitted(true);
|
|
4905
4902
|
try {
|
|
4906
4903
|
onEvent("Dynamic Flow - PersistAsync", { status: "pending", schemaId: allOf_default.$id });
|
|
4907
|
-
const persistAsyncFetch =
|
|
4904
|
+
const persistAsyncFetch = httpClient(persistAsyncSpec.url, {
|
|
4908
4905
|
method: persistAsyncSpec.method,
|
|
4909
4906
|
headers: { "Content-Type": "application/json" },
|
|
4910
4907
|
body: JSON.stringify(requestBody),
|
|
@@ -4978,7 +4975,7 @@ var PersistAsyncBasicSchema_default = PersistAsyncBasicSchema;
|
|
|
4978
4975
|
// src/common/hooks/usePersistAsync/usePersistAsync.ts
|
|
4979
4976
|
var usePersistAsync = (persistAsync) => {
|
|
4980
4977
|
const [abortController, setAbortController] = (0, import_react23.useState)(null);
|
|
4981
|
-
const
|
|
4978
|
+
const httpClient = useHttpClient();
|
|
4982
4979
|
const intl = (0, import_react_intl16.useIntl)();
|
|
4983
4980
|
const { schema: schema2 } = persistAsync;
|
|
4984
4981
|
async function handlePersistAsync(model) {
|
|
@@ -5010,7 +5007,7 @@ var usePersistAsync = (persistAsync) => {
|
|
|
5010
5007
|
}
|
|
5011
5008
|
async function performPersistAsync(payload) {
|
|
5012
5009
|
try {
|
|
5013
|
-
const response = await
|
|
5010
|
+
const response = await httpClient(persistAsync.url, constructFetchInit(payload));
|
|
5014
5011
|
if (!response.ok) {
|
|
5015
5012
|
return handleHTTPError(response);
|
|
5016
5013
|
}
|
|
@@ -5126,11 +5123,11 @@ var usePrevious = (value) => {
|
|
|
5126
5123
|
// src/common/hooks/useStepPolling/useStepPolling.tsx
|
|
5127
5124
|
var import_react26 = require("react");
|
|
5128
5125
|
function useStepPolling(polling, onAction) {
|
|
5129
|
-
const
|
|
5126
|
+
const httpClient = useHttpClient();
|
|
5130
5127
|
const asyncFn = (0, import_react26.useMemo)(() => {
|
|
5131
5128
|
if (polling) {
|
|
5132
5129
|
return () => {
|
|
5133
|
-
return
|
|
5130
|
+
return httpClient(polling.url).then((response) => {
|
|
5134
5131
|
if (response.ok) {
|
|
5135
5132
|
return response.json().then((pollingResponse) => pollingResponse).catch((error) => null);
|
|
5136
5133
|
} else {
|
|
@@ -5141,7 +5138,7 @@ function useStepPolling(polling, onAction) {
|
|
|
5141
5138
|
} else {
|
|
5142
5139
|
return void 0;
|
|
5143
5140
|
}
|
|
5144
|
-
}, [polling,
|
|
5141
|
+
}, [polling, httpClient]);
|
|
5145
5142
|
const onPollingResponse = (0, import_react26.useCallback)(
|
|
5146
5143
|
(pollingResponse) => {
|
|
5147
5144
|
if (pollingResponse == null ? void 0 : pollingResponse.action) {
|
|
@@ -6113,14 +6110,13 @@ var noop7 = () => {
|
|
|
6113
6110
|
};
|
|
6114
6111
|
var DynamicFlowComponent = ({
|
|
6115
6112
|
flowId,
|
|
6116
|
-
|
|
6113
|
+
httpClient,
|
|
6117
6114
|
flowUrl,
|
|
6118
6115
|
initialAction,
|
|
6119
6116
|
initialStep,
|
|
6120
6117
|
loaderConfig,
|
|
6121
6118
|
displayStepTitle = true,
|
|
6122
|
-
|
|
6123
|
-
onStepChange = noop7,
|
|
6119
|
+
onCompletion,
|
|
6124
6120
|
onError,
|
|
6125
6121
|
onEvent = noop7,
|
|
6126
6122
|
onLog = noop7
|
|
@@ -6160,7 +6156,7 @@ var DynamicFlowComponent = ({
|
|
|
6160
6156
|
const triggerActionRequest = (0, import_react35.useCallback)(
|
|
6161
6157
|
({ action: action2, data, etag: etag2 }) => {
|
|
6162
6158
|
const { url, method = "POST" } = action2;
|
|
6163
|
-
return
|
|
6159
|
+
return httpClient(url != null ? url : "", {
|
|
6164
6160
|
method,
|
|
6165
6161
|
headers: __spreadValues({
|
|
6166
6162
|
"accept-language": locale,
|
|
@@ -6171,7 +6167,7 @@ var DynamicFlowComponent = ({
|
|
|
6171
6167
|
body: method === "GET" ? void 0 : JSON.stringify(data)
|
|
6172
6168
|
});
|
|
6173
6169
|
},
|
|
6174
|
-
[
|
|
6170
|
+
[httpClient, locale]
|
|
6175
6171
|
);
|
|
6176
6172
|
const fetchNextStep = async (action2, data = {}) => {
|
|
6177
6173
|
setLoadingState(loadingState === "initial" ? "initial" : "submission");
|
|
@@ -6198,18 +6194,18 @@ var DynamicFlowComponent = ({
|
|
|
6198
6194
|
try {
|
|
6199
6195
|
const response = await triggerActionRequest({ action: action2, data });
|
|
6200
6196
|
const exitResult = await parseExitResponse(response);
|
|
6201
|
-
|
|
6197
|
+
dispatchEventAndComplete(__spreadValues(__spreadValues({}, exitResult), action2.result));
|
|
6202
6198
|
} catch (error) {
|
|
6203
6199
|
handleFetchError(error, "Error fetching exit result");
|
|
6204
6200
|
}
|
|
6205
6201
|
};
|
|
6206
6202
|
const debouncedFetchRefresh = useDebouncedRefresh(fetchRefreshStep);
|
|
6207
|
-
const
|
|
6203
|
+
const dispatchEventAndComplete = (0, import_react35.useCallback)(
|
|
6208
6204
|
(result) => {
|
|
6209
6205
|
dispatchEvent("Dynamic Flow - Flow Finished", { result: "success" });
|
|
6210
|
-
|
|
6206
|
+
onCompletion(result);
|
|
6211
6207
|
},
|
|
6212
|
-
[
|
|
6208
|
+
[onCompletion, dispatchEvent]
|
|
6213
6209
|
);
|
|
6214
6210
|
(0, import_react35.useEffect)(() => {
|
|
6215
6211
|
dispatchEvent("Dynamic Flow - Flow Started", {});
|
|
@@ -6222,7 +6218,7 @@ var DynamicFlowComponent = ({
|
|
|
6222
6218
|
}, initialAction);
|
|
6223
6219
|
void fetchNextStep(action2, action2.data);
|
|
6224
6220
|
}
|
|
6225
|
-
}, [flowUrl,
|
|
6221
|
+
}, [flowUrl, httpClient, locale, JSON.stringify(initialStep), JSON.stringify(initialAction)]);
|
|
6226
6222
|
const handleFetchResponse = async (response, fetchType) => {
|
|
6227
6223
|
if (response.ok) {
|
|
6228
6224
|
try {
|
|
@@ -6232,7 +6228,7 @@ var DynamicFlowComponent = ({
|
|
|
6232
6228
|
void fetchNextStep(parsedResponse.action, parsedResponse.action.data);
|
|
6233
6229
|
return;
|
|
6234
6230
|
case "exit":
|
|
6235
|
-
return
|
|
6231
|
+
return dispatchEventAndComplete(parsedResponse.result);
|
|
6236
6232
|
case "step":
|
|
6237
6233
|
default: {
|
|
6238
6234
|
const { step: step32, etag: etag2 } = parsedResponse;
|
|
@@ -6246,9 +6242,7 @@ var DynamicFlowComponent = ({
|
|
|
6246
6242
|
return handleErrorResponse(response, fetchType);
|
|
6247
6243
|
};
|
|
6248
6244
|
const updateStepAfterSubmission = (newStep, etag2) => {
|
|
6249
|
-
const previousStep = step31;
|
|
6250
6245
|
setStepAndEtag(newStep, etag2);
|
|
6251
|
-
onStepChange(newStep, previousStep);
|
|
6252
6246
|
setSubmitted(false);
|
|
6253
6247
|
setLoadingState("idle");
|
|
6254
6248
|
dispatchEvent("Dynamic Flow - Step Started", __spreadValues({ stepId: newStep.key }, newStep == null ? void 0 : newStep.analytics));
|
|
@@ -6350,7 +6344,7 @@ var DynamicFlowComponent = ({
|
|
|
6350
6344
|
}
|
|
6351
6345
|
return;
|
|
6352
6346
|
}
|
|
6353
|
-
|
|
6347
|
+
dispatchEventAndComplete(result);
|
|
6354
6348
|
return;
|
|
6355
6349
|
}
|
|
6356
6350
|
if (isSubmissionMethod(method)) {
|
|
@@ -6367,7 +6361,7 @@ var DynamicFlowComponent = ({
|
|
|
6367
6361
|
}
|
|
6368
6362
|
void fetchNextStep(action2);
|
|
6369
6363
|
};
|
|
6370
|
-
return /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(LogProvider, { flowId, stepId: step31 == null ? void 0 : step31.key, onLog, children: /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(EventsContextProvider, { metadata: analyticsMetadata, onEvent, children: /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(DynamicFlowProvider, { loading: loadingState !== "idle", children: /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(
|
|
6364
|
+
return /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(LogProvider, { flowId, stepId: step31 == null ? void 0 : step31.key, onLog, children: /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(EventsContextProvider, { metadata: analyticsMetadata, onEvent, children: /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(DynamicFlowProvider, { loading: loadingState !== "idle", children: /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(HttpClientProvider, { httpClient, children: loader !== null ? loader : /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(
|
|
6371
6365
|
DynamicFlowStep,
|
|
6372
6366
|
{
|
|
6373
6367
|
step: step31,
|
|
@@ -6521,7 +6515,7 @@ var step3 = {
|
|
|
6521
6515
|
...buttons,
|
|
6522
6516
|
{
|
|
6523
6517
|
type: "paragraph",
|
|
6524
|
-
text: "Press any buttons and see the
|
|
6518
|
+
text: "Press any buttons and see the httpClient calls below.",
|
|
6525
6519
|
align: "center"
|
|
6526
6520
|
}
|
|
6527
6521
|
]
|