Skip to content

Commit 4b70e61

Browse files
authored
chore(updates): update sdk-middleware-http package version to laatest (#1721)
- add documentation for new changes to sdk-middleware-auth
1 parent 9fadb17 commit 4b70e61

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

docs/sdk/api/sdkMiddlewareAuth.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Creates a [middleware](/sdk/Glossary.md#middleware) to handle authentication for
3030
3. `credentials` _(Object)_: the client credentials for authentication (`clientId`, `clientSecret`)
3131
4. `scopes` _(Array)_: a list of [scopes](https://docs.commercetools.com/http-api-authorization.html#scopes) (default `manage_project:{projectKey}`) to assign to the OAuth token
3232
5. `fetch` _(Function)_: A `fetch` implementation which can be e.g. `node-fetch` or `unfetch` but also the native browser `fetch` function. Only needs be be passed if not globally available (e.g. through `isomorphic-fetch`)
33+
6. `timeout` _(Number)_: An optional number value (in milliseconds) which specifies when a request should timeout if authentication request fails to complete.
34+
7. `getAbortController` _(Function)_: An optional abortController class instance that should signal the http-client to abandon the current request instance.
3335

3436
#### Usage example
3537

@@ -50,6 +52,8 @@ const client = createClient({
5052

5153
// Optional if not globally available
5254
fetch,
55+
timeout: 10000, // timeout the request if it doesn't complete in 10000ms or 10 seconds
56+
getAbortController: () => new AbortController(),
5357
}),
5458
],
5559
})
@@ -69,6 +73,8 @@ Creates a [middleware](/sdk/Glossary.md#middleware) to handle authentication for
6973

7074
4. `scopes` _(Array)_: a list of [scopes](https://docs.commercetools.com/http-api-authorization.html#scopes) to assign to the OAuth token. _No default scope is sent_
7175
5. `fetch` _(Function)_: A `fetch` implementation which can be e.g. `node-fetch` or `unfetch` but also the native browser `fetch` function. Only needs be be passed if not globally available (e.g. through `isomorphic-fetch`)
76+
6. `timeout` _(Number)_: An optional number value (in milliseconds) which specifies when a request should timeout if authentication request fails to complete.
77+
7. `getAbortController` _(Function)_: An optional abortController class instance that should signal the http-client to abandon the current request instance.
7278

7379
#### Usage example
7480

@@ -93,6 +99,8 @@ const client = createClient({
9399

94100
// Optional if not globally available
95101
fetch,
102+
timeout: 10000, // timeout the request if it doesn't complete in 10000ms or 10 seconds
103+
getAbortController: () => new AbortController(),
96104
}),
97105
],
98106
})
@@ -109,6 +117,8 @@ Creates a [middleware](/sdk/Glossary.md#middleware) to handle authentication for
109117
3. `credentials` _(Object)_: the client credentials for authentication (`clientId`, `clientSecret`, `anonymousId`)
110118
4. `scopes` _(Array)_: a list of [scopes](https://docs.commercetools.com/http-api-authorization.html#scopes) (default `manage_project:{projectKey}`) to assign to the OAuth token
111119
5. `fetch` _(Function)_: A `fetch` implementation which can be e.g. `node-fetch` or `unfetch` but also the native browser `fetch` function. Only needs be be passed if not globally available (e.g. through `isomorphic-fetch`)
120+
6. `timeout` _(Number)_: An optional number value (in milliseconds) which specifies when a request should timeout if authentication request fails to complete.
121+
7. `getAbortController` _(Function)_: An optional abortController class instance that should signal the http-client to abandon the current request instance.
112122

113123
#### Usage example
114124

@@ -130,6 +140,8 @@ const client = createClient({
130140

131141
// Optional if not globally available
132142
fetch,
143+
timeout: 10000, // timeout the request if it doesn't complete in 10000ms or 10 seconds
144+
getAbortController: () => new AbortController(),
133145
}),
134146
],
135147
})
@@ -146,6 +158,8 @@ Creates a [middleware](/sdk/Glossary.md#middleware) to handle authentication for
146158
3. `credentials` _(Object)_: the client credentials for authentication (`clientId`, `clientSecret`)
147159
4. `refreshToken` _(String)_: refreshToken from the API to use to fetch new token.
148160
5. `fetch` _(Function)_: A `fetch` implementation which can be e.g. `node-fetch` or `unfetch` but also the native browser `fetch` function. Only needs be be passed if not globally available (e.g. through `isomorphic-fetch`)
161+
6. `timeout` _(Number)_: An optional number value (in milliseconds) which specifies when a request should timeout if authentication request fails to complete.
162+
7. `getAbortController` _(Function)_: An optional abortController class instance that should signal the http-client to abandon the current request instance.
149163

150164
#### Usage example
151165

@@ -166,6 +180,8 @@ const client = createClient({
166180

167181
// Optional if not globally available
168182
fetch,
183+
timeout: 10000, // timeout the request if it doesn't complete in 10000ms or 10 seconds
184+
getAbortController: () => new AbortController(),
169185
}),
170186
],
171187
})
@@ -182,6 +198,10 @@ Creates a [middleware](/sdk/Glossary.md#middleware) that attaches a provided acc
182198
`options` is an optional _(Object)_, having the following properties:
183199

184200
1. `force` _(Boolean)_: if set to true, existing Authorization header (if any) in the request will be overridden with the supplied access token (Default: `true`)
201+
2. `timeout` _(Number)_: An optional number value (in milliseconds) which specifies when a request should timeout if authentication request fails to complete.
202+
3. `getAbortController` _(Function)_: An optional abortController class instance that should signal the http-client to abandon the current request instance.
203+
204+
**Note**: if timeout is specified, then it's mandatory to also specify the getAbortController property.
185205

186206
```js
187207
import { createClient } from '@commercetools/sdk-client'
@@ -193,6 +213,8 @@ const client = createClient({
193213
middlewares: [
194214
createAuthMiddlewareWithExistingToken(`Bearer ${accessToken}`, {
195215
force: true,
216+
timeout: 10000, // timeout the request if it doesn't complete in 10000ms or 10 seconds
217+
getAbortController: () => new AbortController(),
196218
}),
197219
],
198220
})

packages/sdk-middleware-auth/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Auth middlewares collection for usage with `@commercetools/sdk-client`
44

55
https://commercetools.github.io/nodejs/sdk/api/sdkMiddlewareAuth.html
66

7-
## Install
7+
### Install
88

99
```bash
1010
npm install --save @commercetools/sdk-middleware-auth

packages/sdk-middleware-http/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"access": "public"
55
},
66
"name": "@commercetools/sdk-middleware-http",
7-
"version": "6.0.11",
7+
"version": "6.1.0",
88
"description": "Middleware for http requests, to use with @commercetools/sdk-client",
99
"keywords": [
1010
"commercetools",

0 commit comments

Comments
 (0)