@wise/dynamic-flow-client-internal 0.3.5 → 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 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
- fetcher={(...args) => fetch(...args)}
88
- onComplete={(result) => {
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
- fetcher={...}
105
- onComplete={...}
104
+ httpClient={...}
105
+ onCompletion={...}
106
106
  onError={...}
107
107
  />
108
108
  ```
109
109
 
110
- ### The `fetcher` function prop
110
+ ### The `httpClient`
111
111
 
112
- You must pass a fetcher function. This can be `window.fetch` itself or some wrapper function where you inject authorisation headers and anything else you many need.
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 `makeFetcher` 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' }`:
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 { makeFetcher, DynamicFlow } from '@wise/dynamic-flow-client';
117
+ import { makeHttpClient, DynamicFlow } from '@wise/dynamic-flow-client';
118
118
 
119
- const myFetcher = makeFetcher('/my-base-url', { 'X-Access-Token': 'Tr4n5f3rw153' });
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
- fetcher={myFetcher}
126
- onComplete={...}
125
+ httpClient={myHttpClient}
126
+ onCompletion={...}
127
127
  onError={...}
128
128
  />
129
129
  ```
130
130
 
131
- #### Custom `fetcher` functions
131
+ #### Using a custom `httpClient`
132
132
 
133
- If you want to write your own fetcher function (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:
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 mockFetcher = (input, init) => {
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 mockFetcher = (input, init) => Promise.resolve(initialResponse);
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 mockFetcher = (input, init) => Promise.resolve(new Response(JSON.stringify(initialStep)));
158
+ const mockHttpClient = (input, init) => Promise.resolve(new Response(JSON.stringify(initialStep)));
159
159
  ```
160
160
 
161
161
  ### Telemetry