@commercetools/ts-client 2.1.0-alpha.1 → 2.1.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,17 @@
1
1
  # @commercetools/ts-client
2
2
 
3
+ ## 2.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#835](https://github.com/commercetools/commercetools-sdk-typescript/pull/835) [`b2c62ba`](https://github.com/commercetools/commercetools-sdk-typescript/commit/b2c62ba105b7fb9fe2eb6a4ae1b95c8d5b67d428) Thanks [@ajimae](https://github.com/ajimae)! - Fix issues with counting special characters' length
8
+
9
+ ## 2.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#814](https://github.com/commercetools/commercetools-sdk-typescript/pull/814) [`57a16d7`](https://github.com/commercetools/commercetools-sdk-typescript/commit/57a16d75ded60923bf080ef2270c3396fe8bc0e5) Thanks [@ajimae](https://github.com/ajimae)! - Restructure middleware logic
14
+
3
15
  ## 2.0.5
4
16
 
5
17
  ### Patch Changes
@@ -35,6 +35,17 @@ function _defineProperty(e, r, t) {
35
35
  }) : e[r] = t, e;
36
36
  }
37
37
 
38
+ var Buffer = require('buffer/').Buffer;
39
+ function byteLength(body) {
40
+ if (body && (typeof body === 'string' || body instanceof Uint8Array)) {
41
+ return Buffer.byteLength(body).toString();
42
+ }
43
+ if (body && typeof body === 'object') {
44
+ return new TextEncoder().encode(JSON.stringify(body)).length.toString();
45
+ }
46
+ return '0';
47
+ }
48
+
38
49
  const HEADERS_CONTENT_TYPES = ['application/json', 'application/graphql'];
39
50
  const CONCURRENCT_REQUEST = 20;
40
51
  const CTP_API_URL = 'https://api.europe-west1.gcp.commercetools.com';
@@ -259,16 +270,9 @@ async function executor(request) {
259
270
  return data;
260
271
  }
261
272
 
262
- // import { v4 as uuidv4 } from 'uuid'
263
-
264
- // export default function generateID() {
265
- // return uuidv4()
266
- // }
267
-
268
273
  function generateID() {
269
274
  // @ts-ignore
270
- const str = ([1e6] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16));
271
- return 'abcdef'[Math.floor(Math.random() * 'abcdef'.length)] + '' + str;
275
+ return ([1e6] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (parseInt(c) ^ Math.floor(Math.random() * 256) & 15 >> parseInt(c) / 4).toString(16));
272
276
  }
273
277
 
274
278
  function parse(headers) {
@@ -457,13 +461,6 @@ function createUserAgent(options) {
457
461
  return [baseInfo, systemInfo, libraryInfo, contactInfo, customAgent].filter(Boolean).join(' ');
458
462
  }
459
463
 
460
- function byteLength(body) {
461
- if (typeof body === 'string') return body.length.toString();
462
- if (body && typeof body === 'object') return new TextEncoder().encode(JSON.stringify(body)).length.toString();
463
- if (body instanceof Uint8Array) return body.length.toString();
464
- return '0';
465
- }
466
-
467
464
  /**
468
465
  * validate some essential http options
469
466
  * @param options
@@ -751,11 +748,9 @@ function createAuthMiddlewareForAnonymousSessionFlow$1(options) {
751
748
  tokenFetchPromise = null;
752
749
  }
753
750
 
754
- // Now the token is present in the tokenCache
751
+ // Now the token is present in the tokenCache and can be accessed
755
752
  tokenCacheObject = tokenCache.get(tokenCacheKey);
756
- if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
757
- return next(mergeAuthHeader(tokenCacheObject.token, request));
758
- }
753
+ return next(mergeAuthHeader(tokenCacheObject.token, request));
759
754
  };
760
755
  };
761
756
  }
@@ -808,9 +803,7 @@ function createAuthMiddlewareForClientCredentialsFlow$1(options) {
808
803
 
809
804
  // Now the token is present in the tokenCache
810
805
  tokenCacheObject = tokenCache.get(tokenCacheKey);
811
- if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
812
- return next(mergeAuthHeader(tokenCacheObject.token, request));
813
- }
806
+ return next(mergeAuthHeader(tokenCacheObject.token, request));
814
807
  };
815
808
  };
816
809
  }
@@ -886,9 +879,7 @@ function createAuthMiddlewareForPasswordFlow$1(options) {
886
879
 
887
880
  // Now the token is present in the tokenCache
888
881
  tokenCacheObject = tokenCache.get(tokenCacheKey);
889
- if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
890
- return next(mergeAuthHeader(tokenCacheObject.token, request));
891
- }
882
+ return next(mergeAuthHeader(tokenCacheObject.token, request));
892
883
  };
893
884
  };
894
885
  }
@@ -937,9 +928,7 @@ function createAuthMiddlewareForRefreshTokenFlow$1(options) {
937
928
 
938
929
  // Now the token is present in the tokenCache
939
930
  tokenCacheObject = tokenCache.get(tokenCacheKey);
940
- if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
941
- return next(mergeAuthHeader(tokenCacheObject.token, request));
942
- }
931
+ return next(mergeAuthHeader(tokenCacheObject.token, request));
943
932
  };
944
933
  };
945
934
  }
@@ -958,7 +947,7 @@ function createConcurrentModificationMiddleware$1(modifierFunction) {
958
947
 
959
948
  // update the resource version here
960
949
  if (version) {
961
- if (modifierFunction) {
950
+ if (modifierFunction && typeof modifierFunction == 'function') {
962
951
  request.body = await modifierFunction(version, request, response);
963
952
  } else {
964
953
  request.body = typeof request.body == 'string' ? {
@@ -1212,8 +1201,8 @@ function createQueueMiddleware$1({
1212
1201
  concurrency = 20
1213
1202
  }) {
1214
1203
  let runningCount = 0;
1204
+ const queue = [];
1215
1205
  const waitForSlot = () => {
1216
- // dont allow negative or 0 value for concurrency
1217
1206
  if (0 >= concurrency) return Promise.resolve();
1218
1207
  return new Promise(resolve => {
1219
1208
  const tryNext = () => {
@@ -1221,43 +1210,48 @@ function createQueueMiddleware$1({
1221
1210
  runningCount++;
1222
1211
  resolve();
1223
1212
  } else {
1224
- // Retry until a slot becomes available
1225
- setTimeout(tryNext, 10);
1213
+ queue.push(tryNext);
1226
1214
  }
1227
1215
  };
1228
-
1229
- // start
1230
1216
  tryNext();
1231
1217
  });
1232
1218
  };
1233
- return next => {
1234
- return async request => {
1235
- return waitForSlot().then(async () => {
1236
- // Patch the request to override resolve and reject
1237
- const patchedRequest = {
1238
- ...request,
1239
- resolve(data) {
1240
- request.resolve(data);
1241
- runningCount--;
1242
- },
1243
- reject(error) {
1244
- request.reject(error);
1245
- runningCount--;
1246
- }
1247
- };
1248
- try {
1249
- return next(patchedRequest);
1250
- } finally {
1251
- runningCount--;
1219
+
1220
+ // Function to free up a slot after a request is completed
1221
+ const freeSlot = () => {
1222
+ runningCount--;
1223
+ if (queue.length > 0) {
1224
+ const nextInQueue = queue.shift();
1225
+ if (nextInQueue) {
1226
+ nextInQueue();
1227
+ }
1228
+ }
1229
+ };
1230
+ return next => request => {
1231
+ return waitForSlot().then(() => {
1232
+ const patchedRequest = {
1233
+ ...request,
1234
+ resolve(data) {
1235
+ request.resolve(data);
1236
+ freeSlot();
1237
+ },
1238
+ reject(error) {
1239
+ request.reject(error);
1240
+ freeSlot();
1252
1241
  }
1242
+ };
1243
+
1244
+ // Process the next middleware
1245
+ return next(patchedRequest).finally(() => {
1246
+ freeSlot();
1253
1247
  });
1254
- };
1248
+ });
1255
1249
  };
1256
1250
  }
1257
1251
 
1258
1252
  var packageJson = {
1259
1253
  name: "@commercetools/ts-client",
1260
- version: "2.1.0-alpha.1",
1254
+ version: "2.1.1",
1261
1255
  engines: {
1262
1256
  node: ">=14"
1263
1257
  },
@@ -1291,14 +1285,12 @@ var packageJson = {
1291
1285
  },
1292
1286
  dependencies: {
1293
1287
  "abort-controller": "3.0.0",
1288
+ buffer: "^6.0.3",
1294
1289
  "node-fetch": "^2.6.1"
1295
1290
  },
1296
1291
  files: [
1297
1292
  "dist",
1298
- "CHANGELOG.md",
1299
- "LICENSE",
1300
- "README.md",
1301
- "package.json"
1293
+ "CHANGELOG.md"
1302
1294
  ],
1303
1295
  author: "Chukwuemeka Ajima <meeky.ae@gmail.com>",
1304
1296
  main: "dist/commercetools-ts-client.cjs.js",
@@ -26,6 +26,17 @@ function _defineProperty(e, r, t) {
26
26
  }) : e[r] = t, e;
27
27
  }
28
28
 
29
+ var Buffer = require('buffer/').Buffer;
30
+ function byteLength(body) {
31
+ if (body && (typeof body === 'string' || body instanceof Uint8Array)) {
32
+ return Buffer.byteLength(body).toString();
33
+ }
34
+ if (body && typeof body === 'object') {
35
+ return new TextEncoder().encode(JSON.stringify(body)).length.toString();
36
+ }
37
+ return '0';
38
+ }
39
+
29
40
  const HEADERS_CONTENT_TYPES = ['application/json', 'application/graphql'];
30
41
  const CONCURRENCT_REQUEST = 20;
31
42
  const CTP_API_URL = 'https://api.europe-west1.gcp.commercetools.com';
@@ -250,16 +261,9 @@ async function executor(request) {
250
261
  return data;
251
262
  }
252
263
 
253
- // import { v4 as uuidv4 } from 'uuid'
254
-
255
- // export default function generateID() {
256
- // return uuidv4()
257
- // }
258
-
259
264
  function generateID() {
260
265
  // @ts-ignore
261
- const str = ([1e6] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16));
262
- return 'abcdef'[Math.floor(Math.random() * 'abcdef'.length)] + '' + str;
266
+ return ([1e6] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (parseInt(c) ^ Math.floor(Math.random() * 256) & 15 >> parseInt(c) / 4).toString(16));
263
267
  }
264
268
 
265
269
  function parse(headers) {
@@ -448,13 +452,6 @@ function createUserAgent(options) {
448
452
  return [baseInfo, systemInfo, libraryInfo, contactInfo, customAgent].filter(Boolean).join(' ');
449
453
  }
450
454
 
451
- function byteLength(body) {
452
- if (typeof body === 'string') return body.length.toString();
453
- if (body && typeof body === 'object') return new TextEncoder().encode(JSON.stringify(body)).length.toString();
454
- if (body instanceof Uint8Array) return body.length.toString();
455
- return '0';
456
- }
457
-
458
455
  /**
459
456
  * validate some essential http options
460
457
  * @param options
@@ -742,11 +739,9 @@ function createAuthMiddlewareForAnonymousSessionFlow$1(options) {
742
739
  tokenFetchPromise = null;
743
740
  }
744
741
 
745
- // Now the token is present in the tokenCache
742
+ // Now the token is present in the tokenCache and can be accessed
746
743
  tokenCacheObject = tokenCache.get(tokenCacheKey);
747
- if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
748
- return next(mergeAuthHeader(tokenCacheObject.token, request));
749
- }
744
+ return next(mergeAuthHeader(tokenCacheObject.token, request));
750
745
  };
751
746
  };
752
747
  }
@@ -799,9 +794,7 @@ function createAuthMiddlewareForClientCredentialsFlow$1(options) {
799
794
 
800
795
  // Now the token is present in the tokenCache
801
796
  tokenCacheObject = tokenCache.get(tokenCacheKey);
802
- if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
803
- return next(mergeAuthHeader(tokenCacheObject.token, request));
804
- }
797
+ return next(mergeAuthHeader(tokenCacheObject.token, request));
805
798
  };
806
799
  };
807
800
  }
@@ -877,9 +870,7 @@ function createAuthMiddlewareForPasswordFlow$1(options) {
877
870
 
878
871
  // Now the token is present in the tokenCache
879
872
  tokenCacheObject = tokenCache.get(tokenCacheKey);
880
- if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
881
- return next(mergeAuthHeader(tokenCacheObject.token, request));
882
- }
873
+ return next(mergeAuthHeader(tokenCacheObject.token, request));
883
874
  };
884
875
  };
885
876
  }
@@ -928,9 +919,7 @@ function createAuthMiddlewareForRefreshTokenFlow$1(options) {
928
919
 
929
920
  // Now the token is present in the tokenCache
930
921
  tokenCacheObject = tokenCache.get(tokenCacheKey);
931
- if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
932
- return next(mergeAuthHeader(tokenCacheObject.token, request));
933
- }
922
+ return next(mergeAuthHeader(tokenCacheObject.token, request));
934
923
  };
935
924
  };
936
925
  }
@@ -949,7 +938,7 @@ function createConcurrentModificationMiddleware$1(modifierFunction) {
949
938
 
950
939
  // update the resource version here
951
940
  if (version) {
952
- if (modifierFunction) {
941
+ if (modifierFunction && typeof modifierFunction == 'function') {
953
942
  request.body = await modifierFunction(version, request, response);
954
943
  } else {
955
944
  request.body = typeof request.body == 'string' ? {
@@ -1203,8 +1192,8 @@ function createQueueMiddleware$1({
1203
1192
  concurrency = 20
1204
1193
  }) {
1205
1194
  let runningCount = 0;
1195
+ const queue = [];
1206
1196
  const waitForSlot = () => {
1207
- // dont allow negative or 0 value for concurrency
1208
1197
  if (0 >= concurrency) return Promise.resolve();
1209
1198
  return new Promise(resolve => {
1210
1199
  const tryNext = () => {
@@ -1212,43 +1201,48 @@ function createQueueMiddleware$1({
1212
1201
  runningCount++;
1213
1202
  resolve();
1214
1203
  } else {
1215
- // Retry until a slot becomes available
1216
- setTimeout(tryNext, 10);
1204
+ queue.push(tryNext);
1217
1205
  }
1218
1206
  };
1219
-
1220
- // start
1221
1207
  tryNext();
1222
1208
  });
1223
1209
  };
1224
- return next => {
1225
- return async request => {
1226
- return waitForSlot().then(async () => {
1227
- // Patch the request to override resolve and reject
1228
- const patchedRequest = {
1229
- ...request,
1230
- resolve(data) {
1231
- request.resolve(data);
1232
- runningCount--;
1233
- },
1234
- reject(error) {
1235
- request.reject(error);
1236
- runningCount--;
1237
- }
1238
- };
1239
- try {
1240
- return next(patchedRequest);
1241
- } finally {
1242
- runningCount--;
1210
+
1211
+ // Function to free up a slot after a request is completed
1212
+ const freeSlot = () => {
1213
+ runningCount--;
1214
+ if (queue.length > 0) {
1215
+ const nextInQueue = queue.shift();
1216
+ if (nextInQueue) {
1217
+ nextInQueue();
1218
+ }
1219
+ }
1220
+ };
1221
+ return next => request => {
1222
+ return waitForSlot().then(() => {
1223
+ const patchedRequest = {
1224
+ ...request,
1225
+ resolve(data) {
1226
+ request.resolve(data);
1227
+ freeSlot();
1228
+ },
1229
+ reject(error) {
1230
+ request.reject(error);
1231
+ freeSlot();
1243
1232
  }
1233
+ };
1234
+
1235
+ // Process the next middleware
1236
+ return next(patchedRequest).finally(() => {
1237
+ freeSlot();
1244
1238
  });
1245
- };
1239
+ });
1246
1240
  };
1247
1241
  }
1248
1242
 
1249
1243
  var packageJson = {
1250
1244
  name: "@commercetools/ts-client",
1251
- version: "2.1.0-alpha.1",
1245
+ version: "2.1.1",
1252
1246
  engines: {
1253
1247
  node: ">=14"
1254
1248
  },
@@ -1282,14 +1276,12 @@ var packageJson = {
1282
1276
  },
1283
1277
  dependencies: {
1284
1278
  "abort-controller": "3.0.0",
1279
+ buffer: "^6.0.3",
1285
1280
  "node-fetch": "^2.6.1"
1286
1281
  },
1287
1282
  files: [
1288
1283
  "dist",
1289
- "CHANGELOG.md",
1290
- "LICENSE",
1291
- "README.md",
1292
- "package.json"
1284
+ "CHANGELOG.md"
1293
1285
  ],
1294
1286
  author: "Chukwuemeka Ajima <meeky.ae@gmail.com>",
1295
1287
  main: "dist/commercetools-ts-client.cjs.js",
@@ -35,6 +35,17 @@ function _defineProperty(e, r, t) {
35
35
  }) : e[r] = t, e;
36
36
  }
37
37
 
38
+ var Buffer = require('buffer/').Buffer;
39
+ function byteLength(body) {
40
+ if (body && (typeof body === 'string' || body instanceof Uint8Array)) {
41
+ return Buffer.byteLength(body).toString();
42
+ }
43
+ if (body && typeof body === 'object') {
44
+ return new TextEncoder().encode(JSON.stringify(body)).length.toString();
45
+ }
46
+ return '0';
47
+ }
48
+
38
49
  const HEADERS_CONTENT_TYPES = ['application/json', 'application/graphql'];
39
50
  const CONCURRENCT_REQUEST = 20;
40
51
  const CTP_API_URL = 'https://api.europe-west1.gcp.commercetools.com';
@@ -259,16 +270,9 @@ async function executor(request) {
259
270
  return data;
260
271
  }
261
272
 
262
- // import { v4 as uuidv4 } from 'uuid'
263
-
264
- // export default function generateID() {
265
- // return uuidv4()
266
- // }
267
-
268
273
  function generateID() {
269
274
  // @ts-ignore
270
- const str = ([1e6] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16));
271
- return 'abcdef'[Math.floor(Math.random() * 'abcdef'.length)] + '' + str;
275
+ return ([1e6] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (parseInt(c) ^ Math.floor(Math.random() * 256) & 15 >> parseInt(c) / 4).toString(16));
272
276
  }
273
277
 
274
278
  function parse(headers) {
@@ -457,13 +461,6 @@ function createUserAgent(options) {
457
461
  return [baseInfo, systemInfo, libraryInfo, contactInfo, customAgent].filter(Boolean).join(' ');
458
462
  }
459
463
 
460
- function byteLength(body) {
461
- if (typeof body === 'string') return body.length.toString();
462
- if (body && typeof body === 'object') return new TextEncoder().encode(JSON.stringify(body)).length.toString();
463
- if (body instanceof Uint8Array) return body.length.toString();
464
- return '0';
465
- }
466
-
467
464
  /**
468
465
  * validate some essential http options
469
466
  * @param options
@@ -751,11 +748,9 @@ function createAuthMiddlewareForAnonymousSessionFlow$1(options) {
751
748
  tokenFetchPromise = null;
752
749
  }
753
750
 
754
- // Now the token is present in the tokenCache
751
+ // Now the token is present in the tokenCache and can be accessed
755
752
  tokenCacheObject = tokenCache.get(tokenCacheKey);
756
- if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
757
- return next(mergeAuthHeader(tokenCacheObject.token, request));
758
- }
753
+ return next(mergeAuthHeader(tokenCacheObject.token, request));
759
754
  };
760
755
  };
761
756
  }
@@ -808,9 +803,7 @@ function createAuthMiddlewareForClientCredentialsFlow$1(options) {
808
803
 
809
804
  // Now the token is present in the tokenCache
810
805
  tokenCacheObject = tokenCache.get(tokenCacheKey);
811
- if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
812
- return next(mergeAuthHeader(tokenCacheObject.token, request));
813
- }
806
+ return next(mergeAuthHeader(tokenCacheObject.token, request));
814
807
  };
815
808
  };
816
809
  }
@@ -886,9 +879,7 @@ function createAuthMiddlewareForPasswordFlow$1(options) {
886
879
 
887
880
  // Now the token is present in the tokenCache
888
881
  tokenCacheObject = tokenCache.get(tokenCacheKey);
889
- if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
890
- return next(mergeAuthHeader(tokenCacheObject.token, request));
891
- }
882
+ return next(mergeAuthHeader(tokenCacheObject.token, request));
892
883
  };
893
884
  };
894
885
  }
@@ -937,9 +928,7 @@ function createAuthMiddlewareForRefreshTokenFlow$1(options) {
937
928
 
938
929
  // Now the token is present in the tokenCache
939
930
  tokenCacheObject = tokenCache.get(tokenCacheKey);
940
- if (tokenCacheObject && tokenCacheObject.token && Date.now() < tokenCacheObject.expirationTime) {
941
- return next(mergeAuthHeader(tokenCacheObject.token, request));
942
- }
931
+ return next(mergeAuthHeader(tokenCacheObject.token, request));
943
932
  };
944
933
  };
945
934
  }
@@ -958,7 +947,7 @@ function createConcurrentModificationMiddleware$1(modifierFunction) {
958
947
 
959
948
  // update the resource version here
960
949
  if (version) {
961
- if (modifierFunction) {
950
+ if (modifierFunction && typeof modifierFunction == 'function') {
962
951
  request.body = await modifierFunction(version, request, response);
963
952
  } else {
964
953
  request.body = typeof request.body == 'string' ? {
@@ -1212,8 +1201,8 @@ function createQueueMiddleware$1({
1212
1201
  concurrency = 20
1213
1202
  }) {
1214
1203
  let runningCount = 0;
1204
+ const queue = [];
1215
1205
  const waitForSlot = () => {
1216
- // dont allow negative or 0 value for concurrency
1217
1206
  if (0 >= concurrency) return Promise.resolve();
1218
1207
  return new Promise(resolve => {
1219
1208
  const tryNext = () => {
@@ -1221,43 +1210,48 @@ function createQueueMiddleware$1({
1221
1210
  runningCount++;
1222
1211
  resolve();
1223
1212
  } else {
1224
- // Retry until a slot becomes available
1225
- setTimeout(tryNext, 10);
1213
+ queue.push(tryNext);
1226
1214
  }
1227
1215
  };
1228
-
1229
- // start
1230
1216
  tryNext();
1231
1217
  });
1232
1218
  };
1233
- return next => {
1234
- return async request => {
1235
- return waitForSlot().then(async () => {
1236
- // Patch the request to override resolve and reject
1237
- const patchedRequest = {
1238
- ...request,
1239
- resolve(data) {
1240
- request.resolve(data);
1241
- runningCount--;
1242
- },
1243
- reject(error) {
1244
- request.reject(error);
1245
- runningCount--;
1246
- }
1247
- };
1248
- try {
1249
- return next(patchedRequest);
1250
- } finally {
1251
- runningCount--;
1219
+
1220
+ // Function to free up a slot after a request is completed
1221
+ const freeSlot = () => {
1222
+ runningCount--;
1223
+ if (queue.length > 0) {
1224
+ const nextInQueue = queue.shift();
1225
+ if (nextInQueue) {
1226
+ nextInQueue();
1227
+ }
1228
+ }
1229
+ };
1230
+ return next => request => {
1231
+ return waitForSlot().then(() => {
1232
+ const patchedRequest = {
1233
+ ...request,
1234
+ resolve(data) {
1235
+ request.resolve(data);
1236
+ freeSlot();
1237
+ },
1238
+ reject(error) {
1239
+ request.reject(error);
1240
+ freeSlot();
1252
1241
  }
1242
+ };
1243
+
1244
+ // Process the next middleware
1245
+ return next(patchedRequest).finally(() => {
1246
+ freeSlot();
1253
1247
  });
1254
- };
1248
+ });
1255
1249
  };
1256
1250
  }
1257
1251
 
1258
1252
  var packageJson = {
1259
1253
  name: "@commercetools/ts-client",
1260
- version: "2.1.0-alpha.1",
1254
+ version: "2.1.1",
1261
1255
  engines: {
1262
1256
  node: ">=14"
1263
1257
  },
@@ -1291,14 +1285,12 @@ var packageJson = {
1291
1285
  },
1292
1286
  dependencies: {
1293
1287
  "abort-controller": "3.0.0",
1288
+ buffer: "^6.0.3",
1294
1289
  "node-fetch": "^2.6.1"
1295
1290
  },
1296
1291
  files: [
1297
1292
  "dist",
1298
- "CHANGELOG.md",
1299
- "LICENSE",
1300
- "README.md",
1301
- "package.json"
1293
+ "CHANGELOG.md"
1302
1294
  ],
1303
1295
  author: "Chukwuemeka Ajima <meeky.ae@gmail.com>",
1304
1296
  main: "dist/commercetools-ts-client.cjs.js",