@commercetools/ts-client 2.1.7 → 3.0.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @commercetools/ts-client
2
2
 
3
+ ## 3.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#902](https://github.com/commercetools/commercetools-sdk-typescript/pull/902) [`a08c782`](https://github.com/commercetools/commercetools-sdk-typescript/commit/a08c78267518c5010940a1f0887319225c8beb6d) Thanks [@ajimae](https://github.com/ajimae)! - remove buffer module and replace with js native String.normalize function
8
+
9
+ - [#841](https://github.com/commercetools/commercetools-sdk-typescript/pull/841) [`626c403`](https://github.com/commercetools/commercetools-sdk-typescript/commit/626c4035544c804db96a6e5f1c63f6ea9073c649) Thanks [@ajimae](https://github.com/ajimae)! - Improve README.md file
10
+
11
+ ## 3.0.0
12
+
13
+ ### Major Changes
14
+
15
+ - [#896](https://github.com/commercetools/commercetools-sdk-typescript/pull/896) [`f9b8cb6`](https://github.com/commercetools/commercetools-sdk-typescript/commit/f9b8cb605d99fe5ece13bdc3c152eb4818e19b3b) Thanks [@lojzatran](https://github.com/lojzatran)! - Remove support of nodejs 16
16
+
3
17
  ## 2.1.7
4
18
 
5
19
  ### Patch Changes
package/README.md CHANGED
@@ -23,10 +23,12 @@ import {
23
23
  type MiddlewareRequest,
24
24
  type MiddlewareResponse,
25
25
  type Client,
26
+ createHttpMiddleware,
27
+ createConcurrentModificationMiddleware,
28
+ createAuthMiddlewareForClientCredentialsFlow,
26
29
  ClientBuilder,
27
30
  } from '@commercetools/ts-client'
28
31
  import { createApiBuilderFromCtpClient } from '@commercetools/platform-sdk'
29
- import fetch from 'node-fetch'
30
32
 
31
33
  const projectKey = 'mc-project-key'
32
34
  const authMiddlewareOptions = {
@@ -50,7 +52,12 @@ const retryOptions = {
50
52
  maxRetries: 3,
51
53
  retryDelay: 200,
52
54
  backoff: true,
53
- retryCodes: [200],
55
+ retryCodes: [503],
56
+ }
57
+
58
+ const loggerFn = (response) => {
59
+ // log response object
60
+ console.log(response)
54
61
  }
55
62
 
56
63
  // custom middleware
@@ -68,15 +75,11 @@ function middleware(options) {
68
75
 
69
76
  const client: Client = new ClientBuilder()
70
77
  .withPasswordFlow(authMiddlewareOptions)
71
- .withLoggerMiddleware({
72
- includeOriginalRequest: false,
73
- includeResponseHeaders: false,
74
- })
78
+ .withLoggerMiddleware({ loggerFn })
75
79
  .withCorrelationIdMiddleware({
76
80
  generate: () => 'fake-correlation-id' + Math.floor(Math.random() + 2),
77
81
  })
78
82
  .withHttpMiddleware(httpMiddlewareOptions)
79
- .withRetryMiddleware(retryOptions)
80
83
  .withMiddleware(middleware({})) // <<<------------------- add the custom middleware here
81
84
  .build()
82
85
 
@@ -150,11 +153,13 @@ const client = new ClientBuilder()
150
153
  .build()
151
154
  ```
152
155
 
153
- > [!WARNING]
154
- > Do not add the built-in middlewares using `withMiddleware` method. Adding by this method does not respect the ordering of the middlewares and could lead to unexpected behavior.
156
+ <!-- > [!WARNING]
157
+ > Do not add the built-in middlewares using `withMiddleware` method. Adding by this method does not respect the ordering of the middlewares and could lead to unexpected behavior. -->
158
+
159
+ The `withMiddleware` method can be used to add middleware functions (both built-in and custom middleware) in an ordered fashion.
155
160
 
156
161
  ```ts
157
- // WRONG CODE!!!!!
162
+ // Example
158
163
  const authMiddlewareOptions = {
159
164
  credentials: {
160
165
  clientId: 'xxx',
@@ -169,12 +174,76 @@ const httpMiddlewareOptions = {
169
174
  httpClient: fetch,
170
175
  }
171
176
 
177
+ const logger = () => {
178
+ return (next) => async (request) => {
179
+ // log request object
180
+ console.log('Request:', request)
181
+ const response = await next(request)
182
+
183
+ // log response object
184
+ console.log('Response', response)
185
+ return response
186
+ }
187
+ }
188
+
172
189
  const client = new ClientBuilder()
173
190
  .withMiddleware(
174
191
  createAuthMiddlewareForClientCredentialsFlow(authMiddlewareOptions)
175
192
  )
176
193
  .withMiddleware(createHttpMiddleware(httpMiddlewareOptions))
177
194
  .withMiddleware(createConcurrentModificationMiddleware())
195
+ .withMiddleware(logger())
178
196
  .build()
179
- // WRONG CODE!!!!!
180
197
  ```
198
+
199
+ This will add the middleware in an ordered fashion starting with the:
200
+
201
+ 1. createAuthMiddlewareForClientCredentialsFlow
202
+ 2. createHttpMiddleware
203
+ 3. createConcurrentModificationMiddleware
204
+ 4. logger
205
+
206
+ Note that when using the `withMiddleware` function to add a custom middleware along side other in built middleware functions, it will add the custom middleware to the start of the execution chain.
207
+
208
+ ```ts
209
+ // Example
210
+ const authMiddlewareOptions = {
211
+ credentials: {
212
+ clientId: 'xxx',
213
+ clientSecret: 'xxx',
214
+ },
215
+ host: 'https://auth.europe-west1.gcp.commercetools.com',
216
+ projectKey: 'xxx',
217
+ }
218
+
219
+ const httpMiddlewareOptions = {
220
+ host: 'https://api.europe-west1.gcp.commercetools.com',
221
+ httpClient: fetch,
222
+ }
223
+
224
+ const logger = () => {
225
+ return (next) => async (request) => {
226
+ // log request object
227
+ console.log('Request:', request)
228
+ const response = await next(request)
229
+
230
+ // log response object
231
+ console.log('Response', response)
232
+ return response
233
+ }
234
+ }
235
+
236
+ const client = new ClientBuilder()
237
+ .withClientCredentialsFlow(authMiddlewareOptions)
238
+ .withHttpMiddleware(httpMiddlewareOptions)
239
+ .withConcurrentModificationMiddleware()
240
+ .withMiddleware(logger())
241
+ .build()
242
+ ```
243
+
244
+ The order of execution is as follows:
245
+
246
+ 1. withMiddleware <------ the custom middleware
247
+ 2. withClientCredentialsFlow
248
+ 3. withHttpMiddleware
249
+ 4. withConcurrentModificationMiddleware
@@ -2,14 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var fetch$1 = require('node-fetch');
6
- var AbortController = require('abort-controller');
7
-
8
- function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
9
-
10
- var fetch__default = /*#__PURE__*/_interopDefault(fetch$1);
11
- var AbortController__default = /*#__PURE__*/_interopDefault(AbortController);
12
-
13
5
  function _toPrimitive(t, r) {
14
6
  if ("object" != typeof t || !t) return t;
15
7
  var e = t[Symbol.toPrimitive];
@@ -35,10 +27,12 @@ function _defineProperty(e, r, t) {
35
27
  }) : e[r] = t, e;
36
28
  }
37
29
 
38
- var Buffer = require('buffer/').Buffer;
39
30
  function byteLength(body) {
40
- if (body && (typeof body === 'string' || body instanceof Uint8Array)) {
41
- return Buffer.byteLength(body).toString();
31
+ if (body && typeof body === 'string') {
32
+ return body.normalize('NFD').length.toString();
33
+ }
34
+ if (body && body instanceof Uint8Array) {
35
+ return new TextDecoder().decode(body).length.toString();
42
36
  }
43
37
  if (body && typeof body === 'object') {
44
38
  return new TextEncoder().encode(JSON.stringify(body)).length.toString();
@@ -192,7 +186,7 @@ async function executor(request) {
192
186
  });
193
187
  }
194
188
  function initializeAbortController() {
195
- const abortController = (getAbortController ? getAbortController() : null) || new AbortController__default["default"]();
189
+ const abortController = (getAbortController ? getAbortController() : null) || new AbortController();
196
190
  rest.abortController = abortController;
197
191
  rest.signal = abortController.signal;
198
192
  return abortController;
@@ -216,7 +210,9 @@ async function executor(request) {
216
210
  };
217
211
  }
218
212
  } catch (e) {
219
- if (e.name.includes('AbortError') && retryWhenAborted) {
213
+ // in nodejs v18, the error is AbortError, in nodejs v20, the error is TimeoutError
214
+ // https://github.com/nodejs/undici/issues/2590
215
+ if ((e.name.includes('AbortError') || e.name.includes('TimeoutError')) && retryWhenAborted) {
220
216
  return {
221
217
  _response: e,
222
218
  shouldRetry: true
@@ -313,7 +309,13 @@ function getHeaders(headers) {
313
309
 
314
310
  // Tmp fix for Firefox until it supports iterables
315
311
  if (!headers.forEach) return parse(headers);
316
- return headers.forEach((value, name) => value);
312
+
313
+ // whatwg-fetch
314
+ const map = {};
315
+ headers.forEach((value, name) => {
316
+ return map[name] = value;
317
+ });
318
+ return map;
317
319
  }
318
320
 
319
321
  function isBuffer(obj) {
@@ -760,7 +762,7 @@ function createAuthMiddlewareForAnonymousSessionFlow$1(options) {
760
762
  request,
761
763
  tokenCache,
762
764
  tokenCacheKey,
763
- httpClient: options.httpClient || fetch__default["default"],
765
+ httpClient: options.httpClient || fetch,
764
766
  httpClientOptions: options.httpClientOptions,
765
767
  ...buildRequestForAnonymousSessionFlow(options),
766
768
  userOption: options,
@@ -815,7 +817,7 @@ function createAuthMiddlewareForClientCredentialsFlow$1(options) {
815
817
  tokenCache,
816
818
  tokenCacheKey,
817
819
  tokenCacheObject,
818
- httpClient: options.httpClient || fetch__default["default"],
820
+ httpClient: options.httpClient || fetch,
819
821
  httpClientOptions: options.httpClientOptions,
820
822
  ...buildRequestForClientCredentialsFlow(options),
821
823
  next
@@ -891,7 +893,7 @@ function createAuthMiddlewareForPasswordFlow$1(options) {
891
893
  request,
892
894
  tokenCache,
893
895
  tokenCacheKey,
894
- httpClient: options.httpClient || fetch__default["default"],
896
+ httpClient: options.httpClient || fetch,
895
897
  httpClientOptions: options.httpClientOptions,
896
898
  ...buildRequestForPasswordFlow(options),
897
899
  userOption: options,
@@ -1271,9 +1273,9 @@ function createQueueMiddleware$1({
1271
1273
 
1272
1274
  var packageJson = {
1273
1275
  name: "@commercetools/ts-client",
1274
- version: "2.1.7",
1276
+ version: "3.0.1",
1275
1277
  engines: {
1276
- node: ">=14"
1278
+ node: ">=18"
1277
1279
  },
1278
1280
  description: "commercetools Composable Commerce TypeScript SDK client.",
1279
1281
  keywords: [
@@ -1304,9 +1306,7 @@ var packageJson = {
1304
1306
  url: "https://github.com/commercetools/commercetools-sdk-typescript/issues"
1305
1307
  },
1306
1308
  dependencies: {
1307
- "abort-controller": "3.0.0",
1308
- buffer: "^6.0.3",
1309
- "node-fetch": "^2.6.1"
1309
+ buffer: "^6.0.3"
1310
1310
  },
1311
1311
  files: [
1312
1312
  "dist",
@@ -1321,9 +1321,9 @@ var packageJson = {
1321
1321
  },
1322
1322
  devDependencies: {
1323
1323
  "common-tags": "1.8.2",
1324
- dotenv: "16.4.5",
1324
+ dotenv: "16.4.7",
1325
1325
  jest: "29.7.0",
1326
- nock: "12.0.3",
1326
+ nock: "^14.0.0-beta.19",
1327
1327
  "organize-imports-cli": "0.10.0"
1328
1328
  },
1329
1329
  scripts: {
@@ -1558,11 +1558,11 @@ class ClientBuilder {
1558
1558
  host: oauthUri,
1559
1559
  projectKey: projectKey || this.projectKey,
1560
1560
  credentials,
1561
- httpClient: httpClient || fetch__default["default"],
1561
+ httpClient: httpClient || fetch,
1562
1562
  scopes
1563
1563
  }).withHttpMiddleware({
1564
1564
  host: baseUri,
1565
- httpClient: httpClient || fetch__default["default"]
1565
+ httpClient: httpClient || fetch
1566
1566
  });
1567
1567
  }
1568
1568
  withAuthMiddleware(authMiddleware) {
@@ -1583,7 +1583,7 @@ class ClientBuilder {
1583
1583
  },
1584
1584
  oauthUri: options.oauthUri || null,
1585
1585
  scopes: options.scopes,
1586
- httpClient: options.httpClient || fetch__default["default"],
1586
+ httpClient: options.httpClient || fetch,
1587
1587
  ...options
1588
1588
  }));
1589
1589
  }
@@ -1599,7 +1599,7 @@ class ClientBuilder {
1599
1599
  password: options.credentials.user.password || null
1600
1600
  }
1601
1601
  },
1602
- httpClient: options.httpClient || fetch__default["default"],
1602
+ httpClient: options.httpClient || fetch,
1603
1603
  ...options
1604
1604
  }));
1605
1605
  }
@@ -1612,7 +1612,7 @@ class ClientBuilder {
1612
1612
  clientSecret: options.credentials.clientSecret || null,
1613
1613
  anonymousId: options.credentials.anonymousId || null
1614
1614
  },
1615
- httpClient: options.httpClient || fetch__default["default"],
1615
+ httpClient: options.httpClient || fetch,
1616
1616
  ...options
1617
1617
  }));
1618
1618
  }
@@ -1624,7 +1624,7 @@ class ClientBuilder {
1624
1624
  clientId: options.credentials.clientId || null,
1625
1625
  clientSecret: options.credentials.clientSecret || null
1626
1626
  },
1627
- httpClient: options.httpClient || fetch__default["default"],
1627
+ httpClient: options.httpClient || fetch,
1628
1628
  refreshToken: options.refreshToken || null,
1629
1629
  ...options
1630
1630
  }));
@@ -1638,7 +1638,7 @@ class ClientBuilder {
1638
1638
  withHttpMiddleware(options) {
1639
1639
  this.httpMiddleware = createHttpMiddleware({
1640
1640
  host: options.host || CTP_API_URL,
1641
- httpClient: options.httpClient || fetch__default["default"],
1641
+ httpClient: options.httpClient || fetch,
1642
1642
  ...options
1643
1643
  });
1644
1644
  return this;
@@ -1,6 +1,3 @@
1
- import fetch$1 from 'node-fetch';
2
- import AbortController from 'abort-controller';
3
-
4
1
  function _toPrimitive(t, r) {
5
2
  if ("object" != typeof t || !t) return t;
6
3
  var e = t[Symbol.toPrimitive];
@@ -26,10 +23,12 @@ function _defineProperty(e, r, t) {
26
23
  }) : e[r] = t, e;
27
24
  }
28
25
 
29
- var Buffer = require('buffer/').Buffer;
30
26
  function byteLength(body) {
31
- if (body && (typeof body === 'string' || body instanceof Uint8Array)) {
32
- return Buffer.byteLength(body).toString();
27
+ if (body && typeof body === 'string') {
28
+ return body.normalize('NFD').length.toString();
29
+ }
30
+ if (body && body instanceof Uint8Array) {
31
+ return new TextDecoder().decode(body).length.toString();
33
32
  }
34
33
  if (body && typeof body === 'object') {
35
34
  return new TextEncoder().encode(JSON.stringify(body)).length.toString();
@@ -207,7 +206,9 @@ async function executor(request) {
207
206
  };
208
207
  }
209
208
  } catch (e) {
210
- if (e.name.includes('AbortError') && retryWhenAborted) {
209
+ // in nodejs v18, the error is AbortError, in nodejs v20, the error is TimeoutError
210
+ // https://github.com/nodejs/undici/issues/2590
211
+ if ((e.name.includes('AbortError') || e.name.includes('TimeoutError')) && retryWhenAborted) {
211
212
  return {
212
213
  _response: e,
213
214
  shouldRetry: true
@@ -304,7 +305,13 @@ function getHeaders(headers) {
304
305
 
305
306
  // Tmp fix for Firefox until it supports iterables
306
307
  if (!headers.forEach) return parse(headers);
307
- return headers.forEach((value, name) => value);
308
+
309
+ // whatwg-fetch
310
+ const map = {};
311
+ headers.forEach((value, name) => {
312
+ return map[name] = value;
313
+ });
314
+ return map;
308
315
  }
309
316
 
310
317
  function isBuffer(obj) {
@@ -751,7 +758,7 @@ function createAuthMiddlewareForAnonymousSessionFlow$1(options) {
751
758
  request,
752
759
  tokenCache,
753
760
  tokenCacheKey,
754
- httpClient: options.httpClient || fetch$1,
761
+ httpClient: options.httpClient || fetch,
755
762
  httpClientOptions: options.httpClientOptions,
756
763
  ...buildRequestForAnonymousSessionFlow(options),
757
764
  userOption: options,
@@ -806,7 +813,7 @@ function createAuthMiddlewareForClientCredentialsFlow$1(options) {
806
813
  tokenCache,
807
814
  tokenCacheKey,
808
815
  tokenCacheObject,
809
- httpClient: options.httpClient || fetch$1,
816
+ httpClient: options.httpClient || fetch,
810
817
  httpClientOptions: options.httpClientOptions,
811
818
  ...buildRequestForClientCredentialsFlow(options),
812
819
  next
@@ -882,7 +889,7 @@ function createAuthMiddlewareForPasswordFlow$1(options) {
882
889
  request,
883
890
  tokenCache,
884
891
  tokenCacheKey,
885
- httpClient: options.httpClient || fetch$1,
892
+ httpClient: options.httpClient || fetch,
886
893
  httpClientOptions: options.httpClientOptions,
887
894
  ...buildRequestForPasswordFlow(options),
888
895
  userOption: options,
@@ -1262,9 +1269,9 @@ function createQueueMiddleware$1({
1262
1269
 
1263
1270
  var packageJson = {
1264
1271
  name: "@commercetools/ts-client",
1265
- version: "2.1.7",
1272
+ version: "3.0.1",
1266
1273
  engines: {
1267
- node: ">=14"
1274
+ node: ">=18"
1268
1275
  },
1269
1276
  description: "commercetools Composable Commerce TypeScript SDK client.",
1270
1277
  keywords: [
@@ -1295,9 +1302,7 @@ var packageJson = {
1295
1302
  url: "https://github.com/commercetools/commercetools-sdk-typescript/issues"
1296
1303
  },
1297
1304
  dependencies: {
1298
- "abort-controller": "3.0.0",
1299
- buffer: "^6.0.3",
1300
- "node-fetch": "^2.6.1"
1305
+ buffer: "^6.0.3"
1301
1306
  },
1302
1307
  files: [
1303
1308
  "dist",
@@ -1312,9 +1317,9 @@ var packageJson = {
1312
1317
  },
1313
1318
  devDependencies: {
1314
1319
  "common-tags": "1.8.2",
1315
- dotenv: "16.4.5",
1320
+ dotenv: "16.4.7",
1316
1321
  jest: "29.7.0",
1317
- nock: "12.0.3",
1322
+ nock: "^14.0.0-beta.19",
1318
1323
  "organize-imports-cli": "0.10.0"
1319
1324
  },
1320
1325
  scripts: {
@@ -1549,11 +1554,11 @@ class ClientBuilder {
1549
1554
  host: oauthUri,
1550
1555
  projectKey: projectKey || this.projectKey,
1551
1556
  credentials,
1552
- httpClient: httpClient || fetch$1,
1557
+ httpClient: httpClient || fetch,
1553
1558
  scopes
1554
1559
  }).withHttpMiddleware({
1555
1560
  host: baseUri,
1556
- httpClient: httpClient || fetch$1
1561
+ httpClient: httpClient || fetch
1557
1562
  });
1558
1563
  }
1559
1564
  withAuthMiddleware(authMiddleware) {
@@ -1574,7 +1579,7 @@ class ClientBuilder {
1574
1579
  },
1575
1580
  oauthUri: options.oauthUri || null,
1576
1581
  scopes: options.scopes,
1577
- httpClient: options.httpClient || fetch$1,
1582
+ httpClient: options.httpClient || fetch,
1578
1583
  ...options
1579
1584
  }));
1580
1585
  }
@@ -1590,7 +1595,7 @@ class ClientBuilder {
1590
1595
  password: options.credentials.user.password || null
1591
1596
  }
1592
1597
  },
1593
- httpClient: options.httpClient || fetch$1,
1598
+ httpClient: options.httpClient || fetch,
1594
1599
  ...options
1595
1600
  }));
1596
1601
  }
@@ -1603,7 +1608,7 @@ class ClientBuilder {
1603
1608
  clientSecret: options.credentials.clientSecret || null,
1604
1609
  anonymousId: options.credentials.anonymousId || null
1605
1610
  },
1606
- httpClient: options.httpClient || fetch$1,
1611
+ httpClient: options.httpClient || fetch,
1607
1612
  ...options
1608
1613
  }));
1609
1614
  }
@@ -1615,7 +1620,7 @@ class ClientBuilder {
1615
1620
  clientId: options.credentials.clientId || null,
1616
1621
  clientSecret: options.credentials.clientSecret || null
1617
1622
  },
1618
- httpClient: options.httpClient || fetch$1,
1623
+ httpClient: options.httpClient || fetch,
1619
1624
  refreshToken: options.refreshToken || null,
1620
1625
  ...options
1621
1626
  }));
@@ -1629,7 +1634,7 @@ class ClientBuilder {
1629
1634
  withHttpMiddleware(options) {
1630
1635
  this.httpMiddleware = createHttpMiddleware({
1631
1636
  host: options.host || CTP_API_URL,
1632
- httpClient: options.httpClient || fetch$1,
1637
+ httpClient: options.httpClient || fetch,
1633
1638
  ...options
1634
1639
  });
1635
1640
  return this;
@@ -2,14 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var fetch$1 = require('node-fetch');
6
- var AbortController = require('abort-controller');
7
-
8
- function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
9
-
10
- var fetch__default = /*#__PURE__*/_interopDefault(fetch$1);
11
- var AbortController__default = /*#__PURE__*/_interopDefault(AbortController);
12
-
13
5
  function _toPrimitive(t, r) {
14
6
  if ("object" != typeof t || !t) return t;
15
7
  var e = t[Symbol.toPrimitive];
@@ -35,10 +27,12 @@ function _defineProperty(e, r, t) {
35
27
  }) : e[r] = t, e;
36
28
  }
37
29
 
38
- var Buffer = require('buffer/').Buffer;
39
30
  function byteLength(body) {
40
- if (body && (typeof body === 'string' || body instanceof Uint8Array)) {
41
- return Buffer.byteLength(body).toString();
31
+ if (body && typeof body === 'string') {
32
+ return body.normalize('NFD').length.toString();
33
+ }
34
+ if (body && body instanceof Uint8Array) {
35
+ return new TextDecoder().decode(body).length.toString();
42
36
  }
43
37
  if (body && typeof body === 'object') {
44
38
  return new TextEncoder().encode(JSON.stringify(body)).length.toString();
@@ -192,7 +186,7 @@ async function executor(request) {
192
186
  });
193
187
  }
194
188
  function initializeAbortController() {
195
- const abortController = (getAbortController ? getAbortController() : null) || new AbortController__default["default"]();
189
+ const abortController = (getAbortController ? getAbortController() : null) || new AbortController();
196
190
  rest.abortController = abortController;
197
191
  rest.signal = abortController.signal;
198
192
  return abortController;
@@ -216,7 +210,9 @@ async function executor(request) {
216
210
  };
217
211
  }
218
212
  } catch (e) {
219
- if (e.name.includes('AbortError') && retryWhenAborted) {
213
+ // in nodejs v18, the error is AbortError, in nodejs v20, the error is TimeoutError
214
+ // https://github.com/nodejs/undici/issues/2590
215
+ if ((e.name.includes('AbortError') || e.name.includes('TimeoutError')) && retryWhenAborted) {
220
216
  return {
221
217
  _response: e,
222
218
  shouldRetry: true
@@ -313,7 +309,13 @@ function getHeaders(headers) {
313
309
 
314
310
  // Tmp fix for Firefox until it supports iterables
315
311
  if (!headers.forEach) return parse(headers);
316
- return headers.forEach((value, name) => value);
312
+
313
+ // whatwg-fetch
314
+ const map = {};
315
+ headers.forEach((value, name) => {
316
+ return map[name] = value;
317
+ });
318
+ return map;
317
319
  }
318
320
 
319
321
  function isBuffer(obj) {
@@ -760,7 +762,7 @@ function createAuthMiddlewareForAnonymousSessionFlow$1(options) {
760
762
  request,
761
763
  tokenCache,
762
764
  tokenCacheKey,
763
- httpClient: options.httpClient || fetch__default["default"],
765
+ httpClient: options.httpClient || fetch,
764
766
  httpClientOptions: options.httpClientOptions,
765
767
  ...buildRequestForAnonymousSessionFlow(options),
766
768
  userOption: options,
@@ -815,7 +817,7 @@ function createAuthMiddlewareForClientCredentialsFlow$1(options) {
815
817
  tokenCache,
816
818
  tokenCacheKey,
817
819
  tokenCacheObject,
818
- httpClient: options.httpClient || fetch__default["default"],
820
+ httpClient: options.httpClient || fetch,
819
821
  httpClientOptions: options.httpClientOptions,
820
822
  ...buildRequestForClientCredentialsFlow(options),
821
823
  next
@@ -891,7 +893,7 @@ function createAuthMiddlewareForPasswordFlow$1(options) {
891
893
  request,
892
894
  tokenCache,
893
895
  tokenCacheKey,
894
- httpClient: options.httpClient || fetch__default["default"],
896
+ httpClient: options.httpClient || fetch,
895
897
  httpClientOptions: options.httpClientOptions,
896
898
  ...buildRequestForPasswordFlow(options),
897
899
  userOption: options,
@@ -1271,9 +1273,9 @@ function createQueueMiddleware$1({
1271
1273
 
1272
1274
  var packageJson = {
1273
1275
  name: "@commercetools/ts-client",
1274
- version: "2.1.7",
1276
+ version: "3.0.1",
1275
1277
  engines: {
1276
- node: ">=14"
1278
+ node: ">=18"
1277
1279
  },
1278
1280
  description: "commercetools Composable Commerce TypeScript SDK client.",
1279
1281
  keywords: [
@@ -1304,9 +1306,7 @@ var packageJson = {
1304
1306
  url: "https://github.com/commercetools/commercetools-sdk-typescript/issues"
1305
1307
  },
1306
1308
  dependencies: {
1307
- "abort-controller": "3.0.0",
1308
- buffer: "^6.0.3",
1309
- "node-fetch": "^2.6.1"
1309
+ buffer: "^6.0.3"
1310
1310
  },
1311
1311
  files: [
1312
1312
  "dist",
@@ -1321,9 +1321,9 @@ var packageJson = {
1321
1321
  },
1322
1322
  devDependencies: {
1323
1323
  "common-tags": "1.8.2",
1324
- dotenv: "16.4.5",
1324
+ dotenv: "16.4.7",
1325
1325
  jest: "29.7.0",
1326
- nock: "12.0.3",
1326
+ nock: "^14.0.0-beta.19",
1327
1327
  "organize-imports-cli": "0.10.0"
1328
1328
  },
1329
1329
  scripts: {
@@ -1558,11 +1558,11 @@ class ClientBuilder {
1558
1558
  host: oauthUri,
1559
1559
  projectKey: projectKey || this.projectKey,
1560
1560
  credentials,
1561
- httpClient: httpClient || fetch__default["default"],
1561
+ httpClient: httpClient || fetch,
1562
1562
  scopes
1563
1563
  }).withHttpMiddleware({
1564
1564
  host: baseUri,
1565
- httpClient: httpClient || fetch__default["default"]
1565
+ httpClient: httpClient || fetch
1566
1566
  });
1567
1567
  }
1568
1568
  withAuthMiddleware(authMiddleware) {
@@ -1583,7 +1583,7 @@ class ClientBuilder {
1583
1583
  },
1584
1584
  oauthUri: options.oauthUri || null,
1585
1585
  scopes: options.scopes,
1586
- httpClient: options.httpClient || fetch__default["default"],
1586
+ httpClient: options.httpClient || fetch,
1587
1587
  ...options
1588
1588
  }));
1589
1589
  }
@@ -1599,7 +1599,7 @@ class ClientBuilder {
1599
1599
  password: options.credentials.user.password || null
1600
1600
  }
1601
1601
  },
1602
- httpClient: options.httpClient || fetch__default["default"],
1602
+ httpClient: options.httpClient || fetch,
1603
1603
  ...options
1604
1604
  }));
1605
1605
  }
@@ -1612,7 +1612,7 @@ class ClientBuilder {
1612
1612
  clientSecret: options.credentials.clientSecret || null,
1613
1613
  anonymousId: options.credentials.anonymousId || null
1614
1614
  },
1615
- httpClient: options.httpClient || fetch__default["default"],
1615
+ httpClient: options.httpClient || fetch,
1616
1616
  ...options
1617
1617
  }));
1618
1618
  }
@@ -1624,7 +1624,7 @@ class ClientBuilder {
1624
1624
  clientId: options.credentials.clientId || null,
1625
1625
  clientSecret: options.credentials.clientSecret || null
1626
1626
  },
1627
- httpClient: options.httpClient || fetch__default["default"],
1627
+ httpClient: options.httpClient || fetch,
1628
1628
  refreshToken: options.refreshToken || null,
1629
1629
  ...options
1630
1630
  }));
@@ -1638,7 +1638,7 @@ class ClientBuilder {
1638
1638
  withHttpMiddleware(options) {
1639
1639
  this.httpMiddleware = createHttpMiddleware({
1640
1640
  host: options.host || CTP_API_URL,
1641
- httpClient: options.httpClient || fetch__default["default"],
1641
+ httpClient: options.httpClient || fetch,
1642
1642
  ...options
1643
1643
  });
1644
1644
  return this;