@wise/dynamic-flow-client-internal 0.3.4 → 0.4.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 +16 -16
- package/build/main.js +1279 -1280
- package/build/main.min.js +3 -3
- package/build/types/index.d.ts +2 -2
- package/build/types/stories/fixtureHttpClient.d.ts +3 -0
- package/build/types/test-utils/NeptuneProviders.d.ts +5 -0
- package/build/types/test-utils/rtl-utils.d.ts +2 -0
- package/package.json +3 -2
- package/build/types/stories/fixtureFetcher.d.ts +0 -3
package/README.md
CHANGED
|
@@ -84,8 +84,8 @@ DF can be initialised with `initialAction` (recommended) or with an `initialStep
|
|
|
84
84
|
```tsx
|
|
85
85
|
<DynamicFlow
|
|
86
86
|
initialAction={{ method: 'GET', url: '/my-amazing-new-flow' }}
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
httpClient={(...args) => fetch(...args)}
|
|
88
|
+
onCompletion={(result) => {
|
|
89
89
|
console.log('Flow exited with', result);
|
|
90
90
|
}}
|
|
91
91
|
onError={(error, statusCode) => {
|
|
@@ -101,39 +101,39 @@ In some cases you may want to obtain the initial step yourself, and then pass it
|
|
|
101
101
|
```tsx
|
|
102
102
|
<DynamicFlow
|
|
103
103
|
initialStep={someInitialStep}
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
httpClient={...}
|
|
105
|
+
onCompletion={...}
|
|
106
106
|
onError={...}
|
|
107
107
|
/>
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
-
### The `
|
|
110
|
+
### The `httpClient`
|
|
111
111
|
|
|
112
|
-
You must pass
|
|
112
|
+
You must pass an http client. This can be `window.fetch` itself or some wrapper function where you inject authorisation headers and anything else you many need.
|
|
113
113
|
|
|
114
|
-
You can take advantage of the `
|
|
114
|
+
You can take advantage of the `makeHttpClient` utility function. This function takes a `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, such as `{ 'X-Access-Token': 'Tr4n5f3rw153' }`:
|
|
115
115
|
|
|
116
116
|
```tsx
|
|
117
|
-
import {
|
|
117
|
+
import { makeHttpClient, DynamicFlow } from '@wise/dynamic-flow-client';
|
|
118
118
|
|
|
119
|
-
const
|
|
119
|
+
const myHttpClient = makeHttpClient('/my-base-url', { 'X-Access-Token': 'Tr4n5f3rw153' });
|
|
120
120
|
|
|
121
121
|
...
|
|
122
122
|
|
|
123
123
|
<DynamicFlow
|
|
124
124
|
initialAction={{ method: 'GET', url: '/my-amazing-new-flow' }}
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
httpClient={myHttpClient}
|
|
126
|
+
onCompletion={...}
|
|
127
127
|
onError={...}
|
|
128
128
|
/>
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
-
####
|
|
131
|
+
#### Using a custom `httpClient`
|
|
132
132
|
|
|
133
|
-
If you want to write your own
|
|
133
|
+
If you want to write your own `httpClient` (or if you're writing mocks), it's important that you return proper `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:
|
|
134
134
|
|
|
135
135
|
```tsx
|
|
136
|
-
const
|
|
136
|
+
const mockHttpClient = (input, init) => {
|
|
137
137
|
switch (input) {
|
|
138
138
|
case '/standard':
|
|
139
139
|
return Promise.resolve(new Response(init.body));
|
|
@@ -150,12 +150,12 @@ Also, please make sure your mocks return a new `Response` instace every time. Th
|
|
|
150
150
|
```ts
|
|
151
151
|
const initialResponse = new Response(JSON.stringify(initialStep));
|
|
152
152
|
// ❌ wrong - the same instance is returned on each request
|
|
153
|
-
const
|
|
153
|
+
const mockHttpClient = (input, init) => Promise.resolve(initialResponse);
|
|
154
154
|
```
|
|
155
155
|
|
|
156
156
|
```ts
|
|
157
157
|
// ✅ correct - a new instance is returned on each request
|
|
158
|
-
const
|
|
158
|
+
const mockHttpClient = (input, init) => Promise.resolve(new Response(JSON.stringify(initialStep)));
|
|
159
159
|
```
|
|
160
160
|
|
|
161
161
|
### Telemetry
|